Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
automatically scroll parent QScrollArea when QgsCollapsibleGroupBox i…
…s expanded
  • Loading branch information
etiennesky committed Sep 14, 2012
1 parent f53aa30 commit db59e1b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
20 changes: 20 additions & 0 deletions src/gui/qgscollapsiblegroupbox.cpp
Expand Up @@ -24,6 +24,7 @@
#include <QMouseEvent>
#include <QStyleOptionGroupBox>
#include <QSettings>
#include <QScrollArea>

QIcon QgsCollapsibleGroupBox::mCollapseIcon;
QIcon QgsCollapsibleGroupBox::mExpandIcon;
Expand Down Expand Up @@ -52,7 +53,9 @@ void QgsCollapsibleGroupBox::init()
mCollapsed = false;
mSaveState = true;
mInitFlat = false;
mScrollOnExpand = true;
mShown = false;
mParentScrollArea = 0;

// init icons
if ( mCollapseIcon.isNull() )
Expand Down Expand Up @@ -87,6 +90,16 @@ void QgsCollapsibleGroupBox::showEvent( QShowEvent * event )
// check if groupbox was set to flat in Designer or in code
mInitFlat = isFlat();

// find parent QScrollArea - this might not work in complex layouts - should we look deeper?
if ( parent() && parent()->parent() )
mParentScrollArea = dynamic_cast<QScrollArea*>( parent()->parent()->parent() );
else
mParentScrollArea = 0;
if ( mParentScrollArea )
QgsDebugMsg( "found a QScrollArea parent: " + mParentScrollArea->objectName() );
else
QgsDebugMsg( "did not find a QScrollArea parent" );

loadState();

updateStyle();
Expand Down Expand Up @@ -278,6 +291,13 @@ void QgsCollapsibleGroupBox::setCollapsed( bool collapse )
setMaximumHeight( collapse ? titleRect().bottom() + 6 : 16777215 );
mCollapseButton->setIcon( collapse ? mExpandIcon : mCollapseIcon );

// if expanding and is in a QScrollArea, scroll down to make entire widget visible
if ( mScrollOnExpand && !collapse && mParentScrollArea )
{
// process events so entire widget is shown
QApplication::processEvents();
mParentScrollArea->ensureWidgetVisible( this );
}
emit collapsedStateChanged( this );
}

10 changes: 9 additions & 1 deletion src/gui/qgscollapsiblegroupbox.h
Expand Up @@ -28,6 +28,7 @@
#include <QGroupBox>

class QToolButton;
class QScrollArea;

class GUI_EXPORT QgsCollapsibleGroupBox : public QGroupBox
{
Expand All @@ -37,17 +38,21 @@ class GUI_EXPORT QgsCollapsibleGroupBox : public QGroupBox
QgsCollapsibleGroupBox( QWidget *parent = 0 );
QgsCollapsibleGroupBox( const QString &title, QWidget *parent = 0 );
~QgsCollapsibleGroupBox();

bool isCollapsed() const { return mCollapsed; }
void setCollapsed( bool collapse );

//! set this to false to not save/restore check and collapse state
void setSaveState( bool save ) { mSaveState = save; }
//! set this to false to not automatically scroll parent QScrollArea to this widget's contents when expanded
void setScrollOnExpand( bool scroll ) { mScrollOnExpand = scroll; }

signals:
void collapsedStateChanged( QWidget* );

public slots:
void checkToggled( bool ckd );
void toggleCollapsed();
void updateStyle();

protected slots:
void loadState();
Expand All @@ -57,13 +62,16 @@ class GUI_EXPORT QgsCollapsibleGroupBox : public QGroupBox
void init();
void showEvent( QShowEvent *event );
void mouseReleaseEvent( QMouseEvent *event );
void updateStyle();
QRect titleRect() const;
QString saveKey() const;

bool mCollapsed;
bool mSaveState;
bool mInitFlat;
bool mScrollOnExpand;
bool mShown;
QScrollArea* mParentScrollArea;
QToolButton* mCollapseButton;

static QIcon mCollapseIcon;
Expand Down
11 changes: 0 additions & 11 deletions src/gui/qgsrasterlayersaveasdialog.cpp
Expand Up @@ -106,11 +106,6 @@ QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterLayer* rasterLa
{
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( collapsedStateChanged( QWidget* ) ),
this, SLOT( groupBoxExpanded( QWidget* ) ) );
}

void QgsRasterLayerSaveAsDialog::setValidators()
Expand Down Expand Up @@ -529,12 +524,6 @@ void QgsRasterLayerSaveAsDialog::on_mRawModeRadioButton_toggled( bool checked )
mNoDataGroupBox->setEnabled( checked && mDataProvider->bandCount() == 1 );
}

void QgsRasterLayerSaveAsDialog::groupBoxExpanded( QWidget * widget )
{
if ( !mCreateOptionsGroupBox->isCollapsed() )
mScrollArea->ensureWidgetVisible( widget );
}

void QgsRasterLayerSaveAsDialog::on_mAddNoDataManuallyToolButton_clicked()
{
addNoDataRow( std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN() );
Expand Down
1 change: 0 additions & 1 deletion src/gui/qgsrasterlayersaveasdialog.h
Expand Up @@ -92,7 +92,6 @@ class GUI_EXPORT QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRast

void on_mCrsComboBox_currentIndexChanged( int ) { crsChanged(); }

void groupBoxExpanded( QWidget * widget );
void on_mAddNoDataManuallyToolButton_clicked();
void on_mLoadTransparentNoDataToolButton_clicked();
void on_mRemoveSelectedNoDataToolButton_clicked();
Expand Down

0 comments on commit db59e1b

Please sign in to comment.