From: Joel Holdsworth Date: Mon, 24 Nov 2014 23:45:17 +0000 (+0000) Subject: RowItemParams: Added font and text_height X-Git-Tag: pulseview-0.3.0~399 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=9ab27c433c838bd604d77e4ee54f16415f85ab7c RowItemParams: Added font and text_height --- diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index 0b129c3b..0b4cd7c5 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -160,9 +160,7 @@ pair DecodeTrace::v_extents() const { /// @todo Replace this with an implementation that knows the true /// height of the trace - QFontMetrics m(QApplication::font()); - const int text_height = m.boundingRect(QRect(), 0, "Tg").height(); - const int row_height = (text_height * 6) / 4; + const int row_height = (RowItemPaintParams::text_height() * 6) / 4; return make_pair(-row_height / 2, row_height * 7 / 2); } @@ -176,8 +174,7 @@ void DecodeTrace::paint_mid(QPainter &p, const RowItemPaintParams &pp) { using namespace pv::data::decode; - QFontMetrics m(QApplication::font()); - text_height_ = m.boundingRect(QRect(), 0, "Tg").height(); + text_height_ = RowItemPaintParams::text_height(); row_height_ = (text_height_ * 6) / 4; const int annotation_height = (text_height_ * 5) / 4; diff --git a/pv/view/rowitempaintparams.cpp b/pv/view/rowitempaintparams.cpp index af5f675a..c46d715b 100644 --- a/pv/view/rowitempaintparams.cpp +++ b/pv/view/rowitempaintparams.cpp @@ -20,6 +20,9 @@ #include +#include +#include + #include "rowitempaintparams.hpp" namespace pv { @@ -35,5 +38,15 @@ RowItemPaintParams::RowItemPaintParams( assert(scale > 0.0); } +QFont RowItemPaintParams::font() +{ + return QApplication::font(); +} + +int RowItemPaintParams::text_height() { + QFontMetrics m(font()); + return m.boundingRect(QRect(), 0, "Tg").height(); +} + } // namespace view } // namespace pv diff --git a/pv/view/rowitempaintparams.hpp b/pv/view/rowitempaintparams.hpp index 5c71edcb..ec66076b 100644 --- a/pv/view/rowitempaintparams.hpp +++ b/pv/view/rowitempaintparams.hpp @@ -21,6 +21,8 @@ #ifndef PULSEVIEW_PV_VIEW_ROWITEMPAINTPARAMS_H #define PULSEVIEW_PV_VIEW_ROWITEMPAINTPARAMS_H +#include + namespace pv { namespace view { @@ -53,6 +55,11 @@ public: return offset_ / scale_; } +public: + static QFont font(); + + static int text_height(); + private: int left_; int right_;