timeline: show marker text even on markers without range

This commit is contained in:
itsmattkc
2022-07-19 11:21:06 -07:00
parent 35bc52ee47
commit 46be693b3e
4 changed files with 30 additions and 5 deletions
+17 -2
View File
@@ -20,6 +20,8 @@
#include "timelinemarker.h"
#include <QApplication>
#include "common/qtutils.h"
#include "common/xmlutils.h"
#include "config/config.h"
@@ -76,7 +78,7 @@ int TimelineMarker::GetMarkerHeight(const QFontMetrics &fm)
return fm.height();
}
QRect TimelineMarker::Draw(QPainter *p, const QPoint &pt, double scale, bool selected)
QRect TimelineMarker::Draw(QPainter *p, const QPoint &pt, int max_right, double scale, bool selected)
{
QFontMetrics fm = p->fontMetrics();
@@ -96,6 +98,9 @@ QRect TimelineMarker::Draw(QPainter *p, const QPoint &pt, double scale, bool sel
int top = pt.y() - marker_height;
QTextOption op(Qt::AlignLeft | Qt::AlignVCenter);
op.setWrapMode(QTextOption::NoWrap);
if (time_.out() != time_.in()) {
QRect marker_rect(pt.x(), top, time_.length().toDouble() * scale, marker_height);
@@ -103,7 +108,7 @@ QRect TimelineMarker::Draw(QPainter *p, const QPoint &pt, double scale, bool sel
if (!name_.isEmpty()) {
p->setPen(ColorCoding::GetUISelectorColor(ColorCoding::GetColor(color_)));
p->drawText(marker_rect.adjusted(marker_width/4, 0, 0, 0), name_, Qt::AlignLeft | Qt::AlignVCenter);
p->drawText(marker_rect.adjusted(marker_width/4, 0, 0, 0), name_, op);
}
return marker_rect;
@@ -125,6 +130,16 @@ QRect TimelineMarker::Draw(QPainter *p, const QPoint &pt, double scale, bool sel
p->setRenderHint(QPainter::Antialiasing);
p->drawPolygon(points, 6);
if (!name_.isEmpty() && max_right != -1) {
QRect text_rect(right, top, max_right - right, marker_height);
int padding = QtUtils::QFontMetricsWidth(p->fontMetrics(), QStringLiteral(" "));
text_rect.adjust(padding, 0, - padding - half_width, 0);
p->setPen(qApp->palette().text().color());
p->drawText(text_rect, name_, op);
}
return QRect(left, top, marker_width, marker_height);
}
}
+1 -1
View File
@@ -51,7 +51,7 @@ public:
void set_color(int c);
static int GetMarkerHeight(const QFontMetrics &fm);
QRect Draw(QPainter *p, const QPoint &pt, double scale, bool selected);
QRect Draw(QPainter *p, const QPoint &pt, int max_right, double scale, bool selected);
signals:
void TimeChanged(const TimeRange& time);
@@ -586,7 +586,7 @@ void TimelineView::DrawBlock(QPainter *painter, bool foreground, Block *block, q
if (marker->time().in() >= clip->media_in() && marker->time().out() <= clip->media_in() + clip->length()) {
QPoint marker_pt(TimeToScene(clip->in() - clip->media_in() + marker->time().in()), block_top + block_height);
painter->setClipRect(r);
QRect marker_rect = marker->Draw(painter, marker_pt, GetScale(), false);
QRect marker_rect = marker->Draw(painter, marker_pt, -1, GetScale(), false);
clip_marker_rects_.insert(marker, marker_rect);
painter->setClipping(false);
}
+11 -1
View File
@@ -277,7 +277,17 @@ void SeekableWidget::DrawMarkers(QPainter *p, int marker_bottom)
break;
}
QRect marker_rect = marker->Draw(p, QPoint(marker_left, marker_bottom), GetScale(), selection_manager_.IsSelected(marker));
int max_marker_right = lim_right;
{
// Check if there's a marker next
auto next = it;
next++;
if (next != markers_->cend()) {
max_marker_right = std::min(max_marker_right, int(TimeToScene((*next)->time().in())));
}
}
QRect marker_rect = marker->Draw(p, QPoint(marker_left, marker_bottom), max_marker_right, GetScale(), selection_manager_.IsSelected(marker));
marker_top_ = marker_rect.top();
selection_manager_.DeclareDrawnObject(marker, marker_rect);
}