mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Add simple tooltip system
This commit is contained in:
parent
47a1911df9
commit
4b36893818
5 changed files with 41 additions and 14 deletions
|
@ -78,7 +78,8 @@ void EmoteManager::reloadBTTVChannelEmotes(const QString &channelName, std::weak
|
||||||
link = link.replace("{{id}}", id).replace("{{image}}", "1x");
|
link = link.replace("{{id}}", id).replace("{{image}}", "1x");
|
||||||
|
|
||||||
auto emote = this->getBTTVChannelEmoteFromCaches().getOrAdd(id, [this, &code, &link] {
|
auto emote = this->getBTTVChannelEmoteFromCaches().getOrAdd(id, [this, &code, &link] {
|
||||||
return EmoteData(new LazyLoadedImage(link, 1, code, code + "\nChannel BTTV Emote"));
|
return EmoteData(
|
||||||
|
new LazyLoadedImage(link, 1, code, code + "<br/>Channel BTTV Emote"));
|
||||||
});
|
});
|
||||||
|
|
||||||
this->bttvChannelEmotes.insert(code, emote);
|
this->bttvChannelEmotes.insert(code, emote);
|
||||||
|
@ -127,7 +128,7 @@ void EmoteManager::reloadFFZChannelEmotes(const QString &channelName, std::weak_
|
||||||
auto emote =
|
auto emote =
|
||||||
this->getFFZChannelEmoteFromCaches().getOrAdd(id, [this, &code, &url1] {
|
this->getFFZChannelEmoteFromCaches().getOrAdd(id, [this, &code, &url1] {
|
||||||
return EmoteData(
|
return EmoteData(
|
||||||
new LazyLoadedImage(url1, 1, code, code + "\nGlobal FFZ Emote"));
|
new LazyLoadedImage(url1, 1, code, code + "<br/>Global FFZ Emote"));
|
||||||
});
|
});
|
||||||
|
|
||||||
this->ffzChannelEmotes.insert(code, emote);
|
this->ffzChannelEmotes.insert(code, emote);
|
||||||
|
@ -222,7 +223,7 @@ void EmoteManager::loadEmojis()
|
||||||
code + ".png";
|
code + ".png";
|
||||||
|
|
||||||
this->emojis.insert(code, EmoteData(new LazyLoadedImage(url, 0.35, ":" + shortCode + ":",
|
this->emojis.insert(code, EmoteData(new LazyLoadedImage(url, 0.35, ":" + shortCode + ":",
|
||||||
":" + shortCode + ":")));
|
":" + shortCode + ":<br/>Emoji")));
|
||||||
|
|
||||||
// TODO(pajlada): The vectors in emojiFirstByte need to be sorted by
|
// TODO(pajlada): The vectors in emojiFirstByte need to be sorted by
|
||||||
// emojiData.code.length()
|
// emojiData.code.length()
|
||||||
|
@ -430,7 +431,7 @@ void EmoteManager::loadBTTVEmotes()
|
||||||
QString url = tmp.replace("{{id}}", id).replace("{{image}}", "1x");
|
QString url = tmp.replace("{{id}}", id).replace("{{image}}", "1x");
|
||||||
|
|
||||||
this->bttvGlobalEmotes.insert(
|
this->bttvGlobalEmotes.insert(
|
||||||
code, new LazyLoadedImage(url, 1, code, code + "\nGlobal BTTV Emote"));
|
code, new LazyLoadedImage(url, 1, code, code + "<br/>Global BTTV Emote"));
|
||||||
codes.push_back(code.toStdString());
|
codes.push_back(code.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -475,7 +476,7 @@ void EmoteManager::loadFFZEmotes()
|
||||||
QString url1 = "http:" + urls.value("1").toString();
|
QString url1 = "http:" + urls.value("1").toString();
|
||||||
|
|
||||||
this->ffzGlobalEmotes.insert(
|
this->ffzGlobalEmotes.insert(
|
||||||
code, new LazyLoadedImage(url1, 1, code, code + "\nGlobal FFZ Emote"));
|
code, new LazyLoadedImage(url1, 1, code, code + "<br/>Global FFZ Emote"));
|
||||||
codes.push_back(code.toStdString());
|
codes.push_back(code.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -495,7 +496,7 @@ EmoteData EmoteManager::getTwitchEmoteById(long id, const QString &emoteName)
|
||||||
return _twitchEmoteFromCache.getOrAdd(id, [this, &emoteName, &id] {
|
return _twitchEmoteFromCache.getOrAdd(id, [this, &emoteName, &id] {
|
||||||
qreal scale;
|
qreal scale;
|
||||||
QString url = getTwitchEmoteLink(id, scale);
|
QString url = getTwitchEmoteLink(id, scale);
|
||||||
return new LazyLoadedImage(url, scale, emoteName, emoteName + "\nTwitch Emote");
|
return new LazyLoadedImage(url, scale, emoteName, emoteName + "<br/>Twitch Emote");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ Message *Message::createSystemMessage(const QString &text)
|
||||||
|
|
||||||
AddCurrentTimestamp(message);
|
AddCurrentTimestamp(message);
|
||||||
|
|
||||||
Word word(text, Word::Type::Default, MessageColor(MessageColor::Type::System), text, text);
|
Word word(text, Word::Type::Default, MessageColor(MessageColor::Type::System), text, QString());
|
||||||
|
|
||||||
message->getWords().push_back(word);
|
message->getWords().push_back(word);
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ Message *Message::createTimeoutMessage(const QString &username, const QString &d
|
||||||
}
|
}
|
||||||
text.append(".");
|
text.append(".");
|
||||||
|
|
||||||
Word word(text, Word::Type::Default, MessageColor(MessageColor::Type::System), text, text);
|
Word word(text, Word::Type::Default, MessageColor(MessageColor::Type::System), text, QString());
|
||||||
|
|
||||||
message->getWords().push_back(word);
|
message->getWords().push_back(word);
|
||||||
|
|
||||||
|
|
|
@ -93,9 +93,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit Word(LazyLoadedImage *_image, Type getType, const QString ©text,
|
explicit Word(LazyLoadedImage *_image, Type getType, const QString ©text,
|
||||||
const QString &getTooltip, const Link &getLink = Link());
|
const QString &tooltip, const Link &getLink = Link());
|
||||||
explicit Word(const QString &_text, Type getType, const MessageColor &getColor,
|
explicit Word(const QString &_text, Type getType, const MessageColor &getColor,
|
||||||
const QString ©text, const QString &getTooltip, const Link &getLink = Link());
|
const QString ©text, const QString &tooltip, const Link &getLink = Link());
|
||||||
|
|
||||||
LazyLoadedImage &getImage() const;
|
LazyLoadedImage &getImage() const;
|
||||||
const QString &getText() const;
|
const QString &getText() const;
|
||||||
|
|
|
@ -225,12 +225,10 @@ SharedMessage TwitchMessageBuilder::parse()
|
||||||
|
|
||||||
this->appendWord(Word(string, Word::Text, textColor, string, QString(), link));
|
this->appendWord(Word(string, Word::Text, textColor, string, QString(), link));
|
||||||
} else { // is emoji
|
} else { // is emoji
|
||||||
static QString emojiTooltip("Emoji");
|
|
||||||
|
|
||||||
this->appendWord(Word(emoteData.image, Word::EmojiImage, emoteData.image->getName(),
|
this->appendWord(Word(emoteData.image, Word::EmojiImage, emoteData.image->getName(),
|
||||||
emojiTooltip));
|
emoteData.image->getTooltip()));
|
||||||
Word(emoteData.image->getName(), Word::EmojiText, textColor,
|
Word(emoteData.image->getName(), Word::EmojiText, textColor,
|
||||||
emoteData.image->getName(), emojiTooltip);
|
emoteData.image->getName(), emoteData.image->getTooltip());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QGraphicsBlurEffect>
|
#include <QGraphicsBlurEffect>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QToolTip>
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -748,13 +749,40 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
|
||||||
this->repaint();
|
this->repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QTimer *tooltipTimer = new QTimer();
|
||||||
|
|
||||||
// check if word underneath cursor
|
// check if word underneath cursor
|
||||||
const messages::Word *hoverWord;
|
const messages::Word *hoverWord;
|
||||||
if ((hoverWord = message->tryGetWordPart(relativePos)) == nullptr) {
|
if ((hoverWord = message->tryGetWordPart(relativePos)) == nullptr) {
|
||||||
this->setCursor(Qt::ArrowCursor);
|
this->setCursor(Qt::ArrowCursor);
|
||||||
|
tooltipTimer->stop();
|
||||||
|
QToolTip::hideText();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto &tooltip = hoverWord->getTooltip();
|
||||||
|
|
||||||
|
static QString targetTooltip;
|
||||||
|
static QPoint tooltipPos;
|
||||||
|
connect(tooltipTimer, &QTimer::timeout, []() {
|
||||||
|
assert(!targetTooltip.isEmpty());
|
||||||
|
QToolTip::showText(tooltipPos, targetTooltip); //
|
||||||
|
});
|
||||||
|
|
||||||
|
tooltipTimer->setSingleShot(true);
|
||||||
|
tooltipTimer->setInterval(500);
|
||||||
|
|
||||||
|
if (!tooltip.isEmpty()) {
|
||||||
|
tooltipPos = event->globalPos();
|
||||||
|
targetTooltip = "<style>.center { text-align: center; }</style>"
|
||||||
|
"<p class = \"center\">" +
|
||||||
|
tooltip + "</p>";
|
||||||
|
tooltipTimer->start();
|
||||||
|
} else {
|
||||||
|
tooltipTimer->stop();
|
||||||
|
QToolTip::hideText();
|
||||||
|
}
|
||||||
|
|
||||||
// check if word has a link
|
// check if word has a link
|
||||||
if (hoverWord->getLink().isValid()) {
|
if (hoverWord->getLink().isValid()) {
|
||||||
this->setCursor(Qt::PointingHandCursor);
|
this->setCursor(Qt::PointingHandCursor);
|
||||||
|
|
Loading…
Reference in a new issue