fixes #531 - changing buffer view colors needs client restart
authorMarcus Eggenberger <egs@quassel-irc.org>
Sat, 14 Feb 2009 00:39:59 +0000 (01:39 +0100)
committerMarcus Eggenberger <egs@quassel-irc.org>
Sat, 14 Feb 2009 00:39:59 +0000 (01:39 +0100)
src/uisupport/bufferview.cpp
src/uisupport/bufferview.h

index 8fbbdd3..ccea4e8 100644 (file)
@@ -465,9 +465,44 @@ QSize BufferView::sizeHint() const {
 // ****************************************
 //  BufferViewDelgate
 // ****************************************
 // ****************************************
 //  BufferViewDelgate
 // ****************************************
+class ColorsChangedEvent : public QEvent {
+public:
+  ColorsChangedEvent() : QEvent(QEvent::User) {};
+};
+
 BufferViewDelegate::BufferViewDelegate(QObject *parent)
 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>();
   UiSettings s("QtUiStyle/Colors");
   _FgColorInactiveActivity = s.value("inactiveActivityFG", QVariant(QColor(Qt::gray))).value<QColor>();
   _FgColorNoActivity = s.value("noActivityFG", QVariant(QColor(Qt::black))).value<QColor>();
index 72fdc96..419f33b 100644 (file)
@@ -105,14 +105,21 @@ public:
   bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index);
 
 protected:
   bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index);
 
 protected:
+  virtual void customEvent(QEvent *event);
   virtual void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const;
 
   virtual void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const;
 
+private slots:
+  void colorsChanged();
+  void loadColors();
+
 private:
   QColor _FgColorInactiveActivity;
   QColor _FgColorNoActivity;
   QColor _FgColorHighlightActivity;
   QColor _FgColorNewMessageActivity;
   QColor _FgColorOtherActivity;
 private:
   QColor _FgColorInactiveActivity;
   QColor _FgColorNoActivity;
   QColor _FgColorHighlightActivity;
   QColor _FgColorNewMessageActivity;
   QColor _FgColorOtherActivity;
+
+  bool _updateColors;
 };
 
 
 };