Add configuration option for a custom stylesheet
authorManuel Nickschas <sputnick@quassel-irc.org>
Tue, 28 Jul 2009 22:02:19 +0000 (00:02 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Thu, 6 Aug 2009 18:25:06 +0000 (20:25 +0200)
Configure -> Appearance now allows you to select a custom stylesheet that should be loaded.
This will override both the default stylesheet and the settings.qss containing your dialog-based
settings; it will be overridden by --qss specified on the command line.

src/qtui/settingspages/appearancesettingspage.cpp
src/qtui/settingspages/appearancesettingspage.h
src/qtui/settingspages/appearancesettingspage.ui
src/uisupport/uistyle.cpp

index 3346eeb..e333816 100644 (file)
@@ -28,6 +28,7 @@
 #include "util.h"
 
 #include <QDir>
+#include <QFileDialog>
 #include <QFontDialog>
 #include <QSignalMapper>
 #include <QStyleFactory>
@@ -37,6 +38,7 @@ AppearanceSettingsPage::AppearanceSettingsPage(QWidget *parent)
   _fontsChanged(false)
 {
   ui.setupUi(this);
+  initAutoWidgets();
   initStyleComboBox();
   initLanguageComboBox();
 
@@ -55,13 +57,13 @@ 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() {
@@ -90,9 +92,9 @@ void AppearanceSettingsPage::defaults() {
   loadFonts(Settings::Default);
   _fontsChanged = true;
 
-  ui.showWebPreview->setChecked(true);
   ui.showUserStateIcons->setChecked(true);
 
+  SettingsPage::defaults();
   widgetHasChanged();
 }
 
@@ -120,14 +122,12 @@ void AppearanceSettingsPage::load() {
   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);
 }
 
@@ -165,9 +165,6 @@ void AppearanceSettingsPage::save() {
     uiSettings.setValue("Locale", selectedLocale());
   }
 
-  ChatViewSettings chatViewSettings;
-  chatViewSettings.enableWebPreview(ui.showWebPreview->isChecked());
-
   BufferSettings bufferSettings;
   bufferSettings.enableUserStateIcons(ui.showUserStateIcons->isChecked());
 
@@ -189,7 +186,7 @@ void AppearanceSettingsPage::save() {
 
   _fontsChanged = false;
 
-  load();
+  SettingsPage::save();
   setChangedState(false);
 }
 
@@ -226,6 +223,12 @@ void AppearanceSettingsPage::chooseFont(QWidget *widget) {
   }
 }
 
+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());
 }
