Skip to content

Commit a02c8ee

Browse files
committedNov 13, 2011
Allow user to select Qt app style
1 parent 8e2e654 commit a02c8ee

File tree

3 files changed

+110
-65
lines changed

3 files changed

+110
-65
lines changed
 

‎src/app/main.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -474,13 +474,17 @@ int main( int argc, char *argv[] )
474474
}
475475
#endif
476476

477-
#ifdef Q_WS_WIN
478-
//for windows lets use plastique style!
479-
QApplication::setStyle( new QPlastiqueStyle );
480-
#endif
481-
482477
QSettings mySettings;
483478

479+
// Set the application style. If it's not set QT will use the platform style except on Windows
480+
// as it looks really ugly so we use QPlastiqueStyle.
481+
QString style = mySettings.value("/qgis/style","").toString();
482+
if ( !style.isNull() )
483+
QApplication::setStyle( style );
484+
#ifdef Q_WS_WIN
485+
else
486+
QApplication::setStyle( new QPlastiqueStyle );
487+
#endif
484488

485489
/* Translation file for QGIS.
486490
*/

‎src/app/qgsoptions.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <QLocale>
3131
#include <QToolBar>
3232
#include <QSize>
33+
#include <QStyleFactory>
3334

3435
#if QT_VERSION >= 0x40500
3536
#include <QNetworkDiskCache>
@@ -58,12 +59,19 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
5859
connect( cmbSize, SIGNAL( activated( const QString& ) ), this, SLOT( iconSizeChanged( const QString& ) ) );
5960
connect( cmbSize, SIGNAL( highlighted( const QString& ) ), this, SLOT( iconSizeChanged( const QString& ) ) );
6061
connect( cmbSize, SIGNAL( textChanged( const QString& ) ), this, SLOT( iconSizeChanged( const QString& ) ) );
62+
6163
connect( this, SIGNAL( accepted() ), this, SLOT( saveOptions() ) );
6264

6365
cmbSize->addItem( "16" );
6466
cmbSize->addItem( "24" );
6567
cmbSize->addItem( "32" );
6668

69+
QStringList styles = QStyleFactory::keys();
70+
foreach(QString style, styles )
71+
{
72+
cmbStyle->addItem( style );
73+
}
74+
6775
cmbIdentifyMode->addItem( tr( "Current layer" ), 0 );
6876
cmbIdentifyMode->addItem( tr( "Top down, stop at first" ), 1 );
6977
cmbIdentifyMode->addItem( tr( "Top down" ), 2 );
@@ -270,6 +278,8 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
270278
// set the theme combo
271279
cmbTheme->setCurrentIndex( cmbTheme->findText( settings.value( "/Themes", "default" ).toString() ) );
272280
cmbSize->setCurrentIndex( cmbSize->findText( settings.value( "/IconSize", 24 ).toString() ) );
281+
QString name = QApplication::style()->objectName();
282+
cmbStyle->setCurrentIndex( cmbStyle->findText( name, Qt::MatchFixedString ) );
273283
//set the state of the checkboxes
274284
//Changed to default to true as of QGIS 1.7
275285
chkAntiAliasing->setChecked( settings.value( "/qgis/enable_anti_aliasing", true ).toBool() );
@@ -589,6 +599,7 @@ void QgsOptions::saveOptions()
589599
settings.setValue( "/qgis/askToSaveProjectChanges", chbAskToSaveProjectChanges->isChecked() );
590600
settings.setValue( "/qgis/warnOldProjectVersion", chbWarnOldProjectVersion->isChecked() );
591601
settings.setValue( "/qgis/nullValue", leNullValue->text() );
602+
settings.setValue( "/qgis/style", cmbStyle->currentText() );
592603

593604
//overlay placement method
594605
int overlayIndex = mOverlayAlgorithmComboBox->currentIndex();

‎src/ui/qgsoptionsbase.ui

