Skip to content

Commit

Permalink
Support for timecodes on timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
rodlie committed Aug 19, 2023
1 parent 79e5440 commit 496a3eb
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 28 deletions.
85 changes: 57 additions & 28 deletions src/app/GUI/animationwidgetscrollbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "GUI/global.h"
#include "colorhelpers.h"

#include "appsupport.h"

FrameScrollBar::FrameScrollBar(const int minSpan,
const int maxSpan,
const bool range,
Expand All @@ -54,6 +56,7 @@ qreal FrameScrollBar::posToFrame(int xPos) {

void FrameScrollBar::setCurrentCanvas(Canvas * const canvas) {
mCurrentCanvas = canvas;
if (mCurrentCanvas) { mDisplayTime = mCurrentCanvas->getDisplayTimecode(); }
}

void FrameScrollBar::paintEvent(QPaintEvent *) {
Expand Down Expand Up @@ -90,17 +93,20 @@ void FrameScrollBar::paintEvent(QPaintEvent *) {
handleRect.setBottom(mBottom ? 4 : height());
p.fillRect(handleRect, col);

if(mCurrentCanvas) {
const int soundHeight = eSizesUI::widget/3;
const int rasterHeight = eSizesUI::widget - soundHeight;
const QRectF rasterRect(x0, 0, w1, rasterHeight);
const auto& rasterCache = mCurrentCanvas->getSceneFramesHandler();
rasterCache.drawCacheOnTimeline(&p, rasterRect, minFrame, maxFrame);

if (mCurrentCanvas) {
const qreal fps = mCurrentCanvas->getFps();
const QRectF soundRect(x0, rasterHeight, w1, soundHeight);
const auto& soundCache = mCurrentCanvas->getSoundCacheHandler();
soundCache.drawCacheOnTimeline(&p, soundRect, minFrame, maxFrame, fps);
mFps = fps;
if (!mRange) {
const int soundHeight = eSizesUI::widget/3;
const int rasterHeight = eSizesUI::widget - soundHeight;
const QRectF rasterRect(x0, 0, w1, rasterHeight);
const auto& rasterCache = mCurrentCanvas->getSceneFramesHandler();
rasterCache.drawCacheOnTimeline(&p, rasterRect, minFrame, maxFrame);

const QRectF soundRect(x0, rasterHeight, w1, soundHeight);
const auto& soundCache = mCurrentCanvas->getSoundCacheHandler();
soundCache.drawCacheOnTimeline(&p, soundRect, minFrame, maxFrame, fps);
}
}

p.setPen(Qt::white);
Expand All @@ -120,12 +126,24 @@ void FrameScrollBar::paintEvent(QPaintEvent *) {
const qreal threeFourthsHeight = height()*0.75;
const qreal maxX = width() + eSizesUI::widget;
while(xL < maxX) {
if(!mRange) {
//if(!mRange) {
p.drawLine(QPointF(xL, threeFourthsHeight + 2),
QPointF(xL, height()));
//}
QString drawValue = QString::number(currentFrame);
qreal leftValue = xL;
if (mDisplayTime && mFps > 0) {
drawValue = AppSupport::getTimeCodeFromFrame(currentFrame, mFps);
if (mRange) {
if (currentFrame == mFrameRange.fMin) {
leftValue = xL + 40;
} else if (currentFrame == mFrameRange.fMax) {
leftValue = xL - 40;
}
}
}
p.drawText(QRectF(xL - inc, 0, 2*inc, height()),
Qt::AlignCenter, QString::number(currentFrame));
p.drawText(QRectF(leftValue - inc, 0, 2*inc, height()),
Qt::AlignCenter, drawValue);
xL += inc;
currentFrame += mDrawFrameInc;
}
Expand Down Expand Up @@ -196,40 +214,51 @@ bool FrameScrollBar::setFirstViewedFrame(const int firstFrame) {

}
#include <QMenu>
void FrameScrollBar::mousePressEvent(QMouseEvent *event) {
if(event->button() == Qt::RightButton) {
void FrameScrollBar::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
QMenu menu(this);
QAction *clampAction = new QAction("Clamp", this);
/*QAction *clampAction = new QAction("Clamp", this);
clampAction->setCheckable(true);
clampAction->setChecked(mClamp);
menu.addAction(clampAction);
menu.addAction(clampAction);*/

menu.addSeparator();
//menu.addSeparator();

/*QAction *timeAction = new QAction("Display Time", this);
QAction *timeAction = new QAction(tr("Display Timecodes"), this);
timeAction->setCheckable(true);
timeAction->setChecked(mDisplayTime);
menu.addAction(timeAction);

QAction *framesAction = new QAction("Display Frames", this);
QAction *framesAction = new QAction(tr("Display Frames"), this);
framesAction->setCheckable(true);
framesAction->setChecked(!mDisplayTime);
menu.addAction(framesAction);*/
menu.addAction(framesAction);

QAction* selectedAction = menu.exec(event->globalPos());
if(selectedAction) {
if(selectedAction == clampAction) {
if (selectedAction) {
/*if (selectedAction == clampAction) {
mClamp = !mClamp;
}/* else if(selectedAction == framesAction) {
} else*/ if (selectedAction == framesAction) {
mDisplayTime = false;
} else if(selectedAction == timeAction) {
update();
if (mCurrentCanvas) {
mCurrentCanvas->setDisplayTimecode(mDisplayTime);
}
} else if (selectedAction == timeAction) {
mDisplayTime = true;
}*/
update();
if (mCurrentCanvas) {
mCurrentCanvas->setDisplayTimecode(mDisplayTime);
}
}
}
return;
}
mPressed = true;
mLastMousePressFrame = posToFrame(event->x() );
if(mLastMousePressFrame < mFirstViewedFrame ||
mLastMousePressFrame > mFirstViewedFrame + mViewedFramesSpan) {
if (mLastMousePressFrame < mFirstViewedFrame ||
mLastMousePressFrame > mFirstViewedFrame + mViewedFramesSpan) {
setFirstViewedFrame(qRound(mLastMousePressFrame - mViewedFramesSpan/2.));
emitTriggeredChange();
}
Expand Down
1 change: 1 addition & 0 deletions src/app/GUI/timelinewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ void TimelineWidget::setCurrentScene(Canvas * const scene) {
mCurrentScene = scene;
mSceneChooser->setCurrentScene(scene);
mFrameScrollBar->setCurrentCanvas(scene);
mFrameRangeScrollBar->setCurrentCanvas(scene);
mBoxesListWidget->setCurrentScene(scene);
mKeysView->setCurrentScene(scene);
if(scene) {
Expand Down
11 changes: 11 additions & 0 deletions src/core/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,15 @@ class CORE_EXPORT Canvas : public CanvasBase
emit fpsChanged(fps);
}

bool getDisplayTimecode()
{
return mDisplayTimeCode;
}
void setDisplayTimecode(bool timecode)
{
mDisplayTimeCode = timecode;
}

BoundingBox *getBoxAt(const QPointF &absPos)
{
if (mClipToCanvasSize) {
Expand Down Expand Up @@ -758,6 +767,8 @@ class CORE_EXPORT Canvas : public CanvasBase
int mHeight;
qreal mFps;

bool mDisplayTimeCode = false;

bool mPivotUpdateNeeded = false;

bool mStartTransform = false;
Expand Down

0 comments on commit 496a3eb

Please sign in to comment.