X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fbufferviewfilter.cpp;h=51f8b0e5d3ccb58ac7e05e9ade4fdc878b1c1d8f;hp=1245579bc28be4080b0ad9a169bd8d9e2c4e4ade;hb=1066294489c2469323a2813b63ae4653d148bbc7;hpb=5cda35fc55cf023172cdf81303cf6b617efc9775 diff --git a/src/uisupport/bufferviewfilter.cpp b/src/uisupport/bufferviewfilter.cpp index 1245579b..51f8b0e5 100644 --- a/src/uisupport/bufferviewfilter.cpp +++ b/src/uisupport/bufferviewfilter.cpp @@ -20,8 +20,6 @@ #include "bufferviewfilter.h" -#include - #include "buffermodel.h" #include "client.h" #include "networkmodel.h" @@ -39,8 +37,18 @@ BufferViewFilter::BufferViewFilter(QAbstractItemModel *model, BufferViewConfig * setSourceModel(model); connect(model, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(source_rowsInserted(const QModelIndex &, int, int))); - // setSortCaseSensitivity(Qt::CaseInsensitive); setDynamicSortFilter(true); + + loadColors(); +} + +void BufferViewFilter::loadColors() { + UiSettings s("QtUi/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(); } void BufferViewFilter::setConfig(BufferViewConfig *config) { @@ -116,7 +124,7 @@ bool BufferViewFilter::dropMimeData(const QMimeData *data, Qt::DropAction action } void BufferViewFilter::addBuffer(const BufferId &bufferId) { - if(config()->bufferList().contains(bufferId)) + if(!config() || config()->bufferList().contains(bufferId)) return; int pos = config()->bufferList().count(); @@ -145,9 +153,11 @@ void BufferViewFilter::removeBuffer(const QModelIndex &index) { bool BufferViewFilter::filterAcceptBuffer(const QModelIndex &source_bufferIndex) const { + BufferId bufferId = sourceModel()->data(source_bufferIndex, NetworkModel::BufferIdRole).value(); + Q_ASSERT(bufferId.isValid()); if(!_config) return true; - + if(config()->networkId().isValid() && config()->networkId() != sourceModel()->data(source_bufferIndex, NetworkModel::NetworkIdRole).value()) return false; @@ -158,11 +168,10 @@ bool BufferViewFilter::filterAcceptBuffer(const QModelIndex &source_bufferIndex) return false; if(_config->minimumActivity() > source_bufferIndex.data(NetworkModel::BufferActivityRole).toInt()) { - if(!Client::bufferModel()->standardSelectionModel()->isSelected(source_bufferIndex)) + if(bufferId != Client::bufferModel()->standardSelectionModel()->currentIndex().data(NetworkModel::BufferIdRole).value()) return false; } - BufferId bufferId = sourceModel()->data(source_bufferIndex, NetworkModel::BufferIdRole).value(); return _config->bufferList().contains(bufferId); } @@ -185,7 +194,7 @@ bool BufferViewFilter::filterAcceptsRow(int source_row, const QModelIndex &sourc return false; } - if(source_parent == QModelIndex()) + if(!source_parent.isValid()) return filterAcceptNetwork(child); else return filterAcceptBuffer(child); @@ -230,27 +239,19 @@ QVariant BufferViewFilter::data(const QModelIndex &index, int role) const { } QVariant BufferViewFilter::foreground(const QModelIndex &index) const { - UiSettings s("QtUi/Colors"); - QVariant inactiveActivity = s.value("inactiveActivityFG", QVariant(QColor(Qt::gray))); - QVariant noActivity = s.value("noActivityFG", QVariant(QColor(Qt::black))); - QVariant highlightActivity = s.value("highlightActivityFG", QVariant(QColor(Qt::magenta))); - QVariant newMessageActivity = s.value("newMessageActivityFG", QVariant(QColor(Qt::green))); - QVariant otherActivity = s.value("otherActivityFG", QVariant(QColor(Qt::darkGreen))); - if(!index.data(NetworkModel::ItemActiveRole).toBool()) - return inactiveActivity; + return _FgColorInactiveActivity; Buffer::ActivityLevel activity = (Buffer::ActivityLevel)index.data(NetworkModel::BufferActivityRole).toInt(); if(activity & Buffer::Highlight) - return highlightActivity; + return _FgColorHighlightActivity; if(activity & Buffer::NewMessage) - return newMessageActivity; + return _FgColorNewMessageActivity; if(activity & Buffer::OtherActivity) - return otherActivity; - - return noActivity; + return _FgColorOtherActivity; + return _FgColorNoActivity; } void BufferViewFilter::source_rowsInserted(const QModelIndex &parent, int start, int end) { @@ -260,8 +261,10 @@ void BufferViewFilter::source_rowsInserted(const QModelIndex &parent, int start, if(!config() || !config()->addNewBuffersAutomatically()) return; + QModelIndex child; for(int row = start; row <= end; row++) { - addBuffer(parent.child(row, 0).data(NetworkModel::BufferIdRole).value()); + child = sourceModel()->index(row, 0, parent); + addBuffer(sourceModel()->data(child, NetworkModel::BufferIdRole).value()); } }