summaryrefslogtreecommitdiff
path: root/widgets/displaytext.cpp
diff options
context:
space:
mode:
authorChristoph Berg <christoph.berg@credativ.de>2020-06-10 12:34:51 +0200
committerChristoph Berg <christoph.berg@credativ.de>2020-06-10 12:34:51 +0200
commit400776e1b7e1992e26c95e2ca79eada65b53aca6 (patch)
tree899589883a2c9be2264af0505039e93594a11bda /widgets/displaytext.cpp
parentbb8622557f9a325e9a925834a5487a32584d0675 (diff)
parentee0e1a654b7e64accea78a5aa66ec1e62bd352c8 (diff)
Update upstream source from tag 'upstream/2.2.1+repack'
Update to upstream version '2.2.1+repack' with Debian dir c0f0555345d2c71b60736c230e3b91e85d74b675
Diffstat (limited to 'widgets/displaytext.cpp')
-rw-r--r--widgets/displaytext.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/widgets/displaytext.cpp b/widgets/displaytext.cpp
index ae865bc9..f0f17f64 100644
--- a/widgets/displaytext.cpp
+++ b/widgets/displaytext.cpp
@@ -13,7 +13,6 @@
#include <QListIterator>
#include <QRegularExpression>
#include <QScrollBar>
-#include <QDebug>
#include "Configuration.hpp"
#include "Network/LotWUsers.hpp"
@@ -126,8 +125,6 @@ namespace
void DisplayText::appendText(QString const& text, QColor bg, QColor fg
, QString const& call1, QString const& call2)
{
-// qDebug () << "DisplayText::appendText: text:" << text << "Nbsp pos:" << text.indexOf (QChar::Nbsp);
-
auto cursor = textCursor ();
cursor.movePosition (QTextCursor::End);
auto block_format = cursor.blockFormat ();
@@ -548,12 +545,18 @@ namespace
void DisplayText::highlight_callsign (QString const& callsign, QColor const& bg,
QColor const& fg, bool last_period_only)
{
- // qDebug () << "DisplayText::highlight_callsign: callsign:" << callsign << "last period:" << last_period_only;
if (!callsign.size ())
{
return;
}
- QRegularExpression target {QString {"<?"} + callsign + QString {">?"}, QRegularExpression::DontCaptureOption};
+ auto regexp = callsign;
+ // allow for hashed callsigns and escape any regexp metacharacters
+ QRegularExpression target {QString {"<?"}
+ + regexp.replace (QLatin1Char {'+'}, QLatin1String {"\\+"})
+ .replace (QLatin1Char {'.'}, QLatin1String {"\\."})
+ .replace (QLatin1Char {'?'}, QLatin1String {"\\?"})
+ + QString {">?"}
+ , QRegularExpression::DontCaptureOption};
QTextCharFormat old_format {currentCharFormat ()};
QTextCursor cursor {document ()};
if (last_period_only)
@@ -568,10 +571,10 @@ void DisplayText::highlight_callsign (QString const& callsign, QColor const& bg,
{
period_start = prior;
}
- while (!cursor.isNull () && cursor > period_start)
+ cursor = period_start;
+ while (!cursor.isNull ())
{
- cursor = document ()->find (target, cursor
- , QTextDocument::FindBackward | QTextDocument::FindWholeWords);
+ cursor = document ()->find (target, cursor, QTextDocument::FindWholeWords);
if (!cursor.isNull () && cursor.hasSelection ())
{
if (bg.isValid () || fg.isValid ())