Add a settingspage for configuring the input widget
[quassel.git] / src / qtui / settingspages / appearancesettingspage.cpp
index 4fcaa0d..228fe40 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-08 by the Quassel IRC Team                         *
+ *   Copyright (C) 2005-09 by the Quassel Project                          *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
 #include "appearancesettingspage.h"
 
 #include "qtui.h"
-#include "uisettings.h"
-#include "util.h"
+#include "qtuisettings.h"
+#include "qtuistyle.h"
 
-#include <QDir>
+#include <QCheckBox>
+#include <QFileDialog>
 #include <QStyleFactory>
 
 AppearanceSettingsPage::AppearanceSettingsPage(QWidget *parent)
-  : SettingsPage(tr("Appearance"), tr("General"), parent) {
+  : SettingsPage(tr("Interface"), QString(), parent)
+{
   ui.setupUi(this);
+  initAutoWidgets();
   initStyleComboBox();
   initLanguageComboBox();
 
-  connect(ui.styleComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(widgetHasChanged())); 
-  connect(ui.languageComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(widgetHasChanged())); 
+  foreach(QComboBox *comboBox, findChildren<QComboBox *>()) {
+    connect(comboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(widgetHasChanged()));
+  }
+  foreach(QCheckBox *checkBox, findChildren<QCheckBox *>()) {
+    connect(checkBox, SIGNAL(clicked()), this, SLOT(widgetHasChanged()));
+  }
+
+  connect(ui.chooseStyleSheet, SIGNAL(clicked()), SLOT(chooseStyleSheet()));
 }
 
 void AppearanceSettingsPage::initStyleComboBox() {
   QStringList styleList = QStyleFactory::keys();
-  ui.styleComboBox->addItem("<default>");
+  ui.styleComboBox->addItem(tr("<System Default>"));
   foreach(QString style, styleList) {
     ui.styleComboBox->addItem(style);
   }
 }
 
 void AppearanceSettingsPage::initLanguageComboBox() {
-  QDir i18nDir(":/i18n", "quassel_*.qm");
+  QDir i18nDir(Quassel::translationDirPath(), "quassel_*.qm");
 
   foreach(QString translationFile, i18nDir.entryList()) {
     QString localeName(translationFile.mid(8));
@@ -55,26 +64,29 @@ void AppearanceSettingsPage::initLanguageComboBox() {
     _locales << locale;
     ui.languageComboBox->addItem(QLocale::languageToString(locale.language()));
   }
-
 }
 
 void AppearanceSettingsPage::defaults() {
   ui.styleComboBox->setCurrentIndex(0);
 
+  SettingsPage::defaults();
   widgetHasChanged();
 }
 
 void AppearanceSettingsPage::load() {
-  UiSettings uiSettings;
+  QtUiSettings uiSettings;
 
-  settings["Style"] = uiSettings.value("Style", QString(""));
-  if(settings["Style"].toString() == "") {
+  // Gui Style
+  QString style = uiSettings.value("Style", QString("")).toString();
+  if(style.isEmpty()) {
     ui.styleComboBox->setCurrentIndex(0);
   } else {
-    ui.styleComboBox->setCurrentIndex(ui.styleComboBox->findText(settings["Style"].toString(), Qt::MatchExactly));
-    QApplication::setStyle(settings["Style"].toString());
+    ui.styleComboBox->setCurrentIndex(ui.styleComboBox->findText(style, Qt::MatchExactly));
+    QApplication::setStyle(style);
   }
+  ui.styleComboBox->setProperty("storedValue", ui.styleComboBox->currentIndex());
 
+  // Language
   QLocale locale = uiSettings.value("Locale", QLocale::system()).value<QLocale>();
   if(locale == QLocale::system())
     ui.languageComboBox->setCurrentIndex(0);
@@ -82,13 +94,15 @@ void AppearanceSettingsPage::load() {
     ui.languageComboBox->setCurrentIndex(1);
   else
     ui.languageComboBox->setCurrentIndex(ui.languageComboBox->findText(QLocale::languageToString(locale.language()), Qt::MatchExactly));
-  loadTranslation(selectedLocale());
+  ui.languageComboBox->setProperty("storedValue", ui.languageComboBox->currentIndex());
+  Quassel::loadTranslation(selectedLocale());
 
+  SettingsPage::load();
   setChangedState(false);
 }
 
 void AppearanceSettingsPage::save() {
-  UiSettings uiSettings;
+  QtUiSettings uiSettings;
 
   if(ui.styleComboBox->currentIndex() < 1) {
     uiSettings.setValue("Style", QString(""));
@@ -101,9 +115,15 @@ void AppearanceSettingsPage::save() {
   } else {
     uiSettings.setValue("Locale", selectedLocale());
   }
-  
-  load();
+
+  bool needsStyleReload =
+        ui.useCustomStyleSheet->isChecked() != ui.useCustomStyleSheet->property("storedValue").toBool()
+    || (ui.useCustomStyleSheet->isChecked() && ui.customStyleSheetPath->text() != ui.customStyleSheetPath->property("storedValue").toString());
+
+  SettingsPage::save();
   setChangedState(false);
+  if(needsStyleReload)
+    QtUi::style()->reload();
 }
 
 QLocale AppearanceSettingsPage::selectedLocale() const {
@@ -119,17 +139,20 @@ QLocale AppearanceSettingsPage::selectedLocale() const {
   return locale;
 }
 
+void AppearanceSettingsPage::chooseStyleSheet() {
+  QString name = QFileDialog::getOpenFileName(this, tr("Please choose a stylesheet file"), QString(), "*.qss");
+  if(!name.isEmpty())
+    ui.customStyleSheetPath->setText(name);
+}
+
 void AppearanceSettingsPage::widgetHasChanged() {
   setChangedState(testHasChanged());
 }
 
 bool AppearanceSettingsPage::testHasChanged() {
-  if(settings["Style"].toString() != ui.styleComboBox->currentText()) return true;
+  if(ui.styleComboBox->currentIndex() != ui.styleComboBox->property("storedValue").toInt()) return true;
+
   if(selectedLocale() != QLocale()) return true; // QLocale() returns the default locale (manipulated via loadTranslation())
 
   return false;
 }
-
-
-
-