Move font settings to general appearance settingspage
[quassel.git] / src / uisupport / bufferview.cpp
index 8fbbdd3..d6c1106 100644 (file)
@@ -60,6 +60,10 @@ BufferView::BufferView(QWidget *parent)
   BufferViewDelegate *tristateDelegate = new BufferViewDelegate(this);
   setItemDelegate(tristateDelegate);
   delete oldDelegate;
+
+  UiStyleSettings s("QtUiStyle/Fonts"); // li'l dirty here, but fonts are stored in QtUiStyle :/
+  s.notify("BufferView", this, SLOT(setCustomFont(QVariant)));
+  setCustomFont(s.value("BufferView", QFont()));
 }
 
 void BufferView::init() {
@@ -188,6 +192,13 @@ void BufferView::setRootIndexForNetworkId(const NetworkId &networkId) {
   }
 }
 
+void BufferView::setCustomFont(const QVariant &v) {
+  QFont font = v.value<QFont>();
+  if(font.family().isEmpty())
+    font = QApplication::font();
+  setFont(font);
+}
+
 void BufferView::joinChannel(const QModelIndex &index) {
   BufferInfo::Type bufferType = (BufferInfo::Type)index.data(NetworkModel::BufferTypeRole).value<int>();
 
@@ -465,9 +476,44 @@ QSize BufferView::sizeHint() const {
 // ****************************************
 //  BufferViewDelgate
 // ****************************************
+class ColorsChangedEvent : public QEvent {
+public:
+  ColorsChangedEvent() : QEvent(QEvent::User) {};
+};
+
 BufferViewDelegate::BufferViewDelegate(QObject *parent)
-  : QStyledItemDelegate(parent)
+  : QStyledItemDelegate(parent),
+    _updateColors(false)
 {
+  loadColors();
+
+  UiSettings s("QtUiStyle/Colors");
+  s.notify("inactiveActivityFG", this, SLOT(colorsChanged()));
+  s.notify("noActivityFG", this, SLOT(colorsChanged()));
+  s.notify("highlightActivityFG", this, SLOT(colorsChanged()));
+  s.notify("newMessageActivityFG", this, SLOT(colorsChanged()));
+  s.notify("otherActivityFG", this, SLOT(colorsChanged()));
+}
+
+void BufferViewDelegate::colorsChanged() {
+  // avoid mutliple unneded reloads of all colors
+  if(_updateColors)
+    return;
+  _updateColors = true;
+  QCoreApplication::postEvent(this, new ColorsChangedEvent());
+}
+
+void BufferViewDelegate::customEvent(QEvent *event) {
+  if(event->type() != QEvent::User)
+    return;
+
+  loadColors();
+  _updateColors = false;
+
+  event->accept();
+}
+
+void BufferViewDelegate::loadColors() {
   UiSettings s("QtUiStyle/Colors");
   _FgColorInactiveActivity = s.value("inactiveActivityFG", QVariant(QColor(Qt::gray))).value<QColor>();
   _FgColorNoActivity = s.value("noActivityFG", QVariant(QColor(Qt::black))).value<QColor>();