mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
profile: show events in ToolTipItem
Reimplement a feature that was lost when porting the ToolTipOtem to QtQuick. This is a bit of a longer commit, because the icon of the event is now drawn explicitly, instead of using HTML. This encompasses a UI change: the icon is now the icon shown on the profile and not a general "warning" icon. This commit also fixes update of the tooltip when panning the profile. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
c6eeeb7d28
commit
06b0a7eeae
8 changed files with 105 additions and 91 deletions
|
@ -99,19 +99,13 @@ static QPixmap drawTissues(const plot_info &pInfo, double dpr, int idx, bool inP
|
|||
return tissues.scaled(new_width, new_height);
|
||||
}
|
||||
|
||||
void ToolTipItem::update(const dive *d, double dpr, int time, const plot_info &pInfo, bool inPlanner)
|
||||
void ToolTipItem::update(const dive *d, double dpr, int time, const plot_info &pInfo,
|
||||
const std::vector<std::pair<QString, QPixmap>> &events, bool inPlanner)
|
||||
{
|
||||
auto [idx, lines] = get_plot_details_new(d, pInfo, time);
|
||||
|
||||
QPixmap tissues = drawTissues(pInfo, dpr, idx, inPlanner);
|
||||
|
||||
//TODO: add event tool tips!
|
||||
//const auto l = scene()->items(pos, Qt::IntersectsItemBoundingRect, Qt::DescendingOrder,
|
||||
//scene()->views().first()->transform());
|
||||
//for (QGraphicsItem *item: l) {
|
||||
//if (!item->toolTip().isEmpty())
|
||||
//addToolTip(item->toolTip(), QPixmap());
|
||||
//}
|
||||
std::vector<QSizeF> event_sizes;
|
||||
|
||||
width = title.size().width();
|
||||
|
||||
|
@ -125,12 +119,21 @@ void ToolTipItem::update(const dive *d, double dpr, int time, const plot_info &p
|
|||
strings.push_back(std::make_pair(s, w));
|
||||
}
|
||||
|
||||
height = (static_cast<double>(strings.size()) + 1.0) * fontHeight;
|
||||
|
||||
for (auto &[s, pixmap]: events) {
|
||||
double text_width = fm.size(Qt::TextSingleLine, s).width();
|
||||
double total_width = pixmap.width() + text_width;
|
||||
double h = std::max(static_cast<double>(pixmap.height()), fontHeight);
|
||||
width = std::max(width, total_width);
|
||||
height += h;
|
||||
event_sizes.emplace_back(text_width, h);
|
||||
}
|
||||
|
||||
width += tissues.width();
|
||||
width += 6.0 * tooltipBorder;
|
||||
|
||||
height = 4.0 * tooltipBorder + title.height() +
|
||||
std::max((static_cast<double>(strings.size()) + 1.0) * fontHeight,
|
||||
static_cast<double>(tissues.height()));
|
||||
height = std::max(height, static_cast<double>(tissues.height()));
|
||||
height += 4.0 * tooltipBorder + title.height();
|
||||
|
||||
ChartRectItem::resize(QSizeF(width, height));
|
||||
painter->setFont(font);
|
||||
|
@ -147,6 +150,15 @@ void ToolTipItem::update(const dive *d, double dpr, int time, const plot_info &p
|
|||
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());
|
||||
QRectF rect(x + pixmap.width(), round(y + (size.height() - fontHeight) / 2.0), size.width(), fontHeight);
|
||||
painter->drawText(rect, s);
|
||||
y += size.height();
|
||||
}
|
||||
setTextureDirty();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue