subsurface/profile-widget/divetextitem.h
Berthold Stoeger 322e2baa8d profile: calculate maximum label sizes on construction
Instead of calculating the label sizes of the axes when
relayouting the chart, calculate them at construction time.

To do so, pass the digits before and after the decimal comma
to the constructor.

This is not so much an optimization thing, but rather an
first stab at more general label rendering. Time, of course,
will always be an exception. But hopefully the remaining
values can be done more generally.

Note that currently this code is a total mess. For example,
the labels for the temperature axes are not converted to
F if needed. And therefore also not shown. This will need
some major rethinking.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00

35 lines
1.1 KiB
C++

// SPDX-License-Identifier: GPL-2.0
#ifndef DIVETEXTITEM_H
#define DIVETEXTITEM_H
#include <QObject>
#include <QFont>
#include <QGraphicsPixmapItem>
class QBrush;
/* A Line Item that has animated-properties. */
class DiveTextItem : public QObject, public QGraphicsPixmapItem {
Q_OBJECT
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
public:
// Note: vertical centring is based on the actual rendered text, not on the font metrics.
// This is fine for placing text in the "tankbar", but it will look disastrous when
// placing text items next to each other. This may have to be fixed.
DiveTextItem(double dpr, double scale, int alignFlags, QGraphicsItem *parent);
void set(const QString &text, const QBrush &brush);
const QString &text();
static QFont getFont(double dpr, double scale);
static double fontHeight(double dpr, double scale);
static double outlineSpace(double dpr); // Additional space needed by outline
double height() const;
private:
int internalAlignFlags;
QString internalText;
double dpr;
double scale;
};
#endif // DIVETEXTITEM_H