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:
Thomas Hartmann
2018-01-31 17:10:26 +01:00
committed by Tim Jenssen
parent e61ec82b09
commit f2e6fc9560
8 changed files with 81 additions and 0 deletions

View File

@@ -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
{
return m_majorVersion;
@@ -270,6 +289,20 @@ void PropertyEditorContextObject::setMinorVersion(int minorVersion)
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)
{
m_qmlContext = context;

View File

@@ -55,6 +55,8 @@ class PropertyEditorContextObject : public QObject
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(QQmlComponent* specificQmlComponent READ specificQmlComponent NOTIFY specificQmlComponentChanged)
@@ -81,6 +83,7 @@ public:
Q_INVOKABLE void toogleExportAlias();
Q_INVOKABLE void changeTypeName(const QString &typeName);
Q_INVOKABLE void insertKeyframe(const QString &propertyName);
int majorVersion() const;
int majorQtQuickVersion() const;
@@ -91,6 +94,9 @@ public:
int minorVersion() const;
void setMinorVersion(int minorVersion);
bool hasActiveTimeline() const;
void setHasActiveTimeline(bool b);
void insertInQmlContext(QQmlContext *context);
QQmlComponent *specificQmlComponent();
@@ -110,6 +116,7 @@ signals:
void minorQtQuickVersionChanged();
void specificQmlComponentChanged();
void hasAliasExportChanged();
void hasActiveTimelineChanged();
public slots:
void setGlobalBaseUrl(const QUrl &newBaseUrl);
@@ -153,6 +160,8 @@ private:
Model *m_model = nullptr;
bool m_aliasExport = false;
bool m_setHasActiveTimeline = false;
};
} //QmlDesigner {

View File

@@ -29,6 +29,7 @@
#include "propertyeditortransaction.h"
#include <qmldesignerconstants.h>
#include <qmldesignerplugin.h>
#include <qmltimelinemutator.h>
#include <qmlobjectnode.h>
#include <nodemetainfo.h>
@@ -328,6 +329,9 @@ void PropertyEditorQmlBackend::setup(const QmlObjectNode &qmlObjectNode, const Q
contextObject()->setIsBaseState(qmlObjectNode.isInBaseState());
contextObject()->setHasAliasExport(qmlObjectNode.isAliasExported());
contextObject()->setHasActiveTimeline(QmlTimelineMutator::hasActiveTimeline(qmlObjectNode.view()));
contextObject()->setSelectionChanged(false);
contextObject()->setSelectionChanged(false);

View File

@@ -30,6 +30,7 @@
#include "propertyeditortransaction.h"
#include <qmldesignerconstants.h>
#include <qmltimelinemutator.h>
#include <nodemetainfo.h>
#include <invalididexception.h>
@@ -368,6 +369,14 @@ bool PropertyEditorView::locked() const
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()
{
if (!m_qmlBackEndForCurrentType)

View File

@@ -93,6 +93,8 @@ public:
bool locked() const;
void nodeCreated(const ModelNode &createdNode);
protected:
void timerEvent(QTimerEvent *event) override;
void setupPane(const TypeName &typeName);

View File

@@ -65,6 +65,7 @@ public:
QList<ModelNode> allTargets() const;
QList<QmlTimelineFrames> framesForTarget(const ModelNode &target) const;
void destroyFramesForTarget(const ModelNode &target);
static bool hasActiveTimeline(AbstractView *view);
private:
void addFramesIfNotExists(const ModelNode &node, const PropertyName &propertyName);

View File

@@ -210,6 +210,23 @@ void QmlTimelineMutator::destroyFramesForTarget(const ModelNode &target)
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)
{
if (!isValid())