X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fsettingspages%2Fappearancesettingspage.cpp;h=ab39344aa43dd46a2f8d39a6975cbaefadc70db2;hp=c6a8b455948b53d1d6a4636918779e99a284c3f3;hb=3f354bcce2cecfe88a46de90cbf94ffd1bc7c506;hpb=c14a00f37179e49f034dc64b4da0c86b51caed5d diff --git a/src/qtui/settingspages/appearancesettingspage.cpp b/src/qtui/settingspages/appearancesettingspage.cpp index c6a8b455..ab39344a 100644 --- a/src/qtui/settingspages/appearancesettingspage.cpp +++ b/src/qtui/settingspages/appearancesettingspage.cpp @@ -27,23 +27,22 @@ #include "qtuistyle.h" #include "util.h" +#include #include +#include #include #include #include AppearanceSettingsPage::AppearanceSettingsPage(QWidget *parent) - : SettingsPage(tr("Appearance"), QString(), parent) + : SettingsPage(tr("Interface"), QString(), parent), + _fontsChanged(false) { ui.setupUi(this); + initAutoWidgets(); initStyleComboBox(); initLanguageComboBox(); -#ifndef HAVE_WEBKIT - ui.showWebPreview->hide(); - ui.showWebPreview->setEnabled(false); -#endif - foreach(QComboBox *comboBox, findChildren()) { connect(comboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(widgetHasChanged())); } @@ -54,13 +53,11 @@ AppearanceSettingsPage::AppearanceSettingsPage(QWidget *parent) mapper = new QSignalMapper(this); connect(mapper, SIGNAL(mapped(QWidget *)), this, SLOT(chooseFont(QWidget *))); - connect(ui.chooseChatView, SIGNAL(clicked()), mapper, SLOT(map())); - connect(ui.chooseBufferView, SIGNAL(clicked()), mapper, SLOT(map())); connect(ui.chooseInputLine, SIGNAL(clicked()), mapper, SLOT(map())); - mapper->setMapping(ui.chooseChatView, ui.demoChatView); - mapper->setMapping(ui.chooseBufferView, ui.demoBufferView); mapper->setMapping(ui.chooseInputLine, ui.demoInputLine); + + connect(ui.chooseStyleSheet, SIGNAL(clicked()), SLOT(chooseStyleSheet())); } void AppearanceSettingsPage::initStyleComboBox() { @@ -88,6 +85,8 @@ void AppearanceSettingsPage::defaults() { loadFonts(Settings::Default); _fontsChanged = true; + + SettingsPage::defaults(); widgetHasChanged(); } @@ -95,13 +94,14 @@ void AppearanceSettingsPage::load() { QtUiSettings uiSettings; // Gui Style - settings["Style"] = uiSettings.value("Style", QString("")); - if(settings["Style"].toString() == "") { + 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(); @@ -111,16 +111,12 @@ void AppearanceSettingsPage::load() { 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()); - ChatViewSettings chatViewSettings; - SettingsPage::load(ui.showWebPreview, chatViewSettings.showWebPreview()); - - BufferSettings bufferSettings; - SettingsPage::load(ui.showUserStateIcons, bufferSettings.showUserStateIcons()); - loadFonts(Settings::Custom); + SettingsPage::load(); setChangedState(false); } @@ -132,14 +128,6 @@ void AppearanceSettingsPage::loadFonts(Settings::Mode mode) { inputLineFont = s.value("InputLine", QFont()).value(); setFont(ui.demoInputLine, inputLineFont); - QFont bufferViewFont; - if(mode == Settings::Custom) - bufferViewFont = s.value("BufferView", QFont()).value(); - setFont(ui.demoBufferView, bufferViewFont); - - QTextCharFormat chatFormat = QtUi::style()->format(UiStyle::None, mode); - setFont(ui.demoChatView, chatFormat.font()); - _fontsChanged = false; } @@ -158,12 +146,6 @@ void AppearanceSettingsPage::save() { uiSettings.setValue("Locale", selectedLocale()); } - ChatViewSettings chatViewSettings; - chatViewSettings.enableWebPreview(ui.showWebPreview->isChecked()); - - BufferSettings bufferSettings; - bufferSettings.enableUserStateIcons(ui.showUserStateIcons->isChecked()); - // Fonts QtUiStyleSettings fontSettings("Fonts"); if(ui.demoInputLine->font() != QApplication::font()) @@ -171,19 +153,16 @@ void AppearanceSettingsPage::save() { else fontSettings.setValue("InputLine", ""); - if(ui.demoBufferView->font() != QApplication::font()) - fontSettings.setValue("BufferView", ui.demoBufferView->font()); - else - fontSettings.setValue("BufferView", ""); - - QTextCharFormat chatFormat = QtUi::style()->format(UiStyle::None); - chatFormat.setFont(ui.demoChatView->font()); - QtUi::style()->setFormat(UiStyle::None, chatFormat, Settings::Custom); - _fontsChanged = false; - 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 { @@ -214,11 +193,17 @@ void AppearanceSettingsPage::chooseFont(QWidget *widget) { bool ok; QFont font = QFontDialog::getFont(&ok, label->font()); if(ok) { - setFont(label, font); _fontsChanged = true; + setFont(label, font); } } +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()); } @@ -226,11 +211,9 @@ void AppearanceSettingsPage::widgetHasChanged() { bool AppearanceSettingsPage::testHasChanged() { if(_fontsChanged) return true; // comparisons are nasty for now - if(settings["Style"].toString() != ui.styleComboBox->currentText()) return true; - if(selectedLocale() != QLocale()) return true; // QLocale() returns the default locale (manipulated via loadTranslation()) + if(ui.styleComboBox->currentIndex() != ui.styleComboBox->property("storedValue").toInt()) return true; - if(SettingsPage::hasChanged(ui.showWebPreview)) return true; - if(SettingsPage::hasChanged(ui.showUserStateIcons)) return true; + if(selectedLocale() != QLocale()) return true; // QLocale() returns the default locale (manipulated via loadTranslation()) return false; }