From e1364f2bd2aea6915a25c1b74402185982bfab13 Mon Sep 17 00:00:00 2001 From: fourtf Date: Sat, 5 Aug 2017 18:44:14 +0200 Subject: [PATCH] gave links color --- src/colorscheme.cpp | 1 + src/messages/messagebuilder.cpp | 13 +++++++++---- src/messages/messagebuilder.hpp | 2 +- src/twitch/twitchmessagebuilder.cpp | 14 +++++++++++--- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/colorscheme.cpp b/src/colorscheme.cpp index b049598eb..0c295f765 100644 --- a/src/colorscheme.cpp +++ b/src/colorscheme.cpp @@ -66,6 +66,7 @@ void ColorScheme::setColors(double hue, double multiplier) DropPreviewBackground = getColor(hue, 0.5, 0.5, 0.6); Text = TextCaret = lightTheme ? QColor(0, 0, 0) : QColor(255, 255, 255); + TextLink = lightTheme ? QColor(66, 134, 244) : QColor(66, 134, 244); // tab if (hasDarkBorder) { diff --git a/src/messages/messagebuilder.cpp b/src/messages/messagebuilder.cpp index 07ebebb7a..59912e811 100644 --- a/src/messages/messagebuilder.cpp +++ b/src/messages/messagebuilder.cpp @@ -10,8 +10,8 @@ MessageBuilder::MessageBuilder() : _words() { _parseTime = std::chrono::system_clock::now(); - regex.setPattern("[[:ascii:]]*\\.[A-Z]+\\/?[[:ascii:]]*"); - regex.setPatternOptions(QRegularExpression::CaseInsensitiveOption); + + linkRegex.setPattern("[[:ascii:]]*\\.[a-zA-Z]+\\/?[[:ascii:]]*"); } SharedMessage MessageBuilder::build() @@ -59,10 +59,15 @@ void MessageBuilder::appendTimestamp(time_t time) QString MessageBuilder::matchLink(const QString &string) { - auto match = regex.match(string); + auto match = linkRegex.match(string); + + if (!match.hasMatch()) { + return QString(); + } + QString captured = match.captured(); - if (!captured.contains(QRegularExpression("\\bhttps?:\/\/")) && match.hasMatch()) { + if (!captured.contains(QRegularExpression("\\bhttps?://"))) { captured.insert(0, "http://"); } return captured; diff --git a/src/messages/messagebuilder.hpp b/src/messages/messagebuilder.hpp index 86f2494ae..70c93cf2d 100644 --- a/src/messages/messagebuilder.hpp +++ b/src/messages/messagebuilder.hpp @@ -22,7 +22,7 @@ public: void setHighlight(const bool &value); QString matchLink(const QString &string); - QRegularExpression regex; + QRegularExpression linkRegex; QString originalMessage; diff --git a/src/twitch/twitchmessagebuilder.cpp b/src/twitch/twitchmessagebuilder.cpp index d2224eb86..08bb6c49d 100644 --- a/src/twitch/twitchmessagebuilder.cpp +++ b/src/twitch/twitchmessagebuilder.cpp @@ -204,10 +204,18 @@ SharedMessage TwitchMessageBuilder::parse() } // Actually just text - QString link = this->matchLink(string); + QString linkString = this->matchLink(string); - this->appendWord(Word(string, Word::Text, textColor, string, QString(), - link.isEmpty() ? Link() : Link(Link::Url, link))); + Link link; + + if (linkString.isEmpty()) { + link = Link(); + } else { + link = Link(Link::Url, linkString); + textColor = this->colorScheme.TextLink; + } + + this->appendWord(Word(string, Word::Text, textColor, string, QString(), link)); } else { // is emoji static QString emojiTooltip("Emoji");