summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBe <be@mixxx.org>2020-05-15 11:36:13 -0500
committerBe <be@mixxx.org>2020-05-15 11:39:15 -0500
commitd01da1213b2a3575bad2a372c476e78fd0e8d8bd (patch)
tree84766115e99fc70ada6a8cd3b0a3fe86602faab6
parentc62d9184f002d473a162ffe6cc80f42935b89631 (diff)
WOverview: factor out CueMenuPopup shifting to utility function
and account for height of screen too
-rw-r--r--src/util/widgethelper.h24
-rw-r--r--src/widget/woverview.cpp14
2 files changed, 30 insertions, 8 deletions
diff --git a/src/util/widgethelper.h b/src/util/widgethelper.h
new file mode 100644
index 0000000000..0000b03f8d
--- /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.
+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 da011cb5d3..7aa366139e 100644
--- a/src/widget/woverview.cpp
+++ b/src/widget/woverview.cpp
@@ -35,6 +35,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"
@@ -530,14 +531,11 @@ void WOverview::mousePressEvent(QMouseEvent* e) {
if (pHoveredCue != nullptr) {
m_pCueMenuPopup->setTrackAndCue(m_pCurrentTrack, pHoveredCue);
- // Shift the popup left if it would go off screen shown at the
- // current cursor position.
- QPoint popupPoint = e->globalPos();
- int screenWidth = windowHandle()->screen()->size().width();
- if (popupPoint.x() + m_pCueMenuPopup->width() > screenWidth) {
- popupPoint.setX(screenWidth - m_pCueMenuPopup->width());
- }
- m_pCueMenuPopup->popup(popupPoint);
+ QPoint cueMenuTopLeft = mixxx::WidgetHelper::mapPopupToScreen(
+ windowHandle()->screen()->size(),
+ e->globalPos(),
+ m_pCueMenuPopup->size());
+ m_pCueMenuPopup->popup(cueMenuTopLeft);
m_bHotcueMenuShowing = true;
}