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