QGIS API Documentation  2.15.0-Master (af20121)
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 
32 class GUI_EXPORT QgsGroupBoxCollapseButton : public QToolButton
33 {
34  Q_OBJECT
35 
36  public:
37  QgsGroupBoxCollapseButton( QWidget *parent = nullptr )
38  : QToolButton( parent )
39  , mAltDown( false )
40  , mShiftDown( false )
41  {}
42 
44 
45  bool altDown() const { return mAltDown; }
46  void setAltDown( bool updown ) { mAltDown = updown; }
47 
48  bool shiftDown() const { return mShiftDown; }
49  void setShiftDown( bool shiftdown ) { mShiftDown = shiftdown; }
50 
51  protected:
52  void mouseReleaseEvent( QMouseEvent *event ) override
53  {
54  mAltDown = ( event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier ) );
55  mShiftDown = ( event->modifiers() & Qt::ShiftModifier );
57  }
58 
59  private:
60  bool mAltDown;
61  bool mShiftDown;
62 };
63 
74 class GUI_EXPORT QgsCollapsibleGroupBoxBasic : public QGroupBox
75 {
76  Q_OBJECT
77 
82  Q_PROPERTY( bool collapsed READ isCollapsed WRITE setCollapsed USER true )
83 
84 
88  Q_PROPERTY( QString syncGroup READ syncGroup WRITE setSyncGroup )
89 
94  Q_PROPERTY( bool scrollOnExpand READ scrollOnExpand WRITE setScrollOnExpand )
95 
96  public:
97  QgsCollapsibleGroupBoxBasic( QWidget *parent = nullptr );
98  QgsCollapsibleGroupBoxBasic( const QString &title, QWidget *parent = nullptr );
100 
104  bool isCollapsed() const { return mCollapsed; }
110  void setCollapsed( bool collapse );
111 
115  QString syncGroup() const { return mSyncGroup; }
116 
120  void setSyncGroup( const QString& grp );
121 
123  void setScrollOnExpand( bool scroll ) { mScrollOnExpand = scroll; }
124 
126  bool scrollOnExpand() {return mScrollOnExpand;}
127 
128  signals:
130  void collapsedStateChanged( bool collapsed );
131 
132  public slots:
133  void checkToggled( bool ckd );
134  void checkClicked( bool ckd );
135  void toggleCollapsed();
136 
137  protected:
138  void init();
139 
141  void collapseExpandFixes();
142 
143  void showEvent( QShowEvent *event ) override;
144  void mousePressEvent( QMouseEvent *event ) override;
145  void mouseReleaseEvent( QMouseEvent *event ) override;
146  void changeEvent( QEvent *event ) override;
147 
148  void updateStyle();
149  QRect titleRect() const;
150  void clearModifiers();
151 
153  bool mInitFlat;
156  bool mShown;
161  bool mAltDown;
164 
167 };
168 
181 {
182  Q_OBJECT
183 
187  Q_PROPERTY( bool saveCollapsedState READ saveCollapsedState WRITE setSaveCollapsedState )
188 
189 
192  Q_PROPERTY( bool saveCheckedState READ saveCheckedState WRITE setSaveCheckedState )
193 
194  public:
195  QgsCollapsibleGroupBox( QWidget *parent = nullptr, QSettings* settings = nullptr );
196  QgsCollapsibleGroupBox( const QString &title, QWidget *parent = nullptr, QSettings* settings = nullptr );
198 
199  // set custom QSettings pointer if group box was already created from QtDesigner promotion
200  void setSettings( QSettings* settings );
201 
203  void setSaveCollapsedState( bool save ) { mSaveCollapsedState = save; }
207  void setSaveCheckedState( bool save ) { mSaveCheckedState = save; }
208  bool saveCollapsedState() { return mSaveCollapsedState; }
209  bool saveCheckedState() { return mSaveCheckedState; }
210 
212  void setSettingGroup( const QString &group ) { mSettingGroup = group; }
214  QString settingGroup() const { return mSettingGroup; }
215 
216  protected slots:
224  void loadState();
232  void saveState() const;
233 
234  protected:
235  void init();
236  void showEvent( QShowEvent *event ) override;
237  QString saveKey() const;
238 
239  // pointer to app or custom, external QSettings
240  // QPointer in case custom settings obj gets deleted while groupbox's dialog is open
243 
247 };
248 
249 #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 ...