Add simple tooltip system
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include <QDesktopServices>
|
||||
#include <QGraphicsBlurEffect>
|
||||
#include <QPainter>
|
||||
#include <QToolTip>
|
||||
|
||||
#include <math.h>
|
||||
#include <algorithm>
|
||||
@@ -748,13 +749,40 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
|
||||
this->repaint();
|
||||
}
|
||||
|
||||
static QTimer *tooltipTimer = new QTimer();
|
||||
|
||||
// check if word underneath cursor
|
||||
const messages::Word *hoverWord;
|
||||
if ((hoverWord = message->tryGetWordPart(relativePos)) == nullptr) {
|
||||
this->setCursor(Qt::ArrowCursor);
|
||||
tooltipTimer->stop();
|
||||
QToolTip::hideText();
|
||||
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
|
||||
if (hoverWord->getLink().isValid()) {
|
||||
this->setCursor(Qt::PointingHandCursor);
|
||||
|
||||
Reference in New Issue
Block a user