Skip to content
Permalink
Browse files
Add collapse toggling synchronization on Alt-click of title to QgsCol…
…lapsibleGroupBoxBasic
  • Loading branch information
dakcarto committed Feb 13, 2013
1 parent 1924ecc commit 4d912c3037c145e4c7f7ebf005e7ad42d22713d5
Showing with 33 additions and 8 deletions.
  1. +30 −8 src/gui/qgscollapsiblegroupbox.cpp
  2. +3 −0 src/gui/qgscollapsiblegroupbox.h
@@ -60,6 +60,8 @@ void QgsCollapsibleGroupBoxBasic::init()
mParentScrollArea = 0;
mSyncParent = 0;
mSyncGroup = "";
mAltDown = false;
mTitleClicked = false;

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

@@ -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;

0 comments on commit 4d912c3

Please sign in to comment.