Commit 79dae814 authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner.property: DeclarativeWidgetView instead of QDeclarativeView

Since the property editor is QWidget based it uses our own
DeclarativeWidgetView instead of QDeclarativeView now

Reviewed-by: Kai Koehne
parent e4fb53e8
#include "declarativewidgetview.h"
#include <qdeclarative.h>
#include <QDeclarativeItem>
#include <QDeclarativeEngine>
#include <QDeclarativeContext>
#include <QPointer>
namespace QmlDesigner {
class DeclarativeWidgetViewPrivate
{
public:
DeclarativeWidgetViewPrivate(DeclarativeWidgetView *view)
: q(view), root(0), component(0) {}
~DeclarativeWidgetViewPrivate() { delete root; }
void execute();
DeclarativeWidgetView *q;
QPointer<QWidget> root;
QUrl source;
QDeclarativeEngine engine;
QDeclarativeComponent *component;
};
void DeclarativeWidgetViewPrivate::execute()
{
if (root) {
delete root;
root = 0;
}
if (component) {
delete component;
component = 0;
}
if (!source.isEmpty()) {
component = new QDeclarativeComponent(&engine, source, q);
if (!component->isLoading()) {
q->continueExecute();
} else {
QObject::connect(component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), q, SLOT(continueExecute()));
}
}
}
DeclarativeWidgetView::DeclarativeWidgetView(QWidget *parent) :
QWidget(parent), d(new DeclarativeWidgetViewPrivate(this))
{
}
DeclarativeWidgetView::~DeclarativeWidgetView()
{
delete d;
}
QUrl DeclarativeWidgetView::source() const
{
return d->source;
}
void DeclarativeWidgetView::setSource(const QUrl& url)
{
d->source = url;
d->execute();
}
QDeclarativeEngine* DeclarativeWidgetView::engine()
{
return &d->engine;
}
QWidget *DeclarativeWidgetView::rootWidget() const
{
return d->root;
}
QDeclarativeContext* DeclarativeWidgetView::rootContext()
{
return d->engine.rootContext();
}
DeclarativeWidgetView::Status DeclarativeWidgetView::status() const
{
if (!d->component)
return DeclarativeWidgetView::Null;
return DeclarativeWidgetView::Status(d->component->status());
}
void DeclarativeWidgetView::continueExecute()
{
disconnect(d->component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), this, SLOT(continueExecute()));
if (d->component->isError()) {
QList<QDeclarativeError> errorList = d->component->errors();
foreach (const QDeclarativeError &error, errorList) {
qWarning() << error;
}
emit statusChanged(status());
return;
}
QObject *obj = d->component->create();
if(d->component->isError()) {
QList<QDeclarativeError> errorList = d->component->errors();
foreach (const QDeclarativeError &error, errorList) {
qWarning() << error;
}
emit statusChanged(status());
return;
}
setRootWidget(qobject_cast<QWidget *>(obj));
emit statusChanged(status());
}
void DeclarativeWidgetView::setRootWidget(QWidget *widget)
{
if (d->root == widget)
return;
window()->setAttribute(Qt::WA_OpaquePaintEvent, false);
window()->setAttribute(Qt::WA_NoSystemBackground, false);
widget->setParent(this);
if (isVisible()) {
widget->setVisible(true);
}
resize(widget->size());
d->root = widget;
if (d->root) {
QSize initialSize = d->root->size();
if (initialSize != size()) {
resize(initialSize);
}
}
}
} //QmlDesigner
#ifndef DECLARATIVEWIDGETVIEW_H
#define DECLARATIVEWIDGETVIEW_H
#include <QWidget>
#include <QUrl>
class QDeclarativeEngine;
class QDeclarativeContext;
class QDeclarativeError;
namespace QmlDesigner {
class DeclarativeWidgetViewPrivate;
class DeclarativeWidgetView : public QWidget
{
Q_OBJECT
Q_PROPERTY(QUrl source READ source WRITE setSource DESIGNABLE true)
public:
explicit DeclarativeWidgetView(QWidget *parent = 0);
virtual ~DeclarativeWidgetView();
QUrl source() const;
void setSource(const QUrl&);
QDeclarativeEngine* engine();
QDeclarativeContext* rootContext();
QWidget *rootWidget() const;
enum Status { Null, Ready, Loading, Error };
Status status() const;
signals:
void statusChanged(DeclarativeWidgetView::Status);
protected:
virtual void setRootWidget(QWidget *);
private Q_SLOTS:
void continueExecute();
private:
friend class DeclarativeWidgetViewPrivate;
DeclarativeWidgetViewPrivate *d;
};
} //QmlDesigner
#endif // DECLARATIVEWIDGETVIEW_H
......@@ -81,12 +81,11 @@ const int collapseButtonOffset = 114;
namespace QmlDesigner {
PropertyEditor::NodeType::NodeType(PropertyEditor *propertyEditor) :
m_view(new QDeclarativeView), m_propertyEditorTransaction(new PropertyEditorTransaction(propertyEditor)), m_dummyPropertyEditorValue(new PropertyEditorValue()),
m_view(new DeclarativeWidgetView), m_propertyEditorTransaction(new PropertyEditorTransaction(propertyEditor)), m_dummyPropertyEditorValue(new PropertyEditorValue()),
m_contextObject(new PropertyEditorContextObject())
{
Q_ASSERT(QFileInfo(":/images/button_normal.png").exists());
m_view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
QDeclarativeContext *ctxt = m_view->rootContext();
m_view->engine()->setOutputWarningsToStandardError(debug);
m_dummyPropertyEditorValue->setValue("#000000");
......
......@@ -31,7 +31,7 @@
#define QmlPropertyView_h
#include <qmlmodelview.h>
#include <QDeclarativeView>
#include <declarativewidgetview.h>
#include <QHash>
#include <QDeclarativePropertyMap>
#include <QStackedWidget>
......@@ -67,7 +67,7 @@ class PropertyEditor: public QmlModelView
void initialSetup(const QString &typeName, const QUrl &qmlSpecificsFile, PropertyEditor *propertyEditor);
void setValue(const QmlObjectNode &fxObjectNode, const QString &name, const QVariant &value);
QDeclarativeView *m_view;
DeclarativeWidgetView *m_view;
Internal::QmlAnchorBindingProxy m_backendAnchorBinding;
DesignerPropertyMap<PropertyEditorValue> m_backendValuesPropertyMap;
QScopedPointer<PropertyEditorTransaction> m_propertyEditorTransaction;
......
......@@ -18,7 +18,8 @@ SOURCES += propertyeditor.cpp \
originwidget.cpp \
siblingcombobox.cpp \
propertyeditortransaction.cpp \
propertyeditorcontextobject.cpp
propertyeditorcontextobject.cpp \
declarativewidgetview.cpp
HEADERS += propertyeditor.h \
qmlanchorbindingproxy.h \
......@@ -38,7 +39,8 @@ HEADERS += propertyeditor.h \
siblingcombobox.h \
propertyeditortransaction.h \
designerpropertymap.h \
propertyeditorcontextobject.h
propertyeditorcontextobject.h \
declarativewidgetview.h
QT += declarative
RESOURCES += propertyeditor.qrc
FORMS += behaviordialog.ui
#include "propertyeditortransaction.h"
#include <QTimerEvent>
#include <QDebug>
......
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