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

Maintain active layer track in view #1867

Merged
merged 6 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions app/src/timeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ GNU General Public License for more details.
#include <QLabel>
#include <QWheelEvent>
#include <QSlider>
#include <QTimer>

#include "editor.h"
#include "layermanager.h"
Expand Down Expand Up @@ -191,12 +192,17 @@ void TimeLine::initUI()
timeLineContent->setLayout(lay);
setWidget(timeLineContent);

mScrollingStoppedTimer = new QTimer();
mScrollingStoppedTimer->setSingleShot(true);

setWindowFlags(Qt::WindowStaysOnTopHint);

connect(mHScrollbar, &QScrollBar::valueChanged, mTracks, &TimeLineCells::hScrollChange);
connect(mTracks, &TimeLineCells::offsetChanged, mHScrollbar, &QScrollBar::setValue);
connect(mVScrollbar, &QScrollBar::valueChanged, mTracks, &TimeLineCells::vScrollChange);
connect(mVScrollbar, &QScrollBar::valueChanged, mLayerList, &TimeLineCells::vScrollChange);
connect(mVScrollbar, &QScrollBar::valueChanged, this, &TimeLine::onScrollbarValueChanged);
connect(mScrollingStoppedTimer, &QTimer::timeout, mLayerList, &TimeLineCells::onScrollingVerticallyStopped);

connect(splitter, &QSplitter::splitterMoved, this, &TimeLine::updateLength);

Expand Down Expand Up @@ -232,7 +238,7 @@ void TimeLine::initUI()

LayerManager* layer = editor()->layers();
connect(layer, &LayerManager::layerCountChanged, this, &TimeLine::updateLayerNumber);
connect(layer, &LayerManager::currentLayerChanged, this, &TimeLine::onLayerChanged);
connect(layer, &LayerManager::currentLayerChanged, this, &TimeLine::onCurrentLayerChanged);
mNumLayers = layer->count();

scrubbing = false;
Expand Down Expand Up @@ -285,6 +291,12 @@ void TimeLine::wheelEvent(QWheelEvent* event)
}
}

void TimeLine::onScrollbarValueChanged()
{
// After the scrollbar has been updated, prepare to trigger stopped event
mScrollingStoppedTimer->start(150);
}

void TimeLine::updateFrame(int frameNumber)
{
Q_ASSERT(mTracks);
Expand Down Expand Up @@ -358,7 +370,27 @@ void TimeLine::onObjectLoaded()
updateLayerNumber(editor()->layers()->count());
}

void TimeLine::onLayerChanged()
void TimeLine::onCurrentLayerChanged()
{
updateVerticalScrollbarPosition();
mLayerDeleteButton->setEnabled(editor()->layers()->canDeleteLayer(editor()->currentLayerIndex()));
}

void TimeLine::updateVerticalScrollbarPosition()
{
// invert index so 0 is at the top
int idx = mNumLayers - editor()->currentLayerIndex() - 1;
// number of visible layers
int height = mNumLayers - mVScrollbar->maximum();
// scroll bar position/offset
int pos = mVScrollbar->value();

if (idx < pos) // above visible area
{
mVScrollbar->setValue(idx);
}
else if (idx >= pos + height) // below visible area
{
mVScrollbar->setValue(idx - height + 1);
}
}
9 changes: 8 additions & 1 deletion app/src/timeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class TimeLineCells;
class TimeControls;

class QToolButton;
class QWheelEvent;


class TimeLine : public BaseDockWidget
Expand Down Expand Up @@ -53,7 +54,8 @@ class TimeLine : public BaseDockWidget
int getRangeUpper();

void onObjectLoaded();
void onLayerChanged();
void onCurrentLayerChanged();
void onScrollbarValueChanged();

signals:
void selectionChanged();
Expand All @@ -76,6 +78,7 @@ class TimeLine : public BaseDockWidget
void onionPrevClick();
void onionNextClick();
void playButtonTriggered();

public:
bool scrubbing = false;

Expand All @@ -84,12 +87,16 @@ class TimeLine : public BaseDockWidget
void wheelEvent( QWheelEvent* ) override;

private:
void updateVerticalScrollbarPosition();

QScrollBar* mHScrollbar = nullptr;
QScrollBar* mVScrollbar = nullptr;
TimeLineCells* mTracks = nullptr;
TimeLineCells* mLayerList = nullptr;
TimeControls* mTimeControls = nullptr;

QTimer* mScrollingStoppedTimer = nullptr;

QToolButton* mLayerDeleteButton = nullptr;
int mNumLayers = 0;
int mLastUpdatedFrame = 0;
Expand Down
8 changes: 7 additions & 1 deletion app/src/timelinecells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ void TimeLineCells::mouseReleaseEvent(QMouseEvent* event)
updateContent();
}
}
if (mType == TIMELINE_CELL_TYPE::Layers && layerNumber != mStartLayerNumber && mStartLayerNumber != -1 && layerNumber != -1)
if (mType == TIMELINE_CELL_TYPE::Layers && !mScrollingVertically && layerNumber != mStartLayerNumber && mStartLayerNumber != -1 && layerNumber != -1)
{
mToLayer = getInbetweenLayerNumber(event->pos().y());
if (mToLayer != mFromLayer && mToLayer > -1 && mToLayer < mEditor->layers()->count())
Expand Down Expand Up @@ -1210,9 +1210,15 @@ void TimeLineCells::hScrollChange(int x)
void TimeLineCells::vScrollChange(int x)
{
mLayerOffset = x;
mScrollingVertically = true;
updateContent();
}

void TimeLineCells::onScrollingVerticallyStopped()
{
mScrollingVertically = false;
}

void TimeLineCells::setMouseMoveY(int x)
{
mMouseMoveY = x;
Expand Down
3 changes: 3 additions & 0 deletions app/src/timelinecells.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public slots:
void updateFrame(int frameNumber);
void hScrollChange(int);
void vScrollChange(int);
void onScrollingVerticallyStopped();
void setMouseMoveY(int x);

protected:
Expand Down Expand Up @@ -152,6 +153,8 @@ private slots:
int mLayerOffset = 0;
Qt::MouseButton primaryButton = Qt::NoButton;

bool mScrollingVertically = false;

bool mCanMoveFrame = false;
bool mMovingFrames = false;

Expand Down
Loading