diff options
author | Harshit Maurya <hmaurya999@gmail.com> | 2020-05-15 22:25:00 +0530 |
---|---|---|
committer | Harshit Maurya <hmaurya999@gmail.com> | 2020-05-16 02:17:43 +0530 |
commit | 68ae87f1ae804e8164bf25756d6600f865ce9583 (patch) | |
tree | 14696f9be33d0f25d621331e50336677cfbcf57a | |
parent | 2918486a06858b5dd9df214348cd3682af7c868d (diff) |
waveformmark: add function to detect point in mark
-rw-r--r-- | src/waveform/renderers/waveformmark.cpp | 16 | ||||
-rw-r--r-- | src/waveform/renderers/waveformmark.h | 3 | ||||
-rw-r--r-- | src/waveform/renderers/waveformwidgetrenderer.cpp | 39 | ||||
-rw-r--r-- | src/widget/woverview.cpp | 15 |
4 files changed, 26 insertions, 47 deletions
diff --git a/src/waveform/renderers/waveformmark.cpp b/src/waveform/renderers/waveformmark.cpp index cb7fae606b..81a3d1cbe5 100644 --- a/src/waveform/renderers/waveformmark.cpp +++ b/src/waveform/renderers/waveformmark.cpp @@ -104,3 +104,19 @@ void WaveformMark::setBaseColor(QColor baseColor) { m_borderColor = Color::chooseContrastColor(baseColor); m_labelColor = Color::chooseColorByBrightness(baseColor, QColor(255,255,255,255), QColor(0,0,0,255)); }; + +bool WaveformMark::contains(QPoint point, Qt::Orientation orientation) { + // Without some padding, the user would only have a single pixel width that + // would count as hovering over the WaveformMark. + float lineHoverPadding = 5.0; + int position; + if (orientation == Qt::Horizontal) { + position = point.x(); + } else { + position = point.y(); + } + bool lineHovered = m_linePosition >= position - lineHoverPadding && + m_linePosition <= position + lineHoverPadding; + + return (m_label.area().contains(point) || lineHovered); +} diff --git a/src/waveform/renderers/waveformmark.h b/src/waveform/renderers/waveformmark.h index caf652adaa..5e3150126a 100644 --- a/src/waveform/renderers/waveformmark.h +++ b/src/waveform/renderers/waveformmark.h @@ -66,6 +66,9 @@ class WaveformMark { return m_labelColor; } + // Check if a point (in image co-ordinates) lies on drawn image. + bool contains(QPoint point, Qt::Orientation orientation); + QColor m_textColor; QString m_text; Qt::Alignment m_align; diff --git a/src/waveform/renderers/waveformwidgetrenderer.cpp b/src/waveform/renderers/waveformwidgetrenderer.cpp index 58f4764651..850a76f5d2 100644 --- a/src/waveform/renderers/waveformwidgetrenderer.cpp +++ b/src/waveform/renderers/waveformwidgetrenderer.cpp @@ -290,44 +290,15 @@ void WaveformWidgetRenderer::setTrack(TrackPointer track) { } WaveformMarkPointer WaveformWidgetRenderer::getCueMarkAtPoint(QPoint point) { - WaveformMarkPointer pSelectedMark; - const int lineHoverpadding = 5; for (const auto& pMark : m_markLabelOffsets.keys()) { - QRectF labelBoundingRectInMarkImageSpace = pMark->m_label.area(); - int markImageOffsetInWaveformWidgetSpace = m_markLabelOffsets[pMark]; - int markLineOffset = markImageOffsetInWaveformWidgetSpace + pMark->m_linePosition; - QRect labelRectangleInWaveformWidgetSpace; - QRect markLineVicinity; + int markImagePositionInWidgetSpace = m_markLabelOffsets[pMark]; + QPoint pointInImageSpace; if (getOrientation() == Qt::Horizontal) { - int labelBoundaryStartOffset = - markImageOffsetInWaveformWidgetSpace + - labelBoundingRectInMarkImageSpace.left(); - labelRectangleInWaveformWidgetSpace = - QRect(labelBoundaryStartOffset, - labelBoundingRectInMarkImageSpace.top(), - labelBoundingRectInMarkImageSpace.width(), - labelBoundingRectInMarkImageSpace.height()); - markLineVicinity = QRect(markLineOffset - lineHoverpadding, - 0, - lineHoverpadding * 2, - getHeight()); + pointInImageSpace = QPoint(point.x() - markImagePositionInWidgetSpace, point.y()); } else { /* Vertical */ - int labelBoundaryStartOffset = - markImageOffsetInWaveformWidgetSpace + - labelBoundingRectInMarkImageSpace.top(); - labelRectangleInWaveformWidgetSpace = - QRect(labelBoundingRectInMarkImageSpace.left(), - labelBoundaryStartOffset, - labelBoundingRectInMarkImageSpace.width(), - labelBoundingRectInMarkImageSpace.height()); - markLineVicinity = QRect(0, - markLineOffset - lineHoverpadding, - getWidth(), - lineHoverpadding * 2); + pointInImageSpace = QPoint(point.x(), point.y() - markImagePositionInWidgetSpace); } - - if (labelRectangleInWaveformWidgetSpace.contains(point) || - markLineVicinity.contains(point)) { + if (pMark->contains(pointInImageSpace, getOrientation())) { return pMark; } } diff --git a/src/widget/woverview.cpp b/src/widget/woverview.cpp index b47f4740ea..c885c3e65e 100644 --- a/src/widget/woverview.cpp +++ b/src/widget/woverview.cpp @@ -442,9 +442,7 @@ void WOverview::mouseMoveEvent(QMouseEvent* e) { } m_pHoveredMark.clear(); - // Without some padding, the user would only have a single pixel width that - // would count as hovering over the WaveformMark. - float lineHoverPadding = 5.0; + // Non-hotcue marks (intro/outro cues, main cue, loop in/out) are sorted // before hotcues in m_marksToRender so if there is a hotcue in the same // location, the hotcue gets rendered on top. When right clicking, the @@ -453,16 +451,7 @@ void WOverview::mouseMoveEvent(QMouseEvent* e) { // reverse and the loop breaks as soon as m_pHoveredMark is set. for (int i = m_marksToRender.size() - 1; i >= 0; --i) { WaveformMarkPointer pMark = m_marksToRender.at(i); - int hoveredPosition; - if (m_orientation == Qt::Horizontal) { - hoveredPosition = e->x(); - } else { - hoveredPosition = e->y(); - } - bool lineHovered = - pMark->m_linePosition >= hoveredPosition - lineHoverPadding && pMark->m_linePosition <= hoveredPosition + lineHoverPadding; - - if (pMark->m_label.area().contains(e->pos()) || lineHovered) { + if (pMark->contains(e->pos(), m_orientation)) { m_pHoveredMark = pMark; break; } |