From 8343691a38f45c199e6dc06d3616a386eb52934f Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Wed, 11 Aug 2021 22:18:52 +0200 Subject: [PATCH] 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 --- profile-widget/divetextitem.cpp | 12 ++++++++++++ profile-widget/divetextitem.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/profile-widget/divetextitem.cpp b/profile-widget/divetextitem.cpp index fd52f68ba..5b955058a 100644 --- a/profile-widget/divetextitem.cpp +++ b/profile-widget/divetextitem.cpp @@ -75,6 +75,18 @@ QFont DiveTextItem::getFont(double dpr, double scale) 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() { if (internalText.isEmpty()) diff --git a/profile-widget/divetextitem.h b/profile-widget/divetextitem.h index 87815d0a6..5c86e462c 100644 --- a/profile-widget/divetextitem.h +++ b/profile-widget/divetextitem.h @@ -22,6 +22,8 @@ public: 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();