1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the designer application of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "qdesigner_integration_p.h"
32
#include <QtDesigner/QtDesigner>
33
#include <QtDesigner/QExtensionManager>
35
#include <QtCore/QVariant>
37
#include <QtCore/qdebug.h>
39
QDesignerIntegration::QDesignerIntegration(QDesignerFormEditorInterface *core, QObject *parent)
46
QDesignerIntegration::~QDesignerIntegration()
50
void QDesignerIntegration::initialize()
53
// integrate the `Form Editor component'
55
connect(core()->propertyEditor(), SIGNAL(propertyChanged(QString,QVariant)),
56
this, SLOT(updateProperty(QString,QVariant)));
58
connect(core()->formWindowManager(), SIGNAL(formWindowAdded(QDesignerFormWindowInterface*)),
59
this, SLOT(setupFormWindow(QDesignerFormWindowInterface*)));
61
connect(core()->formWindowManager(), SIGNAL(activeFormWindowChanged(QDesignerFormWindowInterface*)),
62
this, SLOT(updateActiveFormWindow(QDesignerFormWindowInterface*)));
65
void QDesignerIntegration::updateProperty(const QString &name, const QVariant &value)
67
if (QDesignerFormWindowInterface *formWindow = core()->formWindowManager()->activeFormWindow()) {
69
QDesignerFormWindowCursorInterface *cursor = formWindow->cursor();
71
if (cursor->isWidgetSelected(formWindow->mainContainer())) {
72
if (name == QLatin1String("windowTitle")) {
73
QString filename = formWindow->fileName().isEmpty()
74
? QString::fromUtf8("Untitled")
75
: formWindow->fileName();
77
formWindow->setWindowTitle(QString::fromUtf8("%1 - (%2)")
78
.arg(value.toString())
81
} else if (name == QLatin1String("geometry")) {
82
if (QWidget *container = containerWindow(formWindow)) {
83
QRect r = containerWindow(formWindow)->geometry();
84
r.setSize(value.toRect().size());
85
container->setGeometry(r);
86
emit propertyChanged(formWindow, name, value);
93
cursor->setProperty(name, value);
95
if (name == QLatin1String("objectName") && core()->objectInspector()) {
96
core()->objectInspector()->setFormWindow(formWindow);
99
emit propertyChanged(formWindow, name, value);
101
if (core()->propertyEditor() && core()->propertyEditor()->object()) {
102
QObject *o = core()->propertyEditor()->object();
103
QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), o);
104
int index = sheet->indexOf(name);
106
core()->propertyEditor()->setPropertyValue(name, sheet->property(index));
111
void QDesignerIntegration::updateActiveFormWindow(QDesignerFormWindowInterface *formWindow)
113
Q_UNUSED(formWindow);
117
void QDesignerIntegration::setupFormWindow(QDesignerFormWindowInterface *formWindow)
119
connect(formWindow, SIGNAL(selectionChanged()), this, SLOT(updateSelection()));
120
connect(formWindow, SIGNAL(activated(QWidget*)), this, SLOT(activateWidget(QWidget*)));
123
void QDesignerIntegration::updateGeometry()
127
void QDesignerIntegration::updateSelection()
129
QDesignerFormWindowInterface *formWindow = core()->formWindowManager()->activeFormWindow();
130
QWidget *selection = 0;
133
selection = formWindow->cursor()->selectedWidget(0);
135
if (QDesignerObjectInspectorInterface *objectInspector = core()->objectInspector())
136
objectInspector->setFormWindow(formWindow);
138
if (QDesignerPropertyEditorInterface *propertyEditor = core()->propertyEditor()) {
139
propertyEditor->setObject(selection);
140
propertyEditor->setEnabled(formWindow && formWindow->cursor()->selectedWidgetCount() == 1);
144
void QDesignerIntegration::activateWidget(QWidget *widget)
149
QWidget *QDesignerIntegration::containerWindow(QWidget *widget)
152
if (widget->isWindow())
154
if (widget->parentWidget() && !qstrcmp(widget->parentWidget()->metaObject()->className(), "QWorkspaceChild"))
157
widget = widget->parentWidget();