X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatscene.cpp;h=5ece1ff87f6dda1b6bdb46b6be7efa856046862d;hp=4dfd8138ab3f5249e852de081ec2688985f2c8db;hb=911f181e0e179eb51279c0880eb701a43163b8b5;hpb=ce26c3770b254362c7bd1e094ba8f8bf22133653 diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index 4dfd8138..5ece1ff8 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2014 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 * @@ -23,19 +23,22 @@ #include #include #include +#include #include #include #include #include #include -#ifdef HAVE_KDE +#ifdef HAVE_KDE4 # include #else # include #endif -#ifdef HAVE_WEBKIT +#ifdef HAVE_WEBENGINE +# include +#elif defined HAVE_WEBKIT # include #endif @@ -48,7 +51,6 @@ #include "clientbacklogmanager.h" #include "columnhandleitem.h" #include "contextmenuactionprovider.h" -#include "iconloader.h" #include "mainwin.h" #include "markerlineitem.h" #include "messagefilter.h" @@ -73,6 +75,7 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, qreal w _markerLineValid(false), _markerLineJumpPending(false), _cutoffMode(CutoffRight), + _alwaysBracketSender(false), _selectingItem(0), _selectionStart(-1), _isSelecting(false), @@ -122,13 +125,23 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, qreal w this, SLOT(rowsRemoved())); connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), SLOT(dataChanged(QModelIndex, QModelIndex))); -#ifdef HAVE_WEBKIT +#if defined HAVE_WEBKIT || defined HAVE_WEBENGINE webPreview.timer.setSingleShot(true); connect(&webPreview.timer, SIGNAL(timeout()), this, SLOT(webPreviewNextStep())); #endif _showWebPreview = defaultSettings.showWebPreview(); defaultSettings.notify("ShowWebPreview", this, SLOT(showWebPreviewChanged())); + _showSenderBrackets = defaultSettings.showSenderBrackets(); + defaultSettings.notify("ShowSenderBrackets", this, SLOT(showSenderBracketsChanged())); + + _useCustomTimestampFormat = defaultSettings.useCustomTimestampFormat(); + defaultSettings.notify("UseCustomTimestampFormat", this, SLOT(useCustomTimestampFormatChanged())); + + _timestampFormatString = defaultSettings.timestampFormatString(); + defaultSettings.notify("TimestampFormat", this, SLOT(timestampFormatStringChanged())); + updateTimestampHasBrackets(); + _clickTimer.setInterval(QApplication::doubleClickInterval()); _clickTimer.setSingleShot(true); connect(&_clickTimer, SIGNAL(timeout()), SLOT(clickTimeout())); @@ -651,7 +664,7 @@ void ChatScene::firstHandlePositionChanged(qreal xpos) QPointF senderPos(firstColumnHandle()->sceneRight(), 0); while (lineIter != lineIterBegin) { - lineIter--; + --lineIter; (*lineIter)->setFirstColumn(timestampWidth, senderWidth, senderPos); } //setItemIndexMethod(QGraphicsScene::BspTreeIndex); @@ -687,7 +700,7 @@ void ChatScene::secondHandlePositionChanged(qreal xpos) qreal contentsWidth = _sceneRect.width() - secondColumnHandle()->sceneRight(); QPointF contentsPos(secondColumnHandle()->sceneRight(), 0); while (lineIter != lineIterBegin) { - lineIter--; + --lineIter; (*lineIter)->setSecondColumn(senderWidth, contentsWidth, contentsPos, linePos); } //setItemIndexMethod(QGraphicsScene::BspTreeIndex); @@ -823,7 +836,7 @@ void ChatScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) // If we have text selected, insert the Copy Selection as first item if (isPosOverSelection(pos)) { QAction *sep = menu.insertSeparator(menu.actions().first()); - QAction *act = new Action(SmallIcon("edit-copy"), tr("Copy Selection"), &menu, this, + QAction *act = new Action(QIcon::fromTheme("edit-copy"), tr("Copy Selection"), &menu, this, SLOT(selectionToClipboard()), QKeySequence::Copy); menu.insertAction(sep, act); @@ -832,7 +845,8 @@ void ChatScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) searchSelectionText = searchSelectionText.left(_webSearchSelectionTextMaxVisible).append(QString::fromUtf8("…")); searchSelectionText = tr("Search '%1'").arg(searchSelectionText); - menu.addAction(SmallIcon("edit-find"), searchSelectionText, this, SLOT(webSearchOnSelection())); + QAction *webSearchAction = new Action(QIcon::fromTheme("edit-find"), searchSelectionText, &menu, this, SLOT(webSearchOnSelection())); + menu.insertAction(sep, webSearchAction); } if (QtUi::mainWindow()->menuBar()->isHidden()) @@ -1020,12 +1034,39 @@ QString ChatScene::selection() const return QString(); } QString result; + for (int l = start; l <= end; l++) { - if (_selectionMinCol == ChatLineModel::TimestampColumn) - result += _lines[l]->item(ChatLineModel::TimestampColumn)->data(MessageModel::DisplayRole).toString() + " "; - if (_selectionMinCol <= ChatLineModel::SenderColumn) - result += _lines[l]->item(ChatLineModel::SenderColumn)->data(MessageModel::DisplayRole).toString() + " "; - result += _lines[l]->item(ChatLineModel::ContentsColumn)->data(MessageModel::DisplayRole).toString() + "\n"; + if (_selectionMinCol == ChatLineModel::TimestampColumn) { + ChatItem *item = _lines[l]->item(ChatLineModel::TimestampColumn); + if (!_showSenderBrackets && !_timestampHasBrackets) { + // Only re-add brackets if the current timestamp format does not include them + // -and- sender brackets are disabled. Don't filter on Message::Plain as + // timestamp brackets affect all types of messages. + // Remove any spaces before and after, otherwise it may look weird. + result += QString("[%1] ").arg(item->data(MessageModel::DisplayRole) + .toString().trimmed()); + } else { + result += item->data(MessageModel::DisplayRole).toString() + " "; + } + } + if (_selectionMinCol <= ChatLineModel::SenderColumn) { + ChatItem *item = _lines[l]->item(ChatLineModel::SenderColumn); + if (!_showSenderBrackets && (_alwaysBracketSender + || item->chatLine()->msgType() == Message::Plain)) { + // Copying to plain-text. Re-add the sender brackets if they're normally hidden + // for... + // * Plain messages + // * All messages in the Chat Monitor + // + // The Chat Monitor sets alwaysBracketSender() to true. + result += QString("<%1> ").arg(item->data(MessageModel::DisplayRole) + .toString()); + } else { + result += item->data(MessageModel::DisplayRole).toString() + " "; + } + } + result += _lines[l]->item(ChatLineModel::ContentsColumn) + ->data(MessageModel::DisplayRole).toString() + "\n"; } return result; } @@ -1170,9 +1211,9 @@ void ChatScene::updateSceneRect(const QRectF &rect) // ======================================== -// Webkit Only stuff +// Webkit/WebEngine Only stuff // ======================================== -#ifdef HAVE_WEBKIT +#if defined HAVE_WEBKIT || defined HAVE_WEBENGINE void ChatScene::loadWebPreview(ChatItem *parentItem, const QUrl &url, const QRectF &urlRect) { if (!_showWebPreview) @@ -1254,7 +1295,8 @@ void ChatScene::webPreviewNextStep() qWarning() << "removing preview"; if (webPreview.previewItem && webPreview.previewItem->scene()) removeItem(webPreview.previewItem); - // Fall through to deletion! + // Fall through to deletion! + [[clang::fallthrough]]; case WebPreview::HidePreview: if (webPreview.previewItem) { delete webPreview.previewItem; @@ -1281,7 +1323,8 @@ void ChatScene::clearWebPreview(ChatItem *parentItem) if (webPreview.previewItem && webPreview.previewItem->scene()) removeItem(webPreview.previewItem); } - // fall through into to set hidden state + // fall through into to set hidden state + [[clang::fallthrough]]; case WebPreview::DelayPreview: // we're just loading, so haven't shown the preview yet. webPreview.previewState = WebPreview::HidePreview; @@ -1301,8 +1344,60 @@ void ChatScene::clearWebPreview(ChatItem *parentItem) // end of webkit only // ======================================== +// Local configuration caching void ChatScene::showWebPreviewChanged() { ChatViewSettings settings; _showWebPreview = settings.showWebPreview(); } + +void ChatScene::showSenderBracketsChanged() +{ + ChatViewSettings settings; + _showSenderBrackets = settings.showSenderBrackets(); +} + +void ChatScene::useCustomTimestampFormatChanged() +{ + ChatViewSettings settings; + _useCustomTimestampFormat = settings.useCustomTimestampFormat(); + updateTimestampHasBrackets(); +} + +void ChatScene::timestampFormatStringChanged() +{ + ChatViewSettings settings; + _timestampFormatString = settings.timestampFormatString(); + updateTimestampHasBrackets(); +} + +void ChatScene::updateTimestampHasBrackets() +{ + // Calculate these parameters only as needed, rather than on-demand + + if (!_useCustomTimestampFormat) { + // The default timestamp format string does not have brackets, no need to check. + // If UiStyle::updateSystemTimestampFormat() has brackets added, change this, too. + _timestampHasBrackets = false; + } else { + // Does the timestamp format contain brackets? For example: + // Classic: "[hh:mm:ss]" + // Modern: " hh:mm:ss" + // + // Match groups of any opening or closing brackets - (), {}, [], <>, (>, {], etc: + // ^\s*[({[<].+[)}\]>]\s*$ + // [...] is a character group containing ... + // ^ matches start of string + // \s* matches any amount of whitespace + // [({[<] matches (, {, [, or < + // .+ matches one or more characters + // [)}\]>] matches ), }, ], or >, escaping the ] + // $ matches end of string + // Alternatively, if opening and closing brackets must be in pairs, use this: + // (^\s*\(.+\)\s*$)|(^\s*\{.+\}\s*$)|(^\s*\[.+\]\s*$)|(^\s*<.+>\s*$) + // Note that '\' must be escaped as '\\' + // Helpful interactive website for debugging and explaining: https://regex101.com/ + const QRegExp regExpMatchBrackets("^\\s*[({[<].+[)}\\]>]\\s*$"); + _timestampHasBrackets = regExpMatchBrackets.exactMatch(_timestampFormatString); + } +}