profile: implement animation of the tooltip item

To do so, generalize the animation routine.

This seems to expose a QtQuick bug: we get spurious
hover-events when the tooltip item is updated in the
animation. We have to check for that to prevent
en endless loop (until the user moves the mouse out
of the profile window).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2023-07-06 16:08:19 +02:00
parent 06b0a7eeae
commit d0c26f42d7
6 changed files with 120 additions and 34 deletions

View file

@ -36,10 +36,10 @@ static QFont makeFont(double dpr)
}
ToolTipItem::ToolTipItem(ChartView &view, double dpr) :
ChartRectItem(view, ProfileZValue::ToolTipItem,
QPen(tooltipBorderColor, tooltipBorder),
QBrush(tooltipColor), tooltipBorderRadius,
true),
AnimatedChartRectItem(view, ProfileZValue::ToolTipItem,
QPen(tooltipBorderColor, tooltipBorder),
QBrush(tooltipColor), tooltipBorderRadius,
true),
font(makeFont(dpr)),
fm(font),
fontHeight(fm.height())
@ -100,7 +100,7 @@ static QPixmap drawTissues(const plot_info &pInfo, double dpr, int idx, bool inP
}
void ToolTipItem::update(const dive *d, double dpr, int time, const plot_info &pInfo,
const std::vector<std::pair<QString, QPixmap>> &events, bool inPlanner)
const std::vector<std::pair<QString, QPixmap>> &events, bool inPlanner, int animSpeed)
{
auto [idx, lines] = get_plot_details_new(d, pInfo, time);
@ -135,31 +135,35 @@ void ToolTipItem::update(const dive *d, double dpr, int time, const plot_info &p
height = std::max(height, static_cast<double>(tissues.height()));
height += 4.0 * tooltipBorder + title.height();
ChartRectItem::resize(QSizeF(width, height));
painter->setFont(font);
painter->setPen(QPen(tooltipFontColor)); // QPainter uses QPen to set text color!
QPixmap pixmap(lrint(width), lrint(height));
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
painter.setFont(font);
painter.setPen(QPen(tooltipFontColor)); // QPainter uses QPen to set text color!
double x = 4.0 * tooltipBorder + tissues.width();
double y = 2.0 * tooltipBorder;
double titleOffset = (width - title.width()) / 2.0;
painter->drawPixmap(lrint(titleOffset), lrint(y), title, 0, 0, title.width(), title.height());
painter.drawPixmap(lrint(titleOffset), lrint(y), title, 0, 0, title.width(), title.height());
y += round(fontHeight);
painter->drawPixmap(lrint(2.0 * tooltipBorder), lrint(y), tissues, 0, 0, tissues.width(), tissues.height());
painter.drawPixmap(lrint(2.0 * tooltipBorder), lrint(y), tissues, 0, 0, tissues.width(), tissues.height());
y += round(fontHeight);
for (auto &[s,w]: strings) {
QRectF rect(x, y, w, fontHeight);
painter->drawText(rect, s);
painter.drawText(rect, s);
y += fontHeight;
}
for (size_t i = 0; i < events.size(); ++i) {
QSizeF size = event_sizes[i];
auto &[s, pixmap] = events[i];
painter->drawPixmap(lrint(x), lrint(y + (size.height() - pixmap.height())/2.0), pixmap,
0, 0, pixmap.width(), pixmap.height());
painter.drawPixmap(lrint(x), lrint(y + (size.height() - pixmap.height())/2.0), pixmap,
0, 0, pixmap.width(), pixmap.height());
QRectF rect(x + pixmap.width(), round(y + (size.height() - fontHeight) / 2.0), size.width(), fontHeight);
painter->drawText(rect, s);
painter.drawText(rect, s);
y += size.height();
}
setTextureDirty();
AnimatedChartRectItem::setPixmap(pixmap, animSpeed);
}
void ToolTipItem::stopDrag(QPointF pos)