Skip to content

Commit

Permalink
Timeline: draw markers text
Browse files Browse the repository at this point in the history
  • Loading branch information
rodlie committed Aug 1, 2024
1 parent 0ed0418 commit ebe4aee
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/ui/widgets/framescrollbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ FrameScrollBar::FrameScrollBar(const int minSpan,
const bool bottom,
QWidget *parent)
: QWidget(parent)
, mFm(QFontMetrics(font()))
{
mDisplayTime = AppSupport::getSettings("ui",
"DisplayTimecode",
Expand Down Expand Up @@ -142,9 +143,20 @@ void FrameScrollBar::paintEvent(QPaintEvent *) {
bool hasOut = hasFrameOut(i+1);
bool hasMark = hasFrameMarker(i+1);
if (!hasIn && !hasOut && !hasMark) { continue; }
p.setPen(QPen(hasMark ? ThemeSupport::getThemeFrameMarkerColor() : ThemeSupport::getThemeHighlightColor(), 2, Qt::DotLine));
const QColor col = hasMark ? ThemeSupport::getThemeFrameMarkerColor() : ThemeSupport::getThemeHighlightColor();
p.setPen(QPen(col, 2, Qt::DotLine));
const qreal xTT = xT + (i - mFrameRange.fMin + 1)*pixPerFrame;
p.drawLine(QPointF(xTT, 4), QPointF(xTT, height()));

QString drawValue = hasIn ? tr("In") : hasOut ? tr("Out") : getFrameMarkerText(i+1);
if (!drawValue.isEmpty()) {
p.setPen(QPen(col, 0, Qt::SolidLine));
const auto rect = QRectF(xTT - 1, 0, mFm.horizontalAdvance(drawValue) + 2, mFm.height());
p.fillRect(rect, QBrush(col, Qt::SolidPattern));
p.drawRect(rect);
p.setPen(Qt::black);
p.drawText(rect, Qt::AlignCenter, drawValue);
}
}

// draw minor
Expand Down Expand Up @@ -216,6 +228,12 @@ bool FrameScrollBar::hasFrameMarker(const int frame)
return mCurrentCanvas->hasMarker(frame);
}

const QString FrameScrollBar::getFrameMarkerText(const int frame)
{
if (!mCurrentCanvas) { return QString(); }
return mCurrentCanvas->getMarkerText(frame);
}

void FrameScrollBar::wheelEvent(QWheelEvent *event) {
if(mRange) {
if(event->modifiers() & Qt::CTRL) {
Expand Down
5 changes: 5 additions & 0 deletions src/ui/widgets/framescrollbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "ui_global.h"

#include <QWidget>
#include <QFontMetrics>

#include "smartPointers/ememory.h"
#include "canvas.h"
#include "themesupport.h"
Expand All @@ -54,6 +56,7 @@ class UI_EXPORT FrameScrollBar : public QWidget
bool hasFrameIn(const int frame);
bool hasFrameOut(const int frame);
bool hasFrameMarker(const int frame);
const QString getFrameMarkerText(const int frame);

FrameRange getViewedRange() const;
int getFirstViewedFrame() const;
Expand Down Expand Up @@ -108,6 +111,8 @@ class UI_EXPORT FrameScrollBar : public QWidget
qreal mFps;
qreal mLastMousePressFrame;

QFontMetrics mFm;

QColor mHandleColor = ThemeSupport::getThemeButtonBaseColor();
qptr<Canvas> mCurrentCanvas;
};
Expand Down

0 comments on commit ebe4aee

Please sign in to comment.