diff options
author | Harshit Maurya <hmaurya999@gmail.com> | 2020-05-13 00:38:28 +0530 |
---|---|---|
committer | Harshit Maurya <hmaurya999@gmail.com> | 2020-05-16 02:17:43 +0530 |
commit | 10ce4c441377389010a7a901747337f9f724e958 (patch) | |
tree | a81b012b367e0fb065af50f5dd7cdcffcb3919a0 | |
parent | 883b97c3d0a7462ff5301ab50b6ea64db9a26f6d (diff) |
wwaveformviewer: limit to cue markers on screen
-rw-r--r-- | src/waveform/renderers/waveformrendermark.cpp | 17 | ||||
-rw-r--r-- | src/waveform/renderers/waveformwidgetrenderer.cpp | 3 |
2 files changed, 13 insertions, 7 deletions
diff --git a/src/waveform/renderers/waveformrendermark.cpp b/src/waveform/renderers/waveformrendermark.cpp index f3ff3f915e..213d74e7e1 100644 --- a/src/waveform/renderers/waveformrendermark.cpp +++ b/src/waveform/renderers/waveformrendermark.cpp @@ -31,7 +31,7 @@ void WaveformRenderMark::setup(const QDomNode& node, const SkinContext& context) void WaveformRenderMark::draw(QPainter* painter, QPaintEvent* /*event*/) { PainterScope PainterScope(painter); - + QMap<WaveformMarkPointer, QRect> marksOnScreen; /* //DEBUG for (int i = 0; i < m_markPoints.size(); i++) { @@ -64,26 +64,31 @@ void WaveformRenderMark::draw(QPainter* painter, QPaintEvent* /*event*/) { if (m_waveformRenderer->getOrientation() == Qt::Horizontal) { // NOTE: vRince I guess image width is odd to display the center on the exact line ! // external image should respect that ... + auto& labelBoundingRect = m_markBoundaries[pMark]; const int markHalfWidth = pMark->m_image.width() / 2.0 / m_waveformRenderer->getDevicePixelRatio(); // Check if the current point need to be displayed if (currentMarkPoint > -markHalfWidth && currentMarkPoint < m_waveformRenderer->getWidth() + markHalfWidth) { int drawOffset = currentMarkPoint - markHalfWidth; + int labelBoundaryOffset = currentMarkPoint - labelBoundingRect.width() / 2.0; const auto topLeft = QPoint(drawOffset, 0); painter->drawImage(topLeft, pMark->m_image); - m_markBoundaries[pMark].setTopLeft(topLeft); + labelBoundingRect.setRect(labelBoundaryOffset, + 0, + labelBoundingRect.width(), + labelBoundingRect.height()); + marksOnScreen[pMark] = labelBoundingRect; } } else { const int markHalfHeight = pMark->m_image.height() / 2.0; - if (currentMarkPoint > -markHalfHeight && currentMarkPoint < m_waveformRenderer->getHeight() + markHalfHeight) { painter->drawImage(QPoint(0,currentMarkPoint - markHalfHeight), pMark->m_image); } } } } - m_waveformRenderer->setMarkLabelBoundaries(m_markBoundaries); + m_waveformRenderer->setMarkLabelBoundaries(marksOnScreen); } void WaveformRenderMark::onResize() { @@ -189,8 +194,6 @@ void WaveformRenderMark::generateMarkImage(WaveformMarkPointer pMark) { int labelRectHeight = wordRect.height() + 2 * marginY + 4; QRectF labelRect(0, 0, (float)labelRectWidth, (float)labelRectHeight); - m_markBoundaries[pMark].setWidth(labelRectWidth); - m_markBoundaries[pMark].setHeight(labelRectHeight); int width; int height; @@ -223,6 +226,8 @@ void WaveformRenderMark::generateMarkImage(WaveformMarkPointer pMark) { labelRect.moveBottom(height - 1); } + m_markBoundaries[pMark].setRect(0, 0, labelRectWidth, labelRectHeight); + // Fill with transparent pixels pMark->m_image.fill(QColor(0, 0, 0, 0).rgba()); diff --git a/src/waveform/renderers/waveformwidgetrenderer.cpp b/src/waveform/renderers/waveformwidgetrenderer.cpp index fb1de6cd7c..d79c2628a6 100644 --- a/src/waveform/renderers/waveformwidgetrenderer.cpp +++ b/src/waveform/renderers/waveformwidgetrenderer.cpp @@ -292,7 +292,8 @@ void WaveformWidgetRenderer::setTrack(TrackPointer track) { std::optional<CuePointer> WaveformWidgetRenderer::getCueAtPoint(QPoint point) { WaveformMarkPointer pSelectedMark; for (auto pMark : m_markBoundaries.keys()) { - if (m_markBoundaries[pMark].contains(point)) { + const auto labelRectangle = m_markBoundaries[pMark]; + if (labelRectangle.contains(point)) { pSelectedMark = pMark; break; } |