From 65bf2c00e3ef18a7696b342b424662dd3d952bcd Mon Sep 17 00:00:00 2001 From: Nick Hastings Date: Thu, 27 Jun 2024 21:30:41 +0900 Subject: [PATCH] Add tool tips to trainer controls (#4517) Add a preferences option to enable/disable these tooltips. Default is enabled. If enabled tooltips will also be shown for disabled controls in TrainBottom so users can preview what they do once the session start. --- src/Core/Settings.h | 1 + src/Gui/Pages.cpp | 5 +++ src/Gui/Pages.h | 1 + src/Train/TrainBottom.cpp | 66 ++++++++++++++++++++++++++++++++++++++- src/Train/TrainBottom.h | 2 ++ 5 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/Core/Settings.h b/src/Core/Settings.h index dc4674e63..918e6aafa 100644 --- a/src/Core/Settings.h +++ b/src/Core/Settings.h @@ -238,6 +238,7 @@ #define TRAIN_USESIMULATEDSPEED "train/usesimulatedspeed" #define TRAIN_USESIMULATEDHYPOXIA "train/usesimulatedhypoxia" #define TRAIN_COALESCE_SECTIONS "train/coalesceSections" +#define TRAIN_TOOLTIPS "train/tooltips" #define TRAIN_TELEMETRY_FONT_SCALING "train/telemetryFontScaling" #define GC_REMOTE_START "remote/start" #define GC_REMOTE_STOP "remote/stop" diff --git a/src/Gui/Pages.cpp b/src/Gui/Pages.cpp index 310590b75..387699f7b 100644 --- a/src/Gui/Pages.cpp +++ b/src/Gui/Pages.cpp @@ -757,6 +757,9 @@ TrainOptionsPage::TrainOptionsPage(QWidget *parent, Context *context) : QWidget( coalesce = new QCheckBox(tr("Coalesce contiguous sections of same wattage"), this); coalesce->setChecked(appsettings->value(this, TRAIN_COALESCE_SECTIONS, false).toBool()); + tooltips = new QCheckBox(tr("Enable Tooltips"), this); + tooltips->setChecked(appsettings->value(this, TRAIN_TOOLTIPS, true).toBool()); + telemetryScalingLabel = new QLabel(tr("Telemetry font scaling")); telemetryScaling = new QComboBox(); telemetryScaling->addItem(tr("Fit to height only"), 0); @@ -785,6 +788,7 @@ TrainOptionsPage::TrainOptionsPage(QWidget *parent, Context *context) : QWidget( all->addRow("", autoHide); all->addRow("", lapAlert); all->addRow("", coalesce); + all->addRow("", tooltips); all->addRow(delayLabel, startDelay); all->addRow(telemetryScalingLabel, telemetryScaling); } @@ -803,6 +807,7 @@ TrainOptionsPage::saveClicked() appsettings->setValue(TRAIN_AUTOHIDE, autoHide->isChecked()); appsettings->setValue(TRAIN_LAPALERT, lapAlert->isChecked()); appsettings->setValue(TRAIN_COALESCE_SECTIONS, coalesce->isChecked()); + appsettings->setValue(TRAIN_TOOLTIPS, tooltips->isChecked()); appsettings->setValue(TRAIN_TELEMETRY_FONT_SCALING, telemetryScaling->currentIndex()); return 0; diff --git a/src/Gui/Pages.h b/src/Gui/Pages.h index 3450a03bd..bd041b330 100644 --- a/src/Gui/Pages.h +++ b/src/Gui/Pages.h @@ -240,6 +240,7 @@ class TrainOptionsPage : public QWidget QCheckBox *autoHide; QCheckBox *lapAlert; QCheckBox *coalesce; + QCheckBox *tooltips; QLabel *telemetryScalingLabel; QComboBox *telemetryScaling; }; diff --git a/src/Train/TrainBottom.cpp b/src/Train/TrainBottom.cpp index c0676a8fe..32ebe35ed 100644 --- a/src/Train/TrainBottom.cpp +++ b/src/Train/TrainBottom.cpp @@ -249,6 +249,8 @@ TrainBottom::TrainBottom(TrainSidebar *trainSidebar, QWidget *parent) : connect(notificationTimer, SIGNAL(timeout()), SLOT(clearNotification())); updateStyles(); + m_tooltips = appsettings->value(this, TRAIN_TOOLTIPS, true).toBool(); + updateTooltips(); } void TrainBottom::updatePlayButtonIcon() @@ -256,14 +258,26 @@ void TrainBottom::updatePlayButtonIcon() if (m_trainSidebar->currentStatus() & RT_PAUSED) { applyIcon(m_playButton, "play"); + if (m_tooltips) + { + m_playButton->setToolTip(tr("Resume")); + } } else if (m_trainSidebar->currentStatus() & RT_RUNNING) { applyIcon(m_playButton, "pause"); + if (m_tooltips) + { + m_playButton->setToolTip(tr("Pause")); + } } else // Not running or paused means stopped { applyIcon(m_playButton, "play"); + if (m_tooltips) + { + m_playButton->setToolTip(tr("Start")); + } } } @@ -278,6 +292,9 @@ void TrainBottom::statusChanged(int status) // not yet connected if ((status&RT_CONNECTED) == 0) { applyIcon(m_connectButton, "offline"); + if (m_tooltips) { + m_connectButton->setToolTip(tr("Connect")); + } m_connectButton->setEnabled(true); m_playButton->setEnabled(false); m_stopButton->setEnabled(false); @@ -296,6 +313,9 @@ void TrainBottom::statusChanged(int status) // connected, but not running if ((status&RT_CONNECTED) && ((status&RT_RUNNING) == 0)) { applyIcon(m_connectButton, "online"); + if (m_tooltips) { + m_connectButton->setToolTip(tr("Disconnect")); + } m_connectButton->setEnabled(true); m_playButton->setEnabled(true); m_stopButton->setEnabled(false); @@ -314,6 +334,9 @@ void TrainBottom::statusChanged(int status) // paused - important to check for paused before running if (status&RT_PAUSED) { applyIcon(m_connectButton, "online"); + if (m_tooltips) { + m_connectButton->setToolTip(tr("Disconnect")); + } m_connectButton->setEnabled(false); m_playButton->setEnabled(true); m_stopButton->setEnabled(true); @@ -332,6 +355,9 @@ void TrainBottom::statusChanged(int status) // running & calibrating if ((status&RT_CALIBRATING) && (status&RT_RUNNING)) { applyIcon(m_connectButton, "online"); + if (m_tooltips) { + m_connectButton->setToolTip(tr("Disconnect")); + } m_connectButton->setEnabled(false); m_playButton->setEnabled(false); m_stopButton->setEnabled(true); @@ -350,6 +376,9 @@ void TrainBottom::statusChanged(int status) // running if (status&RT_RUNNING) { applyIcon(m_connectButton, "online"); + if (m_tooltips) { + m_connectButton->setToolTip(tr("Disconnect")); + } m_connectButton->setEnabled(false); m_playButton->setEnabled(true); m_stopButton->setEnabled(true); @@ -362,6 +391,7 @@ void TrainBottom::statusChanged(int status) loadUp->setEnabled(true); loadDown->setEnabled(true); intensitySlider->setEnabled(true); + intensitySlider->setToolTip(tr("Adjust intensity")); return; } @@ -419,7 +449,36 @@ void TrainBottom::updateStyles() setStyleSheet(bss); } - +void TrainBottom::updateTooltips() +{ + if (m_tooltips) { + m_connectButton->setToolTip(tr("Connect")); + m_rewindButton->setToolTip(tr("Rewind")); + m_stopButton->setToolTip(tr("Stop")); + m_playButton->setToolTip(tr("Start")); + m_forwardButton->setToolTip(tr("Fast forward")); + backLap->setToolTip(tr("Back 1 lap")); + m_lapButton->setToolTip(tr("Lap")); + fwdLap->setToolTip(tr("Forward 1 lap")); + cal->setToolTip(tr("Calibrate")); + loadDown->setToolTip(tr("Decrease intensity")); + loadUp->setToolTip(tr("Increase intensity")); + } + else { + m_connectButton->setToolTip(""); + m_playButton->setToolTip(""); + m_stopButton->setToolTip(""); + m_forwardButton->setToolTip(""); + m_rewindButton->setToolTip(""); + backLap->setToolTip(""); + m_lapButton->setToolTip(""); + fwdLap->setToolTip(""); + cal->setToolTip(""); + loadUp->setToolTip(""); + loadDown->setToolTip(""); + intensitySlider->setToolTip(""); + } +} QFrame* TrainBottom::newSep() { QFrame *sep = new QFrame(this); @@ -433,6 +492,11 @@ QFrame* TrainBottom::newSep() void TrainBottom::configChanged(qint32) { updateStyles(); + const bool tooltips = appsettings->value(this, TRAIN_TOOLTIPS, true).toBool(); + if (m_tooltips != tooltips) { + m_tooltips = tooltips; + updateTooltips(); + } } diff --git a/src/Train/TrainBottom.h b/src/Train/TrainBottom.h index 9bd52d396..f996debb6 100644 --- a/src/Train/TrainBottom.h +++ b/src/Train/TrainBottom.h @@ -47,8 +47,10 @@ private: QPlainTextEdit *notificationText; QTimer *notificationTimer; QMap iconNames; + bool m_tooltips; void updateStyles(); + void updateTooltips(); QFrame *newSep(); void applyIcon(QPushButton *button, QString iconName, bool dark); void applyIcon(QPushButton *button, QString iconName);