forked from qt-creator/qt-creator
QmlDesigner: Use QQuickWidget in states editor
Change-Id: Ic2f5b75eb470687b4985d61a38a8346d7947a4eb Reviewed-by: Tim Jenssen <tim.jenssen@digia.com>
This commit is contained in:
@@ -45,7 +45,6 @@
|
|||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
#include <QKeySequence>
|
#include <QKeySequence>
|
||||||
|
|
||||||
#include <QQuickView>
|
|
||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
#include <QQmlEngine>
|
#include <QQmlEngine>
|
||||||
#include <QQuickItem>
|
#include <QQuickItem>
|
||||||
@@ -58,15 +57,15 @@ namespace QmlDesigner {
|
|||||||
|
|
||||||
int StatesEditorWidget::currentStateInternalId() const
|
int StatesEditorWidget::currentStateInternalId() const
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_quickView->rootObject());
|
Q_ASSERT(rootObject());
|
||||||
Q_ASSERT(m_quickView->rootObject()->property("currentStateInternalId").isValid());
|
Q_ASSERT(rootObject()->property("currentStateInternalId").isValid());
|
||||||
|
|
||||||
return m_quickView->rootObject()->property("currentStateInternalId").toInt();
|
return rootObject()->property("currentStateInternalId").toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatesEditorWidget::setCurrentStateInternalId(int internalId)
|
void StatesEditorWidget::setCurrentStateInternalId(int internalId)
|
||||||
{
|
{
|
||||||
m_quickView->rootObject()->setProperty("currentStateInternalId", internalId);
|
rootObject()->setProperty("currentStateInternalId", internalId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatesEditorWidget::setNodeInstanceView(NodeInstanceView *nodeInstanceView)
|
void StatesEditorWidget::setNodeInstanceView(NodeInstanceView *nodeInstanceView)
|
||||||
@@ -76,12 +75,11 @@ void StatesEditorWidget::setNodeInstanceView(NodeInstanceView *nodeInstanceView)
|
|||||||
|
|
||||||
void StatesEditorWidget::showAddNewStatesButton(bool showAddNewStatesButton)
|
void StatesEditorWidget::showAddNewStatesButton(bool showAddNewStatesButton)
|
||||||
{
|
{
|
||||||
m_quickView->rootContext()->setContextProperty("canAddNewStates", showAddNewStatesButton);
|
rootContext()->setContextProperty("canAddNewStates", showAddNewStatesButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
StatesEditorWidget::StatesEditorWidget(StatesEditorView *statesEditorView, StatesEditorModel *statesEditorModel)
|
StatesEditorWidget::StatesEditorWidget(StatesEditorView *statesEditorView, StatesEditorModel *statesEditorModel)
|
||||||
: QWidget(),
|
: QQuickWidget(),
|
||||||
m_quickView(new QQuickView()),
|
|
||||||
m_statesEditorView(statesEditorView),
|
m_statesEditorView(statesEditorView),
|
||||||
m_imageProvider(0),
|
m_imageProvider(0),
|
||||||
m_qmlSourceUpdateShortcut(0)
|
m_qmlSourceUpdateShortcut(0)
|
||||||
@@ -89,25 +87,20 @@ StatesEditorWidget::StatesEditorWidget(StatesEditorView *statesEditorView, State
|
|||||||
m_imageProvider = new Internal::StatesEditorImageProvider;
|
m_imageProvider = new Internal::StatesEditorImageProvider;
|
||||||
m_imageProvider->setNodeInstanceView(statesEditorView->nodeInstanceView());
|
m_imageProvider->setNodeInstanceView(statesEditorView->nodeInstanceView());
|
||||||
|
|
||||||
m_quickView->engine()->addImageProvider(QStringLiteral("qmldesigner_stateseditor"), m_imageProvider);
|
engine()->addImageProvider(QStringLiteral("qmldesigner_stateseditor"), m_imageProvider);
|
||||||
m_quickView->engine()->addImportPath(qmlSourcesPath());
|
engine()->addImportPath(qmlSourcesPath());
|
||||||
|
|
||||||
m_qmlSourceUpdateShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F4), this);
|
m_qmlSourceUpdateShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F4), this);
|
||||||
connect(m_qmlSourceUpdateShortcut, SIGNAL(activated()), this, SLOT(reloadQmlSource()));
|
connect(m_qmlSourceUpdateShortcut, SIGNAL(activated()), this, SLOT(reloadQmlSource()));
|
||||||
|
|
||||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
setResizeMode(QQuickWidget::SizeRootObjectToView);
|
||||||
layout->setMargin(0);
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
layout->setSpacing(0);
|
|
||||||
QWidget *container = createWindowContainer(m_quickView.data());
|
|
||||||
layout->addWidget(container);
|
|
||||||
m_quickView->setResizeMode(QQuickView::SizeRootObjectToView);
|
|
||||||
container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
||||||
|
|
||||||
m_quickView->rootContext()->setContextProperty(QStringLiteral("statesEditorModel"), statesEditorModel);
|
rootContext()->setContextProperty(QStringLiteral("statesEditorModel"), statesEditorModel);
|
||||||
m_quickView->rootContext()->setContextProperty(QStringLiteral("highlightColor"), Utils::StyleHelper::notTooBrightHighlightColor());
|
rootContext()->setContextProperty(QStringLiteral("highlightColor"), Utils::StyleHelper::notTooBrightHighlightColor());
|
||||||
|
|
||||||
|
|
||||||
m_quickView->rootContext()->setContextProperty("canAddNewStates", true);
|
rootContext()->setContextProperty("canAddNewStates", true);
|
||||||
|
|
||||||
setWindowTitle(tr("States", "Title of Editor widget"));
|
setWindowTitle(tr("States", "Title of Editor widget"));
|
||||||
|
|
||||||
@@ -127,21 +120,21 @@ void StatesEditorWidget::reloadQmlSource()
|
|||||||
{
|
{
|
||||||
QString statesListQmlFilePath = qmlSourcesPath() + QStringLiteral("/StatesList.qml");
|
QString statesListQmlFilePath = qmlSourcesPath() + QStringLiteral("/StatesList.qml");
|
||||||
QTC_ASSERT(QFileInfo::exists(statesListQmlFilePath), return);
|
QTC_ASSERT(QFileInfo::exists(statesListQmlFilePath), return);
|
||||||
m_quickView->engine()->clearComponentCache();
|
engine()->clearComponentCache();
|
||||||
m_quickView->setSource(QUrl::fromLocalFile(statesListQmlFilePath));
|
setSource(QUrl::fromLocalFile(statesListQmlFilePath));
|
||||||
|
|
||||||
QTC_ASSERT(m_quickView->rootObject(), return);
|
QTC_ASSERT(rootObject(), return);
|
||||||
connect(m_quickView->rootObject(), SIGNAL(currentStateInternalIdChanged()), m_statesEditorView.data(), SLOT(synchonizeCurrentStateFromWidget()));
|
connect(rootObject(), SIGNAL(currentStateInternalIdChanged()), m_statesEditorView.data(), SLOT(synchonizeCurrentStateFromWidget()));
|
||||||
connect(m_quickView->rootObject(), SIGNAL(createNewState()), m_statesEditorView.data(), SLOT(createNewState()));
|
connect(rootObject(), SIGNAL(createNewState()), m_statesEditorView.data(), SLOT(createNewState()));
|
||||||
connect(m_quickView->rootObject(), SIGNAL(deleteState(int)), m_statesEditorView.data(), SLOT(removeState(int)));
|
connect(rootObject(), SIGNAL(deleteState(int)), m_statesEditorView.data(), SLOT(removeState(int)));
|
||||||
m_statesEditorView.data()->synchonizeCurrentStateFromWidget();
|
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()
|
void StatesEditorWidget::changeHeight()
|
||||||
{
|
{
|
||||||
setFixedHeight(m_quickView->rootObject()->height());
|
setFixedHeight(rootObject()->height());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -30,11 +30,10 @@
|
|||||||
#ifndef STATESEDITORWIDGET_H
|
#ifndef STATESEDITORWIDGET_H
|
||||||
#define STATESEDITORWIDGET_H
|
#define STATESEDITORWIDGET_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QQuickWidget>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QQuickView;
|
|
||||||
class QShortcut;
|
class QShortcut;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
@@ -48,7 +47,7 @@ class NodeInstanceView;
|
|||||||
|
|
||||||
namespace Internal { class StatesEditorImageProvider; }
|
namespace Internal { class StatesEditorImageProvider; }
|
||||||
|
|
||||||
class StatesEditorWidget : public QWidget
|
class StatesEditorWidget : public QQuickWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -69,7 +68,6 @@ private slots:
|
|||||||
void changeHeight();
|
void changeHeight();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointer<QQuickView> m_quickView;
|
|
||||||
QPointer<StatesEditorView> m_statesEditorView;
|
QPointer<StatesEditorView> m_statesEditorView;
|
||||||
Internal::StatesEditorImageProvider *m_imageProvider;
|
Internal::StatesEditorImageProvider *m_imageProvider;
|
||||||
QShortcut *m_qmlSourceUpdateShortcut;
|
QShortcut *m_qmlSourceUpdateShortcut;
|
||||||
|
@@ -1,3 +1,4 @@
|
|||||||
|
QT += quickwidgets
|
||||||
CONFIG += exceptions
|
CONFIG += exceptions
|
||||||
|
|
||||||
INCLUDEPATH += $$PWD
|
INCLUDEPATH += $$PWD
|
||||||
|
Reference in New Issue
Block a user