mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-14 00:28:42 +00:00
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
This commit is contained in:
@@ -157,7 +157,7 @@ GcWindow::GcWindow()
|
||||
qRegisterMetaType<QColor>("color");
|
||||
qRegisterMetaType<DateRange>("dateRange");
|
||||
qRegisterMetaType<bool>("nomenu");
|
||||
popOverOpen = false;
|
||||
revealed = false;
|
||||
setControls(NULL);
|
||||
setRideItem(NULL);
|
||||
setTitle("");
|
||||
@@ -192,7 +192,7 @@ GcWindow::GcWindow(QWidget *parent) : QFrame(parent), dragState(None) {
|
||||
qRegisterMetaType<QColor>("color");
|
||||
qRegisterMetaType<DateRange>("dateRange");
|
||||
qRegisterMetaType<bool>("nomenu");
|
||||
popOverOpen = false;
|
||||
revealed = false;
|
||||
setParent(parent);
|
||||
setControls(NULL);
|
||||
setRideItem(NULL);
|
||||
|
||||
@@ -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(); }
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
#include "QtMacSegmentedButton.h"
|
||||
#endif
|
||||
|
||||
extern QApplication *application;
|
||||
|
||||
class HomeWindow : public GcWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
14
src/main.cpp
14
src/main.cpp
@@ -28,6 +28,8 @@
|
||||
#include <X11/Xlib.h>
|
||||
#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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user