Make topicwidget font and resize behavior configurable
authorManuel Nickschas <sputnick@quassel-irc.org>
Tue, 8 Sep 2009 21:54:27 +0000 (23:54 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Tue, 8 Sep 2009 22:02:25 +0000 (00:02 +0200)
Adds a new settingspage "Interface -> Topic Widget" to configure the topicline.
By default, now the whole topic is shown whilst the mouse hovers over the topic widget.

src/qtui/mainwin.cpp
src/qtui/settingspages/settingspages.inc
src/qtui/settingspages/topicwidgetsettingspage.cpp [new file with mode: 0644]
src/qtui/settingspages/topicwidgetsettingspage.h [new file with mode: 0644]
src/qtui/settingspages/topicwidgetsettingspage.ui [new file with mode: 0644]
src/qtui/topicwidget.cpp
src/qtui/topicwidget.h

index d14ebec..0431468 100644 (file)
 #include "settingspages/itemviewsettingspage.h"
 #include "settingspages/networkssettingspage.h"
 #include "settingspages/notificationssettingspage.h"
+#include "settingspages/topicwidgetsettingspage.h"
 
 MainWin::MainWin(QWidget *parent)
 #ifdef HAVE_KDE
@@ -836,6 +837,7 @@ void MainWin::showSettingsDlg() {
   dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
   dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
   dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
+  dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
   dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
   dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
   dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
index 2f1df1c..d96bddc 100644 (file)
@@ -1,9 +1,11 @@
 # Putting $FOO in SETTINGSPAGES automatically includes
 # $FOOsettingspage.cpp, $FOOsettingspage.h and $FOOsettingspage.ui
 
-set(SETTINGSPAGES aliases appearance backlog bufferview chatview connection chatmonitor general highlight identities ignorelist inputwidget itemview networks)
+set(SETTINGSPAGES aliases appearance backlog bufferview chatview connection chatmonitor general 
+                  highlight identities ignorelist inputwidget itemview networks topicwidget)
 
 # Specify additional files (e.g. for subdialogs) here!
 set(SP_SOURCES aliasesmodel.cpp identityeditwidget.cpp ignorelistmodel.cpp notificationssettingspage.cpp)
 set(SP_HEADERS aliasesmodel.h identityeditwidget.h ignorelistmodel.h notificationssettingspage.h previewbufferview.h)
-set(SP_FORMS buffervieweditdlg.ui createidentitydlg.ui identityeditwidget.ui ignorelisteditdlg.ui saveidentitiesdlg.ui networkadddlg.ui networkeditdlg.ui nickeditdlg.ui servereditdlg.ui)
+set(SP_FORMS buffervieweditdlg.ui createidentitydlg.ui identityeditwidget.ui ignorelisteditdlg.ui saveidentitiesdlg.ui 
+             networkadddlg.ui networkeditdlg.ui nickeditdlg.ui servereditdlg.ui)
diff --git a/src/qtui/settingspages/topicwidgetsettingspage.cpp b/src/qtui/settingspages/topicwidgetsettingspage.cpp
new file mode 100644 (file)
index 0000000..46f40cb
--- /dev/null
@@ -0,0 +1,28 @@
+/***************************************************************************
+ *   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 General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) version 3.                                           *
+ *                                                                         *
+ *   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 General Public License for more details.                          *
+ *                                                                         *
+ *   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.             *
+ ***************************************************************************/
+#include "topicwidgetsettingspage.h"
+
+TopicWidgetSettingsPage::TopicWidgetSettingsPage(QWidget *parent)
+  : SettingsPage(tr("Interface"), tr("Topic Widget"), parent)
+{
+  ui.setupUi(this);
+
+  initAutoWidgets();
+}
diff --git a/src/qtui/settingspages/topicwidgetsettingspage.h b/src/qtui/settingspages/topicwidgetsettingspage.h
new file mode 100644 (file)
index 0000000..adc3ed4
--- /dev/null
@@ -0,0 +1,41 @@
+/***************************************************************************
+ *   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 General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) version 3.                                           *
+ *                                                                         *
+ *   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 General Public License for more details.                          *
+ *                                                                         *
+ *   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.             *
+ ***************************************************************************/
+
+#ifndef TOPICWIDGETSETTINGSPAGE_H_
+#define TOPICWIDGETSETTINGSPAGE_H_
+
+#include "settingspage.h"
+#include "ui_topicwidgetsettingspage.h"
+
+class TopicWidgetSettingsPage : public SettingsPage {
+  Q_OBJECT
+
+public:
+  TopicWidgetSettingsPage(QWidget *parent = 0);
+
+  inline bool hasDefaults() const { return true; }
+
+private:
+  Ui::TopicWidgetSettingsPage ui;
+
+  inline QString settingsKey() const { return QString("TopicWidget"); }
+};
+
+#endif
diff --git a/src/qtui/settingspages/topicwidgetsettingspage.ui b/src/qtui/settingspages/topicwidgetsettingspage.ui
new file mode 100644 (file)
index 0000000..2328fe2
--- /dev/null
@@ -0,0 +1,157 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>TopicWidgetSettingsPage</class>
+ <widget class="QWidget" name="TopicWidgetSettingsPage">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>470</width>
+    <height>370</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QCheckBox" name="customFont">
+       <property name="text">
+        <string>Custom font:</string>
+       </property>
+       <property name="settingsKey" stdset="0">
+        <string>/UiStyle/Fonts/UseCustomTopicWidgetFont</string>
+       </property>
+       <property name="defaultValue" stdset="0">
+        <bool>false</bool>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="FontSelector" name="topicWidgetFont" native="true">
+       <property name="enabled">
+        <bool>false</bool>
+       </property>
+       <property name="settingsKey" stdset="0">
+        <string>/UiStyle/Fonts/TopicWidget</string>
+       </property>
+       <property name="defaultValue" stdset="0">
+        <font/>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QCheckBox" name="dynamicResize">
+     <property name="text">
+      <string>Resize dynamically to fit contents</string>
+     </property>
+     <property name="checked">
+      <bool>true</bool>
+     </property>
+     <property name="settingsKey" stdset="0">
+      <string>DynamicResize</string>
+     </property>
+     <property name="defaultValue" stdset="0">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout_2">
+     <item>
+      <spacer name="horizontalSpacer">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeType">
+        <enum>QSizePolicy::Fixed</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>20</width>
+         <height>16</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QCheckBox" name="resizeOnHover">
+       <property name="text">
+        <string>On hover only</string>
+       </property>
+       <property name="checked">
+        <bool>true</bool>
+       </property>
+       <property name="settingsKey" stdset="0">
+        <string>ResizeOnHover</string>
+       </property>
+       <property name="defaultValue" stdset="0">
+        <bool>true</bool>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <spacer name="verticalSpacer">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>274</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+  </layout>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>FontSelector</class>
+   <extends>QWidget</extends>
+   <header>fontselector.h</header>
+   <container>1</container>
+  </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>customFont</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>topicWidgetFont</receiver>
+   <slot>setEnabled(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>105</x>
+     <y>19</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>242</x>
+     <y>20</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>dynamicResize</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>resizeOnHover</receiver>
+   <slot>setEnabled(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>56</x>
+     <y>46</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>65</x>
+     <y>73</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>
index 2f8f5fa..0854647 100644 (file)
@@ -23,6 +23,7 @@
 #include "client.h"
 #include "iconloader.h"
 #include "networkmodel.h"
+#include "uisettings.h"
 
 TopicWidget::TopicWidget(QWidget *parent)
   : AbstractItemView(parent)
@@ -33,6 +34,18 @@ TopicWidget::TopicWidget(QWidget *parent)
   ui.topicLineEdit->installEventFilter(this);
 
   connect(ui.topicLabel, SIGNAL(clickableActivated(Clickable)), SLOT(clickableActivated(Clickable)));
+
+  UiSettings s("TopicWidget");
+  s.notify("DynamicResize", this, SLOT(updateResizeMode()));
+  s.notify("ResizeOnHover", this, SLOT(updateResizeMode()));
+  updateResizeMode();
+
+  UiStyleSettings fs("Fonts");
+  fs.notify("UseCustomTopicWidgetFont", this, SLOT(setUseCustomFont(QVariant)));
+  fs.notify("TopicWidget", this, SLOT(setCustomFont(QVariant)));
+  if(fs.value("UseCustomTopicWidgetFont", false).toBool())
+    setCustomFont(fs.value("TopicWidget", QFont()));
+
 }
 
 void TopicWidget::currentChanged(const QModelIndex &current, const QModelIndex &previous) {
@@ -47,6 +60,31 @@ void TopicWidget::dataChanged(const QModelIndex &topLeft, const QModelIndex &bot
     setTopic(currentTopicIndex.data().toString());
 };
 
+void TopicWidget::setUseCustomFont(const QVariant &v) {
+  if(v.toBool()) {
+    UiStyleSettings fs("Fonts");
+    setCustomFont(fs.value("TopicWidget").value<QFont>());
+  } else
+    setCustomFont(QFont());
+}
+
+void TopicWidget::setCustomFont(const QVariant &v) {
+  UiStyleSettings fs("Fonts");
+  if(!fs.value("UseCustomTopicWidgetFont", false).toBool())
+    return;
+
+  setCustomFont(v.value<QFont>());
+}
+
+void TopicWidget::setCustomFont(const QFont &f) {
+  QFont font = f;
+  if(font.family().isEmpty())
+    font = QApplication::font();
+
+  ui.topicLineEdit->setCustomFont(font);
+  ui.topicLabel->setCustomFont(font);
+}
+
 void TopicWidget::setTopic(const QString &newtopic) {
   if(_topic == newtopic)
     return;
@@ -57,6 +95,19 @@ void TopicWidget::setTopic(const QString &newtopic) {
   switchPlain();
 }
 
+void TopicWidget::updateResizeMode() {
+  StyledLabel::ResizeMode mode = StyledLabel::NoResize;
+  UiSettings s("TopicWidget");
+  if(s.value("DynamicResize", true).toBool()) {
+    if(s.value("ResizeOnHover", true).toBool())
+      mode = StyledLabel::ResizeOnHover;
+    else
+      mode = StyledLabel::DynamicResize;
+  }
+
+  ui.topicLabel->setResizeMode(mode);
+}
+
 void TopicWidget::clickableActivated(const Clickable &click) {
   NetworkId networkId = selectionModel()->currentIndex().data(NetworkModel::NetworkIdRole).value<NetworkId>();
   click.activate(networkId, _topic);
index 18eae86..29e45c6 100644 (file)
@@ -32,6 +32,7 @@ public:
   TopicWidget(QWidget *parent = 0);
 
   void setTopic(const QString &newtopic);
+  void setCustomFont(const QFont &);
 
   virtual bool eventFilter(QObject *obj, QEvent *event);
 
@@ -45,6 +46,9 @@ private slots:
   void switchEditable();
   void switchPlain();
   void clickableActivated(const Clickable &);
+  void updateResizeMode();
+  void setCustomFont(const QVariant &);
+  void setUseCustomFont(const QVariant &);
 
 private:
   Ui::TopicWidget ui;