mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
2ebe6e3684
Alignment and scale of DiveTextItems are never changed. Therefore, pass them at construction time. This makes things much easier if we want to cache the rendered text [currently the text is rerendered at every paint() event]. This also removes the "parent=0" default parameter of the constructor, because inadvertently leaving out the last argument led to a subtle bug. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
36 lines
997 B
C++
36 lines
997 B
C++
// SPDX-License-Identifier: GPL-2.0
|
|
#ifndef DIVETEXTITEM_H
|
|
#define DIVETEXTITEM_H
|
|
|
|
#include <QObject>
|
|
#include <QFont>
|
|
#include <QGraphicsItemGroup>
|
|
|
|
class QBrush;
|
|
|
|
/* A Line Item that has animated-properties. */
|
|
class DiveTextItem : public QObject, public QGraphicsItemGroup {
|
|
Q_OBJECT
|
|
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
|
|
Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
|
|
public:
|
|
DiveTextItem(double dpr, double scale, int alignFlags, QGraphicsItem *parent);
|
|
void setText(const QString &text);
|
|
void setBrush(const QBrush &brush);
|
|
const QString &text();
|
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
|
static QFont getFont(double dpr, double scale);
|
|
static double fontHeight(double dpr, double scale);
|
|
double height() const;
|
|
|
|
private:
|
|
void updateText();
|
|
int internalAlignFlags;
|
|
QGraphicsPathItem *textBackgroundItem;
|
|
QGraphicsPathItem *textItem;
|
|
QString internalText;
|
|
double dpr;
|
|
double scale;
|
|
};
|
|
|
|
#endif // DIVETEXTITEM_H
|