Skip to content

Commit cd08b17

Browse files
authored
Merge pull request #13741 from ronso0/overview-abort-drag-leave-zone
Overview: abort play pos dragging if cursor is relased outside the valid area
2 parents 2e99a80 + b923d19 commit cd08b17

2 files changed

Lines changed: 67 additions & 28 deletions

File tree

src/widget/woverview.cpp

Lines changed: 56 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
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+
2935
WOverview::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) {
407415
void 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

474487
void 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

508530
void 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
}

src/widget/woverview.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ class WOverview : public WWidget, public TrackDropTarget {
122122
return m_orientation == Qt::Horizontal ? height() : width();
123123
}
124124

125+
inline bool isPosInAllowedPosDragZone(const QPoint pos) {
126+
const QRect dragZone = rect().marginsAdded(QMargins(
127+
m_dragMarginH,
128+
m_dragMarginV,
129+
m_dragMarginH,
130+
m_dragMarginV));
131+
return dragZone.contains(pos);
132+
}
133+
125134
ConstWaveformPointer getWaveform() const {
126135
return m_pWaveform;
127136
}
@@ -162,6 +171,8 @@ class WOverview : public WWidget, public TrackDropTarget {
162171
int m_iPlayPos;
163172
bool m_bTimeRulerActive;
164173
Qt::Orientation m_orientation;
174+
int m_dragMarginH;
175+
int m_dragMarginV;
165176
int m_iLabelFontSize;
166177

167178
// Coefficient value-position linear transposition
@@ -213,5 +224,4 @@ class WOverview : public WWidget, public TrackDropTarget {
213224
std::vector<WaveformMarkRange> m_markRanges;
214225
WaveformMarkLabel m_cuePositionLabel;
215226
WaveformMarkLabel m_cueTimeDistanceLabel;
216-
217227
};

0 commit comments

Comments
 (0)