Skip to content

Commit fe6923b

Browse files
committedAug 24, 2012
add qgscollapsiblegroupbox, use in raster save dialog
1 parent 13a790d commit fe6923b

9 files changed

+175
-148
lines changed
 

‎images/images.qrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@
210210
<file>themes/default/mIconWarn.png</file>
211211
<file>themes/default/mIconZoom.png</file>
212212
<file>themes/default/mIconZip.png</file>
213+
<file>themes/default/mIconCollapse.png</file>
214+
<file>themes/default/mIconExpand.png</file>
213215
<file>themes/default/mMapserverExport.png</file>
214216
<file>themes/default/plugin.png</file>
215217
<file>themes/default/propertyicons/action.png</file>
1.34 KB
Loading

‎images/themes/default/mIconExpand.png

1.34 KB
Loading

‎src/gui/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ qgsexpressionbuilderwidget.cpp
9393
qgsexpressionbuilderdialog.cpp
9494
qgsexpressionhighlighter.cpp
9595
qgsquerybuilder.cpp
96+
qgscollapsiblegroupbox.cpp
9697
)
9798

9899
IF (WITH_TOUCH)
@@ -176,6 +177,7 @@ qgsscalecombobox.h
176177
qgsexpressionbuilderwidget.h
177178
qgsexpressionhighlighter.h
178179
qgsquerybuilder.h
180+
qgscollapsiblegroupbox.h
179181
)
180182

181183
QT4_WRAP_CPP(QGIS_GUI_MOC_SRCS ${QGIS_GUI_MOC_HDRS})
@@ -213,6 +215,7 @@ qgsfieldvalidator.h
213215
qgsexpressionbuilderwidget.h
214216
qgsexpressionbuilderdialog.h
215217
qgsexpressionhighlighter.h
218+
qgscollapsiblegroupbox.h
216219

217220
attributetable/qgsattributetablemodel.h
218221
attributetable/qgsattributetablememorymodel.h

‎src/gui/qgscollapsiblegroupbox.cpp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/***************************************************************************
2+
qgscollapsiblegroupbox.cpp
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+
#include "qgscollapsiblegroupbox.h"
19+
20+
#include "qgsapplication.h"
21+
#include "qgslogger.h"
22+
23+
#include <QStyleOptionGroupBox>
24+
#include <QStylePainter>
25+
#include <QLayout>
26+
27+
QgsCollapsibleGroupBox::QgsCollapsibleGroupBox( QWidget *parent )
28+
: QGroupBox( parent ), mCollapsed( false )
29+
{
30+
connect( this, SIGNAL( toggled( bool ) ), this, SLOT( setToggled( bool ) ) );
31+
}
32+
33+
QgsCollapsibleGroupBox::QgsCollapsibleGroupBox( const QString &title, QWidget *parent )
34+
: QGroupBox( title, parent ), mCollapsed( false )
35+
{}
36+
37+
void QgsCollapsibleGroupBox::paintEvent( QPaintEvent * event )
38+
{
39+
QGroupBox::paintEvent( event );
40+
41+
// paint expand/collapse icon only if groupbox is checkable as icon replaces check box
42+
if ( ! isCheckable() )
43+
return;
44+
45+
// create background mask + expand/collapse icon
46+
// icons from http://www.iconfinder.com/search/?q=iconset%3AsplashyIcons
47+
QPixmap icon( mCollapsed ?
48+
QgsApplication::getThemePixmap( "/mIconExpand.png" ) :
49+
QgsApplication::getThemePixmap( "/mIconCollapse.png" ) );
50+
QPixmap background( icon.width() + 2, icon.height() + 2 );
51+
background.fill( palette().color( backgroundRole() ) );
52+
53+
// paint on top of checkbox - does this work with all platforms/themes?
54+
QStylePainter paint( this );
55+
QStyleOptionGroupBox option;
56+
initStyleOption( &option );
57+
paint.drawComplexControl( QStyle::CC_GroupBox, option );
58+
paint.drawItemPixmap( option.rect.adjusted( 4, -1, 0, 0 ),
59+
Qt::AlignTop | Qt::AlignLeft,
60+
background );
61+
paint.drawItemPixmap( option.rect.adjusted( 6, 0, 0, 0 ),
62+
Qt::AlignTop | Qt::AlignLeft,
63+
icon );
64+
}
65+
66+
void QgsCollapsibleGroupBox::showEvent( QShowEvent * event )
67+
{
68+
QGroupBox::showEvent( event );
69+
// collapse if needed - any calls to setCollapsed() before have no effect
70+
if ( isCheckable() && ! isChecked() && ! isCollapsed() )
71+
setCollapsed( true );
72+
}
73+
74+
void QgsCollapsibleGroupBox::setCollapsed( bool collapse )
75+
{
76+
if ( ! isVisible() )
77+
return;
78+
79+
// minimize layout margins and save for subsequent restore
80+
if ( collapse )
81+
{
82+
if ( layout() )
83+
{
84+
mMargins = layout()->contentsMargins();
85+
layout()->setContentsMargins( 1, 1, 1, 1 );
86+
}
87+
}
88+
else
89+
{
90+
if ( layout() )
91+
{
92+
layout()->setContentsMargins( mMargins );
93+
}
94+
}
95+
96+
mCollapsed = collapse;
97+
foreach ( QWidget *widget, findChildren<QWidget*>() )
98+
widget->setHidden( collapse );
99+
100+
if ( mCollapsed )
101+
emit collapsed( this );
102+
else
103+
emit expanded( this );
104+
}
105+

‎src/gui/qgscollapsiblegroupbox.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
/** \ingroup gui
24+
* A groupbox that collapses/expands when toggled and draws an expand/collapse icon in lieu of checkbox.
25+
* Widget must be checkable for expand/collapse icon to appear.
26+
*/
27+
28+
#include <QGroupBox>
29+
30+
class GUI_EXPORT QgsCollapsibleGroupBox : public QGroupBox
31+
{
32+
Q_OBJECT
33+
34+
public:
35+
QgsCollapsibleGroupBox( QWidget *parent = 0 );
36+
QgsCollapsibleGroupBox( const QString &title, QWidget *parent = 0 );
37+
38+
bool isCollapsed() const { return mCollapsed; }
39+
40+
signals:
41+
void collapsed( QWidget* );
42+
void expanded( QWidget* );
43+
44+
public slots:
45+
void setToggled( bool toggled ) { setCollapsed( ! toggled ); }
46+
void setCollapsed( bool collapse );
47+
48+
protected:
49+
void paintEvent( QPaintEvent * );
50+
void showEvent( QShowEvent * event );
51+
52+
private:
53+
bool mCollapsed;
54+
QMargins mMargins;
55+
};
56+
57+
#endif

