Skip to content
Permalink
Browse files

automatically scroll parent QScrollArea when QgsCollapsibleGroupBox i…

…s expanded
  • Loading branch information
etiennesky committed Sep 14, 2012
1 parent f53aa30 commit db59e1b1b3192079c88f5e1b4377448d439b0329
@@ -24,6 +24,7 @@
#include <QMouseEvent>
#include <QStyleOptionGroupBox>
#include <QSettings>
#include <QScrollArea>

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

// init icons
if ( mCollapseIcon.isNull() )
@@ -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();
@@ -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 );
}

@@ -28,6 +28,7 @@
#include <QGroupBox>

class QToolButton;
class QScrollArea;

class GUI_EXPORT QgsCollapsibleGroupBox : public QGroupBox
{
@@ -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();
@@ -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;
@@ -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()
@@ -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() );
@@ -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();

0 comments on commit db59e1b

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