+90-60
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
<rect>
6767
<x>0</x>
6868
<y>0</y>
69-
<width>979</width>
70-
<height>1135</height>
69+
<width>851</width>
70+
<height>1068</height>
7171
</rect>
7272
</property>
7373
<layout class="QGridLayout" name="gridLayout_12">
@@ -127,19 +127,6 @@
127127
</property>
128128
</widget>
129129
</item>
130-
<item row="1" column="2">
131-
<spacer>
132-
<property name="orientation">
133-
<enum>Qt::Horizontal</enum>
134-
</property>
135-
<property name="sizeHint" stdset="0">
136-
<size>
137-
<width>40</width>
138-
<height>20</height>
139-
</size>
140-
</property>
141-
</spacer>
142-
</item>
143130
<item row="1" column="3">
144131
<widget class="QgsColorButton" name="pbnCanvasColor">
145132
<property name="minimumSize">
@@ -153,7 +140,20 @@
153140
</property>
154141
</widget>
155142
</item>
156-
<item row="0" column="2">
143+
<item row="0" column="4">
144+
<spacer>
145+
<property name="orientation">
146+
<enum>Qt::Horizontal</enum>
147+
</property>
148+
<property name="sizeHint" stdset="0">
149+
<size>
150+
<width>40</width>
151+
<height>20</height>
152+
</size>
153+
</property>
154+
</spacer>
155+
</item>
156+
<item row="1" column="4">
157157
<spacer>
158158
<property name="orientation">
159159
<enum>Qt::Horizontal</enum>
@@ -176,22 +176,22 @@
176176
</property>
177177
<layout class="QVBoxLayout" name="verticalLayout_2">
178178
<item>
179-
<layout class="QHBoxLayout" name="horizontalLayout_3">
179+
<layout class="QHBoxLayout" name="horizontalLayout_9">
180+
<property name="topMargin">
181+
<number>0</number>
182+
</property>
180183
<item>
181-
<widget class="QLabel" name="textLabel1_4">
182-
<property name="sizePolicy">
183-
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
184-
<horstretch>0</horstretch>
185-
<verstretch>0</verstretch>
186-
</sizepolicy>
187-
</property>
184+
<widget class="QLabel" name="label_18">
188185
<property name="text">
189-
<string>Icon theme</string>
186+
<string>Style</string>
190187
</property>
191188
</widget>
192189
</item>
193190
<item>
194-
<spacer name="horizontalSpacer_2">
191+
<widget class="QComboBox" name="cmbStyle"/>
192+
</item>
193+
<item>
194+
<spacer name="horizontalSpacer_7">
195195
<property name="orientation">
196196
<enum>Qt::Horizontal</enum>
197197
</property>
@@ -203,6 +203,23 @@
203203
</property>
204204
</spacer>
205205
</item>
206+
</layout>
207+
</item>
208+
<item>
209+
<layout class="QHBoxLayout" name="horizontalLayout_3">
210+
<item>
211+
<widget class="QLabel" name="textLabel1_4">
212+
<property name="sizePolicy">
213+
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
214+
<horstretch>0</horstretch>
215+
<verstretch>0</verstretch>
216+
</sizepolicy>
217+
</property>
218+
<property name="text">
219+
<string>Icon theme</string>
220+
</property>
221+
</widget>
222+
</item>
206223
<item>
207224
<widget class="QComboBox" name="cmbTheme">
208225
<property name="duplicatesEnabled">
@@ -215,6 +232,19 @@
215232
</item>
216233
</widget>
217234
</item>
235+
<item>
236+
<spacer name="horizontalSpacer_2">
237+
<property name="orientation">
238+
<enum>Qt::Horizontal</enum>
239+
</property>
240+
<property name="sizeHint" stdset="0">
241+
<size>
242+
<width>40</width>
243+
<height>20</height>
244+
</size>
245+
</property>
246+
</spacer>
247+
</item>
218248
</layout>
219249
</item>
220250
<item>
@@ -232,6 +262,13 @@
232262
</property>
233263
</widget>
234264
</item>
265+
<item>
266+
<widget class="QComboBox" name="cmbSize">
267+
<property name="duplicatesEnabled">
268+
<bool>false</bool>
269+
</property>
270+
</widget>
271+
</item>
235272
<item>
236273
<spacer name="horizontalSpacer_5">
237274
<property name="orientation">
@@ -245,13 +282,6 @@
245282
</property>
246283
</spacer>
247284
</item>
248-
<item>
249-
<widget class="QComboBox" name="cmbSize">
250-
<property name="duplicatesEnabled">
251-
<bool>false</bool>
252-
</property>
253-
</widget>
254-
</item>
255285
</layout>
256286
</item>
257287
<item>
@@ -263,19 +293,6 @@
263293
</property>
264294
</widget>
265295
</item>
266-
<item>
267-
<spacer name="horizontalSpacer_6">
268-
<property name="orientation">
269-
<enum>Qt::Horizontal</enum>
270-
</property>
271-
<property name="sizeHint" stdset="0">
272-
<size>
273-
<width>40</width>
274-
<height>20</height>
275-
</size>
276-
</property>
277-
</spacer>
278-
</item>
279296
<item>
280297
<widget class="QComboBox" name="cmbLegendDoubleClickAction">
281298
<item>
@@ -290,6 +307,19 @@
290307
</item>
291308
</widget>
292309
</item>
310+
<item>
311+
<spacer name="horizontalSpacer_6">
312+
<property name="orientation">
313+
<enum>Qt::Horizontal</enum>
314+
</property>
315+
<property name="sizeHint" stdset="0">
316+
<size>
317+
<width>40</width>
318+
<height>20</height>
319+
</size>
320+
</property>
321+
</spacer>
322+
</item>
293323
</layout>
294324
</item>
295325
<item>
@@ -537,8 +567,8 @@
537567
<rect>
538568
<x>0</x>
539569
<y>0</y>
540-
<width>641</width>
541-
<height>512</height>
570+
<width>786</width>
571+
<height>473</height>
542572
</rect>
543573
</property>
544574
<layout class="QGridLayout" name="gridLayout_8">
@@ -711,8 +741,8 @@
711741
<rect>
712742
<x>0</x>
713743
<y>0</y>
714-
<width>567</width>
715-
<height>532</height>
744+
<width>786</width>
745+
<height>473</height>
716746
</rect>
717747
</property>
718748
<layout class="QGridLayout" name="gridLayout_4">
@@ -997,8 +1027,8 @@
9971027
<rect>
9981028
<x>0</x>
9991029
<y>0</y>
1000-
<width>289</width>
1001-
<height>94</height>
1030+
<width>803</width>
1031+
<height>414</height>
10021032
</rect>
10031033
</property>
10041034
<layout class="QGridLayout" name="gridLayout_10">
@@ -1072,8 +1102,8 @@
10721102
<rect>
10731103
<x>0</x>
10741104
<y>0</y>
1075-
<width>797</width>
1076-
<height>490</height>
1105+
<width>766</width>
1106+
<height>432</height>
10771107
</rect>
10781108
</property>
10791109
<layout class="QGridLayout" name="gridLayout_13">
@@ -1408,8 +1438,8 @@
14081438
<rect>
14091439
<x>0</x>
14101440
<y>0</y>
1411-
<width>446</width>
1412-
<height>420</height>
1441+
<width>803</width>
1442+
<height>414</height>
14131443
</rect>
14141444
</property>
14151445
<layout class="QGridLayout" name="gridLayout_15">
@@ -1582,8 +1612,8 @@
15821612
<rect>
15831613
<x>0</x>
15841614
<y>0</y>
1585-
<width>519</width>
1586-
<height>583</height>
1615+
<width>786</width>
1616+
<height>542</height>
15871617
</rect>
15881618
</property>
15891619
<layout class="QGridLayout" name="gridLayout_17">
@@ -1679,8 +1709,8 @@
16791709
<rect>
16801710
<x>0</x>
16811711
<y>0</y>
1682-
<width>384</width>
1683-
<height>573</height>
1712+
<width>786</width>
1713+
<height>533</height>
16841714
</rect>
16851715
</property>
16861716
<layout class="QGridLayout" name="gridLayout_20">

0 commit comments

Comments
 (0)
Please sign in to comment.