Skip to content
Permalink
Browse files

implement collapsible groupbox items - needs feedback before implemen…

…ting as a widget in qgis_gui
  • Loading branch information
etiennesky committed Aug 23, 2012
1 parent 5579962 commit 523b56f58f57aab8da991d77846c0c1d29391f14
Showing with 344 additions and 94 deletions.
  1. +110 −1 src/gui/qgsrasterlayersaveasdialog.cpp
  2. +42 −0 src/gui/qgsrasterlayersaveasdialog.h
  3. +192 −93 src/ui/qgsrasterlayersaveasdialogbase.ui
@@ -9,6 +9,109 @@
#include <QFileDialog>
#include <QSettings>


// this widget class will go into its separate file

// #include <QMouseEvent>
// #include <QStyleOptionGroupBox>
// #include <QStylePainter>

GroupBox::GroupBox( QWidget *parent )
: QGroupBox( parent ), m_collapsed( false )
{
connect( this, SIGNAL( toggled ( bool ) ), this, SLOT( setToggled( bool ) ) );
//setToggled( isChecked() );
}

GroupBox::GroupBox( const QString &title, QWidget *parent )
: QGroupBox(title, parent ), m_collapsed( false )
{}

bool GroupBox::isCollapsed() { return m_collapsed; }

// void GroupBox::mousePressEvent( QMouseEvent *e )
// {
// QgsDebugMsg("press event");
// if( e->button() == Qt::LeftButton )
// {
// QgsDebugMsg("left but");
// QStyleOptionGroupBox option;
// initStyleOption( &option );
// QRect buttonArea( 0, 0, 16, 16 );
// buttonArea.moveTopRight( option.rect.adjusted( 0, 0, -10, 0
// ).topRight() );
// if( buttonArea.contains( e->pos() ) )
// {
// clickPos = e->pos();
// return;
// }
// }
// QGroupBox::mousePressEvent( e );
// }

// void GroupBox::mouseReleaseEvent( QMouseEvent *e )
// {
// QgsDebugMsg("release");
// if( e->button() == Qt::LeftButton && clickPos == e->pos() )
// setCollapse( !isCollapsed() );
// }

// void GroupBox::paintEvent( QPaintEvent * )
// {
// QgsDebugMsg("paint event");

// QStylePainter paint( this );
// QStyleOptionGroupBox option;
// initStyleOption( &option );
// paint.drawComplexControl( QStyle::CC_GroupBox, option );
// paint.drawItemPixmap(
// option.rect.adjusted( 0, 0, -10, 0 ),
// Qt::AlignTop | Qt::AlignRight,
// QPixmap( m_collapsed ?
// ":/images/images/navigate_down2_16x16.png" :
// ":/images/images/navigate_up2_16x16.png" ) );
// }

void GroupBox::showEvent( QShowEvent * event )
{
// QgsDebugMsg(QString("%1 showEvent %2 %3").arg(objectName()).arg(isChecked()).arg(isCollapsed()));
QGroupBox::showEvent( event );
if ( ! isChecked() && ! isCollapsed() )
setCollapsed( true );
}

void GroupBox::setCollapsed( bool collapse )
{
if ( ! isVisible() )
return;
// QgsDebugMsg(QString("%1 setcollapse %2").arg(objectName()).arg(collapse));

// minimize layout margins, restore later
if ( collapse )
{
if ( layout() )
{
margins = layout()->contentsMargins();
layout()->setContentsMargins(1,1,1,1);
}
}
else
{
if ( layout() )
{
layout()->setContentsMargins( margins );
}
}
m_collapsed = collapse;
foreach( QWidget *widget, findChildren<QWidget*>() )
widget->setHidden( collapse );

if ( m_collapsed )
emit collapsed( this );
else
emit expanded( this );
}

QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* sourceProvider, const QgsRectangle& currentExtent,
const QgsCoordinateReferenceSystem& layerCrs,
const QgsCoordinateReferenceSystem& currentCrs,
@@ -26,7 +129,7 @@ QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* s
mLoadTransparentNoDataToolButton->setIcon( QgsApplication::getThemeIcon( "/mActionCopySelected.png" ) );
mRemoveSelectedNoDataToolButton->setIcon( QgsApplication::getThemeIcon( "/mActionDeleteAttribute.png" ) );
mRemoveAllNoDataToolButton->setIcon( QgsApplication::getThemeIcon( "/mActionRemove.png" ) );
mNoDataGroupBox->setEnabled( false ); // not yet implemented
// mNoDataGroupBox->setEnabled( false ); // not yet implemented

setValidators();
// Translated labels + EPSG are updated later
@@ -81,6 +184,12 @@ QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* s
{
okButton->setEnabled( false );
}

// this should scroll down to make widget visible, but it's not happening
// (at least part of it is visible)...
connect( mCreateOptionsGroupBox, SIGNAL( expanded( QWidget* ) ),
this, SLOT( groupBoxExpanded( QWidget* ) ) );

}

void QgsRasterLayerSaveAsDialog::setValidators()
@@ -79,6 +79,8 @@ class GUI_EXPORT QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRast

void on_mCrsComboBox_currentIndexChanged( int ) { crsChanged(); }

void groupBoxExpanded( QWidget * widget ) { mScrollArea->ensureWidgetVisible( widget ); }

private:
QgsRasterDataProvider* mDataProvider;
QgsRectangle mCurrentExtent;
@@ -105,4 +107,44 @@ class GUI_EXPORT QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRast
void updateCrsGroup();
};


#endif // QGSRASTERLAYERSAVEASDIALOG_H


// this widget class will go into its separate file
#ifndef GROUPBOX_H
#define GROUPBOX_H

#include <QGroupBox>

class GroupBox : public QGroupBox
{
Q_OBJECT

public:
GroupBox( QWidget *parent = 0 );
GroupBox( const QString &title, QWidget *parent = 0 );

bool isCollapsed();

signals:
void collapsed( QWidget* );
void expanded( QWidget* );

public slots:
void setToggled( bool toggled ) { setCollapsed( ! toggled ); }
void setCollapsed( bool collapsed );

protected:
/* void mousePressEvent( QMouseEvent *e ); */
/* void mouseReleaseEvent( QMouseEvent *e ); */
/* void paintEvent( QPaintEvent * ); */
void showEvent( QShowEvent * event );

private:
QPoint clickPos;
bool m_collapsed;
QMargins margins;
};

#endif

0 comments on commit 523b56f

Please sign in to comment.
You can’t perform that action at this time.