[krita] krita: Play currently selected frames only
Dmitry Kazakov
dimula73 at gmail.com
Wed Dec 16 18:52:32 UTC 2015
Git commit ae2996a73d53158067f26410e7c0190d633fb666 by Dmitry Kazakov.
Committed on 16/12/2015 at 18:46.
Pushed by dkazakov into branch 'master'.
Play currently selected frames only
Now one can play only a portion of the clip by selecting a range
on the timeline and clicking 'Play' button.
CC:kimageshop at kde.org
M +12 -0 krita/image/kis_image_animation_interface.cpp
M +4 -0 krita/image/kis_image_animation_interface.h
M +11 -1 krita/plugins/extensions/dockers/animation/timeline_frames_model.cpp
M +3 -0 krita/plugins/extensions/dockers/animation/timeline_frames_model.h
M +35 -2 krita/plugins/extensions/dockers/animation/timeline_frames_view.cpp
M +1 -0 krita/plugins/extensions/dockers/animation/timeline_frames_view.h
M +5 -1 krita/ui/canvas/kis_animation_player.cpp
http://commits.kde.org/krita/ae2996a73d53158067f26410e7c0190d633fb666
diff --git a/krita/image/kis_image_animation_interface.cpp b/krita/image/kis_image_animation_interface.cpp
index dc1166e..621afb9 100644
--- a/krita/image/kis_image_animation_interface.cpp
+++ b/krita/image/kis_image_animation_interface.cpp
@@ -48,6 +48,7 @@ struct KisImageAnimationInterface::Private
bool frameInvalidationBlocked;
KisTimeRange currentRange;
+ KisTimeRange playbackRange;
int framerate;
int cachedLastFrameValue;
};
@@ -88,6 +89,17 @@ void KisImageAnimationInterface::setRange(const KisTimeRange range) {
emit sigRangeChanged();
}
+const KisTimeRange& KisImageAnimationInterface::playbackRange() const
+{
+ return m_d->playbackRange.isValid() ? m_d->playbackRange : m_d->currentRange;
+}
+
+void KisImageAnimationInterface::setPlaybackRange(const KisTimeRange range)
+{
+ m_d->playbackRange = range;
+ emit sigPlaybackRangeChanged();
+}
+
int KisImageAnimationInterface::framerate() const
{
return m_d->framerate;
diff --git a/krita/image/kis_image_animation_interface.h b/krita/image/kis_image_animation_interface.h
index 7fe2e9e..b5ffa43 100644
--- a/krita/image/kis_image_animation_interface.h
+++ b/krita/image/kis_image_animation_interface.h
@@ -103,6 +103,9 @@ public:
const KisTimeRange ¤tRange() const;
void setRange(const KisTimeRange range);
+ const KisTimeRange &playbackRange() const;
+ void setPlaybackRange(const KisTimeRange range);
+
int framerate() const;
public Q_SLOTS:
@@ -134,6 +137,7 @@ Q_SIGNALS:
void sigFramerateChanged();
void sigRangeChanged();
+ void sigPlaybackRangeChanged();
private:
struct Private;
diff --git a/krita/plugins/extensions/dockers/animation/timeline_frames_model.cpp b/krita/plugins/extensions/dockers/animation/timeline_frames_model.cpp
index d3fe5a2..3658e39 100644
--- a/krita/plugins/extensions/dockers/animation/timeline_frames_model.cpp
+++ b/krita/plugins/extensions/dockers/animation/timeline_frames_model.cpp
@@ -43,7 +43,7 @@
#include "timeline_color_scheme.h"
#include "kis_node_model.h"
#include "kis_projection_leaf.h"
-
+#include "kis_time_range.h"
struct TimelineFramesModel::Private
{
@@ -875,5 +875,15 @@ void TimelineFramesModel::slotPlaybackStopped()
setData(index(0, m_d->image->animationInterface()->currentUITime()), true, ActiveFrameRole);
}
+void TimelineFramesModel::setPlaybackRange(const KisTimeRange &range)
+{
+ if (!m_d->dummiesFacade) return;
+ KisImageAnimationInterface *i = m_d->image->animationInterface();
+ i->setPlaybackRange(range);
+}
+bool TimelineFramesModel::isPlaybackActive() const
+{
+ return m_d->animationPlayer && m_d->animationPlayer->isPlaying();
+}
diff --git a/krita/plugins/extensions/dockers/animation/timeline_frames_model.h b/krita/plugins/extensions/dockers/animation/timeline_frames_model.h
index a3a2571..0f1f896 100644
--- a/krita/plugins/extensions/dockers/animation/timeline_frames_model.h
+++ b/krita/plugins/extensions/dockers/animation/timeline_frames_model.h
@@ -60,6 +60,9 @@ public:
void setScrubState(bool active);
void scrubTo(int time, bool preview);
+ void setPlaybackRange(const KisTimeRange &range);
+ bool isPlaybackActive() const;
+
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
diff --git a/krita/plugins/extensions/dockers/animation/timeline_frames_view.cpp b/krita/plugins/extensions/dockers/animation/timeline_frames_view.cpp
index 6f4a70e..b240c49 100644
--- a/krita/plugins/extensions/dockers/animation/timeline_frames_view.cpp
+++ b/krita/plugins/extensions/dockers/animation/timeline_frames_view.cpp
@@ -46,6 +46,8 @@
#include "kis_animation_utils.h"
#include "kis_custom_modifiers_catcher.h"
#include "kis_action.h"
+#include "kis_signal_compressor.h"
+#include "kis_time_range.h"
typedef QPair<QRect, QModelIndex> QItemViewPaintPair;
typedef QList<QItemViewPaintPair> QItemViewPaintPairs;
@@ -60,7 +62,8 @@ struct TimelineFramesView::Private
zoomStillPointIndex(-1),
zoomStillPointOriginalOffset(0),
dragInProgress(false),
- modifiersCatcher(0)
+ modifiersCatcher(0),
+ selectionChangedCompressor(300, KisSignalCompressor::FIRST_INACTIVE)
{}
TimelineFramesView *q;
@@ -94,7 +97,7 @@ struct TimelineFramesView::Private
KisCustomModifiersCatcher *modifiersCatcher;
QPoint lastPressedPosition;
-
+ KisSignalCompressor selectionChangedCompressor;
QStyleOptionViewItemV4 viewOptionsV4() const;
QItemViewPaintPairs draggablePaintPairs(const QModelIndexList &indexes, QRect *r) const;
@@ -198,6 +201,9 @@ TimelineFramesView::TimelineFramesView(QWidget *parent)
setFramesPerSecond(12);
setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
+
+ connect(&m_d->selectionChangedCompressor, SIGNAL(timeout()),
+ SLOT(slotSelectionChanged()));
}
TimelineFramesView::~TimelineFramesView()
@@ -256,6 +262,9 @@ void TimelineFramesView::setModel(QAbstractItemModel *model)
connect(m_d->model, SIGNAL(sigInfiniteTimelineUpdateNeeded()),
this, SLOT(slotUpdateInfiniteFramesCount()));
+
+ connect(selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
+ &m_d->selectionChangedCompressor, SLOT(start()));
}
void TimelineFramesView::setFramesPerSecond(int fps)
@@ -353,6 +362,28 @@ void TimelineFramesView::currentChanged(const QModelIndex ¤t, const QModel
}
}
+void TimelineFramesView::slotSelectionChanged()
+{
+ int minColumn = std::numeric_limits<int>::max();
+ int maxColumn = std::numeric_limits<int>::min();
+
+ foreach (const QModelIndex &idx, selectedIndexes()) {
+ if (idx.column() > maxColumn) {
+ maxColumn = idx.column();
+ }
+
+ if (idx.column() < minColumn) {
+ minColumn = idx.column();
+ }
+ }
+
+ KisTimeRange range;
+ if (maxColumn > minColumn) {
+ range = KisTimeRange(minColumn, maxColumn - minColumn + 1);
+ }
+ m_d->model->setPlaybackRange(range);
+}
+
void TimelineFramesView::slotReselectCurrentIndex()
{
QModelIndex index = currentIndex();
@@ -361,6 +392,8 @@ void TimelineFramesView::slotReselectCurrentIndex()
void TimelineFramesView::slotDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
+ if (m_d->model->isPlaybackActive()) return;
+
int selectedColumn = -1;
for (int j = topLeft.column(); j <= bottomRight.column(); j++) {
diff --git a/krita/plugins/extensions/dockers/animation/timeline_frames_view.h b/krita/plugins/extensions/dockers/animation/timeline_frames_view.h
index bf72086..a0e3497 100644
--- a/krita/plugins/extensions/dockers/animation/timeline_frames_view.h
+++ b/krita/plugins/extensions/dockers/animation/timeline_frames_view.h
@@ -45,6 +45,7 @@ public:
public Q_SLOTS:
void setZoom(qreal zoom);
void setZoomDouble(double zoom);
+ void slotSelectionChanged();
private Q_SLOTS:
void slotUpdateLayersMenu();
diff --git a/krita/ui/canvas/kis_animation_player.cpp b/krita/ui/canvas/kis_animation_player.cpp
index 33b8369..4db2f13 100644
--- a/krita/ui/canvas/kis_animation_player.cpp
+++ b/krita/ui/canvas/kis_animation_player.cpp
@@ -103,6 +103,10 @@ void KisAnimationPlayer::connectCancelSignals()
m_d->cancelStrokeConnections.addConnection(
m_d->canvas->image()->animationInterface(), SIGNAL(sigRangeChanged()),
this, SLOT(slotUpdatePlaybackTimer()));
+
+ m_d->cancelStrokeConnections.addConnection(
+ m_d->canvas->image()->animationInterface(), SIGNAL(sigPlaybackRangeChanged()),
+ this, SLOT(slotUpdatePlaybackTimer()));
}
void KisAnimationPlayer::disconnectCancelSignals()
@@ -115,7 +119,7 @@ void KisAnimationPlayer::slotUpdatePlaybackTimer()
m_d->timer->stop();
const KisImageAnimationInterface *animation = m_d->canvas->image()->animationInterface();
- const KisTimeRange &range = animation->currentRange();
+ const KisTimeRange &range = animation->playbackRange();
if (!range.isValid()) return;
m_d->fps = animation->framerate();
More information about the kimageshop
mailing list