profile: add DiveCartesianAxis::height()

This is needed to properly layout the axes.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-08-28 14:25:04 +02:00 committed by Dirk Hohndel
parent 15f20961c7
commit abadbb6783
2 changed files with 12 additions and 3 deletions

View file

@ -8,7 +8,8 @@
#include "profile-widget/divelineitem.h" #include "profile-widget/divelineitem.h"
#include "profile-widget/profilescene.h" #include "profile-widget/profilescene.h"
static const double labelSpace = 2.0; // space between label and ticks static const double labelSpaceHorizontal = 2.0; // space between label and ticks
static const double labelSpaceVertical = 2.0; // space between label and ticks
QPen DiveCartesianAxis::gridPen() const QPen DiveCartesianAxis::gridPen() const
{ {
@ -123,7 +124,7 @@ double DiveCartesianAxis::textWidth(const QString &s) const
{ {
QFont fnt = DiveTextItem::getFont(dpr, labelScale); QFont fnt = DiveTextItem::getFont(dpr, labelScale);
QFontMetrics fm(fnt); QFontMetrics fm(fnt);
return fm.size(Qt::TextSingleLine, s).width() + labelSpace * dpr; return fm.size(Qt::TextSingleLine, s).width() + labelSpaceHorizontal * dpr;
} }
double DiveCartesianAxis::width() const double DiveCartesianAxis::width() const
@ -131,6 +132,13 @@ double DiveCartesianAxis::width() const
return textWidth("999"); return textWidth("999");
} }
double DiveCartesianAxis::height() const
{
QFont fnt = DiveTextItem::getFont(dpr, labelScale);
QFontMetrics fm(fnt);
return fm.height() + labelSpaceVertical * dpr;
}
void DiveCartesianAxis::updateTicks(int animSpeed, color_index_t color) void DiveCartesianAxis::updateTicks(int animSpeed, color_index_t color)
{ {
if (!changed && !printMode) if (!changed && !printMode)

View file

@ -49,7 +49,8 @@ public:
void setLineSize(qreal lineSize); void setLineSize(qreal lineSize);
void setLine(const QLineF& line); void setLine(const QLineF& line);
virtual void updateTicks(int animSpeed, color_index_t color = TIME_GRID); virtual void updateTicks(int animSpeed, color_index_t color = TIME_GRID);
double width() const; double width() const; // only for vertical axes
double height() const; // only for horizontal axes
signals: signals:
void sizeChanged(); void sizeChanged();