profile: convert the "ruler item" to qt-quick

Code is mostly based on the "tooltip item". The dragging code was
slightly reworked to be more logical. A "disk item" was added for
the handles.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-01-12 22:26:32 +01:00
parent b167e130a4
commit ea0085fef6
14 changed files with 313 additions and 228 deletions

View file

@ -11,7 +11,6 @@
#include <cmath>
#include <QApplication>
#include <QFontMetrics>
static const int tooltipBorder = 2;
static const double tooltipBorderRadius = 4.0; // Radius of rounded corners
@ -37,8 +36,8 @@ static QFont makeFont(double dpr)
ToolTipItem::ToolTipItem(ChartView &view, double dpr) :
AnimatedChartRectItem(view, ProfileZValue::ToolTipItem,
QPen(tooltipBorderColor, tooltipBorder),
QBrush(tooltipColor), tooltipBorderRadius,
QPen(tooltipBorderColor, lrint(tooltipBorder * dpr)),
QBrush(tooltipColor), tooltipBorderRadius * dpr,
true),
font(makeFont(dpr)),
fm(font),
@ -131,9 +130,9 @@ void ToolTipItem::update(const dive *d, double dpr, int time, const plot_info &p
}
width += tissues.width();
width += 6.0 * tooltipBorder;
width += 6.0 * tooltipBorder * dpr;
height = std::max(height, static_cast<double>(tissues.height()));
height += 4.0 * tooltipBorder + title.height();
height += 4.0 * tooltipBorder * dpr + title.height();
QPixmap pixmap(lrint(width), lrint(height));
pixmap.fill(Qt::transparent);
@ -141,12 +140,12 @@ void ToolTipItem::update(const dive *d, double dpr, int time, const plot_info &p
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 x = 4.0 * tooltipBorder * dpr + tissues.width();
double y = 2.0 * tooltipBorder * dpr;
double titleOffset = (width - title.width()) / 2.0;
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 * dpr), lrint(y), tissues, 0, 0, tissues.width(), tissues.height());
y += round(fontHeight);
for (auto &[s,w]: strings) {
QRectF rect(x, y, w, fontHeight);