QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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:
38  : QToolButton( parent ), mAltDown( false ), mShiftDown( false ) {}
39 
41 
42  bool altDown() const { return mAltDown; }
43  void setAltDown( bool updown ) { mAltDown = updown; }
44 
45  bool shiftDown() const { return mShiftDown; }
46  void setShiftDown( bool shiftdown ) { mShiftDown = shiftdown; }
47 
48  protected:
49  void mouseReleaseEvent( QMouseEvent *event ) override
50  {
51  mAltDown = ( event->modifiers() & ( Qt::AltModifier | Qt::ControlModifier ) );
52  mShiftDown = ( event->modifiers() & Qt::ShiftModifier );
54  }
55 
56  private:
57  bool mAltDown;
58  bool mShiftDown;
59 };
60 
71 class GUI_EXPORT QgsCollapsibleGroupBoxBasic : public QGroupBox
72 {
73  Q_OBJECT
74 
79  Q_PROPERTY( bool collapsed READ isCollapsed WRITE setCollapsed USER true )
80 
81 
85  Q_PROPERTY( QString syncGroup READ syncGroup WRITE setSyncGroup )
86 
91  Q_PROPERTY( bool scrollOnExpand READ scrollOnExpand WRITE setScrollOnExpand )
92 
93  public:
94  QgsCollapsibleGroupBoxBasic( QWidget *parent = 0 );
95  QgsCollapsibleGroupBoxBasic( const QString &title, QWidget *parent = 0 );
97 
101  bool isCollapsed() const { return mCollapsed; }
107  void setCollapsed( bool collapse );
108 
112  QString syncGroup() const { return mSyncGroup; }
113 
117  void setSyncGroup( QString grp );
118 
120  void setScrollOnExpand( bool scroll ) { mScrollOnExpand = scroll; }
121 
123  bool scrollOnExpand() {return mScrollOnExpand;}
124 
125  signals:
127  void collapsedStateChanged( bool collapsed );
128 
129  public slots:
130  void checkToggled( bool ckd );
131  void checkClicked( bool ckd );
132  void toggleCollapsed();
133 
134  protected:
135  void init();
136 
138  void collapseExpandFixes();
139 
140  void showEvent( QShowEvent *event ) override;
141  void mousePressEvent( QMouseEvent *event ) override;
142  void mouseReleaseEvent( QMouseEvent *event ) override;
143  void changeEvent( QEvent *event ) override;
144 
145  void updateStyle();
146  QRect titleRect() const;
147  void clearModifiers();
148 
150  bool mInitFlat;
153  bool mShown;
158  bool mAltDown;
161 
164 };
165 
178 {
179  Q_OBJECT
180 
184  Q_PROPERTY( bool saveCollapsedState READ saveCollapsedState WRITE setSaveCollapsedState )
185 
186 
189  Q_PROPERTY( bool saveCheckedState READ saveCheckedState WRITE setSaveCheckedState )
190 
191  public:
192  QgsCollapsibleGroupBox( QWidget *parent = 0, QSettings* settings = 0 );
193  QgsCollapsibleGroupBox( const QString &title, QWidget *parent = 0, QSettings* settings = 0 );
195 
196  // set custom QSettings pointer if group box was already created from QtDesigner promotion
197  void setSettings( QSettings* settings );
198 
200  void setSaveCollapsedState( bool save ) { mSaveCollapsedState = save; }
204  void setSaveCheckedState( bool save ) { mSaveCheckedState = save; }
205  bool saveCollapsedState() { return mSaveCollapsedState; }
206  bool saveCheckedState() { return mSaveCheckedState; }
207 
209  void setSettingGroup( const QString &group ) { mSettingGroup = group; }
211  QString settingGroup() const { return mSettingGroup; }
212 
213  protected slots:
221  void loadState();
229  void saveState() const;
230 
231  protected:
232  void init();
233  void showEvent( QShowEvent *event ) override;
234  QString saveKey() const;
235 
236  // pointer to app or custom, external QSettings
237  // QPointer in case custom settings obj gets deleted while groupbox's dialog is open
240 
244 };
245 
246 #endif
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'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'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)
QgsGroupBoxCollapseButton(QWidget *parent=0)
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 ...