QGIS API Documentation  2.17.0-Master (8784312)
qgscollapsiblegroupbox.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscollapsiblegroupbox.h
3  -------------------
4  begin : August 2012
5  copyright : (C) 2012 by Etienne Tourigny
6  email : etourigny dot dev at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSCOLLAPSIBLEGROUPBOX_H
19 #define QGSCOLLAPSIBLEGROUPBOX_H
20 
21 #include "qgisgui.h"
22 
23 #include <QGroupBox>
24 #include <QSettings>
25 #include <QPointer>
26 #include <QToolButton>
27 #include <QMouseEvent>
28 
29 class QToolButton;
30 class QScrollArea;
31 
35 class GUI_EXPORT QgsGroupBoxCollapseButton : public QToolButton
36 {
37  Q_OBJECT
38 
39  public:
40  QgsGroupBoxCollapseButton( QWidget *parent = nullptr )
41  : QToolButton( parent )
42  , mAltDown( false )
43  , mShiftDown( false )
44  {}
45 
47 
48  bool altDown() const { return mAltDown; }
49  void setAltDown( bool updown ) { mAltDown = updown; }
50 
51  bool shiftDown() const { return mShiftDown; }
52  void setShiftDown( bool shiftdown ) { mShiftDown = shiftdown; }
53 
54  protected:
55  void mouseReleaseEvent( QMouseEvent *event ) override
56  {
57  mAltDown = ( event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier ) );
58  mShiftDown = ( event->modifiers() & Qt::ShiftModifier );
60  }
61 
62  private:
63  bool mAltDown;
64  bool mShiftDown;
65 };
66 
77 class GUI_EXPORT QgsCollapsibleGroupBoxBasic : public QGroupBox
78 {
79  Q_OBJECT
80 
85  Q_PROPERTY( bool collapsed READ isCollapsed WRITE setCollapsed USER true )
86 
87 
91  Q_PROPERTY( QString syncGroup READ syncGroup WRITE setSyncGroup )
92 
97  Q_PROPERTY( bool scrollOnExpand READ scrollOnExpand WRITE setScrollOnExpand )
98 
99  public:
100  QgsCollapsibleGroupBoxBasic( QWidget *parent = nullptr );
101  QgsCollapsibleGroupBoxBasic( const QString &title, QWidget *parent = nullptr );
103 
107  bool isCollapsed() const { return mCollapsed; }
113  void setCollapsed( bool collapse );
114 
118  QString syncGroup() const { return mSyncGroup; }
119 
123  void setSyncGroup( const QString& grp );
124 
126  void setScrollOnExpand( bool scroll ) { mScrollOnExpand = scroll; }
127 
129  bool scrollOnExpand() {return mScrollOnExpand;}
130 
131  signals:
133  void collapsedStateChanged( bool collapsed );
134 
135  public slots:
136  void checkToggled( bool ckd );
137  void checkClicked( bool ckd );
138  void toggleCollapsed();
139 
140  protected:
141  void init();
142 
144  void collapseExpandFixes();
145 
146  void showEvent( QShowEvent *event ) override;
147  void mousePressEvent( QMouseEvent *event ) override;
148  void mouseReleaseEvent( QMouseEvent *event ) override;
149  void changeEvent( QEvent *event ) override;
150 
151  void updateStyle();
152  QRect titleRect() const;
153  void clearModifiers();
154 
156  bool mInitFlat;
159  bool mShown;
164  bool mAltDown;
167 
170 };
171 
184 {
185  Q_OBJECT
186 
190  Q_PROPERTY( bool saveCollapsedState READ saveCollapsedState WRITE setSaveCollapsedState )
191 
192 
195  Q_PROPERTY( bool saveCheckedState READ saveCheckedState WRITE setSaveCheckedState )
196 
197  public:
198  QgsCollapsibleGroupBox( QWidget *parent = nullptr, QSettings* settings = nullptr );
199  QgsCollapsibleGroupBox( const QString &title, QWidget *parent = nullptr, QSettings* settings = nullptr );
201 
202  // set custom QSettings pointer if group box was already created from QtDesigner promotion
203  void setSettings( QSettings* settings );
204 
206  void setSaveCollapsedState( bool save ) { mSaveCollapsedState = save; }
210  void setSaveCheckedState( bool save ) { mSaveCheckedState = save; }
211  bool saveCollapsedState() { return mSaveCollapsedState; }
212  bool saveCheckedState() { return mSaveCheckedState; }
213 
215  void setSettingGroup( const QString &group ) { mSettingGroup = group; }
217  QString settingGroup() const { return mSettingGroup; }
218 
219  protected slots:
227  void loadState();
235  void saveState() const;
236 
237  protected:
238  void init();
239  void showEvent( QShowEvent *event ) override;
240  QString saveKey() const;
241 
242  // pointer to app or custom, external QSettings
243  // QPointer in case custom settings obj gets deleted while groupbox's dialog is open
246 
250 };
251 
252 #endif
QgsGroupBoxCollapseButton(QWidget *parent=nullptr)
QString settingGroup() const
Returns the name of the setting group in which the collapsed state will be saved. ...
A groupbox that collapses/expands when toggled and can save its collapsed and checked states...
void setSaveCheckedState(bool save)
Set this to true to save/restore checked state.
void setScrollOnExpand(bool scroll)
Set this to false to not automatically scroll parent QScrollArea to this widget&#39;s contents when expan...
void showEvent(QShowEvent *event) override
void setShiftDown(bool shiftdown)
QgsGroupBoxCollapseButton * mCollapseButton
virtual void showEvent(QShowEvent *event)
A groupbox that collapses/expands when toggled.
virtual void mouseReleaseEvent(QMouseEvent *event)
virtual void mouseReleaseEvent(QMouseEvent *e)
bool scrollOnExpand()
If this is set to false the parent QScrollArea will not be automatically scrolled to this widget&#39;s co...
void setSettingGroup(const QString &group)
Set this to a defined string to share save/restore states across different parent dialogs...
void mouseReleaseEvent(QMouseEvent *event) override
virtual void changeEvent(QEvent *ev)
virtual void mousePressEvent(QMouseEvent *event)
void scroll(int dx, int dy)
QPointer< QSettings > mSettings
QString syncGroup() const
Named group which synchronizes collapsing action when triangle is clicked while holding alt modifier ...