Skip to content

Commit 4d912c3

Browse files
committed
Add collapse toggling synchronization on Alt-click of title to QgsCollapsibleGroupBoxBasic
1 parent 1924ecc commit 4d912c3

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

src/gui/qgscollapsiblegroupbox.cpp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ void QgsCollapsibleGroupBoxBasic::init()
6060
mParentScrollArea = 0;
6161
mSyncParent = 0;
6262
mSyncGroup = "";
63+
mAltDown = false;
64+
mTitleClicked = false;
6365

6466
// init icons
6567
if ( mCollapseIcon.isNull() )
@@ -130,17 +132,35 @@ void QgsCollapsibleGroupBoxBasic::showEvent( QShowEvent * event )
130132
event->accept();
131133
}
132134

135+
void QgsCollapsibleGroupBoxBasic::mousePressEvent( QMouseEvent *event )
136+
{
137+
// avoid leaving checkbox in pressed state if alt-clicking
138+
if ( event->modifiers() & Qt::AltModifier
139+
&& titleRect().contains( event->pos() )
140+
&& isCheckable() )
141+
{
142+
event->ignore();
143+
return;
144+
}
145+
146+
// default behaviour - pass to QGroupBox
147+
QGroupBox::mousePressEvent( event );
148+
}
149+
133150
void QgsCollapsibleGroupBoxBasic::mouseReleaseEvent( QMouseEvent *event )
134151
{
135-
// catch mouse release over title when non checkable, to collapse/expand
136-
if ( !isCheckable() && event->button() == Qt::LeftButton )
152+
mAltDown = ( event->modifiers() & Qt::AltModifier );
153+
mTitleClicked = ( titleRect().contains( event->pos() ) );
154+
155+
// sync group when title is alt-clicked
156+
// collapse/expand when title is clicked and non-checkable
157+
if ( event->button() == Qt::LeftButton && mTitleClicked &&
158+
( mAltDown || !isCheckable() ) )
137159
{
138-
if ( titleRect().contains( event->pos() ) )
139-
{
140-
toggleCollapsed();
141-
return;
142-
}
160+
toggleCollapsed();
161+
return;
143162
}
163+
144164
// default behaviour - pass to QGroupBox
145165
QGroupBox::mouseReleaseEvent( event );
146166
}
@@ -183,9 +203,11 @@ void QgsCollapsibleGroupBoxBasic::toggleCollapsed()
183203
senderCollBtn = ( collBtn && collBtn == mCollapseButton );
184204

185205
// find any sync group siblings and toggle them
186-
if ( senderCollBtn && mCollapseButton->altDown() && !mSyncGroup.isEmpty() )
206+
if ((( senderCollBtn && mCollapseButton->altDown() ) || ( mTitleClicked && mAltDown ) )
207+
&& !mSyncGroup.isEmpty() )
187208
{
188209
mCollapseButton->setAltDown( false );
210+
mAltDown = false;
189211
QgsDebugMsg( "Alt key down, syncing group" );
190212
// get pointer to parent or grandparent widget
191213
if ( parentWidget() )

src/gui/qgscollapsiblegroupbox.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class GUI_EXPORT QgsCollapsibleGroupBoxBasic : public QGroupBox
9595
protected:
9696
void init();
9797
void showEvent( QShowEvent *event );
98+
void mousePressEvent( QMouseEvent *event );
9899
void mouseReleaseEvent( QMouseEvent *event );
99100
void changeEvent( QEvent *event );
100101

@@ -110,6 +111,8 @@ class GUI_EXPORT QgsCollapsibleGroupBoxBasic : public QGroupBox
110111
QgsGroupBoxCollapseButton* mCollapseButton;
111112
QWidget* mSyncParent;
112113
QString mSyncGroup;
114+
bool mAltDown;
115+
bool mTitleClicked;
113116

114117
static QIcon mCollapseIcon;
115118
static QIcon mExpandIcon;

0 commit comments

Comments
 (0)