forked from qt-creator/qt-creator
QmlDesigner: Break dependencies in the timeline graphics view
This allows to reuse big parts of the timeline infrastructure. To allow this I introduced AbstractScrollGraphicsScene and other view can derive from it to implement similar behaivour. Change-Id: I4a4d2d5711d4a4fbb4cf7af29f689459ccf89f00 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io> Reviewed-by: Henning Gründl <henning.gruendl@qt.io>
This commit is contained in:
@@ -31,12 +31,12 @@
|
|||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
TimelineAbstractTool::TimelineAbstractTool(TimelineGraphicsScene *scene)
|
TimelineAbstractTool::TimelineAbstractTool(AbstractScrollGraphicsScene *scene)
|
||||||
: m_scene(scene)
|
: m_scene(scene)
|
||||||
, m_delegate(nullptr)
|
, m_delegate(nullptr)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
TimelineAbstractTool::TimelineAbstractTool(TimelineGraphicsScene *scene,
|
TimelineAbstractTool::TimelineAbstractTool(AbstractScrollGraphicsScene *scene,
|
||||||
TimelineToolDelegate *delegate)
|
TimelineToolDelegate *delegate)
|
||||||
: m_scene(scene)
|
: m_scene(scene)
|
||||||
, m_delegate(delegate)
|
, m_delegate(delegate)
|
||||||
@@ -44,7 +44,7 @@ TimelineAbstractTool::TimelineAbstractTool(TimelineGraphicsScene *scene,
|
|||||||
|
|
||||||
TimelineAbstractTool::~TimelineAbstractTool() = default;
|
TimelineAbstractTool::~TimelineAbstractTool() = default;
|
||||||
|
|
||||||
TimelineGraphicsScene *TimelineAbstractTool::scene() const
|
AbstractScrollGraphicsScene *TimelineAbstractTool::scene() const
|
||||||
{
|
{
|
||||||
return m_scene;
|
return m_scene;
|
||||||
}
|
}
|
||||||
|
@@ -36,14 +36,14 @@ namespace QmlDesigner {
|
|||||||
enum class ToolType { Move, Select };
|
enum class ToolType { Move, Select };
|
||||||
|
|
||||||
class TimelineMovableAbstractItem;
|
class TimelineMovableAbstractItem;
|
||||||
class TimelineGraphicsScene;
|
class AbstractScrollGraphicsScene;
|
||||||
class TimelineToolDelegate;
|
class TimelineToolDelegate;
|
||||||
|
|
||||||
class TimelineAbstractTool
|
class TimelineAbstractTool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit TimelineAbstractTool(TimelineGraphicsScene *scene);
|
explicit TimelineAbstractTool(AbstractScrollGraphicsScene *scene);
|
||||||
explicit TimelineAbstractTool(TimelineGraphicsScene *scene, TimelineToolDelegate *delegate);
|
explicit TimelineAbstractTool(AbstractScrollGraphicsScene *scene, TimelineToolDelegate *delegate);
|
||||||
virtual ~TimelineAbstractTool();
|
virtual ~TimelineAbstractTool();
|
||||||
|
|
||||||
virtual void mousePressEvent(TimelineMovableAbstractItem *item, QGraphicsSceneMouseEvent *event) = 0;
|
virtual void mousePressEvent(TimelineMovableAbstractItem *item, QGraphicsSceneMouseEvent *event) = 0;
|
||||||
@@ -56,7 +56,7 @@ public:
|
|||||||
virtual void keyPressEvent(QKeyEvent *keyEvent) = 0;
|
virtual void keyPressEvent(QKeyEvent *keyEvent) = 0;
|
||||||
virtual void keyReleaseEvent(QKeyEvent *keyEvent) = 0;
|
virtual void keyReleaseEvent(QKeyEvent *keyEvent) = 0;
|
||||||
|
|
||||||
TimelineGraphicsScene *scene() const;
|
AbstractScrollGraphicsScene *scene() const;
|
||||||
|
|
||||||
TimelineToolDelegate *delegate() const;
|
TimelineToolDelegate *delegate() const;
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ public:
|
|||||||
TimelineMovableAbstractItem *currentItem() const;
|
TimelineMovableAbstractItem *currentItem() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TimelineGraphicsScene *m_scene;
|
AbstractScrollGraphicsScene *m_scene;
|
||||||
|
|
||||||
TimelineToolDelegate *m_delegate;
|
TimelineToolDelegate *m_delegate;
|
||||||
};
|
};
|
||||||
|
@@ -91,7 +91,7 @@ QList<QmlTimelineKeyframeGroup> allTimelineFrames(const QmlTimeline &timeline)
|
|||||||
}
|
}
|
||||||
|
|
||||||
TimelineGraphicsScene::TimelineGraphicsScene(TimelineWidget *parent)
|
TimelineGraphicsScene::TimelineGraphicsScene(TimelineWidget *parent)
|
||||||
: QGraphicsScene(parent)
|
: AbstractScrollGraphicsScene(parent)
|
||||||
, m_parent(parent)
|
, m_parent(parent)
|
||||||
, m_layout(new TimelineGraphicsLayout(this))
|
, m_layout(new TimelineGraphicsLayout(this))
|
||||||
, m_currentFrameIndicator(new TimelineFrameHandle)
|
, m_currentFrameIndicator(new TimelineFrameHandle)
|
||||||
@@ -378,17 +378,17 @@ void TimelineGraphicsScene::commitCurrentFrame(qreal frame)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<TimelineKeyframeItem *> TimelineGraphicsScene::selectedKeyframes() const
|
QList<TimelineKeyframeItem *> AbstractScrollGraphicsScene::selectedKeyframes() const
|
||||||
{
|
{
|
||||||
return m_selectedKeyframes;
|
return m_selectedKeyframes;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TimelineGraphicsScene::hasSelection() const
|
bool AbstractScrollGraphicsScene::hasSelection() const
|
||||||
{
|
{
|
||||||
return !m_selectedKeyframes.empty();
|
return !m_selectedKeyframes.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TimelineGraphicsScene::isCurrent(TimelineKeyframeItem *keyframe) const
|
bool AbstractScrollGraphicsScene::isCurrent(TimelineKeyframeItem *keyframe) const
|
||||||
{
|
{
|
||||||
if (m_selectedKeyframes.empty())
|
if (m_selectedKeyframes.empty())
|
||||||
return false;
|
return false;
|
||||||
@@ -396,12 +396,12 @@ bool TimelineGraphicsScene::isCurrent(TimelineKeyframeItem *keyframe) const
|
|||||||
return m_selectedKeyframes.back() == keyframe;
|
return m_selectedKeyframes.back() == keyframe;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TimelineGraphicsScene::isKeyframeSelected(TimelineKeyframeItem *keyframe) const
|
bool AbstractScrollGraphicsScene::isKeyframeSelected(TimelineKeyframeItem *keyframe) const
|
||||||
{
|
{
|
||||||
return m_selectedKeyframes.contains(keyframe);
|
return m_selectedKeyframes.contains(keyframe);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TimelineGraphicsScene::multipleKeyframesSelected() const
|
bool AbstractScrollGraphicsScene::multipleKeyframesSelected() const
|
||||||
{
|
{
|
||||||
return m_selectedKeyframes.count() > 1;
|
return m_selectedKeyframes.count() > 1;
|
||||||
}
|
}
|
||||||
@@ -456,19 +456,19 @@ void TimelineGraphicsScene::invalidateRecordButtonsStatus()
|
|||||||
TimelinePropertyItem::updateRecordButtonStatus(item);
|
TimelinePropertyItem::updateRecordButtonStatus(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
int TimelineGraphicsScene::scrollOffset() const
|
int AbstractScrollGraphicsScene::scrollOffset() const
|
||||||
{
|
{
|
||||||
return m_scrollOffset;
|
return m_scrollOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimelineGraphicsScene::setScrollOffset(int offset)
|
void AbstractScrollGraphicsScene::setScrollOffset(int offset)
|
||||||
{
|
{
|
||||||
m_scrollOffset = offset;
|
m_scrollOffset = offset;
|
||||||
emitScrollOffsetChanged();
|
emitScrollOffsetChanged();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
QGraphicsView *TimelineGraphicsScene::graphicsView() const
|
QGraphicsView *AbstractScrollGraphicsScene::graphicsView() const
|
||||||
{
|
{
|
||||||
for (auto *v : views())
|
for (auto *v : views())
|
||||||
if (v->objectName() == "SceneView")
|
if (v->objectName() == "SceneView")
|
||||||
@@ -477,7 +477,7 @@ QGraphicsView *TimelineGraphicsScene::graphicsView() const
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
QGraphicsView *TimelineGraphicsScene::rulerView() const
|
QGraphicsView *AbstractScrollGraphicsScene::rulerView() const
|
||||||
{
|
{
|
||||||
for (auto *v : views())
|
for (auto *v : views())
|
||||||
if (v->objectName() == "RulerView")
|
if (v->objectName() == "RulerView")
|
||||||
@@ -491,7 +491,7 @@ QmlTimeline TimelineGraphicsScene::currentTimeline() const
|
|||||||
return QmlTimeline(timelineModelNode());
|
return QmlTimeline(timelineModelNode());
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF TimelineGraphicsScene::selectionBounds() const
|
QRectF AbstractScrollGraphicsScene::selectionBounds() const
|
||||||
{
|
{
|
||||||
QRectF bbox;
|
QRectF bbox;
|
||||||
|
|
||||||
@@ -501,7 +501,7 @@ QRectF TimelineGraphicsScene::selectionBounds() const
|
|||||||
return bbox;
|
return bbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimelineGraphicsScene::selectKeyframes(const SelectionMode &mode,
|
void AbstractScrollGraphicsScene::selectKeyframes(const SelectionMode &mode,
|
||||||
const QList<TimelineKeyframeItem *> &items)
|
const QList<TimelineKeyframeItem *> &items)
|
||||||
{
|
{
|
||||||
if (mode == SelectionMode::Remove || mode == SelectionMode::Toggle) {
|
if (mode == SelectionMode::Remove || mode == SelectionMode::Toggle) {
|
||||||
@@ -536,13 +536,14 @@ void TimelineGraphicsScene::selectKeyframes(const SelectionMode &mode,
|
|||||||
emit selectionChanged();
|
emit selectionChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimelineGraphicsScene::clearSelection()
|
void AbstractScrollGraphicsScene::clearSelection()
|
||||||
{
|
{
|
||||||
for (auto *keyframe : m_selectedKeyframes)
|
for (auto *keyframe : m_selectedKeyframes)
|
||||||
if (keyframe)
|
if (keyframe)
|
||||||
keyframe->setHighlighted(false);
|
keyframe->setHighlighted(false);
|
||||||
|
|
||||||
m_selectedKeyframes.clear();
|
m_selectedKeyframes.clear();
|
||||||
|
emit selectionChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QGraphicsItem *> TimelineGraphicsScene::itemsAt(const QPointF &pos)
|
QList<QGraphicsItem *> TimelineGraphicsScene::itemsAt(const QPointF &pos)
|
||||||
@@ -681,7 +682,7 @@ ModelNode TimelineGraphicsScene::timelineModelNode() const
|
|||||||
void TimelineGraphicsScene::handleKeyframeDeletion()
|
void TimelineGraphicsScene::handleKeyframeDeletion()
|
||||||
{
|
{
|
||||||
QList<ModelNode> nodesToBeDeleted;
|
QList<ModelNode> nodesToBeDeleted;
|
||||||
for (auto keyframe : m_selectedKeyframes) {
|
for (auto keyframe : selectedKeyframes()) {
|
||||||
nodesToBeDeleted.append(keyframe->frameNode());
|
nodesToBeDeleted.append(keyframe->frameNode());
|
||||||
}
|
}
|
||||||
deleteKeyframes(nodesToBeDeleted);
|
deleteKeyframes(nodesToBeDeleted);
|
||||||
@@ -710,7 +711,7 @@ void TimelineGraphicsScene::pasteKeyframesToTarget(const ModelNode &targetNode)
|
|||||||
void TimelineGraphicsScene::copySelectedKeyframes()
|
void TimelineGraphicsScene::copySelectedKeyframes()
|
||||||
{
|
{
|
||||||
TimelineActions::copyKeyframes(
|
TimelineActions::copyKeyframes(
|
||||||
Utils::transform(m_selectedKeyframes, &TimelineKeyframeItem::frameNode));
|
Utils::transform(selectedKeyframes(), &TimelineKeyframeItem::frameNode));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimelineGraphicsScene::pasteSelectedKeyframes()
|
void TimelineGraphicsScene::pasteSelectedKeyframes()
|
||||||
@@ -756,7 +757,20 @@ void TimelineGraphicsScene::activateLayout()
|
|||||||
m_layout->activate();
|
m_layout->activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimelineGraphicsScene::emitScrollOffsetChanged()
|
AbstractView *TimelineGraphicsScene::abstractView() const
|
||||||
|
{
|
||||||
|
return timelineView();
|
||||||
|
}
|
||||||
|
|
||||||
|
int AbstractScrollGraphicsScene::getScrollOffset(QGraphicsScene *scene)
|
||||||
|
{
|
||||||
|
auto scrollScene = qobject_cast<AbstractScrollGraphicsScene*>(scene);
|
||||||
|
if (scrollScene)
|
||||||
|
return scrollScene->scrollOffset();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractScrollGraphicsScene::emitScrollOffsetChanged()
|
||||||
{
|
{
|
||||||
for (QGraphicsItem *item : items())
|
for (QGraphicsItem *item : items())
|
||||||
TimelineMovableAbstractItem::emitScrollOffsetChanged(item);
|
TimelineMovableAbstractItem::emitScrollOffsetChanged(item);
|
||||||
@@ -783,4 +797,8 @@ bool TimelineGraphicsScene::event(QEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QmlDesigner::AbstractScrollGraphicsScene::AbstractScrollGraphicsScene(QWidget *parent)
|
||||||
|
: QGraphicsScene(parent)
|
||||||
|
{}
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
@@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QGraphicsLinearLayout)
|
QT_FORWARD_DECLARE_CLASS(QGraphicsLinearLayout)
|
||||||
QT_FORWARD_DECLARE_CLASS(QComboBox)
|
QT_FORWARD_DECLARE_CLASS(QComboBox)
|
||||||
|
QT_FORWARD_DECLARE_CLASS(QWidget)
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
@@ -51,15 +52,66 @@ class TimelinePlaceholder;
|
|||||||
class TimelineGraphicsLayout;
|
class TimelineGraphicsLayout;
|
||||||
class TimelineToolBar;
|
class TimelineToolBar;
|
||||||
|
|
||||||
class TimelineGraphicsScene : public QGraphicsScene
|
class AbstractScrollGraphicsScene : public QGraphicsScene
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
signals:
|
public:
|
||||||
void selectionChanged();
|
AbstractScrollGraphicsScene(QWidget *parent);
|
||||||
|
;
|
||||||
|
|
||||||
|
int scrollOffset() const;
|
||||||
|
void setScrollOffset(int offset);
|
||||||
|
static int getScrollOffset(QGraphicsScene *scene);
|
||||||
|
|
||||||
|
QRectF selectionBounds() const;
|
||||||
|
|
||||||
|
void selectKeyframes(const SelectionMode &mode, const QList<TimelineKeyframeItem *> &items);
|
||||||
|
virtual void clearSelection();
|
||||||
|
QList<TimelineKeyframeItem *> selectedKeyframes() const;
|
||||||
|
bool hasSelection() const;
|
||||||
|
bool isCurrent(TimelineKeyframeItem *keyframe) const;
|
||||||
|
bool isKeyframeSelected(TimelineKeyframeItem *keyframe) const;
|
||||||
|
bool multipleKeyframesSelected() const;
|
||||||
|
|
||||||
|
virtual qreal rulerScaling() const = 0;
|
||||||
|
virtual int rulerWidth() const = 0;
|
||||||
|
virtual qreal rulerDuration() const = 0;
|
||||||
|
|
||||||
|
virtual AbstractView *abstractView() const = 0;
|
||||||
|
|
||||||
|
virtual void setCurrentFrame(int) {}
|
||||||
|
|
||||||
|
virtual qreal startFrame() const = 0;
|
||||||
|
virtual qreal endFrame() const = 0;
|
||||||
|
|
||||||
|
virtual void invalidateScrollbar() = 0;
|
||||||
|
|
||||||
|
virtual qreal snap(qreal frame, bool snapToPlayhead = true)
|
||||||
|
{
|
||||||
|
Q_UNUSED(snapToPlayhead);
|
||||||
|
return frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
QGraphicsView *graphicsView() const;
|
||||||
|
QGraphicsView *rulerView() const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void statusBarMessageChanged(const QString &message);
|
||||||
|
void selectionChanged();
|
||||||
void scroll(const TimelineUtils::Side &side);
|
void scroll(const TimelineUtils::Side &side);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void emitScrollOffsetChanged();
|
||||||
|
|
||||||
|
int m_scrollOffset = 0;
|
||||||
|
QList<TimelineKeyframeItem *> m_selectedKeyframes;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TimelineGraphicsScene : public AbstractScrollGraphicsScene
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TimelineGraphicsScene(TimelineWidget *parent);
|
explicit TimelineGraphicsScene(TimelineWidget *parent);
|
||||||
|
|
||||||
@@ -74,7 +126,7 @@ public:
|
|||||||
|
|
||||||
void invalidateLayout();
|
void invalidateLayout();
|
||||||
qreal setCurrenFrame(const QmlTimeline &timeline, qreal frame);
|
qreal setCurrenFrame(const QmlTimeline &timeline, qreal frame);
|
||||||
void setCurrentFrame(int frame);
|
void setCurrentFrame(int frame) override;
|
||||||
void setStartFrame(int frame);
|
void setStartFrame(int frame);
|
||||||
void setEndFrame(int frame);
|
void setEndFrame(int frame);
|
||||||
|
|
||||||
@@ -82,11 +134,12 @@ public:
|
|||||||
TimelineWidget *timelineWidget() const;
|
TimelineWidget *timelineWidget() const;
|
||||||
TimelineToolBar *toolBar() const;
|
TimelineToolBar *toolBar() const;
|
||||||
|
|
||||||
qreal rulerScaling() const;
|
qreal rulerScaling() const override;
|
||||||
int rulerWidth() const;
|
int rulerWidth() const override;
|
||||||
qreal rulerDuration() const;
|
qreal rulerDuration() const override;
|
||||||
qreal startFrame() const;
|
|
||||||
qreal endFrame() const;
|
qreal startFrame() const override;
|
||||||
|
qreal endFrame() const override;
|
||||||
|
|
||||||
void updateKeyframePositionsCache();
|
void updateKeyframePositionsCache();
|
||||||
|
|
||||||
@@ -97,39 +150,22 @@ public:
|
|||||||
QVector<qreal> keyframePositions() const;
|
QVector<qreal> keyframePositions() const;
|
||||||
QVector<qreal> keyframePositions(const QmlTimelineKeyframeGroup &frames) const;
|
QVector<qreal> keyframePositions(const QmlTimelineKeyframeGroup &frames) const;
|
||||||
|
|
||||||
qreal snap(qreal frame, bool snapToPlayhead = true);
|
qreal snap(qreal frame, bool snapToPlayhead = true) override;
|
||||||
|
|
||||||
void setRulerScaling(int scaling);
|
void setRulerScaling(int scaling);
|
||||||
|
|
||||||
void commitCurrentFrame(qreal frame);
|
void commitCurrentFrame(qreal frame);
|
||||||
|
|
||||||
QList<TimelineKeyframeItem *> selectedKeyframes() const;
|
|
||||||
|
|
||||||
bool hasSelection() const;
|
|
||||||
bool isCurrent(TimelineKeyframeItem *keyframe) const;
|
|
||||||
bool isKeyframeSelected(TimelineKeyframeItem *keyframe) const;
|
|
||||||
bool multipleKeyframesSelected() const;
|
|
||||||
|
|
||||||
void invalidateSectionForTarget(const ModelNode &modelNode);
|
void invalidateSectionForTarget(const ModelNode &modelNode);
|
||||||
void invalidateKeyframesForTarget(const ModelNode &modelNode);
|
void invalidateKeyframesForTarget(const ModelNode &modelNode);
|
||||||
|
|
||||||
void invalidateScene();
|
void invalidateScene();
|
||||||
void invalidateScrollbar();
|
void invalidateScrollbar() override;
|
||||||
void invalidateCurrentValues();
|
void invalidateCurrentValues();
|
||||||
void invalidateRecordButtonsStatus();
|
void invalidateRecordButtonsStatus();
|
||||||
|
|
||||||
int scrollOffset() const;
|
|
||||||
void setScrollOffset(int offset);
|
|
||||||
QGraphicsView *graphicsView() const;
|
|
||||||
QGraphicsView *rulerView() const;
|
|
||||||
|
|
||||||
QmlTimeline currentTimeline() const;
|
QmlTimeline currentTimeline() const;
|
||||||
|
|
||||||
QRectF selectionBounds() const;
|
|
||||||
|
|
||||||
void selectKeyframes(const SelectionMode &mode, const QList<TimelineKeyframeItem *> &items);
|
|
||||||
void clearSelection();
|
|
||||||
|
|
||||||
void handleKeyframeDeletion();
|
void handleKeyframeDeletion();
|
||||||
void deleteAllKeyframesForTarget(const ModelNode &targetNode);
|
void deleteAllKeyframesForTarget(const ModelNode &targetNode);
|
||||||
void insertAllKeyframesForTarget(const ModelNode &targetNode);
|
void insertAllKeyframesForTarget(const ModelNode &targetNode);
|
||||||
@@ -143,8 +179,7 @@ public:
|
|||||||
|
|
||||||
void activateLayout();
|
void activateLayout();
|
||||||
|
|
||||||
signals:
|
AbstractView *abstractView() const override;
|
||||||
void statusBarMessageChanged(const QString &message);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool event(QEvent *event) override;
|
bool event(QEvent *event) override;
|
||||||
@@ -163,7 +198,6 @@ private:
|
|||||||
void invalidateSections();
|
void invalidateSections();
|
||||||
ModelNode timelineModelNode() const;
|
ModelNode timelineModelNode() const;
|
||||||
|
|
||||||
void emitScrollOffsetChanged();
|
|
||||||
void emitStatusBarPlayheadFrameChanged(int frame);
|
void emitStatusBarPlayheadFrameChanged(int frame);
|
||||||
|
|
||||||
QList<QGraphicsItem *> itemsAt(const QPointF &pos);
|
QList<QGraphicsItem *> itemsAt(const QPointF &pos);
|
||||||
@@ -178,12 +212,8 @@ private:
|
|||||||
|
|
||||||
TimelineToolDelegate m_tools;
|
TimelineToolDelegate m_tools;
|
||||||
|
|
||||||
QList<TimelineKeyframeItem *> m_selectedKeyframes;
|
|
||||||
|
|
||||||
// sorted, unique cache of keyframes positions, used for snapping
|
// sorted, unique cache of keyframes positions, used for snapping
|
||||||
QVector<qreal> m_keyframePositionsCache;
|
QVector<qreal> m_keyframePositionsCache;
|
||||||
|
|
||||||
int m_scrollOffset = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
@@ -52,8 +52,7 @@ TimelineItem::TimelineItem(TimelineItem *parent)
|
|||||||
|
|
||||||
TimelineGraphicsScene *TimelineItem::timelineScene() const
|
TimelineGraphicsScene *TimelineItem::timelineScene() const
|
||||||
{
|
{
|
||||||
return static_cast<TimelineGraphicsScene *>(scene());
|
return qobject_cast<TimelineGraphicsScene *>(scene());
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TimelineFrameHandle::TimelineFrameHandle(TimelineItem *parent)
|
TimelineFrameHandle::TimelineFrameHandle(TimelineItem *parent)
|
||||||
@@ -93,7 +92,7 @@ void TimelineFrameHandle::setPosition(qreal frame)
|
|||||||
|
|
||||||
void TimelineFrameHandle::setPositionInteractive(const QPointF &position)
|
void TimelineFrameHandle::setPositionInteractive(const QPointF &position)
|
||||||
{
|
{
|
||||||
const double width = timelineScene()->width();
|
const double width = abstractScrollGraphicsScene()->width();
|
||||||
|
|
||||||
if (position.x() > width) {
|
if (position.x() > width) {
|
||||||
callSetClampedXPosition(width - (rect().width() / 2) - 1);
|
callSetClampedXPosition(width - (rect().width() / 2) - 1);
|
||||||
@@ -104,7 +103,7 @@ void TimelineFrameHandle::setPositionInteractive(const QPointF &position)
|
|||||||
} else {
|
} else {
|
||||||
callSetClampedXPosition(position.x() - rect().width() / 2);
|
callSetClampedXPosition(position.x() - rect().width() / 2);
|
||||||
const qreal frame = std::round(mapFromSceneToFrame(rect().center().x()));
|
const qreal frame = std::round(mapFromSceneToFrame(rect().center().x()));
|
||||||
timelineScene()->commitCurrentFrame(frame);
|
timelineGraphicsScene()->commitCurrentFrame(frame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,6 +127,11 @@ TimelineFrameHandle *TimelineFrameHandle::asTimelineFrameHandle()
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TimelineGraphicsScene *TimelineFrameHandle::timelineGraphicsScene() const
|
||||||
|
{
|
||||||
|
return qobject_cast<TimelineGraphicsScene* >(abstractScrollGraphicsScene());
|
||||||
|
}
|
||||||
|
|
||||||
void TimelineFrameHandle::scrollOffsetChanged()
|
void TimelineFrameHandle::scrollOffsetChanged()
|
||||||
{
|
{
|
||||||
setPosition(position());
|
setPosition(position());
|
||||||
@@ -182,7 +186,7 @@ void TimelineFrameHandle::paint(QPainter *painter,
|
|||||||
|
|
||||||
QPointF TimelineFrameHandle::mapFromGlobal(const QPoint &pos) const
|
QPointF TimelineFrameHandle::mapFromGlobal(const QPoint &pos) const
|
||||||
{
|
{
|
||||||
for (auto *view : timelineScene()->views()) {
|
for (auto *view : abstractScrollGraphicsScene()->views()) {
|
||||||
if (view->objectName() == "SceneView") {
|
if (view->objectName() == "SceneView") {
|
||||||
auto graphicsViewCoords = view->mapFromGlobal(pos);
|
auto graphicsViewCoords = view->mapFromGlobal(pos);
|
||||||
auto sceneCoords = view->mapToScene(graphicsViewCoords);
|
auto sceneCoords = view->mapToScene(graphicsViewCoords);
|
||||||
@@ -195,7 +199,7 @@ QPointF TimelineFrameHandle::mapFromGlobal(const QPoint &pos) const
|
|||||||
int TimelineFrameHandle::computeScrollSpeed() const
|
int TimelineFrameHandle::computeScrollSpeed() const
|
||||||
{
|
{
|
||||||
const double mouse = mapFromGlobal(QCursor::pos()).x();
|
const double mouse = mapFromGlobal(QCursor::pos()).x();
|
||||||
const double width = timelineScene()->width();
|
const double width = abstractScrollGraphicsScene()->width();
|
||||||
|
|
||||||
const double acc = mouse > width ? mouse - width
|
const double acc = mouse > width ? mouse - width
|
||||||
: double(TimelineConstants::sectionWidth) - mouse;
|
: double(TimelineConstants::sectionWidth) - mouse;
|
||||||
@@ -216,7 +220,7 @@ void TimelineFrameHandle::callSetClampedXPosition(double x)
|
|||||||
const int minimumWidth = TimelineConstants::sectionWidth + TimelineConstants::timelineLeftOffset
|
const int minimumWidth = TimelineConstants::sectionWidth + TimelineConstants::timelineLeftOffset
|
||||||
- rect().width() / 2;
|
- rect().width() / 2;
|
||||||
const int maximumWidth = minimumWidth
|
const int maximumWidth = minimumWidth
|
||||||
+ timelineScene()->rulerDuration() * timelineScene()->rulerScaling()
|
+ abstractScrollGraphicsScene()->rulerDuration() * abstractScrollGraphicsScene()->rulerScaling()
|
||||||
- scrollOffset();
|
- scrollOffset();
|
||||||
|
|
||||||
setClampedXPosition(x, minimumWidth, maximumWidth);
|
setClampedXPosition(x, minimumWidth, maximumWidth);
|
||||||
@@ -225,7 +229,7 @@ void TimelineFrameHandle::callSetClampedXPosition(double x)
|
|||||||
// Auto scroll when dragging playhead out of bounds.
|
// Auto scroll when dragging playhead out of bounds.
|
||||||
void TimelineFrameHandle::scrollOutOfBounds()
|
void TimelineFrameHandle::scrollOutOfBounds()
|
||||||
{
|
{
|
||||||
const double width = timelineScene()->width();
|
const double width = abstractScrollGraphicsScene()->width();
|
||||||
const double mouse = mapFromGlobal(QCursor::pos()).x();
|
const double mouse = mapFromGlobal(QCursor::pos()).x();
|
||||||
|
|
||||||
if (mouse > width)
|
if (mouse > width)
|
||||||
@@ -236,14 +240,14 @@ void TimelineFrameHandle::scrollOutOfBounds()
|
|||||||
|
|
||||||
void TimelineFrameHandle::scrollOutOfBoundsMax()
|
void TimelineFrameHandle::scrollOutOfBoundsMax()
|
||||||
{
|
{
|
||||||
const double width = timelineScene()->width();
|
const double width = abstractScrollGraphicsScene()->width();
|
||||||
if (QApplication::mouseButtons() == Qt::LeftButton) {
|
if (QApplication::mouseButtons() == Qt::LeftButton) {
|
||||||
const double frameWidth = timelineScene()->rulerScaling();
|
const double frameWidth = abstractScrollGraphicsScene()->rulerScaling();
|
||||||
const double upperThreshold = width - frameWidth;
|
const double upperThreshold = width - frameWidth;
|
||||||
|
|
||||||
if (rect().center().x() > upperThreshold) {
|
if (rect().center().x() > upperThreshold) {
|
||||||
timelineScene()->setScrollOffset(computeScrollSpeed());
|
abstractScrollGraphicsScene()->setScrollOffset(computeScrollSpeed());
|
||||||
timelineScene()->invalidateScrollbar();
|
abstractScrollGraphicsScene()->invalidateScrollbar();
|
||||||
}
|
}
|
||||||
|
|
||||||
callSetClampedXPosition(width - (rect().width() / 2) - 1);
|
callSetClampedXPosition(width - (rect().width() / 2) - 1);
|
||||||
@@ -253,8 +257,8 @@ void TimelineFrameHandle::scrollOutOfBoundsMax()
|
|||||||
callSetClampedXPosition(width - (rect().width() / 2) - 1);
|
callSetClampedXPosition(width - (rect().width() / 2) - 1);
|
||||||
|
|
||||||
const int frame = std::floor(mapFromSceneToFrame(rect().center().x()));
|
const int frame = std::floor(mapFromSceneToFrame(rect().center().x()));
|
||||||
const int ef = timelineScene()->endFrame();
|
const int ef = abstractScrollGraphicsScene()->endFrame();
|
||||||
timelineScene()->commitCurrentFrame(frame <= ef ? frame : ef);
|
timelineGraphicsScene()->commitCurrentFrame(frame <= ef ? frame : ef);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,11 +268,11 @@ void TimelineFrameHandle::scrollOutOfBoundsMin()
|
|||||||
auto offset = computeScrollSpeed();
|
auto offset = computeScrollSpeed();
|
||||||
|
|
||||||
if (offset >= 0)
|
if (offset >= 0)
|
||||||
timelineScene()->setScrollOffset(offset);
|
abstractScrollGraphicsScene()->setScrollOffset(offset);
|
||||||
else
|
else
|
||||||
timelineScene()->setScrollOffset(0);
|
abstractScrollGraphicsScene()->setScrollOffset(0);
|
||||||
|
|
||||||
timelineScene()->invalidateScrollbar();
|
abstractScrollGraphicsScene()->invalidateScrollbar();
|
||||||
|
|
||||||
callSetClampedXPosition(TimelineConstants::sectionWidth);
|
callSetClampedXPosition(TimelineConstants::sectionWidth);
|
||||||
m_timer.start();
|
m_timer.start();
|
||||||
@@ -278,7 +282,7 @@ void TimelineFrameHandle::scrollOutOfBoundsMin()
|
|||||||
|
|
||||||
int frame = mapFromSceneToFrame(rect().center().x());
|
int frame = mapFromSceneToFrame(rect().center().x());
|
||||||
|
|
||||||
const int sframe = timelineScene()->startFrame();
|
const int sframe = abstractScrollGraphicsScene()->startFrame();
|
||||||
if (frame != sframe) {
|
if (frame != sframe) {
|
||||||
const qreal framePos = mapFromFrameToScene(frame);
|
const qreal framePos = mapFromFrameToScene(frame);
|
||||||
|
|
||||||
@@ -287,7 +291,7 @@ void TimelineFrameHandle::scrollOutOfBoundsMin()
|
|||||||
frame++;
|
frame++;
|
||||||
}
|
}
|
||||||
|
|
||||||
timelineScene()->commitCurrentFrame(frame >= sframe ? frame : sframe);
|
timelineGraphicsScene()->commitCurrentFrame(frame >= sframe ? frame : sframe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,6 +35,8 @@ QT_FORWARD_DECLARE_CLASS(QPainterPath)
|
|||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
|
class TimelineGraphicsScene;
|
||||||
|
|
||||||
class TimelineItem : public QGraphicsWidget
|
class TimelineItem : public QGraphicsWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -59,6 +61,8 @@ public:
|
|||||||
|
|
||||||
TimelineFrameHandle *asTimelineFrameHandle() override;
|
TimelineFrameHandle *asTimelineFrameHandle() override;
|
||||||
|
|
||||||
|
TimelineGraphicsScene *timelineGraphicsScene() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void scrollOffsetChanged() override;
|
void scrollOffsetChanged() override;
|
||||||
QPainterPath shape() const override;
|
QPainterPath shape() const override;
|
||||||
|
@@ -53,7 +53,7 @@ void TimelineMovableAbstractItem::itemDoubleClicked()
|
|||||||
|
|
||||||
int TimelineMovableAbstractItem::scrollOffset() const
|
int TimelineMovableAbstractItem::scrollOffset() const
|
||||||
{
|
{
|
||||||
return timelineScene()->scrollOffset();
|
return abstractScrollGraphicsScene()->scrollOffset();
|
||||||
}
|
}
|
||||||
|
|
||||||
int TimelineMovableAbstractItem::xPosScrollOffset(int x) const
|
int TimelineMovableAbstractItem::xPosScrollOffset(int x) const
|
||||||
@@ -63,7 +63,7 @@ int TimelineMovableAbstractItem::xPosScrollOffset(int x) const
|
|||||||
|
|
||||||
qreal TimelineMovableAbstractItem::mapFromFrameToScene(qreal x) const
|
qreal TimelineMovableAbstractItem::mapFromFrameToScene(qreal x) const
|
||||||
{
|
{
|
||||||
return TimelineConstants::sectionWidth + (x - timelineScene()->startFrame()) * rulerScaling()
|
return TimelineConstants::sectionWidth + (x - abstractScrollGraphicsScene()->startFrame()) * rulerScaling()
|
||||||
- scrollOffset() + TimelineConstants::timelineLeftOffset;
|
- scrollOffset() + TimelineConstants::timelineLeftOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,8 +71,8 @@ qreal TimelineMovableAbstractItem::mapFromSceneToFrame(qreal x) const
|
|||||||
{
|
{
|
||||||
return xPosScrollOffset(x - TimelineConstants::sectionWidth
|
return xPosScrollOffset(x - TimelineConstants::sectionWidth
|
||||||
- TimelineConstants::timelineLeftOffset)
|
- TimelineConstants::timelineLeftOffset)
|
||||||
/ timelineScene()->rulerScaling()
|
/ abstractScrollGraphicsScene()->rulerScaling()
|
||||||
+ timelineScene()->startFrame();
|
+ abstractScrollGraphicsScene()->startFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimelineMovableAbstractItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
void TimelineMovableAbstractItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
@@ -133,7 +133,7 @@ TimelineKeyframeItem *TimelineMovableAbstractItem::asTimelineKeyframeItem(QGraph
|
|||||||
|
|
||||||
qreal TimelineMovableAbstractItem::rulerScaling() const
|
qreal TimelineMovableAbstractItem::rulerScaling() const
|
||||||
{
|
{
|
||||||
return static_cast<TimelineGraphicsScene *>(scene())->rulerScaling();
|
return qobject_cast<AbstractScrollGraphicsScene *>(scene())->rulerScaling();
|
||||||
}
|
}
|
||||||
|
|
||||||
int TimelineMovableAbstractItem::type() const
|
int TimelineMovableAbstractItem::type() const
|
||||||
@@ -141,9 +141,9 @@ int TimelineMovableAbstractItem::type() const
|
|||||||
return Type;
|
return Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
TimelineGraphicsScene *TimelineMovableAbstractItem::timelineScene() const
|
AbstractScrollGraphicsScene *TimelineMovableAbstractItem::abstractScrollGraphicsScene() const
|
||||||
{
|
{
|
||||||
return static_cast<TimelineGraphicsScene *>(scene());
|
return qobject_cast<AbstractScrollGraphicsScene *>(scene());
|
||||||
}
|
}
|
||||||
|
|
||||||
TimelineKeyframeItem *TimelineMovableAbstractItem::asTimelineKeyframeItem()
|
TimelineKeyframeItem *TimelineMovableAbstractItem::asTimelineKeyframeItem()
|
||||||
|
@@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
class TimelineGraphicsScene;
|
class AbstractScrollGraphicsScene;
|
||||||
class TimelineKeyframeItem;
|
class TimelineKeyframeItem;
|
||||||
class TimelineFrameHandle;
|
class TimelineFrameHandle;
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ protected:
|
|||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
|
|
||||||
void setClampedXPosition(qreal x, qreal min, qreal max);
|
void setClampedXPosition(qreal x, qreal min, qreal max);
|
||||||
TimelineGraphicsScene *timelineScene() const;
|
AbstractScrollGraphicsScene *abstractScrollGraphicsScene() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
@@ -61,7 +61,7 @@ QPointF mapToItem(TimelineMovableAbstractItem *item, QGraphicsSceneMouseEvent *e
|
|||||||
return event->scenePos();
|
return event->scenePos();
|
||||||
}
|
}
|
||||||
|
|
||||||
TimelineMoveTool::TimelineMoveTool(TimelineGraphicsScene *scene, TimelineToolDelegate *delegate)
|
TimelineMoveTool::TimelineMoveTool(AbstractScrollGraphicsScene *scene, TimelineToolDelegate *delegate)
|
||||||
: TimelineAbstractTool(scene, delegate)
|
: TimelineAbstractTool(scene, delegate)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@@ -155,7 +155,7 @@ void TimelineMoveTool::mouseReleaseEvent(TimelineMovableAbstractItem *item,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scene()->timelineView()->executeInTransaction("TimelineMoveTool::mouseReleaseEvent",
|
scene()->abstractView()->executeInTransaction("TimelineMoveTool::mouseReleaseEvent",
|
||||||
[this, current]() {
|
[this, current]() {
|
||||||
current->commitPosition(mapToItem(current, current->rect().center()));
|
current->commitPosition(mapToItem(current, current->rect().center()));
|
||||||
|
|
||||||
|
@@ -41,7 +41,7 @@ class TimelineMoveTool : public TimelineAbstractTool
|
|||||||
Q_DECLARE_TR_FUNCTIONS(TimelineMoveTool)
|
Q_DECLARE_TR_FUNCTIONS(TimelineMoveTool)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TimelineMoveTool(TimelineGraphicsScene *scene, TimelineToolDelegate *delegate);
|
explicit TimelineMoveTool(AbstractScrollGraphicsScene *scene, TimelineToolDelegate *delegate);
|
||||||
void mousePressEvent(TimelineMovableAbstractItem *item,
|
void mousePressEvent(TimelineMovableAbstractItem *item,
|
||||||
QGraphicsSceneMouseEvent *event) override;
|
QGraphicsSceneMouseEvent *event) override;
|
||||||
void mouseMoveEvent(TimelineMovableAbstractItem *item, QGraphicsSceneMouseEvent *event) override;
|
void mouseMoveEvent(TimelineMovableAbstractItem *item, QGraphicsSceneMouseEvent *event) override;
|
||||||
|
@@ -505,7 +505,7 @@ TimelineKeyframeItem::TimelineKeyframeItem(TimelinePropertyItem *parent, const M
|
|||||||
|
|
||||||
TimelineKeyframeItem::~TimelineKeyframeItem()
|
TimelineKeyframeItem::~TimelineKeyframeItem()
|
||||||
{
|
{
|
||||||
timelineScene()->selectKeyframes(SelectionMode::Remove, {this});
|
abstractScrollGraphicsScene()->selectKeyframes(SelectionMode::Remove, {this});
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimelineKeyframeItem::updateFrame()
|
void TimelineKeyframeItem::updateFrame()
|
||||||
@@ -555,8 +555,8 @@ void TimelineKeyframeItem::commitPosition(const QPointF &point)
|
|||||||
|
|
||||||
void TimelineKeyframeItem::itemDoubleClicked()
|
void TimelineKeyframeItem::itemDoubleClicked()
|
||||||
{
|
{
|
||||||
std::pair<qreal, qreal> timelineRange = {timelineScene()->currentTimeline().startKeyframe(),
|
std::pair<qreal, qreal> timelineRange = {timelineGraphicsScene()->currentTimeline().startKeyframe(),
|
||||||
timelineScene()->currentTimeline().endKeyframe()};
|
timelineGraphicsScene()->currentTimeline().endKeyframe()};
|
||||||
editValue(m_frame, timelineRange, propertyItem()->propertyName());
|
editValue(m_frame, timelineRange, propertyItem()->propertyName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -565,6 +565,11 @@ TimelineKeyframeItem *TimelineKeyframeItem::asTimelineKeyframeItem()
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TimelineGraphicsScene *TimelineKeyframeItem::timelineGraphicsScene() const
|
||||||
|
{
|
||||||
|
return qobject_cast<TimelineGraphicsScene *>(abstractScrollGraphicsScene());
|
||||||
|
}
|
||||||
|
|
||||||
void TimelineKeyframeItem::blockUpdates()
|
void TimelineKeyframeItem::blockUpdates()
|
||||||
{
|
{
|
||||||
s_blockUpdates = true;
|
s_blockUpdates = true;
|
||||||
@@ -643,21 +648,21 @@ void TimelineKeyframeItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *even
|
|||||||
QMenu mainMenu;
|
QMenu mainMenu;
|
||||||
QAction *removeAction = mainMenu.addAction(tr("Delete Keyframe"));
|
QAction *removeAction = mainMenu.addAction(tr("Delete Keyframe"));
|
||||||
QObject::connect(removeAction, &QAction::triggered, [this]() {
|
QObject::connect(removeAction, &QAction::triggered, [this]() {
|
||||||
timelineScene()->handleKeyframeDeletion();
|
timelineGraphicsScene()->handleKeyframeDeletion();
|
||||||
});
|
});
|
||||||
|
|
||||||
QAction *editEasingAction = mainMenu.addAction(tr("Edit Easing Curve..."));
|
QAction *editEasingAction = mainMenu.addAction(tr("Edit Easing Curve..."));
|
||||||
QObject::connect(editEasingAction, &QAction::triggered, [this]() {
|
QObject::connect(editEasingAction, &QAction::triggered, [this]() {
|
||||||
const QList<ModelNode> keys = Utils::transform(timelineScene()->selectedKeyframes(),
|
const QList<ModelNode> keys = Utils::transform(abstractScrollGraphicsScene()->selectedKeyframes(),
|
||||||
&TimelineKeyframeItem::m_frame);
|
&TimelineKeyframeItem::m_frame);
|
||||||
|
|
||||||
setEasingCurve(timelineScene(), keys);
|
setEasingCurve(timelineGraphicsScene(), keys);
|
||||||
});
|
});
|
||||||
|
|
||||||
QAction *editValueAction = mainMenu.addAction(tr("Edit Keyframe..."));
|
QAction *editValueAction = mainMenu.addAction(tr("Edit Keyframe..."));
|
||||||
QObject::connect(editValueAction, &QAction::triggered, [this]() {
|
QObject::connect(editValueAction, &QAction::triggered, [this]() {
|
||||||
std::pair<qreal, qreal> timelineRange = {timelineScene()->currentTimeline().startKeyframe(),
|
std::pair<qreal, qreal> timelineRange = {timelineGraphicsScene()->currentTimeline().startKeyframe(),
|
||||||
timelineScene()->currentTimeline().endKeyframe()};
|
timelineGraphicsScene()->currentTimeline().endKeyframe()};
|
||||||
editValue(m_frame, timelineRange, propertyItem()->propertyName());
|
editValue(m_frame, timelineRange, propertyItem()->propertyName());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -67,6 +67,7 @@ public:
|
|||||||
void itemDoubleClicked() override;
|
void itemDoubleClicked() override;
|
||||||
|
|
||||||
TimelineKeyframeItem *asTimelineKeyframeItem() override;
|
TimelineKeyframeItem *asTimelineKeyframeItem() override;
|
||||||
|
TimelineGraphicsScene *timelineGraphicsScene() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool hasManualBezier() const;
|
bool hasManualBezier() const;
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2018 The Qt Company Ltd.
|
** Copyright (C) 2018 The Qt Company Ltd.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
@@ -215,15 +215,7 @@ QVector<qreal> TimelineSectionItem::keyframePositions() const
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
QTransform rotatationTransform(qreal degrees)
|
static QPixmap rotateby90(const QPixmap &pixmap)
|
||||||
{
|
|
||||||
QTransform transform;
|
|
||||||
transform.rotate(degrees);
|
|
||||||
|
|
||||||
return transform;
|
|
||||||
}
|
|
||||||
|
|
||||||
QPixmap rotateby90(const QPixmap &pixmap)
|
|
||||||
{
|
{
|
||||||
QImage sourceImage = pixmap.toImage();
|
QImage sourceImage = pixmap.toImage();
|
||||||
QImage destImage(pixmap.height(), pixmap.width(), sourceImage.format());
|
QImage destImage(pixmap.height(), pixmap.width(), sourceImage.format());
|
||||||
@@ -550,6 +542,13 @@ void TimelineRulerSectionItem::invalidateRulerSize(const QmlTimeline &timeline)
|
|||||||
m_end = timeline.endKeyframe();
|
m_end = timeline.endKeyframe();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TimelineRulerSectionItem::invalidateRulerSize(const qreal length)
|
||||||
|
{
|
||||||
|
m_duration = length;
|
||||||
|
m_start = 0;
|
||||||
|
m_end = length;
|
||||||
|
}
|
||||||
|
|
||||||
void TimelineRulerSectionItem::setRulerScaleFactor(int scaling)
|
void TimelineRulerSectionItem::setRulerScaleFactor(int scaling)
|
||||||
{
|
{
|
||||||
qreal blend = qreal(scaling) / 100.0;
|
qreal blend = qreal(scaling) / 100.0;
|
||||||
@@ -627,10 +626,12 @@ void TimelineRulerSectionItem::paint(QPainter *painter, const QStyleOptionGraphi
|
|||||||
static const QColor highlightColor = Theme::instance()->Theme::qmlDesignerButtonColor();
|
static const QColor highlightColor = Theme::instance()->Theme::qmlDesignerButtonColor();
|
||||||
static const QColor handleColor = Theme::getColor(Theme::QmlDesigner_HighlightColor);
|
static const QColor handleColor = Theme::getColor(Theme::QmlDesigner_HighlightColor);
|
||||||
|
|
||||||
|
const int scrollOffset = TimelineGraphicsScene::getScrollOffset(scene());
|
||||||
|
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->setRenderHint(QPainter::Antialiasing);
|
painter->setRenderHint(QPainter::Antialiasing);
|
||||||
painter->translate(-timelineScene()->scrollOffset(), 0);
|
painter->translate(-scrollOffset, 0);
|
||||||
painter->fillRect(TimelineConstants::sectionWidth,
|
painter->fillRect(TimelineConstants::sectionWidth,
|
||||||
0,
|
0,
|
||||||
size().width() - TimelineConstants::sectionWidth,
|
size().width() - TimelineConstants::sectionWidth,
|
||||||
@@ -666,11 +667,13 @@ void TimelineRulerSectionItem::paint(QPainter *painter, const QStyleOptionGraphi
|
|||||||
|
|
||||||
const int height = size().height() - 1;
|
const int height = size().height() - 1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
drawLine(painter,
|
drawLine(painter,
|
||||||
TimelineConstants::sectionWidth + timelineScene()->scrollOffset()
|
TimelineConstants::sectionWidth + scrollOffset
|
||||||
- TimelineConstants::timelineLeftOffset,
|
- TimelineConstants::timelineLeftOffset,
|
||||||
height,
|
height,
|
||||||
size().width() + timelineScene()->scrollOffset(),
|
size().width() + scrollOffset,
|
||||||
height);
|
height);
|
||||||
|
|
||||||
QFont font = painter->font();
|
QFont font = painter->font();
|
||||||
@@ -720,9 +723,12 @@ void TimelineRulerSectionItem::paintTicks(QPainter *painter)
|
|||||||
|
|
||||||
m_frameTick = qreal(deltaLine);
|
m_frameTick = qreal(deltaLine);
|
||||||
|
|
||||||
|
int scrollOffset = TimelineGraphicsScene::getScrollOffset(scene());
|
||||||
|
|
||||||
int height = size().height();
|
int height = size().height();
|
||||||
const int totalWidth = (size().width() + timelineScene()->scrollOffset()) / m_scaling;
|
const int totalWidth = (size().width() + scrollOffset) / m_scaling;
|
||||||
for (int i = timelineScene()->scrollOffset() / m_scaling; i < totalWidth; ++i) {
|
|
||||||
|
for (int i = scrollOffset / m_scaling; i < totalWidth; ++i) {
|
||||||
if ((i % deltaText) == 0) {
|
if ((i % deltaText) == 0) {
|
||||||
drawCenteredText(painter,
|
drawCenteredText(painter,
|
||||||
TimelineConstants::sectionWidth + i * m_scaling,
|
TimelineConstants::sectionWidth + i * m_scaling,
|
||||||
@@ -794,11 +800,11 @@ void TimelineBarItem::itemMoved(const QPointF &start, const QPointF &end)
|
|||||||
|
|
||||||
qreal min = qreal(TimelineConstants::sectionWidth + TimelineConstants::timelineLeftOffset
|
qreal min = qreal(TimelineConstants::sectionWidth + TimelineConstants::timelineLeftOffset
|
||||||
- scrollOffset());
|
- scrollOffset());
|
||||||
qreal max = qreal(timelineScene()->rulerWidth() - TimelineConstants::sectionWidth
|
qreal max = qreal(abstractScrollGraphicsScene()->rulerWidth() - TimelineConstants::sectionWidth
|
||||||
+ rect().width());
|
+ rect().width());
|
||||||
|
|
||||||
const qreal minFrameX = mapFromFrameToScene(timelineScene()->startFrame());
|
const qreal minFrameX = mapFromFrameToScene(abstractScrollGraphicsScene()->startFrame() - 1);
|
||||||
const qreal maxFrameX = mapFromFrameToScene(timelineScene()->endFrame());
|
const qreal maxFrameX = mapFromFrameToScene(abstractScrollGraphicsScene()->endFrame()+ 1000);
|
||||||
|
|
||||||
if (min < minFrameX)
|
if (min < minFrameX)
|
||||||
min = minFrameX;
|
min = minFrameX;
|
||||||
@@ -811,7 +817,7 @@ void TimelineBarItem::itemMoved(const QPointF &start, const QPointF &end)
|
|||||||
else
|
else
|
||||||
dragHandle(rect(), end, min, max);
|
dragHandle(rect(), end, min, max);
|
||||||
|
|
||||||
timelineScene()->statusBarMessageChanged(
|
abstractScrollGraphicsScene()->statusBarMessageChanged(
|
||||||
tr("Range from %1 to %2")
|
tr("Range from %1 to %2")
|
||||||
.arg(qRound(mapFromSceneToFrame(rect().x())))
|
.arg(qRound(mapFromSceneToFrame(rect().x())))
|
||||||
.arg(qRound(mapFromSceneToFrame(rect().width() + rect().x()))));
|
.arg(qRound(mapFromSceneToFrame(rect().width() + rect().x()))));
|
||||||
@@ -975,7 +981,7 @@ void TimelineBarItem::dragCenter(QRectF rect, const QPointF &pos, qreal min, qre
|
|||||||
if (validateBounds(pos.x() - rect.topLeft().x())) {
|
if (validateBounds(pos.x() - rect.topLeft().x())) {
|
||||||
qreal targetX = pos.x() - m_pivot;
|
qreal targetX = pos.x() - m_pivot;
|
||||||
if (QApplication::keyboardModifiers() & Qt::ShiftModifier) { // snapping
|
if (QApplication::keyboardModifiers() & Qt::ShiftModifier) { // snapping
|
||||||
qreal snappedTargetFrame = timelineScene()->snap(mapFromSceneToFrame(targetX));
|
qreal snappedTargetFrame = abstractScrollGraphicsScene()->snap(mapFromSceneToFrame(targetX));
|
||||||
targetX = mapFromFrameToScene(snappedTargetFrame);
|
targetX = mapFromFrameToScene(snappedTargetFrame);
|
||||||
}
|
}
|
||||||
rect.moveLeft(targetX);
|
rect.moveLeft(targetX);
|
||||||
@@ -999,7 +1005,7 @@ void TimelineBarItem::dragHandle(QRectF rect, const QPointF &pos, qreal min, qre
|
|||||||
if (validateBounds(pos.x() - left.topLeft().x())) {
|
if (validateBounds(pos.x() - left.topLeft().x())) {
|
||||||
qreal targetX = pos.x() - m_pivot;
|
qreal targetX = pos.x() - m_pivot;
|
||||||
if (QApplication::keyboardModifiers() & Qt::ShiftModifier) { // snapping
|
if (QApplication::keyboardModifiers() & Qt::ShiftModifier) { // snapping
|
||||||
qreal snappedTargetFrame = timelineScene()->snap(mapFromSceneToFrame(targetX));
|
qreal snappedTargetFrame = abstractScrollGraphicsScene()->snap(mapFromSceneToFrame(targetX));
|
||||||
targetX = mapFromFrameToScene(snappedTargetFrame);
|
targetX = mapFromFrameToScene(snappedTargetFrame);
|
||||||
}
|
}
|
||||||
rect.setLeft(targetX);
|
rect.setLeft(targetX);
|
||||||
@@ -1015,7 +1021,7 @@ void TimelineBarItem::dragHandle(QRectF rect, const QPointF &pos, qreal min, qre
|
|||||||
if (validateBounds(pos.x() - right.topRight().x())) {
|
if (validateBounds(pos.x() - right.topRight().x())) {
|
||||||
qreal targetX = pos.x() - m_pivot;
|
qreal targetX = pos.x() - m_pivot;
|
||||||
if (QApplication::keyboardModifiers() & Qt::ShiftModifier) { // snapping
|
if (QApplication::keyboardModifiers() & Qt::ShiftModifier) { // snapping
|
||||||
qreal snappedTargetFrame = timelineScene()->snap(mapFromSceneToFrame(targetX));
|
qreal snappedTargetFrame = abstractScrollGraphicsScene()->snap(mapFromSceneToFrame(targetX));
|
||||||
targetX = mapFromFrameToScene(snappedTargetFrame);
|
targetX = mapFromFrameToScene(snappedTargetFrame);
|
||||||
}
|
}
|
||||||
rect.setRight(targetX);
|
rect.setRight(targetX);
|
||||||
|
@@ -151,6 +151,7 @@ public:
|
|||||||
static TimelineRulerSectionItem *create(QGraphicsScene *parentScene, TimelineItem *parent);
|
static TimelineRulerSectionItem *create(QGraphicsScene *parentScene, TimelineItem *parent);
|
||||||
|
|
||||||
void invalidateRulerSize(const QmlTimeline &timeline);
|
void invalidateRulerSize(const QmlTimeline &timeline);
|
||||||
|
void invalidateRulerSize(const qreal length);
|
||||||
|
|
||||||
void setRulerScaleFactor(int scaling);
|
void setRulerScaleFactor(int scaling);
|
||||||
|
|
||||||
|
@@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
TimelineSelectionTool::TimelineSelectionTool(TimelineGraphicsScene *scene,
|
TimelineSelectionTool::TimelineSelectionTool(AbstractScrollGraphicsScene *scene,
|
||||||
TimelineToolDelegate *delegate)
|
TimelineToolDelegate *delegate)
|
||||||
: TimelineAbstractTool(scene, delegate)
|
: TimelineAbstractTool(scene, delegate)
|
||||||
, m_selectionRect(new QGraphicsRectItem)
|
, m_selectionRect(new QGraphicsRectItem)
|
||||||
|
@@ -45,7 +45,7 @@ enum class SelectionMode { New, Add, Remove, Toggle };
|
|||||||
class TimelineSelectionTool : public TimelineAbstractTool
|
class TimelineSelectionTool : public TimelineAbstractTool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit TimelineSelectionTool(TimelineGraphicsScene *scene, TimelineToolDelegate *delegate);
|
explicit TimelineSelectionTool(AbstractScrollGraphicsScene *scene, TimelineToolDelegate *delegate);
|
||||||
|
|
||||||
~TimelineSelectionTool() override;
|
~TimelineSelectionTool() override;
|
||||||
|
|
||||||
|
@@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
TimelineToolDelegate::TimelineToolDelegate(TimelineGraphicsScene *scene)
|
TimelineToolDelegate::TimelineToolDelegate(AbstractScrollGraphicsScene *scene)
|
||||||
: m_scene(scene)
|
: m_scene(scene)
|
||||||
, m_start()
|
, m_start()
|
||||||
, m_moveTool(new TimelineMoveTool(scene, this))
|
, m_moveTool(new TimelineMoveTool(scene, this))
|
||||||
|
@@ -38,7 +38,7 @@ class TimelineGraphicsScene;
|
|||||||
class TimelineToolDelegate
|
class TimelineToolDelegate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TimelineToolDelegate(TimelineGraphicsScene* scene);
|
TimelineToolDelegate(AbstractScrollGraphicsScene* scene);
|
||||||
|
|
||||||
QPointF startPoint() const;
|
QPointF startPoint() const;
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ private:
|
|||||||
private:
|
private:
|
||||||
static const int dragDistance = 20;
|
static const int dragDistance = 20;
|
||||||
|
|
||||||
TimelineGraphicsScene* m_scene;
|
AbstractScrollGraphicsScene* m_scene;
|
||||||
|
|
||||||
QPointF m_start;
|
QPointF m_start;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user