From deba2421d87cbdea05c925cb3425042559d6ba21 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Mon, 3 Aug 2009 19:39:12 +0200 Subject: [PATCH] Style BufferView via UiStyle BufferView now asks UiStyle for appropriate Qt::ItemDataRoles for styling its items, including the item icons. This replaces the need for setting the palette of custom delegates. --- src/uisupport/bufferview.cpp | 55 +----------------------------- src/uisupport/bufferview.h | 17 +-------- src/uisupport/bufferviewfilter.cpp | 53 ++++------------------------ src/uisupport/bufferviewfilter.h | 11 ------ 4 files changed, 8 insertions(+), 128 deletions(-) diff --git a/src/uisupport/bufferview.cpp b/src/uisupport/bufferview.cpp index 26ddf00e..8debe240 100644 --- a/src/uisupport/bufferview.cpp +++ b/src/uisupport/bufferview.cpp @@ -37,7 +37,6 @@ #include "client.h" #include "contextmenuactionprovider.h" #include "graphicalui.h" -#include "iconloader.h" #include "network.h" #include "networkmodel.h" #include "contextmenuactionprovider.h" @@ -490,46 +489,17 @@ public: }; BufferViewDelegate::BufferViewDelegate(QObject *parent) - : QStyledItemDelegate(parent), - _updateColors(false) + : QStyledItemDelegate(parent) { - 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(); - _FgColorHighlightActivity = s.value("highlightActivityFG", QVariant(QColor(Qt::magenta))).value(); - _FgColorNewMessageActivity = s.value("newMessageActivityFG", QVariant(QColor(Qt::green))).value(); - _FgColorOtherActivity = s.value("otherActivityFG", QVariant(QColor(Qt::darkGreen))).value(); -} - bool BufferViewDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) { if(event->type() != QEvent::MouseButtonRelease) return QStyledItemDelegate::editorEvent(event, model, option, index); @@ -561,29 +531,6 @@ bool BufferViewDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, c return true; } -void BufferViewDelegate::initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const { - QStyledItemDelegate::initStyleOption(option, index); - - if(!index.isValid()) - return; - - BufferInfo::ActivityLevel activity = (BufferInfo::ActivityLevel)index.data(NetworkModel::BufferActivityRole).toInt(); - - QColor fgColor = _FgColorNoActivity; - if(activity & BufferInfo::Highlight) { - fgColor = _FgColorHighlightActivity; - } else if(activity & BufferInfo::NewMessage) { - fgColor = _FgColorNewMessageActivity; - } else if(activity & BufferInfo::OtherActivity) { - fgColor = _FgColorOtherActivity; - } else if(!index.data(NetworkModel::ItemActiveRole).toBool() || index.data(NetworkModel::UserAwayRole).toBool()) { - fgColor = _FgColorInactiveActivity; - } - - option->palette.setColor(QPalette::Text, fgColor); -} - - // ============================== // BufferView Dock // ============================== diff --git a/src/uisupport/bufferview.h b/src/uisupport/bufferview.h index b2d1e0ed..411cd89b 100644 --- a/src/uisupport/bufferview.h +++ b/src/uisupport/bufferview.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -98,7 +99,6 @@ private: // ****************************** // BufferViewDelgate // ****************************** -#include class BufferViewDelegate : public QStyledItemDelegate { Q_OBJECT @@ -109,23 +109,8 @@ public: 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; }; - // ============================== // BufferView Dock // ============================== diff --git a/src/uisupport/bufferviewfilter.cpp b/src/uisupport/bufferviewfilter.cpp index 5b58ee56..5b9d6845 100644 --- a/src/uisupport/bufferviewfilter.cpp +++ b/src/uisupport/bufferviewfilter.cpp @@ -29,8 +29,10 @@ #include "buffersettings.h" #include "client.h" #include "clientbufferviewconfig.h" +#include "graphicalui.h" #include "iconloader.h" #include "networkmodel.h" +#include "uistyle.h" class CheckRemovalEvent : public QEvent { public: @@ -45,11 +47,6 @@ BufferViewFilter::BufferViewFilter(QAbstractItemModel *model, BufferViewConfig * : QSortFilterProxyModel(model), _config(0), _sortOrder(Qt::AscendingOrder), - _channelJoinedIcon(SmallIcon("irc-channel-active")), - _channelPartedIcon(SmallIcon("irc-channel-inactive")), - _userOfflineIcon(SmallIcon("im-user-offline")), - _userAwayIcon(SmallIcon("im-user-away")), - _userOnlineIcon(SmallIcon("im-user")), _editMode(false), _enableEditMode(tr("Show / Hide buffers"), this) { @@ -65,14 +62,6 @@ BufferViewFilter::BufferViewFilter(QAbstractItemModel *model, BufferViewConfig * _enableEditMode.setChecked(_editMode); connect(&_enableEditMode, SIGNAL(toggled(bool)), this, SLOT(enableEditMode(bool))); - BufferSettings bufferSettings; - _showUserStateIcons = bufferSettings.showUserStateIcons(); - bufferSettings.notify("ShowUserStateIcons", this, SLOT(showUserStateIconsChanged())); -} - -void BufferViewFilter::showUserStateIconsChanged() { - BufferSettings bufferSettings; - _showUserStateIcons = bufferSettings.showUserStateIcons(); } void BufferViewFilter::setConfig(BufferViewConfig *config) { @@ -401,8 +390,11 @@ bool BufferViewFilter::networkLessThan(const QModelIndex &source_left, const QMo QVariant BufferViewFilter::data(const QModelIndex &index, int role) const { switch(role) { + case Qt::FontRole: + case Qt::ForegroundRole: + case Qt::BackgroundRole: case Qt::DecorationRole: - return icon(index); + return GraphicalUi::uiStyle()->bufferViewItemData(mapToSource(index), role); case Qt::CheckStateRole: return checkedState(index); default: @@ -410,39 +402,6 @@ QVariant BufferViewFilter::data(const QModelIndex &index, int role) const { } } -QVariant BufferViewFilter::icon(const QModelIndex &index) const { - if(!_showUserStateIcons || (config() && config()->disableDecoration())) - return QVariant(); - - if(index.column() != 0) - return QVariant(); - - QModelIndex source_index = mapToSource(index); - NetworkModel::ItemType itemType = (NetworkModel::ItemType)sourceModel()->data(source_index, NetworkModel::ItemTypeRole).toInt(); - BufferInfo::Type bufferType = (BufferInfo::Type)sourceModel()->data(source_index, NetworkModel::BufferTypeRole).toInt(); - bool isActive = sourceModel()->data(source_index, NetworkModel::ItemActiveRole).toBool(); - - if(itemType != NetworkModel::BufferItemType) - return QVariant(); - - switch(bufferType) { - case BufferInfo::ChannelBuffer: - if(isActive) - return _channelJoinedIcon; - else - return _channelPartedIcon; - case BufferInfo::QueryBuffer: - if(!isActive) - return _userOfflineIcon; - if(sourceModel()->data(source_index, NetworkModel::UserAwayRole).toBool()) - return _userAwayIcon; - else - return _userOnlineIcon; - default: - return QVariant(); - } -} - QVariant BufferViewFilter::checkedState(const QModelIndex &index) const { if(!_editMode || !config()) return QVariant(); diff --git a/src/uisupport/bufferviewfilter.h b/src/uisupport/bufferviewfilter.h index ba3778a4..b20c860d 100644 --- a/src/uisupport/bufferviewfilter.h +++ b/src/uisupport/bufferviewfilter.h @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -57,8 +56,6 @@ public: virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); QVariant data(const QModelIndex &index, int role) const; - QVariant icon(const QModelIndex &index) const; -// QVariant foreground(const QModelIndex &index) const; QVariant checkedState(const QModelIndex &index) const; bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); @@ -89,20 +86,12 @@ signals: private slots: void configInitialized(); - void showUserStateIconsChanged(); void enableEditMode(bool enable); private: QPointer _config; Qt::SortOrder _sortOrder; - QPixmap _channelJoinedIcon; - QPixmap _channelPartedIcon; - QPixmap _userOfflineIcon; - QPixmap _userAwayIcon; - QPixmap _userOnlineIcon; - bool _showUserStateIcons; - bool _editMode; QAction _enableEditMode; QSet _toAdd; -- 2.20.1