Skip to content

Commit ae0771e

Browse files
committedNov 22, 2011
Merge pull request #59 from NathanW2/window_theme
[FEATURE] Allow the user to select the Qt windows style they want
2 parents 1b3c383 + a0dad9c commit ae0771e

File tree

3 files changed

+94
-49
lines changed

3 files changed

+94
-49
lines changed
 

‎src/app/main.cpp

Lines changed: 9 additions & 5 deletions
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

Lines changed: 11 additions & 0 deletions
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

Lines changed: 74 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -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 &lt;i&gt;(QGIS restart required)&lt;/i&gt;</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>

0 commit comments

Comments
 (0)
Please sign in to comment.