X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fsettingspages%2Fappearancesettingspage.cpp;h=228fe40391888a51fe6fb7ccd75179dadef16ec9;hp=a6745f61c4ff84b349a78d2638e7b0cc51b3116d;hb=d7832127ff8412b09d9fa4e56570d8a890abcbbe;hpb=22fea756df3d68f8bc433d2540ac6e7400853d7b diff --git a/src/qtui/settingspages/appearancesettingspage.cpp b/src/qtui/settingspages/appearancesettingspage.cpp index a6745f61..228fe403 100644 --- a/src/qtui/settingspages/appearancesettingspage.cpp +++ b/src/qtui/settingspages/appearancesettingspage.cpp @@ -1,18 +1,18 @@ /*************************************************************************** - * 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 * - * it under the terms of the GNU Appearance Public License as published by * + * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Appearance Public License for more details. * + * GNU General Public License for more details. * * * - * You should have received a copy of the GNU Appearance Public License * + * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * @@ -21,52 +21,88 @@ #include "appearancesettingspage.h" #include "qtui.h" -#include "uisettings.h" +#include "qtuisettings.h" +#include "qtuistyle.h" +#include +#include #include AppearanceSettingsPage::AppearanceSettingsPage(QWidget *parent) - : SettingsPage(tr("General"), tr("Appearance"), parent) { + : SettingsPage(tr("Interface"), QString(), parent) +{ ui.setupUi(this); + initAutoWidgets(); initStyleComboBox(); + initLanguageComboBox(); - connect(ui.styleComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(widgetHasChanged())); + foreach(QComboBox *comboBox, findChildren()) { + connect(comboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(widgetHasChanged())); + } + foreach(QCheckBox *checkBox, findChildren()) { + connect(checkBox, SIGNAL(clicked()), this, SLOT(widgetHasChanged())); + } + + connect(ui.chooseStyleSheet, SIGNAL(clicked()), SLOT(chooseStyleSheet())); } void AppearanceSettingsPage::initStyleComboBox() { QStringList styleList = QStyleFactory::keys(); - ui.styleComboBox->addItem(""); + ui.styleComboBox->addItem(tr("")); foreach(QString style, styleList) { ui.styleComboBox->addItem(style); } } -bool AppearanceSettingsPage::hasDefaults() const { - return true; +void AppearanceSettingsPage::initLanguageComboBox() { + QDir i18nDir(Quassel::translationDirPath(), "quassel_*.qm"); + + foreach(QString translationFile, i18nDir.entryList()) { + QString localeName(translationFile.mid(8)); + localeName.chop(3); + QLocale locale(localeName); + _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(); + if(locale == QLocale::system()) + ui.languageComboBox->setCurrentIndex(0); + else if(locale.language() == QLocale::C) + ui.languageComboBox->setCurrentIndex(1); + else + ui.languageComboBox->setCurrentIndex(ui.languageComboBox->findText(QLocale::languageToString(locale.language()), Qt::MatchExactly)); + 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("")); @@ -74,21 +110,49 @@ void AppearanceSettingsPage::save() { uiSettings.setValue("Style", ui.styleComboBox->currentText()); } - load(); + if(ui.languageComboBox->currentIndex() == 0) { + uiSettings.remove("Locale"); // force the default (QLocale::system()) + } else { + uiSettings.setValue("Locale", selectedLocale()); + } + + 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(); } -void AppearanceSettingsPage::widgetHasChanged() { - bool changed = testHasChanged(); - if(changed != hasChanged()) setChangedState(changed); +QLocale AppearanceSettingsPage::selectedLocale() const { + QLocale locale; + int index = ui.languageComboBox->currentIndex(); + if(index == 0) + locale = QLocale::system(); + else if(index == 1) + locale = QLocale::c(); + else if(index > 1) + locale = _locales[index - 2]; + + return locale; } -bool AppearanceSettingsPage::testHasChanged() { - if(settings["Style"].toString() != ui.styleComboBox->currentText()) return true; - - return false; +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(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; +}