Skip to content

Commit

Permalink
Add collapse toggling synchronization on Alt-click of title to QgsCol…
Browse files Browse the repository at this point in the history
…lapsibleGroupBoxBasic
  • Loading branch information
dakcarto committed Feb 13, 2013
1 parent 1924ecc commit 4d912c3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
38 changes: 30 additions & 8 deletions src/gui/qgscollapsiblegroupbox.cpp
Expand Up @@ -60,6 +60,8 @@ void QgsCollapsibleGroupBoxBasic::init()
mParentScrollArea = 0;
mSyncParent = 0;
mSyncGroup = "";
mAltDown = false;
mTitleClicked = false;

// init icons
if ( mCollapseIcon.isNull() )
Expand Down Expand Up @@ -130,17 +132,35 @@ void QgsCollapsibleGroupBoxBasic::showEvent( QShowEvent * event )
event->accept();
}

void QgsCollapsibleGroupBoxBasic::mousePressEvent( QMouseEvent *event )
{
// avoid leaving checkbox in pressed state if alt-clicking
if ( event->modifiers() & Qt::AltModifier
&& titleRect().contains( event->pos() )
&& isCheckable() )
{
event->ignore();
return;
}

// default behaviour - pass to QGroupBox
QGroupBox::mousePressEvent( event );
}

void QgsCollapsibleGroupBoxBasic::mouseReleaseEvent( QMouseEvent *event )
{
// catch mouse release over title when non checkable, to collapse/expand
if ( !isCheckable() && event->button() == Qt::LeftButton )
mAltDown = ( event->modifiers() & Qt::AltModifier );
mTitleClicked = ( titleRect().contains( event->pos() ) );

// sync group when title is alt-clicked
// collapse/expand when title is clicked and non-checkable
if ( event->button() == Qt::LeftButton && mTitleClicked &&
( mAltDown || !isCheckable() ) )
{
if ( titleRect().contains( event->pos() ) )
{
toggleCollapsed();
return;
}
toggleCollapsed();
return;
}

// default behaviour - pass to QGroupBox
QGroupBox::mouseReleaseEvent( event );
}
Expand Down Expand Up @@ -183,9 +203,11 @@ void QgsCollapsibleGroupBoxBasic::toggleCollapsed()
senderCollBtn = ( collBtn && collBtn == mCollapseButton );

// find any sync group siblings and toggle them
if ( senderCollBtn && mCollapseButton->altDown() && !mSyncGroup.isEmpty() )
if ((( senderCollBtn && mCollapseButton->altDown() ) || ( mTitleClicked && mAltDown ) )
&& !mSyncGroup.isEmpty() )
{
mCollapseButton->setAltDown( false );
mAltDown = false;
QgsDebugMsg( "Alt key down, syncing group" );
// get pointer to parent or grandparent widget
if ( parentWidget() )
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgscollapsiblegroupbox.h
Expand Up @@ -95,6 +95,7 @@ class GUI_EXPORT QgsCollapsibleGroupBoxBasic : public QGroupBox
protected:
void init();
void showEvent( QShowEvent *event );
void mousePressEvent( QMouseEvent *event );
void mouseReleaseEvent( QMouseEvent *event );
void changeEvent( QEvent *event );

Expand All @@ -110,6 +111,8 @@ class GUI_EXPORT QgsCollapsibleGroupBoxBasic : public QGroupBox
QgsGroupBoxCollapseButton* mCollapseButton;
QWidget* mSyncParent;
QString mSyncGroup;
bool mAltDown;
bool mTitleClicked;

static QIcon mCollapseIcon;
static QIcon mExpandIcon;
Expand Down

0 comments on commit 4d912c3

Please sign in to comment.