forked from qt-creator/qt-creator
QmlDesigner: Add keyframe support to property editor
This patch allows to insert key frames if a timeline is present. Change-Id: I39c8281e5e559a838ad61939d3f2db7c6abcf76b Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
committed by
Tim Jenssen
parent
e61ec82b09
commit
f2e6fc9560
@@ -155,6 +155,12 @@ Item {
|
|||||||
}
|
}
|
||||||
checkable: true
|
checkable: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Controls.MenuItem {
|
||||||
|
text: qsTr("Insert keyframe")
|
||||||
|
visible: hasActiveTimeline
|
||||||
|
onTriggered: insertKeyframe(backendValue.name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -208,6 +208,25 @@ void PropertyEditorContextObject::changeTypeName(const QString &typeName)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PropertyEditorContextObject::insertKeyframe(const QString &propertyName)
|
||||||
|
{
|
||||||
|
if (!m_model || !m_model->rewriterView())
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* Ideally we should not missuse the rewriterView
|
||||||
|
* If we add more code here we have to forward the property editor view */
|
||||||
|
RewriterView *rewriterView = m_model->rewriterView();
|
||||||
|
|
||||||
|
if (rewriterView->selectedModelNodes().isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
ModelNode selectedNode = rewriterView->selectedModelNodes().constFirst();
|
||||||
|
|
||||||
|
rewriterView->emitCustomNotification("INSERT_KEYFRAME",
|
||||||
|
{ selectedNode },
|
||||||
|
{ propertyName });
|
||||||
|
}
|
||||||
|
|
||||||
int PropertyEditorContextObject::majorVersion() const
|
int PropertyEditorContextObject::majorVersion() const
|
||||||
{
|
{
|
||||||
return m_majorVersion;
|
return m_majorVersion;
|
||||||
@@ -270,6 +289,20 @@ void PropertyEditorContextObject::setMinorVersion(int minorVersion)
|
|||||||
emit minorVersionChanged();
|
emit minorVersionChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PropertyEditorContextObject::hasActiveTimeline() const
|
||||||
|
{
|
||||||
|
return m_setHasActiveTimeline;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PropertyEditorContextObject::setHasActiveTimeline(bool b)
|
||||||
|
{
|
||||||
|
if (b == m_setHasActiveTimeline)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_setHasActiveTimeline = b;
|
||||||
|
emit hasActiveTimelineChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void PropertyEditorContextObject::insertInQmlContext(QQmlContext *context)
|
void PropertyEditorContextObject::insertInQmlContext(QQmlContext *context)
|
||||||
{
|
{
|
||||||
m_qmlContext = context;
|
m_qmlContext = context;
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ class PropertyEditorContextObject : public QObject
|
|||||||
|
|
||||||
Q_PROPERTY(bool hasAliasExport READ hasAliasExport NOTIFY hasAliasExportChanged)
|
Q_PROPERTY(bool hasAliasExport READ hasAliasExport NOTIFY hasAliasExportChanged)
|
||||||
|
|
||||||
|
Q_PROPERTY(bool hasActiveTimeline READ hasActiveTimeline NOTIFY hasActiveTimelineChanged)
|
||||||
|
|
||||||
Q_PROPERTY(QQmlPropertyMap* backendValues READ backendValues WRITE setBackendValues NOTIFY backendValuesChanged)
|
Q_PROPERTY(QQmlPropertyMap* backendValues READ backendValues WRITE setBackendValues NOTIFY backendValuesChanged)
|
||||||
|
|
||||||
Q_PROPERTY(QQmlComponent* specificQmlComponent READ specificQmlComponent NOTIFY specificQmlComponentChanged)
|
Q_PROPERTY(QQmlComponent* specificQmlComponent READ specificQmlComponent NOTIFY specificQmlComponentChanged)
|
||||||
@@ -81,6 +83,7 @@ public:
|
|||||||
Q_INVOKABLE void toogleExportAlias();
|
Q_INVOKABLE void toogleExportAlias();
|
||||||
|
|
||||||
Q_INVOKABLE void changeTypeName(const QString &typeName);
|
Q_INVOKABLE void changeTypeName(const QString &typeName);
|
||||||
|
Q_INVOKABLE void insertKeyframe(const QString &propertyName);
|
||||||
|
|
||||||
int majorVersion() const;
|
int majorVersion() const;
|
||||||
int majorQtQuickVersion() const;
|
int majorQtQuickVersion() const;
|
||||||
@@ -91,6 +94,9 @@ public:
|
|||||||
int minorVersion() const;
|
int minorVersion() const;
|
||||||
void setMinorVersion(int minorVersion);
|
void setMinorVersion(int minorVersion);
|
||||||
|
|
||||||
|
bool hasActiveTimeline() const;
|
||||||
|
void setHasActiveTimeline(bool b);
|
||||||
|
|
||||||
void insertInQmlContext(QQmlContext *context);
|
void insertInQmlContext(QQmlContext *context);
|
||||||
QQmlComponent *specificQmlComponent();
|
QQmlComponent *specificQmlComponent();
|
||||||
|
|
||||||
@@ -110,6 +116,7 @@ signals:
|
|||||||
void minorQtQuickVersionChanged();
|
void minorQtQuickVersionChanged();
|
||||||
void specificQmlComponentChanged();
|
void specificQmlComponentChanged();
|
||||||
void hasAliasExportChanged();
|
void hasAliasExportChanged();
|
||||||
|
void hasActiveTimelineChanged();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setGlobalBaseUrl(const QUrl &newBaseUrl);
|
void setGlobalBaseUrl(const QUrl &newBaseUrl);
|
||||||
@@ -153,6 +160,8 @@ private:
|
|||||||
Model *m_model = nullptr;
|
Model *m_model = nullptr;
|
||||||
|
|
||||||
bool m_aliasExport = false;
|
bool m_aliasExport = false;
|
||||||
|
|
||||||
|
bool m_setHasActiveTimeline = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //QmlDesigner {
|
} //QmlDesigner {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include "propertyeditortransaction.h"
|
#include "propertyeditortransaction.h"
|
||||||
#include <qmldesignerconstants.h>
|
#include <qmldesignerconstants.h>
|
||||||
#include <qmldesignerplugin.h>
|
#include <qmldesignerplugin.h>
|
||||||
|
#include <qmltimelinemutator.h>
|
||||||
|
|
||||||
#include <qmlobjectnode.h>
|
#include <qmlobjectnode.h>
|
||||||
#include <nodemetainfo.h>
|
#include <nodemetainfo.h>
|
||||||
@@ -328,6 +329,9 @@ void PropertyEditorQmlBackend::setup(const QmlObjectNode &qmlObjectNode, const Q
|
|||||||
contextObject()->setIsBaseState(qmlObjectNode.isInBaseState());
|
contextObject()->setIsBaseState(qmlObjectNode.isInBaseState());
|
||||||
|
|
||||||
contextObject()->setHasAliasExport(qmlObjectNode.isAliasExported());
|
contextObject()->setHasAliasExport(qmlObjectNode.isAliasExported());
|
||||||
|
|
||||||
|
contextObject()->setHasActiveTimeline(QmlTimelineMutator::hasActiveTimeline(qmlObjectNode.view()));
|
||||||
|
|
||||||
contextObject()->setSelectionChanged(false);
|
contextObject()->setSelectionChanged(false);
|
||||||
|
|
||||||
contextObject()->setSelectionChanged(false);
|
contextObject()->setSelectionChanged(false);
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
#include "propertyeditortransaction.h"
|
#include "propertyeditortransaction.h"
|
||||||
|
|
||||||
#include <qmldesignerconstants.h>
|
#include <qmldesignerconstants.h>
|
||||||
|
#include <qmltimelinemutator.h>
|
||||||
#include <nodemetainfo.h>
|
#include <nodemetainfo.h>
|
||||||
|
|
||||||
#include <invalididexception.h>
|
#include <invalididexception.h>
|
||||||
@@ -368,6 +369,14 @@ bool PropertyEditorView::locked() const
|
|||||||
return m_locked;
|
return m_locked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PropertyEditorView::nodeCreated(const ModelNode &modelNode)
|
||||||
|
{
|
||||||
|
if (!m_qmlBackEndForCurrentType->contextObject()->hasActiveTimeline()
|
||||||
|
&& QmlTimelineMutator::isValidQmlTimelineMutator(modelNode)) {
|
||||||
|
m_qmlBackEndForCurrentType->contextObject()->setHasActiveTimeline(QmlTimelineMutator::hasActiveTimeline(this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PropertyEditorView::updateSize()
|
void PropertyEditorView::updateSize()
|
||||||
{
|
{
|
||||||
if (!m_qmlBackEndForCurrentType)
|
if (!m_qmlBackEndForCurrentType)
|
||||||
|
|||||||
@@ -93,6 +93,8 @@ public:
|
|||||||
|
|
||||||
bool locked() const;
|
bool locked() const;
|
||||||
|
|
||||||
|
void nodeCreated(const ModelNode &createdNode);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void timerEvent(QTimerEvent *event) override;
|
void timerEvent(QTimerEvent *event) override;
|
||||||
void setupPane(const TypeName &typeName);
|
void setupPane(const TypeName &typeName);
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ public:
|
|||||||
QList<ModelNode> allTargets() const;
|
QList<ModelNode> allTargets() const;
|
||||||
QList<QmlTimelineFrames> framesForTarget(const ModelNode &target) const;
|
QList<QmlTimelineFrames> framesForTarget(const ModelNode &target) const;
|
||||||
void destroyFramesForTarget(const ModelNode &target);
|
void destroyFramesForTarget(const ModelNode &target);
|
||||||
|
static bool hasActiveTimeline(AbstractView *view);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addFramesIfNotExists(const ModelNode &node, const PropertyName &propertyName);
|
void addFramesIfNotExists(const ModelNode &node, const PropertyName &propertyName);
|
||||||
|
|||||||
@@ -210,6 +210,23 @@ void QmlTimelineMutator::destroyFramesForTarget(const ModelNode &target)
|
|||||||
frames.destroy();
|
frames.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QmlTimelineMutator::hasActiveTimeline(AbstractView *view)
|
||||||
|
{
|
||||||
|
if (view && view->isAttached()) {
|
||||||
|
if (!view->model()->hasImport(Import::createLibraryImport("QtQuick.Timeline", "1.0"), true, true))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const ModelNode root = view->rootModelNode();
|
||||||
|
if (root.isValid())
|
||||||
|
for (const ModelNode &child : root.directSubModelNodes()) {
|
||||||
|
if (QmlTimelineMutator::isValidQmlTimelineMutator(child))
|
||||||
|
return QmlTimelineMutator(child).isEnabled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void QmlTimelineMutator::addFramesIfNotExists(const ModelNode &node, const PropertyName &propertyName)
|
void QmlTimelineMutator::addFramesIfNotExists(const ModelNode &node, const PropertyName &propertyName)
|
||||||
{
|
{
|
||||||
if (!isValid())
|
if (!isValid())
|
||||||
|
|||||||
Reference in New Issue
Block a user