Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Overview add units to metric cards
.. only if non-blank and not units of time since the time
   format indicates units
  • Loading branch information
liversedge committed Feb 10, 2017
1 parent f9f466a commit d12e03f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/Charts/OverviewWindow.cpp
Expand Up @@ -144,21 +144,45 @@ Card::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) {
painter->drawText(QPointF(ROWHEIGHT /2.0f, QFontMetrics(titlefont, parent->device()).height()), name);

if (type == METRIC) {

// we need the metric units
if (metric == NULL) {
// get the metric details
RideMetricFactory &factory = RideMetricFactory::instance();
metric = const_cast<RideMetric*>(factory.rideMetric(settings.symbol));
if (metric) units = metric->units(parent->context->athlete->useMetricUnits);
}

// paint the value in the middle using a font 2xROWHEIGHT
QFont bigfont;
bigfont.setPointSize(ROWHEIGHT*2);
painter->setPen(GColor(CPLOTMARKER));
painter->setFont(bigfont);

// mid is slightly higher to account for space around title
double mid = (ROWHEIGHT*1.5f) + ((geometry().height() - (ROWHEIGHT*2)) / 2.0f);
QFont smallfont;
smallfont.setPointSize(ROWHEIGHT*0.6f);

double addy = 0;
if (units != "" && units != tr("seconds")) addy = QFontMetrics(smallfont).height();

// mid is slightly higher to account for space around title, move mid up
double mid = (ROWHEIGHT*1.5f) + ((geometry().height() - (ROWHEIGHT*2)) / 2.0f) - (addy/2);

// we align centre and mid
QFontMetrics fm(bigfont);
QRectF rect = QFontMetrics(bigfont, parent->device()).boundingRect(value);

painter->drawText(QPointF((geometry().width() - rect.width()) / 2.0f,
mid + (fm.ascent() / 3.0f)), value); // divided by 3 to account for "gap" at top of font

// now units
if (addy > 0) {
painter->setPen(QColor(100,100,100));
painter->setFont(smallfont);

painter->drawText(QPointF((geometry().width() - QFontMetrics(smallfont).width(units)) / 2.0f,
mid + (fm.ascent() / 3.0f) + addy), units); // divided by 3 to account for "gap" at top of font
}
}
}

Expand Down Expand Up @@ -747,7 +771,7 @@ OverviewWindow::eventFilter(QObject *, QEvent *event)
int setdeep = stateData.yresize.deep + addrows;

//min height
if (setdeep < 7) setdeep=7; // min of 5 rows
if (setdeep < 6) setdeep=6; // min of 6 rows

stateData.yresize.card->deep = setdeep;

Expand Down
3 changes: 3 additions & 0 deletions src/Charts/OverviewWindow.h
Expand Up @@ -26,6 +26,7 @@
#include "Colors.h"
#include "Context.h"
#include "RideItem.h"
#include "RideMetric.h"

// QGraphics
#include <QGraphicsScene>
Expand Down Expand Up @@ -73,6 +74,7 @@ class Card : public QGraphicsWidget

// a sensible default?
type = NONE;
metric = NULL;
}

void setData(RideItem *item);
Expand All @@ -81,6 +83,7 @@ class Card : public QGraphicsWidget
enum cardType { NONE, METRIC, META, SERIES, ZONE } type;
typedef enum cardType CardType;
QString value, units;
RideMetric *metric;

// settings
struct {
Expand Down

0 comments on commit d12e03f

Please sign in to comment.