From 4676123eef4ea6e89635404438d698e4e50c7bdb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Thu, 9 Oct 2014 21:11:32 +0200 Subject: [PATCH] Draw numeric cues on axes with the same font as value labels and do not draw cues that would overflow --- signaldrawer.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/signaldrawer.cpp b/signaldrawer.cpp index 91f334e..013088d 100644 --- a/signaldrawer.cpp +++ b/signaldrawer.cpp @@ -22,7 +22,7 @@ #include "logger.h" #include "signaldrawer.h" - +#include #include const QString SignalDrawer::ME_SENDER_STR("SignalDrawer"); @@ -220,6 +220,7 @@ bool SignalDrawer::drawScale(const SignalController::Axis axis, QPixmap* const t } p.begin(target); + p.setFont(m_axisLabelFont); switch (axis) { case SignalController::Axis::TIME: relMin = m_relXMin; relMax = m_relXMax; @@ -269,13 +270,24 @@ bool SignalDrawer::drawScale(const SignalController::Axis axis, QPixmap* const t void SignalDrawer::renderTimeScaleText(QPainter* const p, const double rel, const double value) { const int xPix = relToXPix(rel); + const QString text = m_locale.toString(value, 'f', 3); + /* Do not draw labels that would overflow */ + QRect br = p->fontMetrics().boundingRect(text); + if (xPix + br.width() > m_gWidth) + return; p->drawText(xPix + 2, m_gHeight + 15, m_locale.toString(value, 'f', 3)); } void SignalDrawer::renderValueScaleText(QPainter* const p, const double rel, const double value) { const int yPix = relToYPix(rel); + const QString text = m_locale.toString(value, 'f', 2); + + /* Do not draw labels that would overflow */ + QRect br = p->fontMetrics().boundingRect(text); + if (yPix - br.height() < 0) + return; p->drawText(1, yPix + 5, m_locale.toString(value, 'f', 2)); } -- 2.43.5