‎src/gui/qgsrasterlayersaveasdialog.cpp

Lines changed: 1 addition & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -10,108 +10,6 @@
1010
#include <QSettings>
1111

1212

13-
// this widget class will go into its separate file
14-
15-
// #include <QMouseEvent>
16-
// #include <QStyleOptionGroupBox>
17-
// #include <QStylePainter>
18-
19-
GroupBox::GroupBox( QWidget *parent )
20-
: QGroupBox( parent ), m_collapsed( false )
21-
{
22-
connect( this, SIGNAL( toggled ( bool ) ), this, SLOT( setToggled( bool ) ) );
23-
//setToggled( isChecked() );
24-
}
25-
26-
GroupBox::GroupBox( const QString &title, QWidget *parent )
27-
: QGroupBox(title, parent ), m_collapsed( false )
28-
{}
29-
30-
bool GroupBox::isCollapsed() { return m_collapsed; }
31-
32-
// void GroupBox::mousePressEvent( QMouseEvent *e )
33-
// {
34-
// QgsDebugMsg("press event");
35-
// if( e->button() == Qt::LeftButton )
36-
// {
37-
// QgsDebugMsg("left but");
38-
// QStyleOptionGroupBox option;
39-
// initStyleOption( &option );
40-
// QRect buttonArea( 0, 0, 16, 16 );
41-
// buttonArea.moveTopRight( option.rect.adjusted( 0, 0, -10, 0
42-
// ).topRight() );
43-
// if( buttonArea.contains( e->pos() ) )
44-
// {
45-
// clickPos = e->pos();
46-
// return;
47-
// }
48-
// }
49-
// QGroupBox::mousePressEvent( e );
50-
// }
51-
52-
// void GroupBox::mouseReleaseEvent( QMouseEvent *e )
53-
// {
54-
// QgsDebugMsg("release");
55-
// if( e->button() == Qt::LeftButton && clickPos == e->pos() )
56-
// setCollapse( !isCollapsed() );
57-
// }
58-
59-
// void GroupBox::paintEvent( QPaintEvent * )
60-
// {
61-
// QgsDebugMsg("paint event");
62-
63-
// QStylePainter paint( this );
64-
// QStyleOptionGroupBox option;
65-
// initStyleOption( &option );
66-
// paint.drawComplexControl( QStyle::CC_GroupBox, option );
67-
// paint.drawItemPixmap(
68-
// option.rect.adjusted( 0, 0, -10, 0 ),
69-
// Qt::AlignTop | Qt::AlignRight,
70-
// QPixmap( m_collapsed ?
71-
// ":/images/images/navigate_down2_16x16.png" :
72-
// ":/images/images/navigate_up2_16x16.png" ) );
73-
// }
74-
75-
void GroupBox::showEvent( QShowEvent * event )
76-
{
77-
// QgsDebugMsg(QString("%1 showEvent %2 %3").arg(objectName()).arg(isChecked()).arg(isCollapsed()));
78-
QGroupBox::showEvent( event );
79-
if ( ! isChecked() && ! isCollapsed() )
80-
setCollapsed( true );
81-
}
82-
83-
void GroupBox::setCollapsed( bool collapse )
84-
{
85-
if ( ! isVisible() )
86-
return;
87-
// QgsDebugMsg(QString("%1 setcollapse %2").arg(objectName()).arg(collapse));
88-
89-
// minimize layout margins, restore later
90-
if ( collapse )
91-
{
92-
if ( layout() )
93-
{
94-
margins = layout()->contentsMargins();
95-
layout()->setContentsMargins(1,1,1,1);
96-
}
97-
}
98-
else
99-
{
100-
if ( layout() )
101-
{
102-
layout()->setContentsMargins( margins );
103-
}
104-
}
105-
m_collapsed = collapse;
106-
foreach( QWidget *widget, findChildren<QWidget*>() )
107-
widget->setHidden( collapse );
108-
109-
if ( m_collapsed )
110-
emit collapsed( this );
111-
else
112-
emit expanded( this );
113-
}
114-
11513
QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* sourceProvider, const QgsRectangle& currentExtent,
11614
const QgsCoordinateReferenceSystem& layerCrs,
11715
const QgsCoordinateReferenceSystem& currentCrs,
@@ -187,7 +85,7 @@ QgsRasterLayerSaveAsDialog::QgsRasterLayerSaveAsDialog( QgsRasterDataProvider* s
18785

18886
// this should scroll down to make widget visible, but it's not happening
18987
// (at least part of it is visible)...
190-
connect( mCreateOptionsGroupBox, SIGNAL( expanded( QWidget* ) ),
88+
connect( mCreateOptionsGroupBox, SIGNAL( expanded( QWidget* ) ),
19189
this, SLOT( groupBoxExpanded( QWidget* ) ) );
19290

19391
}

‎src/gui/qgsrasterlayersaveasdialog.h

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -110,41 +110,3 @@ class GUI_EXPORT QgsRasterLayerSaveAsDialog: public QDialog, private Ui::QgsRast
110110

111111
#endif // QGSRASTERLAYERSAVEASDIALOG_H
112112

113-
114-
// this widget class will go into its separate file
115-
#ifndef GROUPBOX_H
116-
#define GROUPBOX_H
117-
118-
#include <QGroupBox>
119-
120-
class GroupBox : public QGroupBox
121-
{
122-
Q_OBJECT
123-
124-
public:
125-
GroupBox( QWidget *parent = 0 );
126-
GroupBox( const QString &title, QWidget *parent = 0 );
127-
128-
bool isCollapsed();
129-
130-
signals:
131-
void collapsed( QWidget* );
132-
void expanded( QWidget* );
133-
134-
public slots:
135-
void setToggled( bool toggled ) { setCollapsed( ! toggled ); }
136-
void setCollapsed( bool collapsed );
137-
138-
protected:
139-
/* void mousePressEvent( QMouseEvent *e ); */
140-
/* void mouseReleaseEvent( QMouseEvent *e ); */
141-
/* void paintEvent( QPaintEvent * ); */
142-
void showEvent( QShowEvent * event );
143-
144-
private:
145-
QPoint clickPos;
146-
bool m_collapsed;
147-
QMargins margins;
148-
};
149-
150-
#endif

‎src/ui/qgsrasterlayersaveasdialogbase.ui

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
</layout>
191191
</item>
192192
<item>
193-
<widget class="GroupBox" name="mExtentGroupBox">
193+
<widget class="QgsCollapsibleGroupBox" name="mExtentGroupBox">
194194
<property name="title">
195195
<string>Extent</string>
196196
</property>
@@ -336,7 +336,7 @@
336336
</widget>
337337
</item>
338338
<item>
339-
<widget class="GroupBox" name="mResolutionGroupBox">
339+
<widget class="QgsCollapsibleGroupBox" name="mResolutionGroupBox">
340340
<property name="title">
341341
<string>Resolution</string>
342342
</property>
@@ -412,7 +412,7 @@
412412
</widget>
413413
</item>
414414
<item>
415-
<widget class="GroupBox" name="mNoDataGroupBox">
415+
<widget class="QgsCollapsibleGroupBox" name="mNoDataGroupBox">
416416
<property name="enabled">
417417
<bool>true</bool>
418418
</property>
@@ -503,7 +503,7 @@
503503
</widget>
504504
</item>
505505
<item>
506-
<widget class="GroupBox" name="mCreateOptionsGroupBox">
506+
<widget class="QgsCollapsibleGroupBox" name="mCreateOptionsGroupBox">
507507
<property name="title">
508508
<string>Create Options</string>
509509
</property>
@@ -524,7 +524,7 @@
524524
</widget>
525525
</item>
526526
<item>
527-
<widget class="GroupBox" name="mTilesGroupBox">
527+
<widget class="QgsCollapsibleGroupBox" name="mTilesGroupBox">
528528
<property name="title">
529529
<string>Tiles</string>
530530
</property>
@@ -622,9 +622,9 @@
622622
<container>1</container>
623623
</customwidget>
624624
<customwidget>
625-
<class>GroupBox</class>
625+
<class>QgsCollapsibleGroupBox</class>
626626
<extends>QGroupBox</extends>
627-
<header>qgsrasterlayersaveasdialog.h</header>
627+
<header>qgscollapsiblegroupbox.h</header>
628628
<container>1</container>
629629
</customwidget>
630630
</customwidgets>

0 commit comments

Comments
 (0)
Please sign in to comment.