From cdc6b6dd319564e94f4fdba47ec4c8feaa2cf8a2 Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Sat, 14 Feb 2009 01:39:59 +0100 Subject: [PATCH 1/1] fixes #531 - changing buffer view colors needs client restart --- src/uisupport/bufferview.cpp | 37 +++++++++++++++++++++++++++++++++++- src/uisupport/bufferview.h | 7 +++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/uisupport/bufferview.cpp b/src/uisupport/bufferview.cpp index 8fbbdd34..ccea4e8c 100644 --- a/src/uisupport/bufferview.cpp +++ b/src/uisupport/bufferview.cpp @@ -465,9 +465,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(); _FgColorNoActivity = s.value("noActivityFG", QVariant(QColor(Qt::black))).value(); diff --git a/src/uisupport/bufferview.h b/src/uisupport/bufferview.h index 72fdc967..419f33b1 100644 --- a/src/uisupport/bufferview.h +++ b/src/uisupport/bufferview.h @@ -105,14 +105,21 @@ public: 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; +private slots: + void colorsChanged(); + void loadColors(); + private: QColor _FgColorInactiveActivity; QColor _FgColorNoActivity; QColor _FgColorHighlightActivity; QColor _FgColorNewMessageActivity; QColor _FgColorOtherActivity; + + bool _updateColors; }; -- 2.20.1