-moved the style option to general->appearance
[quassel.git] / src / qtui / settingspages / appearancesettingspage.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel IRC Team                         *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU Appearance Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU Appearance Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU Appearance Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #include "appearancesettingspage.h"
22
23 #include "qtui.h"
24 #include "uisettings.h"
25
26 #include <QStyleFactory>
27
28 AppearanceSettingsPage::AppearanceSettingsPage(QWidget *parent)
29   : SettingsPage(tr("General"), tr("Appearance"), parent) {
30   ui.setupUi(this);
31   initStyleComboBox();
32
33   connect(ui.styleComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(widgetHasChanged())); 
34 }
35
36 void AppearanceSettingsPage::initStyleComboBox() {
37   QStringList styleList = QStyleFactory::keys();
38   ui.styleComboBox->addItem("<default>");
39   foreach(QString style, styleList) {
40     ui.styleComboBox->addItem(style);
41   }
42 }
43
44 bool AppearanceSettingsPage::hasDefaults() const {
45   return true;
46 }
47
48 void AppearanceSettingsPage::defaults() {
49   ui.styleComboBox->setCurrentIndex(0);
50
51   widgetHasChanged();
52 }
53
54 void AppearanceSettingsPage::load() {
55   UiSettings uiSettings;
56
57   settings["Style"] = uiSettings.value("Style", QString(""));
58   if(settings["Style"].toString() == "") {
59     ui.styleComboBox->setCurrentIndex(0);
60   } else {
61     ui.styleComboBox->setCurrentIndex(ui.styleComboBox->findText(settings["Style"].toString(), Qt::MatchExactly));
62     QApplication::setStyle(settings["Style"].toString());
63   }
64
65   setChangedState(false);
66 }
67
68 void AppearanceSettingsPage::save() {
69   UiSettings uiSettings;
70
71   if(ui.styleComboBox->currentIndex() < 1) {
72     uiSettings.setValue("Style", QString(""));
73   } else {
74     uiSettings.setValue("Style", ui.styleComboBox->currentText());
75   }
76
77   load();
78   setChangedState(false);
79 }
80
81 void AppearanceSettingsPage::widgetHasChanged() {
82   bool changed = testHasChanged();
83   if(changed != hasChanged()) setChangedState(changed);
84 }
85
86 bool AppearanceSettingsPage::testHasChanged() {
87   if(settings["Style"].toString() != ui.styleComboBox->currentText()) return true;
88
89   return false;
90 }
91
92
93
94