X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fqtui%2Fchatscene.cpp;h=1588f4df5c9b0cf13eba50a599e7043133aa1b75;hb=106526817f753cdd680c783fc58968d5111d16eb;hp=96546261d818117b412bdd6e395824a65f5fac80;hpb=b82e9603ab7ce1164e8f550132f0c649653ad8ab;p=quassel.git diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index 96546261..1588f4df 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -75,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), @@ -134,6 +135,13 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, qreal w _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())); @@ -1026,14 +1034,31 @@ 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::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 && item->chatLine()->msgType() == Message::Plain) { - // Copying to plain-text. Only re-add the sender brackets if they're normally - // hidden. + 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 { @@ -1271,6 +1296,7 @@ void ChatScene::webPreviewNextStep() if (webPreview.previewItem && webPreview.previewItem->scene()) removeItem(webPreview.previewItem); // Fall through to deletion! + [[fallthrough]]; case WebPreview::HidePreview: if (webPreview.previewItem) { delete webPreview.previewItem; @@ -1298,6 +1324,7 @@ void ChatScene::clearWebPreview(ChatItem *parentItem) removeItem(webPreview.previewItem); } // fall through into to set hidden state + [[fallthrough]]; case WebPreview::DelayPreview: // we're just loading, so haven't shown the preview yet. webPreview.previewState = WebPreview::HidePreview; @@ -1329,3 +1356,48 @@ 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); + } +}