diff options
author | Uwe Klotz <uklotz@mixxx.org> | 2020-05-15 23:37:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-15 23:37:12 +0200 |
commit | c2827eee84aab5333bc7f20a33635cd436acb7b5 (patch) | |
tree | 62db8e32b04312d0337c52ff25ab0e55b440df91 | |
parent | 399bd96b08eaf8fb6fb8dc27425c926e7250ebaa (diff) | |
parent | 5e6f87bbc1735e423b5b58e325c374e4d04f7f85 (diff) |
Merge pull request #2663 from Be-ing/hotcue_dialog_on_screen
WOverview: shift hotcue popup left if it would exceed screen width
-rw-r--r-- | src/util/widgethelper.h | 24 | ||||
-rw-r--r-- | src/widget/woverview.cpp | 9 |
2 files changed, 32 insertions, 1 deletions
diff --git a/src/util/widgethelper.h b/src/util/widgethelper.h new file mode 100644 index 0000000000..dc552663a7 --- /dev/null +++ b/src/util/widgethelper.h @@ -0,0 +1,24 @@ +#pragma once + +#include <QScreen> + +namespace mixxx { +namespace widgethelper { +/// Returns an adjusted upper left point for displaying the popup +/// with the given size on the screen, shifting the popup if it would go off +/// the right or bottom edges of the screen. +inline QPoint mapPopupToScreen( + const QSize& screenSize, + const QPoint& popupUpperLeft, + const QSize& popupSize) { + QPoint newTopLeft = popupUpperLeft; + if (popupUpperLeft.x() + popupSize.width() > screenSize.width()) { + newTopLeft.setX(screenSize.width() - popupSize.width()); + } + if (popupUpperLeft.y() + popupSize.height() > screenSize.height()) { + newTopLeft.setY(screenSize.height() - popupSize.height()); + } + return newTopLeft; +} +} // namespace widgethelper +} // namespace mixxx diff --git a/src/widget/woverview.cpp b/src/widget/woverview.cpp index 85841680d5..daa64d937f 100644 --- a/src/widget/woverview.cpp +++ b/src/widget/woverview.cpp @@ -34,6 +34,7 @@ #include "util/math.h" #include "util/painterscope.h" #include "util/timer.h" +#include "util/widgethelper.h" #include "waveform/waveform.h" #include "waveform/waveformwidgetfactory.h" #include "widget/controlwidgetconnection.h" @@ -538,7 +539,13 @@ void WOverview::mousePressEvent(QMouseEvent* e) { } if (pHoveredCue != nullptr) { m_pCueMenuPopup->setTrackAndCue(m_pCurrentTrack, pHoveredCue); - m_pCueMenuPopup->popup(e->globalPos()); + + QPoint cueMenuTopLeft = mixxx::widgethelper::mapPopupToScreen( + windowHandle()->screen()->size(), + e->globalPos(), + m_pCueMenuPopup->size()); + m_pCueMenuPopup->popup(cueMenuTopLeft); + m_bHotcueMenuShowing = true; } } |