From 0fe044cc50fddc722b76e874a30469994a1d4e42 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Sun, 13 Jan 2013 14:55:16 +0000 Subject: [PATCH] Autohidden chart settings framework Setup code to enable revealed chart controls. When in tabbed mode, if the cursor is towards the title then the chart controls are revealed, as the cursor moves away or off the chart the controls are hidden. Each chart, that wants revealed controls must implement; bool hasReveal() -- return true if controls are available void reveal() -- show controls (must be at top of chart and a single line) void unrveal() -- hide controls Will now work through each chart adding the controls as needed. Will also probably end up with a 'standard' flat stylesheet for the controls, can implement this later. See description for this feature here: https://github.com/GoldenCheetah/GoldenCheetah/issues/31#issuecomment-12040318 --- src/GoldenCheetah.cpp | 4 ++-- src/GoldenCheetah.h | 8 ++++---- src/HomeWindow.cpp | 35 +++++++++++++++++++++++++++++++++++ src/HomeWindow.h | 2 ++ src/main.cpp | 14 ++++++++------ 5 files changed, 51 insertions(+), 12 deletions(-) diff --git a/src/GoldenCheetah.cpp b/src/GoldenCheetah.cpp index b23205578..3e099ae8c 100644 --- a/src/GoldenCheetah.cpp +++ b/src/GoldenCheetah.cpp @@ -157,7 +157,7 @@ GcWindow::GcWindow() qRegisterMetaType("color"); qRegisterMetaType("dateRange"); qRegisterMetaType("nomenu"); - popOverOpen = false; + revealed = false; setControls(NULL); setRideItem(NULL); setTitle(""); @@ -192,7 +192,7 @@ GcWindow::GcWindow(QWidget *parent) : QFrame(parent), dragState(None) { qRegisterMetaType("color"); qRegisterMetaType("dateRange"); qRegisterMetaType("nomenu"); - popOverOpen = false; + revealed = false; setParent(parent); setControls(NULL); setRideItem(NULL); diff --git a/src/GoldenCheetah.h b/src/GoldenCheetah.h index b8881cd42..bf011771c 100644 --- a/src/GoldenCheetah.h +++ b/src/GoldenCheetah.h @@ -164,10 +164,10 @@ public: virtual bool amVisible(); // popover controls - virtual bool hasPopOver() { return false;} - virtual void showPopOver() {} - virtual void hidePopOver() {} - bool popOverOpen; + virtual bool hasReveal() { return false;} + virtual void reveal() {} + virtual void unreveal() {} + bool revealed; // for sorting... we look at x bool operator< (GcWindow right) const { return geometry().x() < right.geometry().x(); } diff --git a/src/HomeWindow.cpp b/src/HomeWindow.cpp index 91ed235c6..ac0baccd9 100644 --- a/src/HomeWindow.cpp +++ b/src/HomeWindow.cpp @@ -219,6 +219,7 @@ HomeWindow::HomeWindow(MainWindow *mainWindow, QString name, QString /* windowti // watch drop operations //setMouseTracking(true); installEventFilter(this); + application->installEventFilter(this); } HomeWindow::~HomeWindow() @@ -841,6 +842,40 @@ HomeWindow::resizeEvent(QResizeEvent * /* e */) bool HomeWindow::eventFilter(QObject *object, QEvent *e) { + if (isHidden()) return false; // ignore when we aren't visible + + // mouse moved and tabbed -- should we show/hide chart popup controls? + if (e->type() == QEvent::MouseMove && currentStyle == 0 && tabbed->currentIndex() >= 0) { + + QPoint pos = tabbed->widget(tabbed->currentIndex())->mapFromGlobal(QCursor::pos()); + GcWindow *us = charts[tabbed->currentIndex()]; + + // lots of nested if statements to breakout as quickly as possible + // this code gets called A LOT, since mouse events are from the + // application + if (us->hasReveal()) { // does this chart have reveal controls? + + if (us->underMouse()) { // is it even under the cursor? + + // mouse towards top so reveal + if (us->revealed == false && pos.y() < 50) { + us->reveal(); + us->revealed = true; + } + + // hide as mouse moves away + if (us->revealed == true && pos.y() > 50) { + us->unreveal(); + us->revealed = false; + } + + } else if (us->revealed) { // not under cursor but revealed + us->unreveal(); + us->revealed = false; + } + } + } + // we watch the mouse when // dropping charts, to update // the cursor position diff --git a/src/HomeWindow.h b/src/HomeWindow.h index 2eb37436e..ac0f938b0 100644 --- a/src/HomeWindow.h +++ b/src/HomeWindow.h @@ -31,6 +31,8 @@ #include "QtMacSegmentedButton.h" #endif +extern QApplication *application; + class HomeWindow : public GcWindow { Q_OBJECT diff --git a/src/main.cpp b/src/main.cpp index 3755a3845..4525644a5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,6 +28,8 @@ #include #endif +QApplication *application; + int main(int argc, char *argv[]) { @@ -35,12 +37,12 @@ main(int argc, char *argv[]) XInitThreads(); #endif - QApplication app(argc, argv); + application = new QApplication(argc, argv); QFont font; font.fromString(appsettings->value(NULL, GC_FONT_DEFAULT, QFont().toString()).toString()); font.setPointSize(appsettings->value(NULL, GC_FONT_DEFAULT_SIZE, 12).toInt()); - app.setFont(font); // set default font + application->setFont(font); // set default font //this is the path within the current directory where GC will look for //files to allow USB stick support @@ -99,7 +101,7 @@ main(int argc, char *argv[]) QTranslator qtTranslator; qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath)); - app.installTranslator(&qtTranslator); + application->installTranslator(&qtTranslator); // Language setting (default to system locale) QVariant lang = appsettings->value(NULL, GC_LANG, QLocale::system().name()); @@ -107,7 +109,7 @@ main(int argc, char *argv[]) // Load specific translation QTranslator gcTranslator; gcTranslator.load(":translations/gc_" + lang.toString() + ".qm"); - app.installTranslator(&gcTranslator); + application->installTranslator(&gcTranslator); // Initialize metrics once the translator is installed RideMetricFactory::instance().initialize(); @@ -118,7 +120,7 @@ main(int argc, char *argv[]) // initialise the trainDB trainDB = new TrainDB(home); - QStringList args( app.arguments() ); + QStringList args( application->arguments() ); QVariant lastOpened; if( args.size() > 1 ){ @@ -157,5 +159,5 @@ main(int argc, char *argv[]) MainWindow *mainWindow = new MainWindow(home); mainWindow->show(); } - return app.exec(); + return application->exec(); }