Skip to content

Commit

Permalink
added comments and minor changed based on review
Browse files Browse the repository at this point in the history
  • Loading branch information
m0dB authored and m0dB committed Dec 8, 2023
1 parent 887dea6 commit f7e7cd5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
11 changes: 7 additions & 4 deletions src/waveform/renderers/waveformmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
#include "widget/wskincolor.h"

namespace {

// Without some padding, the user would only have a single pixel width that
// would count as hovering over the WaveformMark.
constexpr float lineHoverPadding = 5.0;

Qt::Alignment decodeAlignmentFlags(const QString& alignString, Qt::Alignment defaultFlags) {
QStringList stringFlags = alignString.toLower()
.split('|',
Expand Down Expand Up @@ -137,10 +142,8 @@ void WaveformMark::setBaseColor(QColor baseColor, int dimBrightThreshold) {
}

bool WaveformMark::lineHovered(QPoint point, Qt::Orientation orientation) const {
// Without some padding, the user would only have a single pixel width that
// would count as hovering over the WaveformMark.
float lineHoverPadding = 5.0;
if (orientation == Qt::Vertical) {
// Note that for vertical orientation, breadth is set to the width.
point = QPoint(point.y(), static_cast<int>(m_breadth) - point.x());
}
return m_linePosition >= point.x() - lineHoverPadding &&
Expand Down Expand Up @@ -306,7 +309,7 @@ QImage WaveformMark::generateImage(float devicePixelRatio) {
const bool useIcon = m_iconPath != "";

// Determine drawing geometries
const MarkerGeometry markerGeometry(label, useIcon, m_align, m_breadth, m_level);
const MarkerGeometry markerGeometry{label, useIcon, m_align, m_breadth, m_level};

m_label.setAreaRect(markerGeometry.m_labelRect);

Expand Down
8 changes: 6 additions & 2 deletions src/waveform/renderers/waveformmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class WaveformMark {
public:
class Graphics {
public:
Graphics() {
}
// To indicate that the image for the mark needs to be regenerated,
// when the text, color, breadth or level are changed.
bool m_obsolete{};
};

Expand Down Expand Up @@ -149,6 +149,10 @@ class WaveformMark {

float m_linePosition;
float m_breadth;

// When there are overlapping marks, level is increased for each overlapping mark,
// so that we can draw them at different positions: The marks at the top go lower
// when the level increased, the marks at the bottom higher.
int m_level;

WaveformMarkLabel m_label;
Expand Down
4 changes: 4 additions & 0 deletions src/waveform/renderers/waveformmarkset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ void WaveformMarkSet::update() {
[](auto const& pair) { return pair.second; });

double prevSamplePosition = Cue::kNoPosition;

// Avoid overlapping marks by increasing the level per alignment.
// We take this into account when drawing the marks aligned at:
// left top, right top, left bottom, right bottom.
std::map<Qt::Alignment, int> levels;
for (auto& pMark : m_marksToRender) {
if (pMark->getSamplePosition() != prevSamplePosition) {
Expand Down
6 changes: 3 additions & 3 deletions src/waveform/renderers/waveformrendermarkbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include "waveform/renderers/waveformwidgetrenderer.h"

WaveformRenderMarkBase::WaveformRenderMarkBase(
WaveformWidgetRenderer* waveformWidgetRenderer,
WaveformWidgetRenderer* pWaveformWidgetRenderer,
bool updateImagesImmediately)
: WaveformRendererAbstract(waveformWidgetRenderer),
: WaveformRendererAbstract(pWaveformWidgetRenderer),
m_updateImagesImmediately(updateImagesImmediately) {
}

Expand Down Expand Up @@ -88,7 +88,7 @@ void WaveformRenderMarkBase::updateMarks() {
}

void WaveformRenderMarkBase::updateMarkImages() {
for (auto& pMark : m_marks) {
for (const auto& pMark : m_marks) {
if (pMark->needsImageUpdate()) {
updateMarkImage(pMark);
}
Expand Down

0 comments on commit f7e7cd5

Please sign in to comment.