X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatmonitorview.cpp;h=07facb59ae072ffd793c31d3dec1db1d0f010225;hp=6b9fe601382744a373d4f92330ff01349b16f88e;hb=f9efdde7f3a6004af8f834c409cfa6ae1d877692;hpb=9d52e49424afb60c2f28073051c1dbf25f47adec diff --git a/src/qtui/chatmonitorview.cpp b/src/qtui/chatmonitorview.cpp index 6b9fe601..07facb59 100644 --- a/src/qtui/chatmonitorview.cpp +++ b/src/qtui/chatmonitorview.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "chatmonitorview.h" @@ -24,44 +24,109 @@ #include #include +#include "action.h" +#include "buffermodel.h" #include "chatmonitorfilter.h" #include "chatlinemodel.h" +#include "chatitem.h" #include "chatscene.h" +#include "client.h" +#include "clientignorelistmanager.h" +#include "icon.h" +#include "networkmodel.h" +#include "messagemodel.h" #include "qtuisettings.h" +#include "settingspagedlg.h" +#include "settingspages/chatmonitorsettingspage.h" ChatMonitorView::ChatMonitorView(ChatMonitorFilter *filter, QWidget *parent) - : ChatView(filter, parent), + : ChatView(filter, parent), _filter(filter) { + scene()->setSenderCutoffMode(ChatScene::CutoffLeft); + // The normal message prefixes get replaced by the network and buffer name. Re-add brackets for + // all message types. + scene()->setAlwaysBracketSender(true); + connect(Client::instance(), &Client::coreConnectionStateChanged, this, &ChatMonitorView::coreConnectionStateChanged); } -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); - - contextMenu.exec(QCursor::pos()); + +void ChatMonitorView::addActionsToMenu(QMenu *menu, const QPointF &pos) +{ + ChatView::addActionsToMenu(menu, pos); + menu->addSeparator(); + auto showOwnNicksAction = new Action(tr("Show Own Messages"), menu, _filter, &ChatMonitorFilter::setShowOwnMessages); + showOwnNicksAction->setCheckable(true); + showOwnNicksAction->setChecked(_filter->showOwnMessages()); + menu->addAction(showOwnNicksAction); + + if (scene()->columnByScenePos(pos) == ChatLineModel::SenderColumn) { + menu->addSeparator(); + + auto showNetworkAction = new Action(tr("Show Network Name"), menu, this, &ChatMonitorView::showFieldsChanged); + showNetworkAction->setCheckable(true); + showNetworkAction->setChecked(_filter->showFields() & ChatMonitorFilter::NetworkField); + showNetworkAction->setData(ChatMonitorFilter::NetworkField); + menu->addAction(showNetworkAction); + + auto showBufferAction = new Action(tr("Show Buffer Name"), menu, this, &ChatMonitorView::showFieldsChanged); + showBufferAction->setCheckable(true); + showBufferAction->setChecked(_filter->showFields() & ChatMonitorFilter::BufferField); + showBufferAction->setData(ChatMonitorFilter::BufferField); + menu->addAction(showBufferAction); + } + + menu->addSeparator(); + menu->addAction(new Action(icon::get("configure"), tr("Configure..."), menu, this, &ChatMonitorView::showSettingsPage)); } -void ChatMonitorView::showFieldsChanged(bool checked) { - QAction *showAction = qobject_cast(sender()); - if(!showAction) - return; - if(checked) - _filter->addShowField(showAction->data().toInt()); - else - _filter->removeShowField(showAction->data().toInt()); +void ChatMonitorView::mouseDoubleClickEvent(QMouseEvent *event) +{ + if (scene()->columnByScenePos(event->pos()) != ChatLineModel::SenderColumn) { + ChatView::mouseDoubleClickEvent(event); + return; + } + + ChatItem *chatItem = scene()->chatItemAt(mapToScene(event->pos())); + if (!chatItem) { + event->ignore(); + return; + } + + event->accept(); + BufferId bufferId = chatItem->data(MessageModel::BufferIdRole).value(); + if (!bufferId.isValid()) + return; + + Client::bufferModel()->switchToBuffer(bufferId); +} + + +void ChatMonitorView::showFieldsChanged(bool checked) +{ + auto *showAction = qobject_cast(sender()); + if (!showAction) + return; + + if (checked) + _filter->addShowField(showAction->data().toInt()); + else + _filter->removeShowField(showAction->data().toInt()); +} + + +void ChatMonitorView::showSettingsPage() +{ + SettingsPageDlg dlg(new ChatMonitorSettingsPage(), this); + dlg.exec(); +} + + +// connect only after client is synced to core since ChatMonitorView is created before +// the ignoreListManager +void ChatMonitorView::coreConnectionStateChanged(bool connected) +{ + if (connected) + connect(Client::ignoreListManager(), &ClientIgnoreListManager::ignoreListChanged, _filter, &ChatMonitorFilter::invalidateFilter); }