QGIS API Documentation  2.0.1-Dufour
 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 QgsGroupBoxCollapseButton: public QToolButton
33 {
34  Q_OBJECT
35 
36  public:
37  QgsGroupBoxCollapseButton( QWidget *parent = 0 )
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 )
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 
75  Q_PROPERTY( bool collapsed READ isCollapsed WRITE setCollapsed USER true )
76  Q_PROPERTY( QString syncGroup READ syncGroup WRITE setSyncGroup )
77 
78  public:
79  QgsCollapsibleGroupBoxBasic( QWidget *parent = 0 );
80  QgsCollapsibleGroupBoxBasic( const QString &title, QWidget *parent = 0 );
82 
83  bool isCollapsed() const { return mCollapsed; }
84  void setCollapsed( bool collapse );
85 
87  QString syncGroup() const { return mSyncGroup; }
88  void setSyncGroup( QString grp );
89 
91  void setScrollOnExpand( bool scroll ) { mScrollOnExpand = scroll; }
92 
93  signals:
95  void collapsedStateChanged( bool collapsed );
96 
97  public slots:
98  void checkToggled( bool ckd );
99  void checkClicked( bool ckd );
100  void toggleCollapsed();
101 
102  protected:
103  void init();
104 
106  void collapseExpandFixes();
107 
108  void showEvent( QShowEvent *event );
109  void mousePressEvent( QMouseEvent *event );
110  void mouseReleaseEvent( QMouseEvent *event );
111  void changeEvent( QEvent *event );
112 
113  void updateStyle();
114  QRect titleRect() const;
115  void clearModifiers();
116 
118  bool mInitFlat;
121  bool mShown;
122  QScrollArea* mParentScrollArea;
124  QWidget* mSyncParent;
125  QString mSyncGroup;
126  bool mAltDown;
129 
130  static QIcon mCollapseIcon;
131  static QIcon mExpandIcon;
132 };
133 
146 {
147  Q_OBJECT
148 
149  Q_PROPERTY( bool collapsed READ isCollapsed WRITE setCollapsed USER true )
150  Q_PROPERTY( bool saveCollapsedState READ saveCollapsedState WRITE setSaveCollapsedState )
151  Q_PROPERTY( bool saveCheckedState READ saveCheckedState WRITE setSaveCheckedState )
152  Q_PROPERTY( QString syncGroup READ syncGroup WRITE setSyncGroup )
153 
154  public:
155  QgsCollapsibleGroupBox( QWidget *parent = 0, QSettings* settings = 0 );
156  QgsCollapsibleGroupBox( const QString &title, QWidget *parent = 0, QSettings* settings = 0 );
158 
159  // set custom QSettings pointer if group box was already created from QtDesigner promotion
160  void setSettings( QSettings* settings );
161 
163  void setSaveCollapsedState( bool save ) { mSaveCollapsedState = save; }
167  void setSaveCheckedState( bool save ) { mSaveCheckedState = save; }
168  bool saveCollapsedState() { return mSaveCollapsedState; }
169  bool saveCheckedState() { return mSaveCheckedState; }
170 
172  void setSettingGroup( const QString &group ) { mSettingGroup = group; }
173  QString settingGroup() const { return mSettingGroup; }
174 
175  protected slots:
176  void loadState();
177  void saveState();
178 
179  protected:
180  void init();
181  void showEvent( QShowEvent *event );
182  QString saveKey() const;
183 
184  // pointer to app or custom, external QSettings
185  // QPointer in case custom settings obj gets deleted while groupbox's dialog is open
186  QPointer<QSettings> mSettings;
188 
191  QString mSettingGroup;
192 };
193 
194 #endif