2626#include " widget/controlwidgetconnection.h"
2727#include " wskincolor.h"
2828
29+ namespace {
30+ // Horizontal and vertical margin around the widget where we accept play pos dragging.
31+ constexpr int kDragOutsideLimitX = 100 ;
32+ constexpr int kDragOutsideLimitY = 50 ;
33+ } // anonymous namespace
34+
2935WOverview::WOverview (
3036 const QString& group,
3137 PlayerManager* pPlayerManager,
@@ -50,6 +56,8 @@ WOverview::WOverview(
5056 m_iPlayPos(0 ),
5157 m_bTimeRulerActive(false ),
5258 m_orientation(Qt::Horizontal),
59+ m_dragMarginH(kDragOutsideLimitX ),
60+ m_dragMarginV(kDragOutsideLimitY ),
5361 m_iLabelFontSize(10 ),
5462 m_a(1.0 ),
5563 m_b(0.0 ),
@@ -407,11 +415,16 @@ void WOverview::onRateRatioChange(double v) {
407415void WOverview::onPassthroughChange (double v) {
408416 m_bPassthroughEnabled = static_cast <bool >(v);
409417
410- if (!m_bPassthroughEnabled) {
418+ if (m_bPassthroughEnabled) {
419+ // Abort play position dragging
420+ m_bLeftClickDragging = false ;
421+ m_bTimeRulerActive = false ;
422+ m_iPickupPos = m_iPlayPos;
423+ } else {
411424 slotWaveformSummaryUpdated ();
412425 }
413426
414- // Always call this to trigger a repaint even if not track is loaded
427+ // Always call this to trigger a repaint even if no track is loaded
415428 update ();
416429}
417430
@@ -473,18 +486,27 @@ void WOverview::receiveCuesUpdated() {
473486
474487void WOverview::mouseMoveEvent (QMouseEvent* e) {
475488 if (m_bLeftClickDragging) {
489+ if (isPosInAllowedPosDragZone (e->pos ())) {
490+ m_bTimeRulerActive = true ;
491+ m_timeRulerPos = e->pos ();
492+ unsetCursor ();
493+ } else {
494+ // Remove the time ruler to indicate dragging position is invalid,
495+ // don't abort dragging!
496+ m_iPickupPos = m_iPlayPos;
497+ m_bTimeRulerActive = false ;
498+
499+ setCursor (Qt::ForbiddenCursor);
500+ // Remember to restore cursor everywhere where we cancel dragging.
501+ // Update immediately.
502+ update ();
503+ return ;
504+ }
505+
476506 if (m_orientation == Qt::Horizontal) {
477- #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
478- m_iPickupPos = math_clamp (static_cast <int >(e->position ().x ()), 0 , width () - 1 );
479- #else
480- m_iPickupPos = math_clamp (e->x (), 0 , width () - 1 );
481- #endif
507+ m_iPickupPos = math_clamp (e->pos ().x (), 0 , width () - 1 );
482508 } else {
483- #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
484- m_iPickupPos = math_clamp (static_cast <int >(e->position ().y ()), 0 , height () - 1 );
485- #else
486- m_iPickupPos = math_clamp (e->y (), 0 , height () - 1 );
487- #endif
509+ m_iPickupPos = math_clamp (e->pos ().y (), 0 , height () - 1 );
488510 }
489511 }
490512
@@ -501,24 +523,36 @@ void WOverview::mouseMoveEvent(QMouseEvent* e) {
501523
502524 m_pHoveredMark = m_marks.findHoveredMark (e->pos (), m_orientation);
503525
504- // qDebug() << "WOverview::mouseMoveEvent" << e->pos() << m_iPos ;
526+ // qDebug() << "WOverview::mouseMoveEvent" << e->pos();
505527 update ();
506528}
507529
508530void WOverview::mouseReleaseEvent (QMouseEvent* e) {
509531 mouseMoveEvent (e);
510532 if (m_bPassthroughEnabled) {
511533 m_bLeftClickDragging = false ;
534+ // We may be dragging, and we may be outside the valid dragging area.
535+ // If so, we've set the 'invalid drag' cursor. Restore the cursor now.
536+ unsetCursor ();
512537 return ;
513538 }
514539 // qDebug() << "WOverview::mouseReleaseEvent" << e->pos() << m_iPos << ">>" << dValue;
515540
516541 if (e->button () == Qt::LeftButton) {
517542 if (m_bLeftClickDragging) {
518- m_iPlayPos = m_iPickupPos;
519- double dValue = positionToValue (m_iPickupPos);
520- setControlParameterUp (dValue);
521- m_bLeftClickDragging = false ;
543+ unsetCursor ();
544+ if (isPosInAllowedPosDragZone (e->pos ())) {
545+ m_iPlayPos = m_iPickupPos;
546+ double dValue = positionToValue (m_iPickupPos);
547+ setControlParameterUp (dValue);
548+ m_bLeftClickDragging = false ;
549+ } else {
550+ // Abort dragging if we are way outside the widget.
551+ m_iPickupPos = m_iPlayPos;
552+ m_bLeftClickDragging = false ;
553+ m_bTimeRulerActive = false ;
554+ return ;
555+ }
522556 }
523557 m_bTimeRulerActive = false ;
524558 } else if (e->button () == Qt::RightButton) {
@@ -533,6 +567,7 @@ void WOverview::mousePressEvent(QMouseEvent* e) {
533567 mouseMoveEvent (e);
534568 if (m_bPassthroughEnabled) {
535569 m_bLeftClickDragging = false ;
570+ unsetCursor ();
536571 return ;
537572 }
538573 double trackSamples = getTrackSamples ();
@@ -541,17 +576,9 @@ void WOverview::mousePressEvent(QMouseEvent* e) {
541576 }
542577 if (e->button () == Qt::LeftButton) {
543578 if (m_orientation == Qt::Horizontal) {
544- #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
545- m_iPickupPos = math_clamp (static_cast <int >(e->position ().x ()), 0 , width () - 1 );
546- #else
547- m_iPickupPos = math_clamp (e->x (), 0 , width () - 1 );
548- #endif
579+ m_iPickupPos = math_clamp (e->pos ().x (), 0 , width () - 1 );
549580 } else {
550- #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
551- m_iPickupPos = math_clamp (static_cast <int >(e->position ().y ()), 0 , height () - 1 );
552- #else
553- m_iPickupPos = math_clamp (e->y (), 0 , height () - 1 );
554- #endif
581+ m_iPickupPos = math_clamp (e->pos ().y (), 0 , height () - 1 );
555582 }
556583
557584 if (m_pHoveredMark != nullptr ) {
@@ -571,6 +598,7 @@ void WOverview::mousePressEvent(QMouseEvent* e) {
571598 m_iPickupPos = m_iPlayPos;
572599 m_bLeftClickDragging = false ;
573600 m_bTimeRulerActive = false ;
601+ unsetCursor ();
574602 } else if (m_pHoveredMark == nullptr ) {
575603 m_bTimeRulerActive = true ;
576604 m_timeRulerPos = e->pos ();
@@ -661,6 +689,7 @@ void WOverview::paintEvent(QPaintEvent* pEvent) {
661689 if (m_bPassthroughEnabled) {
662690 drawPassthroughOverlay (&painter);
663691 m_pPassthroughLabel->show ();
692+ unsetCursor ();
664693 } else {
665694 m_pPassthroughLabel->hide ();
666695 }
0 commit comments