Commit 846616c4 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Sync current image time with the model

parent 0054e64e
......@@ -228,5 +228,8 @@ int KisImageAnimationInterface::totalLength()
{
int lastKey = findLastKeyframeTimeRecursive(m_d->image->root());
return std::max(lastKey, m_d->currentRange.end()) + 1;
lastKey = std::max(lastKey, m_d->currentRange.end());
lastKey = std::max(lastKey, m_d->currentUITime);
return lastKey + 1;
}
......@@ -353,12 +353,15 @@ void FramesTableView::slotHeaderDataChanged(Qt::Orientation orientation, int fir
void FramesTableView::dragEnterEvent(QDragEnterEvent *event)
{
m_d->dragInProgress = true;
m_d->model->setScrubState(true);
QTableView::dragEnterEvent(event);
}
void FramesTableView::dragMoveEvent(QDragMoveEvent *event)
{
m_d->dragInProgress = true;
m_d->model->setScrubState(true);
QTableView::dragMoveEvent(event);
......@@ -375,6 +378,7 @@ void FramesTableView::dragMoveEvent(QDragMoveEvent *event)
void FramesTableView::dropEvent(QDropEvent *event)
{
m_d->dragInProgress = false;
m_d->model->setScrubState(false);
QAbstractItemView::dropEvent(event);
setCurrentIndex(currentIndex());
......@@ -383,6 +387,7 @@ void FramesTableView::dropEvent(QDropEvent *event)
void FramesTableView::dragLeaveEvent(QDragLeaveEvent *event)
{
m_d->dragInProgress = false;
m_d->model->setScrubState(false);
QAbstractItemView::dragLeaveEvent(event);
setCurrentIndex(currentIndex());
......@@ -441,6 +446,7 @@ void FramesTableView::mouseMoveEvent(QMouseEvent *e)
}
e->accept();
} else {
m_d->model->setScrubState(true);
QTableView::mouseMoveEvent(e);
}
}
......@@ -450,6 +456,7 @@ void FramesTableView::mouseReleaseEvent(QMouseEvent *e)
if (e->modifiers() & Qt::ControlModifier) {
e->accept();
} else {
m_d->model->setScrubState(false);
QTableView::mouseReleaseEvent(e);
}
}
......
......@@ -122,6 +122,10 @@ void TimelineModelTest::testView()
QSpinBox *intFps = new QSpinBox(&dlg);
intFps->setValue(12);
QSpinBox *intTime = new QSpinBox(&dlg);
intTime->setValue(0);
intTime->setMaximum(10000);
FramesTableView *framesTable = new FramesTableView(&dlg);
TimelineFramesModel *model = new TimelineFramesModel(&dlg);
......@@ -140,17 +144,30 @@ void TimelineModelTest::testView()
connect(intFps, SIGNAL(valueChanged(int)),
m_image->animationInterface(), SLOT(setFramerate(int)));
connect(intTime, SIGNAL(valueChanged(int)),
SLOT(setCurrentTime(int)));
connect(m_image->animationInterface(), SIGNAL(sigTimeChanged(int)),
intTime, SLOT(setValue(int)));
QVBoxLayout *layout = new QVBoxLayout(&dlg);
layout->addWidget(intFps);
layout->addWidget(intTime);
layout->addWidget(framesTable);
layout->setStretch(0, 0);
layout->setStretch(1, 1);
layout->setStretch(1, 0);
layout->setStretch(2, 1);
dlg.resize(600, 400);
dlg.exec();
}
void TimelineModelTest::setCurrentTime(int time)
{
m_image->animationInterface()->requestTimeSwitchWithUndo(time);
}
QTEST_KDEMAIN(TimelineModelTest, GUI)
......@@ -38,6 +38,9 @@ private Q_SLOTS:
void testModel();
void testView();
private Q_SLOTS:
void setCurrentTime(int time);
private:
KisDocument *m_doc;
KisNameServer *m_nameServer;
......
......@@ -53,7 +53,9 @@ struct TimelineFramesModel::Private
needFinishRemoveRows(false),
numFramesOverride(0),
updateTimer(200, KisSignalCompressor::FIRST_INACTIVE),
parentOfRemovedNode(0)
parentOfRemovedNode(0),
scrubInProgress(false),
scrubStartFrame(-1)
{}
// TODO!!!!
......@@ -75,6 +77,9 @@ struct TimelineFramesModel::Private
KisNodeDummy* parentOfRemovedNode;
QScopedPointer<TimelineNodeListKeeper> converter;
bool scrubInProgress;
int scrubStartFrame;
QVariant layerName(int row) const {
KisNodeDummy *dummy = converter->dummyFromRow(row);
if (!dummy) return QVariant();
......@@ -266,6 +271,8 @@ void TimelineFramesModel::setDummiesFacade(KisDummiesFacadeBase *dummiesFacade,
SLOT(slotDummyChanged(KisNodeDummy*)));
connect(m_d->image->animationInterface(),
SIGNAL(sigFramerateChanged()), SLOT(slotFramerateChanged()));
connect(m_d->image->animationInterface(),
SIGNAL(sigTimeChanged(int)), SLOT(slotCurrentTimeChanged(int)));
}
if(m_d->dummiesFacade != oldDummiesFacade) {
......@@ -299,6 +306,13 @@ void TimelineFramesModel::slotFramerateChanged()
emit headerDataChanged(Qt::Horizontal, 0, columnCount() - 1);
}
void TimelineFramesModel::slotCurrentTimeChanged(int time)
{
if (time != m_d->activeFrameIndex) {
setData(index(m_d->activeLayerIndex, time), true, ActiveFrameRole);
}
}
int TimelineFramesModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
......@@ -378,10 +392,14 @@ bool TimelineFramesModel::setData(const QModelIndex &index, const QVariant &valu
break;
}
case ActiveFrameRole: {
if (value.toBool()) {
if (value.toBool() &&
index.column() != m_d->activeFrameIndex) {
int prevFrame = m_d->activeFrameIndex;
m_d->activeFrameIndex = index.column();
scrubTo(m_d->activeFrameIndex, m_d->scrubInProgress);
emit dataChanged(this->index(0, prevFrame), this->index(rowCount() - 1, prevFrame));
emit dataChanged(this->index(0, m_d->activeFrameIndex), this->index(rowCount() - 1, m_d->activeFrameIndex));
......@@ -664,3 +682,33 @@ void TimelineFramesModel::setLastVisibleFrame(int time)
endRemoveColumns();
}
}
void TimelineFramesModel::setScrubState(bool active)
{
if (!m_d->scrubInProgress && active) {
m_d->scrubStartFrame = m_d->activeFrameIndex;
m_d->scrubInProgress = true;
}
if (m_d->scrubInProgress && !active &&
m_d->scrubStartFrame > 0 &&
m_d->scrubStartFrame != m_d->activeFrameIndex) {
m_d->scrubStartFrame = -1;
m_d->scrubInProgress = false;
scrubTo(m_d->activeFrameIndex, false);
}
}
void TimelineFramesModel::scrubTo(int time, bool preview)
{
KIS_ASSERT_RECOVER_RETURN(m_d->image);
if (preview) {
// TODO:
// m_canvas->animationPlayer()->displayFrame(time);
} else {
m_d->image->animationInterface()->requestTimeSwitchWithUndo(time);
}
}
......@@ -50,6 +50,9 @@ public:
void setLastVisibleFrame(int time);
void setScrubState(bool active);
void scrubTo(int time, bool preview);
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
......@@ -89,7 +92,10 @@ public:
private Q_SLOTS:
void slotDummyChanged(KisNodeDummy *dummy);
void processUpdateQueue();
public Q_SLOTS:
void slotFramerateChanged();
void slotCurrentTimeChanged(int time);
private:
struct Private;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment