summaryrefslogtreecommitdiffhomepage
path: root/spline/spline-widget.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2019-06-25 21:04:53 +0200
committerStanislaw Halik <sthalik@misaki.pl>2019-06-25 21:04:53 +0200
commitf166d006330c788c8706c93d3290eff6265cde58 (patch)
tree627ff129532d71116fa21ae670062868309d3d3e /spline/spline-widget.cpp
parent0b7de47259713acef2682755cc79263883741bf1 (diff)
spline: fix text going out of bounds
Diffstat (limited to 'spline/spline-widget.cpp')
-rw-r--r--spline/spline-widget.cpp27
1 files changed, 11 insertions, 16 deletions
diff --git a/spline/spline-widget.cpp b/spline/spline-widget.cpp
index 363720c8..8f8bdfb4 100644
--- a/spline/spline-widget.cpp
+++ b/spline/spline-widget.cpp
@@ -96,7 +96,6 @@ void spline_widget::drawBackground()
font.setStyleHint(QFont::Monospace, QFont::PreferAntialias);
painter.setFont(font);
const QFontMetricsF metrics(font);
- const double height = metrics.height();
QColor color__(176, 190, 209, 127);
@@ -109,6 +108,8 @@ void spline_widget::drawBackground()
const double maxx = config->max_input();
const double maxy = config->max_output();
+ const double space_width = metrics.horizontalAdvance(' ');
+
// vertical grid
for (int i = 0; i <= maxy; i += ystep)
{
@@ -117,11 +118,11 @@ void spline_widget::drawBackground()
QPointF(pixel_bounds.x(), y),
QPointF(pixel_bounds.x() + pixel_bounds.width(), y),
pen);
- painter.drawText(QRectF(10,
- y - height/2,
- pixel_bounds.left(),
- height),
- QString::number(i));
+ QString text = QString::number(i);
+ QRectF rect = metrics.boundingRect(text);
+ painter.drawText(QPointF(pixel_bounds.x() - metrics.horizontalAdvance(text) - space_width,
+ y - rect.height()/2 - rect.top()),
+ text);
}
// horizontal grid
@@ -135,16 +136,10 @@ void spline_widget::drawBackground()
const QString text = QString::number(i);
- const double width =
-#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
- metrics.horizontalAdvance(text);
-#else
- metrics.width(text);
-#endif
+ QRectF rect = metrics.boundingRect(text);
- painter.drawText(QRectF{x - width/2,
- pixel_bounds.height() + 10 + height,
- width, height},
+ painter.drawText(QPointF(x - rect.width()/2 - rect.left(),
+ pixel_bounds.height() - rect.top() + rect.height() + metrics.descent()/4),
text);
}
}
@@ -188,7 +183,7 @@ void spline_widget::drawFunction()
}
);
- painter.setPen(QPen(color_, 1.75, Qt::SolidLine, Qt::FlatCap));
+ painter.setPen(QPen(color_, 2, Qt::SolidLine, Qt::FlatCap));
const double dpr = devicePixelRatioF();
const double line_length_pixels = std::fmax(1, 2 * dpr);