gave links color

This commit is contained in:
fourtf 2017-08-05 18:44:14 +02:00
parent c8ce55a54e
commit e1364f2bd2
4 changed files with 22 additions and 8 deletions

View file

@ -66,6 +66,7 @@ void ColorScheme::setColors(double hue, double multiplier)
DropPreviewBackground = getColor(hue, 0.5, 0.5, 0.6); DropPreviewBackground = getColor(hue, 0.5, 0.5, 0.6);
Text = TextCaret = lightTheme ? QColor(0, 0, 0) : QColor(255, 255, 255); Text = TextCaret = lightTheme ? QColor(0, 0, 0) : QColor(255, 255, 255);
TextLink = lightTheme ? QColor(66, 134, 244) : QColor(66, 134, 244);
// tab // tab
if (hasDarkBorder) { if (hasDarkBorder) {

View file

@ -10,8 +10,8 @@ MessageBuilder::MessageBuilder()
: _words() : _words()
{ {
_parseTime = std::chrono::system_clock::now(); _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() SharedMessage MessageBuilder::build()
@ -59,10 +59,15 @@ void MessageBuilder::appendTimestamp(time_t time)
QString MessageBuilder::matchLink(const QString &string) 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(); QString captured = match.captured();
if (!captured.contains(QRegularExpression("\\bhttps?:\/\/")) && match.hasMatch()) { if (!captured.contains(QRegularExpression("\\bhttps?://"))) {
captured.insert(0, "http://"); captured.insert(0, "http://");
} }
return captured; return captured;

View file

@ -22,7 +22,7 @@ public:
void setHighlight(const bool &value); void setHighlight(const bool &value);
QString matchLink(const QString &string); QString matchLink(const QString &string);
QRegularExpression regex; QRegularExpression linkRegex;
QString originalMessage; QString originalMessage;

View file

@ -204,10 +204,18 @@ SharedMessage TwitchMessageBuilder::parse()
} }
// Actually just text // Actually just text
QString link = this->matchLink(string); QString linkString = this->matchLink(string);
this->appendWord(Word(string, Word::Text, textColor, string, QString(), Link link;
link.isEmpty() ? Link() : Link(Link::Url, 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 } else { // is emoji
static QString emojiTooltip("Emoji"); static QString emojiTooltip("Emoji");