From c62d9184f002d473a162ffe6cc80f42935b89631 Mon Sep 17 00:00:00 2001 From: Be Date: Mon, 13 Apr 2020 20:39:05 -0500 Subject: [PATCH 1/4] WOverview: shift hotcue popup left if it would exceed screen width --- src/widget/woverview.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/widget/woverview.cpp b/src/widget/woverview.cpp index 1d86575c290..da011cb5d37 100644 --- a/src/widget/woverview.cpp +++ b/src/widget/woverview.cpp @@ -529,7 +529,16 @@ void WOverview::mousePressEvent(QMouseEvent* e) { } if (pHoveredCue != nullptr) { m_pCueMenuPopup->setTrackAndCue(m_pCurrentTrack, pHoveredCue); - m_pCueMenuPopup->popup(e->globalPos()); + + // 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); + m_bHotcueMenuShowing = true; } } From d01da1213b2a3575bad2a372c476e78fd0e8d8bd Mon Sep 17 00:00:00 2001 From: Be Date: Fri, 15 May 2020 11:36:13 -0500 Subject: [PATCH 2/4] WOverview: factor out CueMenuPopup shifting to utility function and account for height of screen too --- src/util/widgethelper.h | 24 ++++++++++++++++++++++++ src/widget/woverview.cpp | 14 ++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 src/util/widgethelper.h diff --git a/src/util/widgethelper.h b/src/util/widgethelper.h new file mode 100644 index 00000000000..0000b03f8df --- /dev/null +++ b/src/util/widgethelper.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +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 da011cb5d37..7aa366139e3 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; } From 70ba21406989bbcb71ea06cbcee84fc5f307a466 Mon Sep 17 00:00:00 2001 From: Be Date: Fri, 15 May 2020 16:13:34 -0500 Subject: [PATCH 3/4] widgethelper: rename namespace to lowercase to match convention --- src/util/widgethelper.h | 4 ++-- src/widget/woverview.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/util/widgethelper.h b/src/util/widgethelper.h index 0000b03f8df..22a46726db6 100644 --- a/src/util/widgethelper.h +++ b/src/util/widgethelper.h @@ -3,7 +3,7 @@ #include namespace mixxx { -namespace WidgetHelper { +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. @@ -20,5 +20,5 @@ QPoint mapPopupToScreen( } return newTopLeft; } -} // namespace WidgetHelper +} // namespace widgethelper } // namespace mixxx diff --git a/src/widget/woverview.cpp b/src/widget/woverview.cpp index 7aa366139e3..1a1d20fe958 100644 --- a/src/widget/woverview.cpp +++ b/src/widget/woverview.cpp @@ -531,7 +531,7 @@ void WOverview::mousePressEvent(QMouseEvent* e) { if (pHoveredCue != nullptr) { m_pCueMenuPopup->setTrackAndCue(m_pCurrentTrack, pHoveredCue); - QPoint cueMenuTopLeft = mixxx::WidgetHelper::mapPopupToScreen( + QPoint cueMenuTopLeft = mixxx::widgethelper::mapPopupToScreen( windowHandle()->screen()->size(), e->globalPos(), m_pCueMenuPopup->size()); From 5e6f87bbc1735e423b5b58e325c374e4d04f7f85 Mon Sep 17 00:00:00 2001 From: Be Date: Fri, 15 May 2020 16:14:05 -0500 Subject: [PATCH 4/4] widgethelper: declare .h file function inline --- src/util/widgethelper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/widgethelper.h b/src/util/widgethelper.h index 22a46726db6..dc552663a7a 100644 --- a/src/util/widgethelper.h +++ b/src/util/widgethelper.h @@ -7,7 +7,7 @@ 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( +inline QPoint mapPopupToScreen( const QSize& screenSize, const QPoint& popupUpperLeft, const QSize& popupSize) {