profile: add height() member function to DiveTextItem

To layout the profile we need to determine the height
of texts. Add versions for a DiveTextItem and a static
function, which is passed the scale and dpr. The latter
is used to setup items, where we do not necessarily
have a text at creation time (e.g. the tankbar).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-08-11 22:18:52 +02:00 committed by Dirk Hohndel
parent 7dd9b65df0
commit 8343691a38
2 changed files with 14 additions and 0 deletions

View file

@ -75,6 +75,18 @@ QFont DiveTextItem::getFont(double dpr, double scale)
return fnt; return fnt;
} }
double DiveTextItem::fontHeight(double dpr, double scale)
{
QFont fnt = getFont(dpr, scale);
QFontMetrics fm(fnt);
return (double)fm.height();
}
double DiveTextItem::height() const
{
return fontHeight(dpr, scale);
}
void DiveTextItem::updateText() void DiveTextItem::updateText()
{ {
if (internalText.isEmpty()) if (internalText.isEmpty())

View file

@ -22,6 +22,8 @@ public:
const QString &text(); const QString &text();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
static QFont getFont(double dpr, double scale); static QFont getFont(double dpr, double scale);
static double fontHeight(double dpr, double scale);
double height() const;
private: private:
void updateText(); void updateText();