QGIS API Documentation  2.6.0-Brighton
 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:
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 );
53  QToolButton::mouseReleaseEvent( event );
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  Q_PROPERTY( bool scrollOnExpand READ scrollOnExpand WRITE setScrollOnExpand )
78 
79  public:
80  QgsCollapsibleGroupBoxBasic( QWidget *parent = 0 );
81  QgsCollapsibleGroupBoxBasic( const QString &title, QWidget *parent = 0 );
83 
84  bool isCollapsed() const { return mCollapsed; }
85  void setCollapsed( bool collapse );
86 
88  QString syncGroup() const { return mSyncGroup; }
89  void setSyncGroup( QString grp );
90 
92  void setScrollOnExpand( bool scroll ) { mScrollOnExpand = scroll; }
93 
94  bool scrollOnExpand() {return mScrollOnExpand;}
95 
96  signals:
98  void collapsedStateChanged( bool collapsed );
99 
100  public slots:
101  void checkToggled( bool ckd );
102  void checkClicked( bool ckd );
103  void toggleCollapsed();
104 
105  protected:
106  void init();
107 
109  void collapseExpandFixes();
110 
111  void showEvent( QShowEvent *event );
112  void mousePressEvent( QMouseEvent *event );
113  void mouseReleaseEvent( QMouseEvent *event );
114  void changeEvent( QEvent *event );
115 
116  void updateStyle();
117  QRect titleRect() const;
118  void clearModifiers();
119 
121  bool mInitFlat;
124  bool mShown;
125  QScrollArea* mParentScrollArea;
127  QWidget* mSyncParent;
128  QString mSyncGroup;
129  bool mAltDown;
132 
133  static QIcon mCollapseIcon;
134  static QIcon mExpandIcon;
135 };
136 
149 {
150  Q_OBJECT
151 
152  Q_PROPERTY( bool collapsed READ isCollapsed WRITE setCollapsed USER true )
153  Q_PROPERTY( bool saveCollapsedState READ saveCollapsedState WRITE setSaveCollapsedState )
154  Q_PROPERTY( bool saveCheckedState READ saveCheckedState WRITE setSaveCheckedState )
155  Q_PROPERTY( QString syncGroup READ syncGroup WRITE setSyncGroup )
156  Q_PROPERTY( bool scrollOnExpand READ scrollOnExpand WRITE setScrollOnExpand )
157 
158  public:
159  QgsCollapsibleGroupBox( QWidget *parent = 0, QSettings* settings = 0 );
160  QgsCollapsibleGroupBox( const QString &title, QWidget *parent = 0, QSettings* settings = 0 );
162 
163  // set custom QSettings pointer if group box was already created from QtDesigner promotion
164  void setSettings( QSettings* settings );
165 
167  void setSaveCollapsedState( bool save ) { mSaveCollapsedState = save; }
171  void setSaveCheckedState( bool save ) { mSaveCheckedState = save; }
172  bool saveCollapsedState() { return mSaveCollapsedState; }
173  bool saveCheckedState() { return mSaveCheckedState; }
174 
176  void setSettingGroup( const QString &group ) { mSettingGroup = group; }
177  QString settingGroup() const { return mSettingGroup; }
178 
179  protected slots:
180  void loadState();
181  void saveState();
182 
183  protected:
184  void init();
185  void showEvent( QShowEvent *event );
186  QString saveKey() const;
187 
188  // pointer to app or custom, external QSettings
189  // QPointer in case custom settings obj gets deleted while groupbox's dialog is open
190  QPointer<QSettings> mSettings;
192 
195  QString mSettingGroup;
196 };
197 
198 #endif