From 0a9aea9900df14bf2c021d8bb7bfb4e5d9da45e2 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Mon, 13 Mar 2017 16:00:11 +0000 Subject: [PATCH] Hi-DPI Support - Workout Editor .. chart marker font still outstanding, but applies to all charts and will be fixed independently of this. --- src/Train/WorkoutWidget.cpp | 28 +++++++++++++++------------- src/Train/WorkoutWidgetItems.cpp | 24 ++++++++++++------------ src/Train/WorkoutWindow.cpp | 4 ++-- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/Train/WorkoutWidget.cpp b/src/Train/WorkoutWidget.cpp index 9ded5bdc6..742e78487 100644 --- a/src/Train/WorkoutWidget.cpp +++ b/src/Train/WorkoutWidget.cpp @@ -36,6 +36,8 @@ #include #include // DBL_EPSILON +#include "Colors.h" + static int MINTOOLHEIGHT = 350; // minimum size for a full editor static double MAXZOOM = 3.0f; @@ -48,16 +50,16 @@ void WorkoutWidget::adjustLayout() if (height() > MINTOOLHEIGHT) { // big, can edit and all widgets shown - IHEIGHT = 10; - THEIGHT = 35; - BHEIGHT = 35; - LWIDTH = 65; - RWIDTH = 35; - XTICLENGTH = 3; + IHEIGHT = 10 *dpiYFactor; + THEIGHT = 35 *dpiYFactor; + BHEIGHT = 35 *dpiYFactor; + LWIDTH = 65 *dpiXFactor; + RWIDTH = 35 *dpiXFactor; + XTICLENGTH = 3 *dpiYFactor; YTICLENGTH = 0; XTICS = 20; YTICS = 10; - SPACING = 2; // between labels and tics (if there are tics) + SPACING = 2 *dpiYFactor; // between labels and tics (if there are tics) XMOVE = 5; // how many to move X when cursoring YMOVE = 1; // how many to move Y when cursoring GRIDLINES = true; @@ -68,14 +70,14 @@ void WorkoutWidget::adjustLayout() // mini mode IHEIGHT = 0; THEIGHT = 0; - BHEIGHT = 20; - LWIDTH = 10; - RWIDTH = 10; - XTICLENGTH = 3; + BHEIGHT = 20 *dpiYFactor; + LWIDTH = 10 *dpiXFactor; + RWIDTH = 10 *dpiXFactor; + XTICLENGTH = 3 *dpiYFactor; YTICLENGTH = 0; XTICS = 20; YTICS = 5; - SPACING = 2; // between labels and tics (if there are tics) + SPACING = 2 * dpiXFactor; // between labels and tics (if there are tics) XMOVE = 5; // how many to move X when cursoring YMOVE = 1; // how many to move Y when cursoring GRIDLINES = false; @@ -2190,7 +2192,7 @@ WorkoutWidget::configChanged(qint32) markerFont.setPointSize(appsettings->value(NULL, GC_FONT_CHARTLABELS_SIZE, 8).toInt()); bigFont = markerFont; - bigFont.setPointSize(markerFont.pointSize() * 2); + bigFont.setPixelSize(pixelSizeForFont(bigFont, 24 * dpiYFactor)); bigFont.setWeight(QFont::Bold); repaint(); diff --git a/src/Train/WorkoutWidgetItems.cpp b/src/Train/WorkoutWidgetItems.cpp index 930a69003..66dadd388 100644 --- a/src/Train/WorkoutWidgetItems.cpp +++ b/src/Train/WorkoutWidgetItems.cpp @@ -24,10 +24,10 @@ #include -static int POWERSCALEWIDTH = 5; -static int WBALSCALEWIDTH = 5; +#define POWERSCALEWIDTH (5 *dpiXFactor) +#define WBALSCALEWIDTH (5 *dpiXFactor) static bool GRIDLINES = true; -static int SPACING = 4; +#define SPACING (4 *dpiXFactor) static int MINTOOLHEIGHT = 350; // don't do lots of decoration on "mini" view @@ -291,7 +291,7 @@ WWPoint::paint(QPainter *painter) // highlight hovered if (hover) { painter->setBrush(Qt::gray); - painter->drawEllipse(QPointF(center.x(), center.y()), 10.0f, 10.0f); + painter->drawEllipse(QPointF(center.x(), center.y()), 10.0f*dpiXFactor, 10.0f*dpiXFactor); } // selected! @@ -299,17 +299,17 @@ WWPoint::paint(QPainter *painter) // selected change color painter->setBrush(Qt::red); - painter->drawEllipse(QPointF(center.x(), center.y()), 3.0f, 3.0f); + painter->drawEllipse(QPointF(center.x(), center.y()), 3.0f*dpiXFactor, 3.0f*dpiXFactor); } else { // draw point painter->setBrush(GColor(CPOWER)); - painter->drawEllipse(QPointF(center.x(), center.y()), 3.0f, 3.0f); + painter->drawEllipse(QPointF(center.x(), center.y()), 3.0f*dpiXFactor, 3.0f*dpiXFactor); } // set bound so we can be moused over etc - bound = QRectF(QPointF(center.x()-3.0f, center.y()-3.0f),QPointF(center.x()+3.0f, center.y()+3.0f)); + bound = QRectF(QPointF(center.x()-(3.0f*dpiXFactor), center.y()-(3.0f*dpiXFactor)),QPointF(center.x()+(3.0f*dpiXFactor), center.y()+(3.0f*dpiXFactor))); } void @@ -317,7 +317,7 @@ WWLine::paint(QPainter *painter) { // thin ? QPen linePen(workoutWidget()->recording() ? GColor(CTPOWER) : GColor(CPOWER)); - linePen.setWidth(1); + linePen.setWidth(1 *dpiXFactor); painter->setPen(linePen); QPoint origin = workoutWidget()->transform(0,0); @@ -396,7 +396,7 @@ WWTelemetry::paint(QPainter *painter) // full color QColor color = GColor(CWBAL); QPen wlinePen(color); - wlinePen.setWidth(1); + wlinePen.setWidth(1 *dpiXFactor); painter->setPen(wlinePen); // top left origin @@ -442,7 +442,7 @@ WWRect::paint(QPainter *painter) // thin ? QPen linePen(GColor(CPLOTMARKER)); - linePen.setWidth(1); + linePen.setWidth(1 *dpiXFactor); painter->setPen(linePen); painter->drawRect(QRectF(onRect,atRect)); @@ -551,7 +551,7 @@ WWWBLine::paint(QPainter *painter) // set pen QPen linePen(color); - linePen.setWidth(1); + linePen.setWidth(1 *dpiXFactor); painter->setPen(linePen); // top left origin @@ -830,7 +830,7 @@ WWNow::paint(QPainter *painter) int px = workoutWidget()->transform(context->getNow()/1000.0f,0).x(); QPen linePen(GColor(CPLOTMARKER)); - linePen.setWidthF(2); + linePen.setWidthF(2 *dpiXFactor); painter->setPen(linePen); // horizontal bar diff --git a/src/Train/WorkoutWindow.cpp b/src/Train/WorkoutWindow.cpp index 5655f3449..6009a8307 100644 --- a/src/Train/WorkoutWindow.cpp +++ b/src/Train/WorkoutWindow.cpp @@ -87,7 +87,7 @@ WorkoutWindow::WorkoutWindow(Context *context) : toolbar = new QToolBar(this); toolbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); toolbar->setFloatable(true); - toolbar->setIconSize(QSize(18,18)); + toolbar->setIconSize(QSize(18 *dpiXFactor,18 *dpiYFactor)); QIcon newIcon(":images/toolbar/new doc.png"); newAct = new QAction(newIcon, tr("New"), this); @@ -271,7 +271,7 @@ WorkoutWindow::configChanged(qint32) // maximum of 20 characters per line ? QFont f; QFontMetrics ff(f); - code->setFixedWidth(ff.boundingRect("99x999s@999-999r999s@999-999").width()+20); + code->setFixedWidth(ff.boundingRect("99x999s@999-999r999s@999-999").width()+(20* dpiXFactor)); // text edit colors QPalette palette;