@@ -237,7 +240,6 @@ bool AppearanceSettingsPage::testHasChanged() {
 
   if(selectedLocale() != QLocale()) return true; // QLocale() returns the default locale (manipulated via loadTranslation())
 
-  if(SettingsPage::hasChanged(ui.showWebPreview)) return true;
   if(SettingsPage::hasChanged(ui.showUserStateIcons)) return true;
 
   return false;
index c3e51a9..302d78b 100644 (file)
@@ -52,6 +52,8 @@ private slots:
   void setFont(QLabel *label, const QFont &font);
   void chooseFont(QWidget *label);
 
+  void chooseStyleSheet();
+
 private:
   bool testHasChanged();
   void initStyleComboBox();
index 87f871d..69bb680 100644 (file)
@@ -7,13 +7,13 @@
     <x>0</x>
     <y>0</y>
     <width>521</width>
-    <height>447</height>
+    <height>524</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>Form</string>
   </property>
-  <layout class="QVBoxLayout" name="verticalLayout">
+  <layout class="QVBoxLayout" name="verticalLayout_2">
    <item>
     <widget class="QGroupBox" name="groupBox">
      <property name="title">
      </layout>
     </widget>
    </item>
+   <item>
+    <widget class="QGroupBox" name="useCustomStylesheet">
+     <property name="title">
+      <string>Use Custom Stylesheet</string>
+     </property>
+     <property name="checkable">
+      <bool>true</bool>
+     </property>
+     <property name="checked">
+      <bool>false</bool>
+     </property>
+     <property name="settingsKey" stdset="0">
+      <string>/UiStyle/UseCustomStyleSheet</string>
+     </property>
+     <property name="defaultValue" stdset="0">
+      <bool>false</bool>
+     </property>
+     <layout class="QVBoxLayout" name="verticalLayout">
+      <item>
+       <layout class="QHBoxLayout" name="horizontalLayout_2">
+        <item>
+         <widget class="QLabel" name="label">
+          <property name="text">
+           <string>Path:</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QLineEdit" name="customStyleSheetPath">
+          <property name="sizePolicy">
+           <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+            <horstretch>0</horstretch>
+            <verstretch>0</verstretch>
+           </sizepolicy>
+          </property>
+          <property name="readOnly">
+           <bool>false</bool>
+          </property>
+          <property name="settingsKey" stdset="0">
+           <string>/UiStyle/CustomStyleSheetPath</string>
+          </property>
+          <property name="defaultValue" stdset="0">
+           <string/>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QToolButton" name="chooseStyleSheet">
+          <property name="text">
+           <string>...</string>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
+     </layout>
+    </widget>
+   </item>
    <item>
     <widget class="QGroupBox" name="groupBox_4">
      <property name="enabled">
      </property>
      <layout class="QGridLayout" name="gridLayout">
       <item row="0" column="0">
-       <widget class="QLabel" name="label_2">
-        <property name="enabled">
-         <bool>false</bool>
-        </property>
-        <property name="toolTip">
-         <string>Set font for the main chat window and the chat monitor</string>
-        </property>
-        <property name="text">
-         <string>Chat window:</string>
-        </property>
-       </widget>
-      </item>
-      <item row="0" column="1">
-       <widget class="QLabel" name="demoChatView">
-        <property name="enabled">
-         <bool>false</bool>
-        </property>
-        <property name="sizePolicy">
-         <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
-          <horstretch>0</horstretch>
-          <verstretch>0</verstretch>
-         </sizepolicy>
-        </property>
-        <property name="toolTip">
-         <string>Set font for the main chat window and the chat monitor</string>
-        </property>
-        <property name="frameShape">
-         <enum>QFrame::StyledPanel</enum>
-        </property>
-        <property name="frameShadow">
-         <enum>QFrame::Sunken</enum>
-        </property>
-        <property name="text">
-         <string>Font</string>
-        </property>
-        <property name="alignment">
-         <set>Qt::AlignCenter</set>
-        </property>
-       </widget>
-      </item>
-      <item row="0" column="2">
-       <widget class="QPushButton" name="chooseChatView">
-        <property name="enabled">
-         <bool>false</bool>
-        </property>
-        <property name="sizePolicy">
-         <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
-          <horstretch>0</horstretch>
-          <verstretch>0</verstretch>
-         </sizepolicy>
-        </property>
-        <property name="text">
-         <string>Choose...</string>
-        </property>
-       </widget>
-      </item>
-      <item row="1" column="0">
        <widget class="QLabel" name="label_4">
         <property name="toolTip">
          <string>Set font for channel and nick lists</string>
         </property>
        </widget>
       </item>
-      <item row="1" column="1">
+      <item row="0" column="1">
        <widget class="QLabel" name="demoBufferView">
         <property name="sizePolicy">
          <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
         </property>
        </widget>
       </item>
-      <item row="1" column="2">
+      <item row="0" column="2">
        <widget class="QPushButton" name="chooseBufferView">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
         </property>
        </widget>
       </item>
-      <item row="2" column="0">
+      <item row="1" column="0">
        <widget class="QLabel" name="label_3">
         <property name="toolTip">
          <string>Set font for the input line</string>
         </property>
        </widget>
       </item>
-      <item row="2" column="1">
+      <item row="1" column="1">
        <widget class="QLabel" name="demoInputLine">
         <property name="sizePolicy">
          <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
         </property>
        </widget>
       </item>
-      <item row="2" column="2">
+      <item row="1" column="2">
        <widget class="QPushButton" name="chooseInputLine">
         <property name="sizePolicy">
          <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
       <string>Misc</string>
      </property>
      <layout class="QVBoxLayout" name="verticalLayout_3">
-      <item>
-       <widget class="QCheckBox" name="showWebPreview">
-        <property name="toolTip">
-         <string>Show a website preview window when hovering the mouse over a web address</string>
-        </property>
-        <property name="text">
-         <string>Show previews of webpages on URL hover</string>
-        </property>
-        <property name="checked">
-         <bool>true</bool>
-        </property>
-       </widget>
-      </item>
       <item>
        <widget class="QCheckBox" name="showUserStateIcons">
         <property name="toolTip">
index 62c7a0e..332344c 100644 (file)
@@ -54,7 +54,7 @@ UiStyle::UiStyle(QObject *parent) : QObject(parent) {
   loadStyleSheet();
 }
 
-UiStyle::~ UiStyle() {
+UiStyle::~UiStyle() {
   qDeleteAll(_metricsCache);
 }
 
@@ -63,11 +63,13 @@ void UiStyle::loadStyleSheet() {
   _metricsCache.clear();
   _formatCache.clear();
 
-  QString styleSheet;
+  UiStyleSettings s;
 
+  QString styleSheet;
   styleSheet += loadStyleSheet("file:///" + Quassel::findDataFilePath("default.qss"));
-  styleSheet += loadStyleSheet("file:///" + Quassel::configDirPath() + "custom.qss");
-  // styleSheet += loadStyleSheet("file:///" + some custom file name);  FIXME
+  styleSheet += loadStyleSheet("file:///" + Quassel::configDirPath() + "settings.qss");
+  if(s.value("UseCustomStyleSheet", false).toBool())
+    styleSheet += loadStyleSheet("file:///" + s.value("CustomStyleSheetPath").toString(), true);
   styleSheet += loadStyleSheet("file:///" + Quassel::optionValue("qss"), true);
 
   if(styleSheet.isEmpty())