From b89019264ed5a8a40ab104c22002e53a2b6ce01d Mon Sep 17 00:00:00 2001 From: Michel Dagenais Date: Mon, 25 May 2020 11:44:54 -0400 Subject: [PATCH] MeterWidgets must move / hide when main window is moved / minimized (#3458) When the main window is minimized on Linux, the MeterWidgets stay on the desktop. A signal were added to the main window for state changes. The VideoWindow connects to that signal and hide/shows the MeterWidgets accordingly. Currently, when you move the main window, the MeterWidgets do not follow and become out of place. On every Telemetry update, check if the real position on screen of the video window has changed in order to update the position of the meter widgets. The Video Window can move for several reasons like when scrolled or when the Main Window is moved. The Meter Widgets are not clipped like the Video Window by its scroll area parent though. --- src/Gui/MainWindow.cpp | 11 +++++++++++ src/Gui/MainWindow.h | 4 ++++ src/Train/VideoWindow.cpp | 13 +++++++++++++ src/Train/VideoWindow.h | 2 ++ 4 files changed, 30 insertions(+) diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp index eb031f127..d5196143e 100644 --- a/src/Gui/MainWindow.cpp +++ b/src/Gui/MainWindow.cpp @@ -1037,6 +1037,17 @@ MainWindow::closeEvent(QCloseEvent* event) appsettings->setValue(GC_SETTINGS_MAIN_STATE, saveState()); } +void +MainWindow::changeEvent(QEvent *event) +{ + if(event->type() != QEvent::WindowStateChange) return; + + // Some overlay Widgets (Meter) are top level windows + // and need to follow the MainWindow state + Qt::WindowStates states = windowState(); + emit mainWindowStateChanged(states & Qt::WindowMinimized, isVisible()); +} + MainWindow::~MainWindow() { // aside from the tabs, we may need to clean diff --git a/src/Gui/MainWindow.h b/src/Gui/MainWindow.h index 50d1f9252..6feac7b3c 100644 --- a/src/Gui/MainWindow.h +++ b/src/Gui/MainWindow.h @@ -94,6 +94,9 @@ class MainWindow : public QMainWindow // currently selected tab Tab *athleteTab() { return currentTab; } + signals: + void mainWindowStateChanged(bool minimized, bool visible); + protected: // used by ChooseCyclistDialog to see which athletes @@ -104,6 +107,7 @@ class MainWindow : public QMainWindow virtual void resizeEvent(QResizeEvent*); virtual void moveEvent(QMoveEvent*); virtual void closeEvent(QCloseEvent*); + virtual void changeEvent(QEvent *); virtual void dragEnterEvent(QDragEnterEvent *); virtual void dropEvent(QDropEvent *); diff --git a/src/Train/VideoWindow.cpp b/src/Train/VideoWindow.cpp index 7635bd85a..238642f37 100644 --- a/src/Train/VideoWindow.cpp +++ b/src/Train/VideoWindow.cpp @@ -163,6 +163,7 @@ VideoWindow::VideoWindow(Context *context) : connect(context, SIGNAL(seek(long)), this, SLOT(seekPlayback(long))); connect(context, SIGNAL(unpause()), this, SLOT(resumePlayback())); connect(context, SIGNAL(mediaSelected(QString)), this, SLOT(mediaSelected(QString))); + connect(this->window(), SIGNAL(mainWindowStateChanged(bool, bool)), this, SLOT(mainWindowStateChanged(bool, bool))); } } @@ -201,6 +202,13 @@ void VideoWindow::resizeEvent(QResizeEvent * ) { foreach(MeterWidget* p_meterWidget , m_metersWidget) p_meterWidget->AdjustSizePos(); + prevPosition = mapToGlobal(pos()); +} + +void VideoWindow::mainWindowStateChanged(bool minimized, bool visible) +{ + if(minimized) foreach(MeterWidget* p, m_metersWidget) p->hide(); + else if(visible && isVisible()) foreach(MeterWidget* p, m_metersWidget) p->show(); } void VideoWindow::startPlayback() @@ -246,6 +254,7 @@ void VideoWindow::startPlayback() p_meterWidget->raise(); p_meterWidget->show(); } + prevPosition = mapToGlobal(pos()); } void VideoWindow::stopPlayback() @@ -416,6 +425,10 @@ void VideoWindow::telemetryUpdate(RealtimeData rtd) } } + // The Meter Widgets need to follow the Video Window when it moves + // (main window moves, scrolling...), we check the position at every update + if(mapToGlobal(pos()) != prevPosition) resizeEvent(NULL); + foreach(MeterWidget* p_meterWidget , m_metersWidget) p_meterWidget->update(); diff --git a/src/Train/VideoWindow.h b/src/Train/VideoWindow.h index b11b6833e..b105e3db0 100644 --- a/src/Train/VideoWindow.h +++ b/src/Train/VideoWindow.h @@ -176,6 +176,7 @@ class VideoWindow : public GcChartWindow void telemetryUpdate(RealtimeData rtd); void seekPlayback(long ms); void mediaSelected(QString filename); + void mainWindowStateChanged(bool minimized, bool visible); protected: @@ -192,6 +193,7 @@ class VideoWindow : public GcChartWindow bool m_MediaChanged; QList m_metersWidget; + QPoint prevPosition; #ifdef GC_VIDEO_VLC