From: Marcus Eggenberger Date: Fri, 24 Oct 2008 11:59:06 +0000 (+0200) Subject: The context menu "hide events" in the bufferviews are now working. X-Git-Tag: 0.3.1~132 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=a3aaabf6254c8c5439af8982cc613c4ced3f50ed The context menu "hide events" in the bufferviews are now working. This is currently on a per buffer basis as default settings require a new settings page (lazy me...) Disabled Indexing of the GraphicsScene again and I intend to leave it that way until my BR @ Qt (which I yet need to file... (lazy me...)) is fixed. --- diff --git a/src/client/buffersettings.cpp b/src/client/buffersettings.cpp index eda11376..c42cd81c 100644 --- a/src/client/buffersettings.cpp +++ b/src/client/buffersettings.cpp @@ -20,14 +20,29 @@ #include "buffersettings.h" -BufferSettings::BufferSettings(const QString &group) : ClientSettings(group) { +BufferSettings::BufferSettings(BufferId bufferId) + : ClientSettings(QString("Buffer/%1").arg(bufferId.toInt())) +{ +} + +BufferSettings::BufferSettings(const QString &idString) + : ClientSettings(QString("Buffer/%1").arg(idString)) +{ +} +bool BufferSettings::hasFilter() { + return localValue("hasMessageTypeFilter", false).toBool(); } -void BufferSettings::setValue(const QString &key, const QVariant &data) { - setLocalValue(key, data); +int BufferSettings::messageFilter() { + return localValue("MessageTypeFilter", 0).toInt(); } -QVariant BufferSettings::value(const QString &key, const QVariant &def) { - return localValue(key, def); +void BufferSettings::filterMessage(Message::Type msgType, bool filter) { + if(!hasFilter()) + setLocalValue("hasMessageTypeFilter", true); + if(filter) + setLocalValue("MessageTypeFilter", localValue("MessageTypeFilter", 0).toInt() | msgType); + else + setLocalValue("MessageTypeFilter", localValue("MessageTypeFilter", 0).toInt() & ~msgType); } diff --git a/src/client/buffersettings.h b/src/client/buffersettings.h index f4266a5d..d60236d0 100644 --- a/src/client/buffersettings.h +++ b/src/client/buffersettings.h @@ -18,20 +18,24 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef _BUFFERSETTINGS_H_ -#define _BUFFERSETTINGS_H_ +#ifndef BUFFERSETTINGS_H +#define BUFFERSETTINGS_H #include "clientsettings.h" +#include "message.h" +#include "types.h" class BufferSettings : public ClientSettings { +public: + BufferSettings(const QString &idString = "__default__"); + BufferSettings(BufferId bufferId); - public: - BufferSettings(const QString &group = "Buffer"); - - void setValue(const QString &key, const QVariant &data); - QVariant value(const QString &key, const QVariant &def = QVariant()); - + inline void setValue(const QString &key, const QVariant &data) { setLocalValue(key, data); } + inline QVariant value(const QString &key, const QVariant &def = QVariant()) { return localValue(key, def); } + bool hasFilter(); + int messageFilter(); + void filterMessage(Message::Type msgType, bool filter); }; diff --git a/src/client/clientsettings.cpp b/src/client/clientsettings.cpp index 02a8c9cb..9a054594 100644 --- a/src/client/clientsettings.cpp +++ b/src/client/clientsettings.cpp @@ -32,8 +32,14 @@ ClientSettings::~ClientSettings() { /***********************************************************************************************/ -CoreAccountSettings::CoreAccountSettings(const QString &subgroup) : ClientSettings("CoreAccounts") { - _subgroup = subgroup; +CoreAccountSettings::CoreAccountSettings(const QString &subgroup) + : ClientSettings("CoreAccounts"), + _subgroup(subgroup) +{ +} + +void CoreAccountSettings::notify(const QString &key, QObject *receiver, const char *slot) { + ClientSettings::notify(QString("%1/%2/%3").arg(Client::currentCoreAccount().toInt()).arg(_subgroup).arg(key), receiver, slot); } QList CoreAccountSettings::knownAccounts() { diff --git a/src/client/clientsettings.h b/src/client/clientsettings.h index 01353d7d..f3ac2471 100644 --- a/src/client/clientsettings.h +++ b/src/client/clientsettings.h @@ -18,20 +18,18 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef _CLIENTSETTINGS_H_ -#define _CLIENTSETTINGS_H_ +#ifndef CLIENTSETTINGS_H +#define CLIENTSETTINGS_H #include "settings.h" #include "types.h" class ClientSettings : public Settings { +public: + virtual ~ClientSettings(); - public: - virtual ~ClientSettings(); - - protected: - ClientSettings(QString group = "General"); - +protected: + ClientSettings(QString group = "General"); }; // Deriving from CoreAccountSettings: @@ -42,30 +40,31 @@ class ClientSettings : public Settings { // Note that you'll get invalid data (and setting is ignored) if you are not connected to a core! class CoreAccountSettings : public ClientSettings { +public: + // stores account-specific data in CoreAccounts/$ACCID/$SUBGROUP/$KEY) + CoreAccountSettings(const QString &subgroup = "General"); - public: - // stores account-specific data in CoreAccounts/$ACCID/$SUBGROUP/$KEY) - CoreAccountSettings(const QString &subgroup = "General"); + virtual void notify(const QString &key, QObject *receiver, const char *slot); - QList knownAccounts(); - AccountId lastAccount(); - void setLastAccount(AccountId); - AccountId autoConnectAccount(); - void setAutoConnectAccount(AccountId); + QList knownAccounts(); + AccountId lastAccount(); + void setLastAccount(AccountId); + AccountId autoConnectAccount(); + void setAutoConnectAccount(AccountId); - void storeAccountData(AccountId id, const QVariantMap &data); - QVariantMap retrieveAccountData(AccountId); - void removeAccount(AccountId); + void storeAccountData(AccountId id, const QVariantMap &data); + QVariantMap retrieveAccountData(AccountId); + void removeAccount(AccountId); - void setJumpKeyMap(const QHash &keyMap); - QHash jumpKeyMap(); + void setJumpKeyMap(const QHash &keyMap); + QHash jumpKeyMap(); - protected: - void setAccountValue(const QString &key, const QVariant &data); - QVariant accountValue(const QString &key, const QVariant &def = QVariant()); +protected: + void setAccountValue(const QString &key, const QVariant &data); + QVariant accountValue(const QString &key, const QVariant &def = QVariant()); - private: - QString _subgroup; +private: + QString _subgroup; }; class NotificationSettings : public ClientSettings { diff --git a/src/client/messagefilter.cpp b/src/client/messagefilter.cpp index c1253da8..3ef02ee5 100644 --- a/src/client/messagefilter.cpp +++ b/src/client/messagefilter.cpp @@ -19,20 +19,51 @@ ***************************************************************************/ #include "messagefilter.h" +#include "buffersettings.h" MessageFilter::MessageFilter(QAbstractItemModel *source, QObject *parent) - : QSortFilterProxyModel(parent) + : QSortFilterProxyModel(parent), + _messageTypeFilter(0) { + init(); setSourceModel(source); } MessageFilter::MessageFilter(MessageModel *source, const QList &buffers, QObject *parent) : QSortFilterProxyModel(parent), - _validBuffers(buffers.toSet()) + _validBuffers(buffers.toSet()), + _messageTypeFilter(0) { + init(); setSourceModel(source); } +void MessageFilter::init() { + BufferSettings defaultSettings; + _messageTypeFilter = defaultSettings.messageFilter(); + defaultSettings.notify("MessageTypeFilter", this, SLOT(messageTypeFilterChanged())); + + BufferSettings mySettings(idString()); + if(mySettings.hasFilter()) + _messageTypeFilter = mySettings.messageFilter(); + mySettings.notify("MessageTypeFilter", this, SLOT(messageTypeFilterChanged())); +} + +void MessageFilter::messageTypeFilterChanged() { + int newFilter; + BufferSettings defaultSettings(); + newFilter = BufferSettings().messageFilter(); + + BufferSettings mySettings(idString()); + if(mySettings.hasFilter()) + newFilter = mySettings.messageFilter(); + + if(_messageTypeFilter != newFilter) { + _messageTypeFilter = newFilter; + invalidateFilter(); + } +} + QString MessageFilter::idString() const { if(_validBuffers.isEmpty()) return "*"; @@ -49,10 +80,14 @@ QString MessageFilter::idString() const { bool MessageFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { Q_UNUSED(sourceParent); + QModelIndex sourceIdx = sourceModel()->index(sourceRow, 0); + if(_messageTypeFilter & sourceModel()->data(sourceIdx, MessageModel::TypeRole).toInt()) + return false; + if(_validBuffers.isEmpty()) return true; - BufferId id = sourceModel()->data(sourceModel()->index(sourceRow, 0), MessageModel::BufferIdRole).value(); + BufferId id = sourceModel()->data(sourceIdx, MessageModel::BufferIdRole).value(); if(!id.isValid()) { return true; } diff --git a/src/client/messagefilter.h b/src/client/messagefilter.h index 09e64fca..8f2cc18c 100644 --- a/src/client/messagefilter.h +++ b/src/client/messagefilter.h @@ -40,8 +40,14 @@ public: inline bool isSingleBufferFilter() const { return _validBuffers.count() == 1; } inline bool containsBuffer(const BufferId &id) const { return _validBuffers.contains(id); } +public slots: + void messageTypeFilterChanged(); + private: + void init(); + QSet _validBuffers; + int _messageTypeFilter; }; #endif diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 83fb8fb3..12f1f692 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -20,7 +20,6 @@ #include #include -#include #ifdef Q_WS_QWS #include diff --git a/src/common/settings.h b/src/common/settings.h index 08db0cd9..8ccee168 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -41,7 +41,7 @@ public: enum Mode { Default, Custom }; public: - void notify(const QString &key, QObject *receiver, const char *slot); + virtual void notify(const QString &key, QObject *receiver, const char *slot); protected: inline Settings(QString group_, QString appName_) : group(group_), appName(appName_) {} diff --git a/src/qtui/chatline.cpp b/src/qtui/chatline.cpp index 1ef2f374..ce208bea 100644 --- a/src/qtui/chatline.cpp +++ b/src/qtui/chatline.cpp @@ -172,14 +172,17 @@ void ChatLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, // new line marker const QAbstractItemModel *model_ = model(); - if(model_ && row() > 0) { + if(model_ && row() > 0 && chatScene()->isSingleBufferScene()) { QModelIndex prevRowIdx = model_->index(row() - 1, 0); - MsgId msgId = model_->data(prevRowIdx, MessageModel::MsgIdRole).value(); - Message::Flags flags = (Message::Flags)model_->data(model_->index(row(), 0), MessageModel::FlagsRole).toInt(); + MsgId prevMsgId = model_->data(prevRowIdx, MessageModel::MsgIdRole).value(); + QModelIndex myIdx = model_->index(row(), 0); + MsgId myMsgId = model_->data(myIdx, MessageModel::MsgIdRole).value(); + Message::Flags flags = (Message::Flags)model_->data(myIdx, MessageModel::FlagsRole).toInt(); // don't show the marker if we wrote that new line if(!(flags & Message::Self)) { - BufferId bufferId = model_->data(prevRowIdx, MessageModel::BufferIdRole).value(); - if(msgId == Client::networkModel()->lastSeenMsgId(bufferId) && chatScene()->isSingleBufferScene()) { + BufferId bufferId = BufferId(chatScene()->idString().toInt()); + MsgId lastSeenMsgId = Client::networkModel()->lastSeenMsgId(bufferId); + if(lastSeenMsgId < myMsgId && lastSeenMsgId >= prevMsgId) { QtUiStyleSettings s("Colors"); QLinearGradient gradient(0, 0, 0, contentsItem().fontMetrics()->lineSpacing()); gradient.setColorAt(0, s.value("newMsgMarkerFG", QColor(Qt::red)).value()); diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index 41032f4f..f71c8572 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -93,6 +93,8 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, qreal w webPreview.deleteTimer.setInterval(600000); connect(&webPreview.deleteTimer, SIGNAL(timeout()), this, SLOT(deleteWebPreviewEvent())); #endif + + setItemIndexMethod(QGraphicsScene::NoIndex); } ChatScene::~ChatScene() { @@ -302,7 +304,7 @@ void ChatScene::setWidth(qreal width) { // disabling the index while doing this complex updates is about // 2 to 10 times faster! - setItemIndexMethod(QGraphicsScene::NoIndex); + //setItemIndexMethod(QGraphicsScene::NoIndex); QList::iterator lineIter = _lines.end(); QList::iterator lineIterBegin = _lines.begin(); @@ -312,7 +314,7 @@ void ChatScene::setWidth(qreal width) { lineIter--; (*lineIter)->setGeometryByWidth(width, contentsWidth, linePos); } - setItemIndexMethod(QGraphicsScene::BspTreeIndex); + //setItemIndexMethod(QGraphicsScene::BspTreeIndex); updateSceneRect(width); setHandleXLimits(); @@ -335,7 +337,7 @@ void ChatScene::firstHandlePositionChanged(qreal xpos) { // disabling the index while doing this complex updates is about // 2 to 10 times faster! - setItemIndexMethod(QGraphicsScene::NoIndex); + //setItemIndexMethod(QGraphicsScene::NoIndex); QList::iterator lineIter = _lines.end(); QList::iterator lineIterBegin = _lines.begin(); @@ -347,7 +349,7 @@ void ChatScene::firstHandlePositionChanged(qreal xpos) { lineIter--; (*lineIter)->setFirstColumn(timestampWidth, senderWidth, senderPos); } - setItemIndexMethod(QGraphicsScene::BspTreeIndex); + //setItemIndexMethod(QGraphicsScene::BspTreeIndex); setHandleXLimits(); @@ -369,7 +371,7 @@ void ChatScene::secondHandlePositionChanged(qreal xpos) { // disabling the index while doing this complex updates is about // 2 to 10 times faster! - setItemIndexMethod(QGraphicsScene::NoIndex); + //setItemIndexMethod(QGraphicsScene::NoIndex); QList::iterator lineIter = _lines.end(); QList::iterator lineIterBegin = _lines.begin(); @@ -381,7 +383,7 @@ void ChatScene::secondHandlePositionChanged(qreal xpos) { lineIter--; (*lineIter)->setSecondColumn(senderWidth, contentsWidth, contentsPos, linePos); } - setItemIndexMethod(QGraphicsScene::BspTreeIndex); + //setItemIndexMethod(QGraphicsScene::BspTreeIndex); setHandleXLimits(); diff --git a/src/uisupport/bufferview.cpp b/src/uisupport/bufferview.cpp index 5f33df45..11564b52 100644 --- a/src/uisupport/bufferview.cpp +++ b/src/uisupport/bufferview.cpp @@ -22,6 +22,7 @@ #include "buffermodel.h" #include "bufferviewfilter.h" +#include "buffersettings.h" #include "buffersyncer.h" #include "client.h" #include "iconloader.h" @@ -61,22 +62,15 @@ BufferView::BufferView(QWidget *parent) _hideJoinAction(tr("Join Events"), this), _hidePartAction(tr("Part Events"), this), - _hideKillAction(tr("Kill Events"), this), _hideQuitAction(tr("Quit Events"), this), _hideModeAction(tr("Mode Events"), this) { _hideJoinAction.setCheckable(true); _hidePartAction.setCheckable(true); - _hideKillAction.setCheckable(true); _hideQuitAction.setCheckable(true); _hideModeAction.setCheckable(true); - _hideJoinAction.setEnabled(false); - _hidePartAction.setEnabled(false); _ignoreListAction.setEnabled(false); - _hideKillAction.setEnabled(false); - _hideQuitAction.setEnabled(false); - _hideModeAction.setEnabled(false); showChannelList.setIcon(SmallIcon("format-list-unordered")); @@ -389,12 +383,16 @@ void BufferView::addSeparatorToMenu(QMenu &menu, const QModelIndex &index, ItemA } } -QMenu *BufferView::createHideEventsSubMenu(QMenu &menu) { - // QMenu *hideEventsMenu = new QMenu(tr("Hide Events"), &menu); +QMenu *BufferView::createHideEventsSubMenu(QMenu &menu, BufferId bufferId) { + int filter = BufferSettings(bufferId).messageFilter(); + _hideJoinAction.setChecked(filter & Message::Join); + _hidePartAction.setChecked(filter & Message::Part); + _hideQuitAction.setChecked(filter & Message::Quit); + _hideModeAction.setChecked(filter & Message::Mode); + QMenu *hideEventsMenu = menu.addMenu(tr("Hide Events")); hideEventsMenu->addAction(&_hideJoinAction); hideEventsMenu->addAction(&_hidePartAction); - hideEventsMenu->addAction(&_hideKillAction); hideEventsMenu->addAction(&_hideQuitAction); hideEventsMenu->addAction(&_hideModeAction); return hideEventsMenu; @@ -445,14 +443,14 @@ void BufferView::contextMenuEvent(QContextMenuEvent *event) { addItemToMenu(_hideBufferTemporarilyAction, contextMenu, (bool)config()); addItemToMenu(_hideBufferPermanentlyAction, contextMenu, (bool)config()); addItemToMenu(_removeBufferAction, contextMenu, index, InactiveState); - createHideEventsSubMenu(contextMenu); + createHideEventsSubMenu(contextMenu, bufferInfo.bufferId()); addItemToMenu(_ignoreListAction, contextMenu); break; case BufferInfo::QueryBuffer: addItemToMenu(_hideBufferTemporarilyAction, contextMenu, (bool)config()); addItemToMenu(_hideBufferPermanentlyAction, contextMenu, (bool)config()); addItemToMenu(_removeBufferAction, contextMenu); - createHideEventsSubMenu(contextMenu); + createHideEventsSubMenu(contextMenu, bufferInfo.bufferId()); break; default: addItemToMenu(_hideBufferTemporarilyAction, contextMenu, (bool)config()); @@ -526,6 +524,27 @@ void BufferView::contextMenuEvent(QContextMenuEvent *event) { return; } + if(result == & _hideJoinAction) { + BufferId bufferId = index.data(NetworkModel::BufferIdRole).value(); + BufferSettings(bufferId).filterMessage(Message::Join, _hideJoinAction.isChecked()); + return; + } + if(result == &_hidePartAction) { + BufferId bufferId = index.data(NetworkModel::BufferIdRole).value(); + BufferSettings(bufferId).filterMessage(Message::Part, _hidePartAction.isChecked()); + return; + } + if(result == &_hideQuitAction) { + BufferId bufferId = index.data(NetworkModel::BufferIdRole).value(); + BufferSettings(bufferId).filterMessage(Message::Quit, _hideQuitAction.isChecked()); + return; + } + if(result == &_hideModeAction) { + BufferId bufferId = index.data(NetworkModel::BufferIdRole).value(); + BufferSettings(bufferId).filterMessage(Message::Mode, _hideModeAction.isChecked()); + return; + } + } void BufferView::wheelEvent(QWheelEvent* event) { diff --git a/src/uisupport/bufferview.h b/src/uisupport/bufferview.h index 10059422..a8231d92 100644 --- a/src/uisupport/bufferview.h +++ b/src/uisupport/bufferview.h @@ -101,7 +101,6 @@ private: QAction _hideJoinAction; QAction _hidePartAction; - QAction _hideKillAction; QAction _hideQuitAction; QAction _hideModeAction; @@ -118,7 +117,7 @@ private: ItemActiveStates requiredActiveState = QFlags(ActiveState) | QFlags(InactiveState)); void addSeparatorToMenu(QMenu &menu, const QModelIndex &index, ItemActiveStates requiredActiveState = QFlags(ActiveState) | QFlags(InactiveState)); - QMenu *createHideEventsSubMenu(QMenu &menu); + QMenu *createHideEventsSubMenu(QMenu &menu, BufferId bufferId); }; Q_DECLARE_OPERATORS_FOR_FLAGS(BufferView::ItemActiveStates)