1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "declarativewidgetview.h"
35 #include <qdeclarative.h>
36 #include <QDeclarativeItem>
37 #include <QDeclarativeEngine>
38 #include <QDeclarativeContext>
41 namespace QmlDesigner {
43 class DeclarativeWidgetViewPrivate
46 DeclarativeWidgetViewPrivate(DeclarativeWidgetView *view)
47 : q(view), root(0), component(0) {}
48 ~DeclarativeWidgetViewPrivate() { delete root; }
51 DeclarativeWidgetView *q;
53 QPointer<QWidget> root;
55 QDeclarativeEngine engine;
56 QDeclarativeComponent *component;
59 void DeclarativeWidgetViewPrivate::execute()
69 if (!source.isEmpty()) {
70 component = new QDeclarativeComponent(&engine, source, q);
71 if (!component->isLoading()) {
74 QObject::connect(component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), q, SLOT(continueExecute()));
79 DeclarativeWidgetView::DeclarativeWidgetView(QWidget *parent) :
80 QWidget(parent), d(new DeclarativeWidgetViewPrivate(this))
84 DeclarativeWidgetView::~DeclarativeWidgetView()
89 QUrl DeclarativeWidgetView::source() const
94 void DeclarativeWidgetView::setSource(const QUrl& url)
100 QDeclarativeEngine* DeclarativeWidgetView::engine()
105 QWidget *DeclarativeWidgetView::rootWidget() const
110 QDeclarativeContext* DeclarativeWidgetView::rootContext()
112 return d->engine.rootContext();
115 DeclarativeWidgetView::Status DeclarativeWidgetView::status() const
118 return DeclarativeWidgetView::Null;
120 return DeclarativeWidgetView::Status(d->component->status());
124 void DeclarativeWidgetView::continueExecute()
127 disconnect(d->component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), this, SLOT(continueExecute()));
129 if (d->component->isError()) {
130 QList<QDeclarativeError> errorList = d->component->errors();
131 foreach (const QDeclarativeError &error, errorList) {
134 emit statusChanged(status());
138 QObject *obj = d->component->create();
140 if(d->component->isError()) {
141 QList<QDeclarativeError> errorList = d->component->errors();
142 foreach (const QDeclarativeError &error, errorList) {
145 emit statusChanged(status());
149 setRootWidget(qobject_cast<QWidget *>(obj));
150 emit statusChanged(status());
153 void DeclarativeWidgetView::setRootWidget(QWidget *widget)
155 if (d->root == widget)
158 window()->setAttribute(Qt::WA_OpaquePaintEvent, false);
159 window()->setAttribute(Qt::WA_NoSystemBackground, false);
160 widget->setParent(this);
162 widget->setVisible(true);
164 resize(widget->size());
168 QSize initialSize = d->root->size();
169 if (initialSize != size()) {