From f2d47c457408ec7f727c436911769561a0d404e2 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Sat, 22 Oct 2011 16:53:51 +0100 Subject: [PATCH] Realtime honours color settings Updated the realtime plots and dials to use the colour settings from the ride plot. So if you prefer plots of light colours on dark backgrounds you can do this now. The use of colour on the telemetry values makes it easier to distinguish which value related to power et al .. especially when you're pushing out that last max power interval. --- src/DialWindow.cpp | 53 ++++++++++++++++++++++++++++++++++++++ src/DialWindow.h | 6 +++++ src/GoldenCheetah.cpp | 6 ++++- src/RealtimePlot.cpp | 23 ++++++++++++++++- src/RealtimePlot.h | 2 ++ src/RealtimePlotWindow.cpp | 1 + src/RealtimePlotWindow.h | 3 +++ src/VideoWindow.cpp | 1 + 8 files changed, 93 insertions(+), 2 deletions(-) diff --git a/src/DialWindow.cpp b/src/DialWindow.cpp index 7ec6326aa..e99264197 100644 --- a/src/DialWindow.cpp +++ b/src/DialWindow.cpp @@ -38,6 +38,7 @@ DialWindow::DialWindow(MainWindow *mainWindow) : // data series selection QLabel *seriesLabel = new QLabel(tr("Data Series"), this); + seriesLabel->setAutoFillBackground(true); seriesSelector = new QComboBox(this); foreach (RealtimeData::DataSeries x, RealtimeData::listDataSeries()) { seriesSelector->addItem(RealtimeData::seriesName(x), static_cast(x)); @@ -52,6 +53,11 @@ DialWindow::DialWindow(MainWindow *mainWindow) : // get updates.. connect(mainWindow, SIGNAL(telemetryUpdate(RealtimeData)), this, SLOT(telemetryUpdate(RealtimeData))); + connect(seriesSelector, SIGNAL(currentIndexChanged(int)), this, SLOT(seriesChanged())); + connect(mainWindow, SIGNAL(configChanged()), this, SLOT(seriesChanged())); + + // setup colors + seriesChanged(); // setup fontsize etc resizeEvent(NULL); @@ -123,3 +129,50 @@ void DialWindow::resizeEvent(QResizeEvent * ) font.setWeight(QFont::Bold); valueLabel->setFont(font); } + +void DialWindow::seriesChanged() +{ + // we got some! + RealtimeData::DataSeries series = static_cast + (seriesSelector->itemData(seriesSelector->currentIndex()).toInt()); + + // the series selector changed so update the colors + switch(series) { + + case RealtimeData::Time: + case RealtimeData::LapTime: + case RealtimeData::Distance: + case RealtimeData::Lap: + case RealtimeData::Load: + case RealtimeData::None: + foreground = GColor(CPLOTMARKER); + break; + + case RealtimeData::XPower: + case RealtimeData::Joules: + case RealtimeData::BikeScore: + case RealtimeData::Watts: + foreground = GColor(CPOWER); + break; + + case RealtimeData::Speed: + foreground = GColor(CSPEED); + break; + + case RealtimeData::Cadence: + foreground = GColor(CCADENCE); + break; + + case RealtimeData::HeartRate: + foreground = GColor(CHEARTRATE); + break; + } + + // ugh. we use style sheets becuase palettes don't work on labels + background = GColor(CRIDEPLOTBACKGROUND); + setProperty("color", background); + QString sh = QString("QLabel { background: %1; color: %2; }") + .arg(background.name()) + .arg(foreground.name()); + valueLabel->setStyleSheet(sh); +} diff --git a/src/DialWindow.h b/src/DialWindow.h index e3f04f747..615a15f32 100644 --- a/src/DialWindow.h +++ b/src/DialWindow.h @@ -28,6 +28,9 @@ #include "RideFile.h" // for data series types #include "RealtimeData.h" // for realtimedata structure +#include "Settings.h" // for realtimedata structure +#include "Colors.h" // for realtimedata structure + class DialWindow : public GcWindow { Q_OBJECT @@ -68,6 +71,7 @@ class DialWindow : public GcWindow public slots: // trap signals + void seriesChanged(); void telemetryUpdate(const RealtimeData &rtData); // got new data void lap(int lapnumber); void start(); @@ -102,6 +106,8 @@ class DialWindow : public GcWindow // display QLabel *valueLabel; + + QColor foreground, background; }; #endif // _GC_DialWindow_h diff --git a/src/GoldenCheetah.cpp b/src/GoldenCheetah.cpp index f3d2cb4dd..35649c7a9 100644 --- a/src/GoldenCheetah.cpp +++ b/src/GoldenCheetah.cpp @@ -137,18 +137,21 @@ GcWindow::GcWindow() qRegisterMetaType("controls"); qRegisterMetaType("ride"); qRegisterMetaType("type"); + qRegisterMetaType("color"); setControls(NULL); setRideItem(NULL); setTitle(""); setContentsMargins(0,0,0,0); setResizable(false); setMouseTracking(true); + setProperty("color", Qt::white); } GcWindow::GcWindow(QWidget *parent) : QFrame(parent), dragState(None) { qRegisterMetaType("controls"); qRegisterMetaType("ride"); qRegisterMetaType("type"); + qRegisterMetaType("color"); setParent(parent); setControls(NULL); setRideItem(NULL); @@ -156,6 +159,7 @@ GcWindow::GcWindow(QWidget *parent) : QFrame(parent), dragState(None) { setContentsMargins(0,0,0,0); setResizable(false); setMouseTracking(true); + setProperty("color", Qt::white); } GcWindow::~GcWindow() @@ -188,7 +192,7 @@ GcWindow::paintEvent(QPaintEvent * /*event*/) QPainter painter(this); // background light gray for now? QRect all(0,0,width(),height()); - painter.fillRect(all, Qt::white); + painter.fillRect(all, property("color").value()); if (contentsMargins().top() > 0) { diff --git a/src/RealtimePlot.cpp b/src/RealtimePlot.cpp index 22ecbdd70..5b6550157 100644 --- a/src/RealtimePlot.cpp +++ b/src/RealtimePlot.cpp @@ -94,13 +94,34 @@ RealtimePlot::RealtimePlot() : pwrCurve(NULL) setAxisTitle(yRight2, "Speed"); setAxisTitle(xBottom, "Seconds Ago"); + QPalette pal; setAxisScale(yLeft, 0, 500); // watts + pal.setColor(QPalette::WindowText, GColor(CPOWER)); + pal.setColor(QPalette::Text, GColor(CPOWER)); + axisWidget(QwtPlot::yLeft)->setPalette(pal); + axisWidget(QwtPlot::yLeft)->scaleDraw()->setTickLength(QwtScaleDiv::MajorTick, 3); + setAxisScale(yRight, 0, 230); // cadence / hr + pal.setColor(QPalette::WindowText, GColor(CHEARTRATE)); + pal.setColor(QPalette::Text, GColor(CHEARTRATE)); + axisWidget(QwtPlot::yRight)->setPalette(pal); + axisWidget(QwtPlot::yRight)->scaleDraw()->setTickLength(QwtScaleDiv::MajorTick, 3); + setAxisScale(xBottom, 50, 0, 15); // time ago + pal.setColor(QPalette::WindowText, GColor(CPLOTMARKER)); + pal.setColor(QPalette::Text, GColor(CPLOTMARKER)); + axisWidget(QwtPlot::xBottom)->setPalette(pal); + axisWidget(QwtPlot::xBottom)->scaleDraw()->setTickLength(QwtScaleDiv::MajorTick, 3); + setAxisScale(yRight2, 0, 60); // speed km/h - 60kmh on a turbo is good going! + pal.setColor(QPalette::WindowText, GColor(CSPEED)); + pal.setColor(QPalette::Text, GColor(CSPEED)); + axisWidget(QwtPlot::yRight2)->setPalette(pal); + axisWidget(QwtPlot::yRight2)->scaleDraw()->setTickLength(QwtScaleDiv::MajorTick, 3); setAxisLabelRotation(yRight2,90); setAxisLabelAlignment(yRight2,Qt::AlignVCenter); + enableAxis(xBottom, false); // very little value and some cpu overhead enableAxis(yLeft, true); enableAxis(yRight, true); @@ -173,7 +194,7 @@ RealtimePlot::setAxisTitle(int axis, QString label) void RealtimePlot::configChanged() { - setCanvasBackground(GColor(CPLOTBACKGROUND)); + setCanvasBackground(GColor(CRIDEPLOTBACKGROUND)); QPen pwr30pen = QPen(GColor(CPOWER), 2.0, Qt::DashLine); pwr30Curve->setPen(pwr30pen); pwr30Curve->setData(pwr30Data); diff --git a/src/RealtimePlot.h b/src/RealtimePlot.h index d10caa2bc..cc4e986be 100644 --- a/src/RealtimePlot.h +++ b/src/RealtimePlot.h @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #include "Settings.h" diff --git a/src/RealtimePlotWindow.cpp b/src/RealtimePlotWindow.cpp index 7853cba2b..0576b50aa 100644 --- a/src/RealtimePlotWindow.cpp +++ b/src/RealtimePlotWindow.cpp @@ -25,6 +25,7 @@ RealtimePlotWindow::RealtimePlotWindow(MainWindow *mainWindow) : setContentsMargins(0,0,0,0); setInstanceName("RT Plot"); setControls(NULL); + setProperty("color", GColor(CRIDEPLOTBACKGROUND)); QVBoxLayout *layout = new QVBoxLayout(this); rtPlot = new RealtimePlot(); diff --git a/src/RealtimePlotWindow.h b/src/RealtimePlotWindow.h index 430e0dd76..e02d7f9f6 100644 --- a/src/RealtimePlotWindow.h +++ b/src/RealtimePlotWindow.h @@ -29,6 +29,9 @@ #include "RealtimePlot.h" #include "RealtimeData.h" // for realtimedata structure +#include "Settings.h" +#include "Colors.h" + class RealtimePlotWindow : public GcWindow { Q_OBJECT diff --git a/src/VideoWindow.cpp b/src/VideoWindow.cpp index a65a91efe..e32470ce6 100644 --- a/src/VideoWindow.cpp +++ b/src/VideoWindow.cpp @@ -23,6 +23,7 @@ GcWindow(parent), home(home), main(parent) { setControls(NULL); setInstanceName("Video Window"); + setProperty("color", Qt::black); QHBoxLayout *layout = new QHBoxLayout(); setLayout(layout);