Commit 7d436649 authored by Marco Bubke's avatar Marco Bubke Committed by Tim Jenssen
Browse files

QmlDesigner: Use QQuickWidget in states editor



Change-Id: Ic2f5b75eb470687b4985d61a38a8346d7947a4eb
Reviewed-by: default avatarTim Jenssen <tim.jenssen@digia.com>
parent 435de838
......@@ -45,7 +45,6 @@
#include <QBoxLayout>
#include <QKeySequence>
#include <QQuickView>
#include <QQmlContext>
#include <QQmlEngine>
#include <QQuickItem>
......@@ -58,15 +57,15 @@ namespace QmlDesigner {
int StatesEditorWidget::currentStateInternalId() const
{
Q_ASSERT(m_quickView->rootObject());
Q_ASSERT(m_quickView->rootObject()->property("currentStateInternalId").isValid());
Q_ASSERT(rootObject());
Q_ASSERT(rootObject()->property("currentStateInternalId").isValid());
return m_quickView->rootObject()->property("currentStateInternalId").toInt();
return rootObject()->property("currentStateInternalId").toInt();
}
void StatesEditorWidget::setCurrentStateInternalId(int internalId)
{
m_quickView->rootObject()->setProperty("currentStateInternalId", internalId);
rootObject()->setProperty("currentStateInternalId", internalId);
}
void StatesEditorWidget::setNodeInstanceView(NodeInstanceView *nodeInstanceView)
......@@ -76,12 +75,11 @@ void StatesEditorWidget::setNodeInstanceView(NodeInstanceView *nodeInstanceView)
void StatesEditorWidget::showAddNewStatesButton(bool showAddNewStatesButton)
{
m_quickView->rootContext()->setContextProperty("canAddNewStates", showAddNewStatesButton);
rootContext()->setContextProperty("canAddNewStates", showAddNewStatesButton);
}
StatesEditorWidget::StatesEditorWidget(StatesEditorView *statesEditorView, StatesEditorModel *statesEditorModel)
: QWidget(),
m_quickView(new QQuickView()),
: QQuickWidget(),
m_statesEditorView(statesEditorView),
m_imageProvider(0),
m_qmlSourceUpdateShortcut(0)
......@@ -89,25 +87,20 @@ StatesEditorWidget::StatesEditorWidget(StatesEditorView *statesEditorView, State
m_imageProvider = new Internal::StatesEditorImageProvider;
m_imageProvider->setNodeInstanceView(statesEditorView->nodeInstanceView());
m_quickView->engine()->addImageProvider(QStringLiteral("qmldesigner_stateseditor"), m_imageProvider);
m_quickView->engine()->addImportPath(qmlSourcesPath());
engine()->addImageProvider(QStringLiteral("qmldesigner_stateseditor"), m_imageProvider);
engine()->addImportPath(qmlSourcesPath());
m_qmlSourceUpdateShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F4), this);
connect(m_qmlSourceUpdateShortcut, SIGNAL(activated()), this, SLOT(reloadQmlSource()));
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setMargin(0);
layout->setSpacing(0);
QWidget *container = createWindowContainer(m_quickView.data());
layout->addWidget(container);
m_quickView->setResizeMode(QQuickView::SizeRootObjectToView);
container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
setResizeMode(QQuickWidget::SizeRootObjectToView);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_quickView->rootContext()->setContextProperty(QStringLiteral("statesEditorModel"), statesEditorModel);
m_quickView->rootContext()->setContextProperty(QStringLiteral("highlightColor"), Utils::StyleHelper::notTooBrightHighlightColor());
rootContext()->setContextProperty(QStringLiteral("statesEditorModel"), statesEditorModel);
rootContext()->setContextProperty(QStringLiteral("highlightColor"), Utils::StyleHelper::notTooBrightHighlightColor());
m_quickView->rootContext()->setContextProperty("canAddNewStates", true);
rootContext()->setContextProperty("canAddNewStates", true);
setWindowTitle(tr("States", "Title of Editor widget"));
......@@ -127,21 +120,21 @@ void StatesEditorWidget::reloadQmlSource()
{
QString statesListQmlFilePath = qmlSourcesPath() + QStringLiteral("/StatesList.qml");
QTC_ASSERT(QFileInfo::exists(statesListQmlFilePath), return);
m_quickView->engine()->clearComponentCache();
m_quickView->setSource(QUrl::fromLocalFile(statesListQmlFilePath));
engine()->clearComponentCache();
setSource(QUrl::fromLocalFile(statesListQmlFilePath));
QTC_ASSERT(m_quickView->rootObject(), return);
connect(m_quickView->rootObject(), SIGNAL(currentStateInternalIdChanged()), m_statesEditorView.data(), SLOT(synchonizeCurrentStateFromWidget()));
connect(m_quickView->rootObject(), SIGNAL(createNewState()), m_statesEditorView.data(), SLOT(createNewState()));
connect(m_quickView->rootObject(), SIGNAL(deleteState(int)), m_statesEditorView.data(), SLOT(removeState(int)));
QTC_ASSERT(rootObject(), return);
connect(rootObject(), SIGNAL(currentStateInternalIdChanged()), m_statesEditorView.data(), SLOT(synchonizeCurrentStateFromWidget()));
connect(rootObject(), SIGNAL(createNewState()), m_statesEditorView.data(), SLOT(createNewState()));
connect(rootObject(), SIGNAL(deleteState(int)), m_statesEditorView.data(), SLOT(removeState(int)));
m_statesEditorView.data()->synchonizeCurrentStateFromWidget();
setFixedHeight(m_quickView->initialSize().height());
setFixedHeight(initialSize().height());
connect(m_quickView->rootObject(), SIGNAL(expandedChanged()), this, SLOT(changeHeight()));
connect(rootObject(), SIGNAL(expandedChanged()), this, SLOT(changeHeight()));
}
void StatesEditorWidget::changeHeight()
{
setFixedHeight(m_quickView->rootObject()->height());
setFixedHeight(rootObject()->height());
}
}
......@@ -30,11 +30,10 @@
#ifndef STATESEDITORWIDGET_H
#define STATESEDITORWIDGET_H
#include <QWidget>
#include <QQuickWidget>
#include <QPointer>
QT_BEGIN_NAMESPACE
class QQuickView;
class QShortcut;
QT_END_NAMESPACE
......@@ -48,7 +47,7 @@ class NodeInstanceView;
namespace Internal { class StatesEditorImageProvider; }
class StatesEditorWidget : public QWidget
class StatesEditorWidget : public QQuickWidget
{
Q_OBJECT
......@@ -69,7 +68,6 @@ private slots:
void changeHeight();
private:
QPointer<QQuickView> m_quickView;
QPointer<StatesEditorView> m_statesEditorView;
Internal::StatesEditorImageProvider *m_imageProvider;
QShortcut *m_qmlSourceUpdateShortcut;
......
QT += quickwidgets
CONFIG += exceptions
INCLUDEPATH += $$PWD
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment