Skip to content

Commit 950f6a9

Browse files
committedSep 11, 2012
Update collapsible groupbox with checkbox and styles
1 parent 73ca04e commit 950f6a9

File tree

6 files changed

+145
-92
lines changed

6 files changed

+145
-92
lines changed
 

‎images/images.qrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,12 @@
169169
<file>themes/default/mActionZoomToLayer.png</file>
170170
<file>themes/default/mActionZoomToSelected.png</file>
171171
<file>themes/default/mIconClose.png</file>
172+
<file>themes/default/mIconCollapse.png</file>
172173
<file>themes/default/mIconConnect.png</file>
173174
<file>themes/default/mIconDbSchema.png</file>
174175
<file>themes/default/mIconDelete.png</file>
175176
<file>themes/default/mIconEditable.png</file>
177+
<file>themes/default/mIconExpand.png</file>
176178
<file>themes/default/mIconFavourites.png</file>
177179
<file>themes/default/mIconFirst.png</file>
178180
<file>themes/default/mIconGeometryLayer.png</file>
346 Bytes
Loading

‎images/themes/default/mIconExpand.png

395 Bytes
Loading

‎src/gui/qgscollapsiblegroupbox.cpp

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,10 @@
2020
#include "qgsapplication.h"
2121
#include "qgslogger.h"
2222

23-
#include <QStyleOptionGroupBox>
24-
#include <QStylePainter>
23+
#include <QToolButton>
2524
#include <QLayout>
26-
#include <QProxyStyle>
25+
#include <QStyle>
2726

28-
class QgsCollapsibleGroupBoxStyle : public QProxyStyle
29-
{
30-
public:
31-
QgsCollapsibleGroupBoxStyle( QStyle * style = 0 ) : QProxyStyle( style ) {}
32-
33-
void drawPrimitive( PrimitiveElement element, const QStyleOption *option,
34-
QPainter *painter, const QWidget *widget ) const
35-
{
36-
if ( element == PE_IndicatorCheckBox )
37-
{
38-
const QgsCollapsibleGroupBox* groupBox =
39-
dynamic_cast<const QgsCollapsibleGroupBox*>( widget );
40-
if ( groupBox )
41-
{
42-
return drawPrimitive( groupBox->isCollapsed() ?
43-
PE_IndicatorArrowRight : PE_IndicatorArrowDown,
44-
option, painter, widget );
45-
}
46-
}
47-
return QProxyStyle::drawPrimitive( element, option, painter, widget );
48-
}
49-
};
5027

5128
QgsCollapsibleGroupBox::QgsCollapsibleGroupBox( QWidget *parent )
5229
: QGroupBox( parent ), mCollapsed( false )
@@ -63,16 +40,54 @@ QgsCollapsibleGroupBox::QgsCollapsibleGroupBox( const QString &title,
6340

6441
void QgsCollapsibleGroupBox::init()
6542
{
66-
setStyle( new QgsCollapsibleGroupBoxStyle( QApplication::style() ) );
67-
connect( this, SIGNAL( toggled( bool ) ), this, SLOT( setToggled( bool ) ) );
43+
44+
connect( this, SIGNAL( toggled( bool ) ), this, SLOT( checkboxToggled() ) );
45+
46+
QString ss;
47+
ss += "QGroupBox {";
48+
ss += " margin-top: 28px;"; // fix for non-checkbox-groupbox spacing
49+
ss += "}";
50+
ss += "QGroupBox::title {";
51+
ss += " subcontrol-origin: margin;";
52+
ss += " subcontrol-position: top left;";
53+
ss += " margin-left: 24px;"; // offset for disclosure triangle
54+
ss += " margin-top: 10px;"; // offset to match extra top margin
55+
ss += "}";
56+
setStyleSheet( ss );
57+
58+
mDisclosure = new QToolButton( this );
59+
mDisclosureName = QString( "grpboxDisclosure" );
60+
mDisclosure->setObjectName( mDisclosureName );
61+
mDisclosure->setFixedSize( 16, 16 );
62+
mDisclosure->move( 0, 10 ); // match title offset
63+
mDisclosure->setIconSize( QSize( 16, 16 ) );
64+
65+
// get rid of toolbutton background
66+
QString ssd;
67+
ssd += QString( "QToolButton#%1 {" ).arg( mDisclosureName );
68+
ssd += " background-color: rgba(255, 255, 255, 0);";
69+
ssd += "}";
70+
mDisclosure->setStyleSheet( ssd );
71+
72+
connect( mDisclosure, SIGNAL( clicked() ), this, SLOT( toggleCollapsed() ) );
6873
}
6974

75+
7076
void QgsCollapsibleGroupBox::showEvent( QShowEvent * event )
7177
{
7278
QGroupBox::showEvent( event );
7379
// collapse if needed - any calls to setCollapsed() before have no effect
74-
if ( isCheckable() && ! isChecked() && ! isCollapsed() )
75-
setCollapsed( true );
80+
setCollapsed( true );
81+
}
82+
83+
void QgsCollapsibleGroupBox::checkboxToggled()
84+
{
85+
mDisclosure->setEnabled( true ); // always keep enabled
86+
}
87+
88+
void QgsCollapsibleGroupBox::toggleCollapsed()
89+
{
90+
setCollapsed( !mCollapsed );
7691
}
7792

7893
void QgsCollapsibleGroupBox::setCollapsed( bool collapse )
@@ -82,41 +97,30 @@ void QgsCollapsibleGroupBox::setCollapsed( bool collapse )
8297

8398
mCollapsed = collapse;
8499

85-
// minimize layout margins and save for subsequent restore
86-
if ( collapse )
87-
{
88-
if ( layout() )
89-
{
90-
mMargins = layout()->contentsMargins();
91-
layout()->setContentsMargins( 1, 1, 1, 1 );
92-
}
93-
}
94-
else
95-
{
96-
if ( layout() )
97-
{
98-
layout()->setContentsMargins( mMargins );
99-
}
100-
}
100+
setFlat( collapse );
101+
setMaximumHeight( collapse ? 36 : 16777215 );
101102

102103
// if we are collapsing, save hidden widgets in a list
103104
if ( collapse )
104105
{
106+
mDisclosure->setIcon( QgsApplication::getThemeIcon( "/mIconExpand.png" ) );
105107
mHiddenWidgets.clear();
106108
foreach ( QWidget *widget, findChildren<QWidget*>() )
107109
{
108-
if ( widget->isHidden() )
110+
if ( widget->isHidden() && widget->objectName() != mDisclosureName )
109111
mHiddenWidgets << widget;
110112
}
111113
}
112114

113115
// show/hide widgets
114116
foreach ( QWidget *widget, findChildren<QWidget*>() )
115-
widget->setHidden( collapse );
117+
if ( widget->objectName() != mDisclosureName )
118+
widget->setHidden( collapse );
116119

117120
// if we are expanding, re-hide saved hidden widgets
118121
if ( ! collapse )
119122
{
123+
mDisclosure->setIcon( QgsApplication::getThemeIcon( "/mIconCollapse.png" ) );
120124
foreach ( QWidget *widget, mHiddenWidgets )
121125
{
122126
widget->setHidden( true );

‎src/gui/qgscollapsiblegroupbox.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
#include <QGroupBox>
2929

30+
class QToolButton;
31+
3032
class GUI_EXPORT QgsCollapsibleGroupBox : public QGroupBox
3133
{
3234
Q_OBJECT
@@ -42,7 +44,8 @@ class GUI_EXPORT QgsCollapsibleGroupBox : public QGroupBox
4244
void expanded( QWidget* );
4345

4446
public slots:
45-
void setToggled( bool toggled ) { setCollapsed( ! toggled ); }
47+
void checkboxToggled();
48+
void toggleCollapsed();
4649
void setCollapsed( bool collapse );
4750

4851
protected:
@@ -53,6 +56,8 @@ class GUI_EXPORT QgsCollapsibleGroupBox : public QGroupBox
5356
bool mCollapsed;
5457
QMargins mMargins;
5558
QList< QWidget* > mHiddenWidgets;
59+
QToolButton* mDisclosure;
60+
QString mDisclosureName;
5661
};
5762

5863
#endif

‎src/ui/qgsrasterlayersaveasdialogbase.ui

Lines changed: 86 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
<property name="geometry">
3030
<rect>
3131
<x>0</x>
32-
<y>-263</y>
33-
<width>549</width>
34-
<height>806</height>
32+
<y>0</y>
33+
<width>536</width>
34+
<height>947</height>
3535
</rect>
3636
</property>
3737
<layout class="QVBoxLayout" name="verticalLayout_5">
@@ -191,11 +191,23 @@
191191
</item>
192192
<item>
193193
<widget class="QgsCollapsibleGroupBox" name="mExtentGroupBox">
194+
<property name="sizePolicy">
195+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
196+
<horstretch>0</horstretch>
197+
<verstretch>0</verstretch>
198+
</sizepolicy>
199+
</property>
200+
<property name="autoFillBackground">
201+
<bool>false</bool>
202+
</property>
194203
<property name="title">
195204
<string>Extent</string>
196205
</property>
206+
<property name="alignment">
207+
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
208+
</property>
197209
<property name="checkable">
198-
<bool>true</bool>
210+
<bool>false</bool>
199211
</property>
200212
<layout class="QVBoxLayout" name="verticalLayout_2">
201213
<item>
@@ -337,11 +349,20 @@
337349
</item>
338350
<item>
339351
<widget class="QgsCollapsibleGroupBox" name="mResolutionGroupBox">
352+
<property name="sizePolicy">
353+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
354+
<horstretch>0</horstretch>
355+
<verstretch>0</verstretch>
356+
</sizepolicy>
357+
</property>
340358
<property name="title">
341359
<string>Resolution</string>
342360
</property>
361+
<property name="flat">
362+
<bool>false</bool>
363+
</property>
343364
<property name="checkable">
344-
<bool>true</bool>
365+
<bool>false</bool>
345366
</property>
346367
<layout class="QVBoxLayout" name="verticalLayout_3">
347368
<item>
@@ -413,6 +434,12 @@
413434
</item>
414435
<item>
415436
<widget class="QgsCollapsibleGroupBox" name="mCreateOptionsGroupBox">
437+
<property name="sizePolicy">
438+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
439+
<horstretch>0</horstretch>
440+
<verstretch>0</verstretch>
441+
</sizepolicy>
442+
</property>
416443
<property name="title">
417444
<string>Create Options</string>
418445
</property>
@@ -423,9 +450,6 @@
423450
<bool>false</bool>
424451
</property>
425452
<layout class="QGridLayout" name="gridLayout_5">
426-
<property name="margin">
427-
<number>9</number>
428-
</property>
429453
<item row="0" column="0">
430454
<widget class="QgsRasterFormatSaveOptionsWidget" name="mCreateOptionsWidget" native="true"/>
431455
</item>
@@ -434,6 +458,12 @@
434458
</item>
435459
<item>
436460
<widget class="QgsCollapsibleGroupBox" name="mTilesGroupBox">
461+
<property name="sizePolicy">
462+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
463+
<horstretch>0</horstretch>
464+
<verstretch>0</verstretch>
465+
</sizepolicy>
466+
</property>
437467
<property name="title">
438468
<string>Tiles</string>
439469
</property>
@@ -444,16 +474,10 @@
444474
<bool>false</bool>
445475
</property>
446476
<layout class="QHBoxLayout" name="horizontalLayout_5">
447-
<property name="spacing">
448-
<number>6</number>
449-
</property>
450-
<property name="margin">
451-
<number>9</number>
452-
</property>
453477
<item>
454478
<widget class="QLabel" name="mMaximumSizeXLabel">
455479
<property name="enabled">
456-
<bool>true</bool>
480+
<bool>false</bool>
457481
</property>
458482
<property name="toolTip">
459483
<string>Maximum number of columns in one tile.</string>
@@ -466,7 +490,7 @@
466490
<item>
467491
<widget class="QLineEdit" name="mMaximumSizeXLineEdit">
468492
<property name="enabled">
469-
<bool>true</bool>
493+
<bool>false</bool>
470494
</property>
471495
<property name="toolTip">
472496
<string>Maximum number of columns in one tile.</string>
@@ -476,7 +500,7 @@
476500
<item>
477501
<widget class="QLabel" name="mMaximumSizeYLabel">
478502
<property name="enabled">
479-
<bool>true</bool>
503+
<bool>false</bool>
480504
</property>
481505
<property name="toolTip">
482506
<string>Maximum number of rows in one tile.</string>
@@ -489,7 +513,7 @@
489513
<item>
490514
<widget class="QLineEdit" name="mMaximumSizeYLineEdit">
491515
<property name="enabled">
492-
<bool>true</bool>
516+
<bool>false</bool>
493517
</property>
494518
<property name="toolTip">
495519
<string>Maximum number of rows in one tile.</string>
@@ -499,7 +523,7 @@
499523
<item>
500524
<widget class="QCheckBox" name="mTileModeCheckBox">
501525
<property name="enabled">
502-
<bool>true</bool>
526+
<bool>false</bool>
503527
</property>
504528
<property name="text">
505529
<string>Create VRT</string>
@@ -509,29 +533,16 @@
509533
</layout>
510534
</widget>
511535
</item>
512-
<item>
513-
<spacer name="verticalSpacer">
514-
<property name="orientation">
515-
<enum>Qt::Vertical</enum>
516-
</property>
517-
<property name="sizeHint" stdset="0">
518-
<size>
519-
<width>20</width>
520-
<height>40</height>
521-
</size>
522-
</property>
523-
</spacer>
524-
</item>
525536
<item>
526537
<widget class="QgsCollapsibleGroupBox" name="mNoDataGroupBox">
527538
<property name="enabled">
528539
<bool>true</bool>
529540
</property>
530-
<property name="minimumSize">
531-
<size>
532-
<width>0</width>
533-
<height>150</height>
534-
</size>
541+
<property name="sizePolicy">
542+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
543+
<horstretch>0</horstretch>
544+
<verstretch>0</verstretch>
545+
</sizepolicy>
535546
</property>
536547
<property name="toolTip">
537548
<string>Additional no data values. The specified values will be set to no data in output raster.</string>
@@ -554,6 +565,12 @@
554565
<verstretch>0</verstretch>
555566
</sizepolicy>
556567
</property>
568+
<property name="minimumSize">
569+
<size>
570+
<width>0</width>
571+
<height>100</height>
572+
</size>
573+
</property>
557574
</widget>
558575
</item>
559576
<item>
@@ -591,6 +608,9 @@
591608
<property name="toolTip">
592609
<string>Remove selected row</string>
593610
</property>
611+
<property name="styleSheet">
612+
<string notr="true"/>
613+
</property>
594614
<property name="text">
595615
<string>...</string>
596616
</property>
@@ -621,6 +641,12 @@
621641
</item>
622642
<item>
623643
<widget class="QgsCollapsibleGroupBox" name="mPyramidsGroupBox">
644+
<property name="sizePolicy">
645+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
646+
<horstretch>0</horstretch>
647+
<verstretch>0</verstretch>
648+
</sizepolicy>
649+
</property>
624650
<property name="title">
625651
<string>Pyramids</string>
626652
</property>
@@ -646,7 +672,7 @@
646672
<string>No pyramids</string>
647673
</property>
648674
<attribute name="buttonGroup">
649-
<string>mPyramidsButtonGroup</string>
675+
<string notr="true">mPyramidsButtonGroup</string>
650676
</attribute>
651677
</widget>
652678
</item>
@@ -656,7 +682,7 @@
656682
<string>Build pyramids</string>
657683
</property>
658684
<attribute name="buttonGroup">
659-
<string>mPyramidsButtonGroup</string>
685+
<string notr="true">mPyramidsButtonGroup</string>
660686
</attribute>
661687
</widget>
662688
</item>
@@ -666,7 +692,7 @@
666692
<string>Use existing</string>
667693
</property>
668694
<attribute name="buttonGroup">
669-
<string>mPyramidsButtonGroup</string>
695+
<string notr="true">mPyramidsButtonGroup</string>
670696
</attribute>
671697
</widget>
672698
</item>
@@ -728,6 +754,22 @@
728754
</layout>
729755
</widget>
730756
</item>
757+
<item>
758+
<spacer name="verticalSpacer">
759+
<property name="orientation">
760+
<enum>Qt::Vertical</enum>
761+
</property>
762+
<property name="sizeType">
763+
<enum>QSizePolicy::Expanding</enum>
764+
</property>
765+
<property name="sizeHint" stdset="0">
766+
<size>
767+
<width>20</width>
768+
<height>40</height>
769+
</size>
770+
</property>
771+
</spacer>
772+
</item>
731773
</layout>
732774
</widget>
733775
</widget>
@@ -773,8 +815,8 @@
773815
<slot>accept()</slot>
774816
<hints>
775817
<hint type="sourcelabel">
776-
<x>248</x>
777-
<y>254</y>
818+
<x>254</x>
819+
<y>575</y>
778820
</hint>
779821
<hint type="destinationlabel">
780822
<x>157</x>
@@ -789,8 +831,8 @@
789831
<slot>reject()</slot>
790832
<hints>
791833
<hint type="sourcelabel">
792-
<x>316</x>
793-
<y>260</y>
834+
<x>322</x>
835+
<y>575</y>
794836
</hint>
795837
<hint type="destinationlabel">
796838
<x>286</x>

0 commit comments

Comments
 (0)
Please sign in to comment.