diff options
-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; } } |