Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gradually "compact" the markers if the waveform height is reduced #12501

Merged
merged 3 commits into from
Jan 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/waveform/renderers/waveformmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ Qt::Alignment decodeAlignmentFlags(const QString& alignString, Qt::Alignment def

return hflags | vflags;
}

float overlappingMarkerIncrement(const float labelRectHeight, const float breadth) {
// gradually "compact" the markers if the waveform height is
// reduced, to avoid multiple markers obscuring the waveform.
const float threshold = 90.f; // above this, the full increment is used
const float fullIncrement = labelRectHeight + 2.f;
const float minIncrement = 2.f; // increment when most compacted

return std::max(minIncrement, fullIncrement - std::max(0.f, threshold - breadth));
}

} // anonymous namespace

WaveformMark::WaveformMark(const QString& group,
Expand Down Expand Up @@ -253,13 +264,16 @@ struct MarkerGeometry {
m_labelRect.moveLeft(0.5f);
}

const float increment = overlappingMarkerIncrement(
static_cast<float>(m_labelRect.height()), breadth);

fwcd marked this conversation as resolved.
Show resolved Hide resolved
if (alignV == Qt::AlignVCenter) {
m_labelRect.moveTop((m_imageSize.height() - m_labelRect.height()) / 2.f);
} else if (alignV == Qt::AlignBottom) {
m_labelRect.moveBottom(m_imageSize.height() - 0.5f -
level * (m_labelRect.height() + 2.f));
level * increment);
} else {
m_labelRect.moveTop(0.5f + level * (m_labelRect.height() + 2.f));
m_labelRect.moveTop(0.5f + level * increment);
}
}
QSize getImageSize(float devicePixelRatio) const {
Expand Down