ChatMonitorFilter::ChatMonitorFilter(MessageModel *model, QObject *parent)
: MessageFilter(model, parent)
{
+ QtUiSettings qtUiSettings;
+ QString showFieldSettingId = QString("ChatView/%1/showFields").arg(idString());
+ QString showOwnMessagesSettingId = QString("ChatView/%1/showOwnMsgs").arg(idString());
+
+ _showFields = qtUiSettings.value(showFieldSettingId, AllFields).toInt();
+ _showOwnMessages = qtUiSettings.value(showOwnMessagesSettingId, true).toBool();
+ qtUiSettings.notify(showFieldSettingId, this, SLOT(showFieldsSettingsChanged(const QVariant &)));
+ qtUiSettings.notify(showOwnMessagesSettingId, this, SLOT(showOwnMessagesSettingChanged(const QVariant &)));
}
bool ChatMonitorFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const {
Q_UNUSED(sourceParent)
Message::Flags flags = (Message::Flags)sourceModel()->data(sourceModel()->index(sourceRow, 0), MessageModel::FlagsRole).toInt();
- if(flags & Message::Backlog || flags & Message::Self)
+ if(flags & Message::Backlog || (!_showOwnMessages && flags & Message::Self))
return false;
Message::Type type = (Message::Type)sourceModel()->data(sourceModel()->index(sourceRow, 0), MessageModel::TypeRole).toInt();
if(index.column() != ChatLineModel::SenderColumn || role != ChatLineModel::DisplayRole)
return MessageFilter::data(index, role);
- int showFields_ = showFields();
-
BufferId bufid = data(index, ChatLineModel::BufferIdRole).value<BufferId>();
if(!bufid.isValid()) {
qDebug() << "ChatMonitorFilter::data(): chatline belongs to an invalid buffer!";
QModelIndex source_index = mapToSource(index);
QStringList fields;
- if(showFields_ & NetworkField) {
+ if(_showFields & NetworkField) {
fields << Client::networkModel()->networkName(bufid);
}
- if(showFields_ & BufferField) {
+ if(_showFields & BufferField) {
fields << Client::networkModel()->bufferName(bufid);
}
}
void ChatMonitorFilter::addShowField(int field) {
- QtUiSettings s;
- int fields = s.value(showFieldSettingId(), AllFields).toInt();
- if(fields & field)
+ if(_showFields & field)
return;
- fields |= field;
- s.setValue(showFieldSettingId(), fields);
- showFieldSettingsChanged();
+ QtUiSettings().setValue(QString("ChatView/%1/showFields").arg(idString()), _showFields | field);
}
void ChatMonitorFilter::removeShowField(int field) {
- QtUiSettings s;
- int fields = s.value(showFieldSettingId(), AllFields).toInt();
- if(!(fields & field))
+ if(!(_showFields & field))
+ return;
+
+ QtUiSettings().setValue(QString("ChatView/%1/showFields").arg(idString()), _showFields ^ field);
+}
+
+void ChatMonitorFilter::setShowOwnMessages(bool show) {
+ if(_showOwnMessages == show)
return;
- fields ^= field;
- s.setValue(showFieldSettingId(), fields);
- showFieldSettingsChanged();
+ QtUiSettings().setValue(QString("ChatView/%1/showOwnMsgs").arg(idString()), show);
}
-void ChatMonitorFilter::showFieldSettingsChanged() {
+void ChatMonitorFilter::showFieldsSettingsChanged(const QVariant &newValue) {
+ int newFields = newValue.toInt();
+ if(_showFields == newFields)
+ return;
+
+ _showFields = newFields;
+
int rows = rowCount();
if(rows == 0)
return;
emit dataChanged(index(0, ChatLineModel::SenderColumn), index(rows - 1, ChatLineModel::SenderColumn));
}
+void ChatMonitorFilter::showOwnMessagesSettingChanged(const QVariant &newValue) {
+ _showOwnMessages = newValue.toBool();
+}
virtual QString idString() const { return "ChatMonitor"; }
virtual QVariant data(const QModelIndex &index, int role) const;
- inline QString showFieldSettingId() const { return QString("ChatView/%1/showFields").arg(idString()); }
- inline int showFields() const { return QtUiSettings().value(showFieldSettingId(), AllFields).toInt(); }
+ int showFields() const { return _showFields; }
+ bool showOwnMessages() const { return _showOwnMessages; }
+
+public slots:
void addShowField(int field);
void removeShowField(int field);
+ void setShowOwnMessages(bool show);
-private:
+private slots:
+ void showFieldsSettingsChanged(const QVariant &newValue);
+ void showOwnMessagesSettingChanged(const QVariant &newValue);
- void showFieldSettingsChanged();
+private:
+ int _showFields;
+ bool _showOwnMessages;
};
#endif
}
void ChatMonitorView::contextMenuEvent(QContextMenuEvent *event) {
- if(scene()->sectionByScenePos(event->pos()) != ChatLineModel::SenderColumn)
- return;
-
- int showFields = _filter->showFields();
-
QMenu contextMenu(this);
- QAction *showNetworkAction = contextMenu.addAction(tr("Show network name"), this, SLOT(showFieldsChanged(bool)));
- showNetworkAction->setCheckable(true);
- showNetworkAction->setChecked(showFields & ChatMonitorFilter::NetworkField);
- showNetworkAction->setData(ChatMonitorFilter::NetworkField);
-
- QAction *showBufferAction = contextMenu.addAction(tr("Show buffer name"), this, SLOT(showFieldsChanged(bool)));
- showBufferAction->setCheckable(true);
- showBufferAction->setChecked(showFields & ChatMonitorFilter::BufferField);
- showBufferAction->setData(ChatMonitorFilter::BufferField);
+
+ QAction *showOwnNicksAction = contextMenu.addAction(tr("Show own messages"), _filter, SLOT(setShowOwnMessages(bool)));
+ showOwnNicksAction->setCheckable(true);
+ showOwnNicksAction->setChecked(_filter->showOwnMessages());
+
+ if(scene()->sectionByScenePos(event->pos()) == ChatLineModel::SenderColumn) {
+ contextMenu.addSeparator();
+
+ QAction *showNetworkAction = contextMenu.addAction(tr("Show network name"), this, SLOT(showFieldsChanged(bool)));
+ showNetworkAction->setCheckable(true);
+ showNetworkAction->setChecked(_filter->showFields() & ChatMonitorFilter::NetworkField);
+ showNetworkAction->setData(ChatMonitorFilter::NetworkField);
+
+ QAction *showBufferAction = contextMenu.addAction(tr("Show buffer name"), this, SLOT(showFieldsChanged(bool)));
+ showBufferAction->setCheckable(true);
+ showBufferAction->setChecked(_filter->showFields() & ChatMonitorFilter::BufferField);
+ showBufferAction->setData(ChatMonitorFilter::BufferField);
+ }
contextMenu.exec(QCursor::pos());
}