X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fnickviewfilter.cpp;h=959ae9c63f91c803cdce69f58d42fb85117c3df4;hp=d7dc6fd397e4609b1f12ea97592f8156916349ff;hb=d37bdc91c5474603e1417c2cd9c40c02e1ad5ee6;hpb=f824db0e31b54969e0b7fa0b5405b1e9173d482c diff --git a/src/uisupport/nickviewfilter.cpp b/src/uisupport/nickviewfilter.cpp index d7dc6fd3..959ae9c6 100644 --- a/src/uisupport/nickviewfilter.cpp +++ b/src/uisupport/nickviewfilter.cpp @@ -19,49 +19,83 @@ ***************************************************************************/ #include "nickviewfilter.h" + +#include "buffersettings.h" +#include "iconloader.h" #include "networkmodel.h" -#include "uisettings.h" /****************************************************************************************** * NickViewFilter ******************************************************************************************/ NickViewFilter::NickViewFilter(const BufferId &bufferId, NetworkModel *parent) : QSortFilterProxyModel(parent), - _bufferId(bufferId) + _bufferId(bufferId), + _userOnlineIcon(SmallIcon("im-user")), + _userAwayIcon(SmallIcon("im-user-away")), + _categoryOpIcon(SmallIcon("irc-operator")), + _categoryVoiceIcon(SmallIcon("irc-voice")), + _opIconLimit(UserCategoryItem::categoryFromModes("o")), + _voiceIconLimit(UserCategoryItem::categoryFromModes("v")) { setSourceModel(parent); setDynamicSortFilter(true); setSortCaseSensitivity(Qt::CaseInsensitive); setSortRole(TreeModel::SortRole); - loadColors(); + + BufferSettings bufferSettings; + _showUserStateIcons = bufferSettings.showUserStateIcons(); + bufferSettings.notify("ShowUserStateIcons", this, SLOT(showUserStateIconsChanged())); } -void NickViewFilter::loadColors() { - UiSettings s("QtUiStyle/Colors"); - _FgOnlineStatus = s.value("onlineStatusFG", QVariant(QColor(Qt::black))).value(); - _FgAwayStatus = s.value("awayStatusFG", QVariant(QColor(Qt::gray))).value(); - // FIXME: use the style interface instead of qsettings +bool NickViewFilter::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { + // root node, networkindexes, the bufferindex of the buffer this filter is active for and it's childs are accepted + if(!source_parent.isValid()) + return true; + + QModelIndex source_child = source_parent.child(source_row, 0); + return (sourceModel()->data(source_child, NetworkModel::BufferIdRole).value() == _bufferId); } QVariant NickViewFilter::data(const QModelIndex &index, int role) const { - if(role == Qt::ForegroundRole) - return foreground(index); - else + switch(role) { + case Qt::DecorationRole: + return icon(index); + default: return QSortFilterProxyModel::data(index, role); + } } -QVariant NickViewFilter::foreground(const QModelIndex &index) const { - if(!index.data(NetworkModel::ItemActiveRole).toBool()) - return _FgAwayStatus; - return _FgOnlineStatus; -} +QVariant NickViewFilter::icon(const QModelIndex &index) const { + if(!_showUserStateIcons) + return QVariant(); + if(index.column() != 0) + return QVariant(); -bool NickViewFilter::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { - // root node, networkindexes, the bufferindex of the buffer this filter is active for and it's childs are accepted - if(!source_parent.isValid()) - return true; + QModelIndex source_index = mapToSource(index); + NetworkModel::ItemType itemType = (NetworkModel::ItemType)sourceModel()->data(source_index, NetworkModel::ItemTypeRole).toInt(); + switch(itemType) { + case NetworkModel::UserCategoryItemType: + { + int categoryId = sourceModel()->data(source_index, TreeModel::SortRole).toInt(); + if(categoryId <= _opIconLimit) + return _categoryOpIcon; + if(categoryId <= _voiceIconLimit) + return _categoryVoiceIcon; + return _userOnlineIcon; + } + case NetworkModel::IrcUserItemType: + if(sourceModel()->data(source_index, NetworkModel::ItemActiveRole).toBool()) + return _userOnlineIcon; + else + return _userAwayIcon; + break; + default: + return QVariant(); + }; +} - QModelIndex source_child = source_parent.child(source_row, 0); - return (sourceModel()->data(source_child, NetworkModel::BufferIdRole).value() == _bufferId); +void NickViewFilter::showUserStateIconsChanged() { + BufferSettings bufferSettings; + _showUserStateIcons = bufferSettings.showUserStateIcons(); }