tools/designer/src/lib/shared/qdesigner_integration.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the Qt Designer of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 #include "qdesigner_integration_p.h"
00025 #include "qdesigner_command_p.h"
00026 
00027 // sdk
00028 #include <QtDesigner/QtDesigner>
00029 #include <QtDesigner/QExtensionManager>
00030 
00031 #include <QtCore/QVariant>
00032 
00033 #include <QtCore/qdebug.h>
00034 
00035 namespace qdesigner_internal {
00036 
00037 QDesignerIntegration::QDesignerIntegration(QDesignerFormEditorInterface *core, QObject *parent)
00038     : QObject(parent),
00039       m_core(core)
00040 {
00041     initialize();
00042 }
00043 
00044 QDesignerIntegration::~QDesignerIntegration()
00045 {
00046 }
00047 
00048 void QDesignerIntegration::initialize()
00049 {
00050     //
00051     // integrate the `Form Editor component'
00052     //
00053     connect(core()->propertyEditor(), SIGNAL(propertyChanged(QString,QVariant)),
00054             this, SLOT(updateProperty(QString,QVariant)));
00055 
00056     connect(core()->formWindowManager(), SIGNAL(formWindowAdded(QDesignerFormWindowInterface*)),
00057             this, SLOT(setupFormWindow(QDesignerFormWindowInterface*)));
00058 
00059     connect(core()->formWindowManager(), SIGNAL(activeFormWindowChanged(QDesignerFormWindowInterface*)),
00060             this, SLOT(updateActiveFormWindow(QDesignerFormWindowInterface*)));
00061 }
00062 
00063 void QDesignerIntegration::updateProperty(const QString &name, const QVariant &value)
00064 {
00065     Q_ASSERT(core()->propertyEditor() != 0);
00066     Q_ASSERT(core()->propertyEditor()->object() != 0);
00067 
00068     if (QDesignerFormWindowInterface *formWindow = core()->formWindowManager()->activeFormWindow()) {
00069         QObject *object = core()->propertyEditor()->object();
00070         QWidget *widget = qobject_cast<QWidget*>(object);
00071 
00072         QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), object);
00073         Q_ASSERT(sheet != 0);
00074 
00075         int propertyIndex = sheet->indexOf(name);
00076         QDesignerFormWindowCursorInterface *cursor = formWindow->cursor();
00077 
00078         if (widget && cursor->isWidgetSelected(widget)) {
00079             if (cursor->isWidgetSelected(formWindow->mainContainer())) {
00080                 if (name == QLatin1String("windowTitle")) {
00081                     QString filename = formWindow->fileName().isEmpty()
00082                             ? QString::fromUtf8("Untitled")
00083                             : formWindow->fileName();
00084 
00085                     formWindow->setWindowTitle(QString::fromUtf8("%1 - (%2)")
00086                                             .arg(value.toString())
00087                                             .arg(filename));
00088 
00089                 } else if (name == QLatin1String("geometry")) {
00090                     if (QWidget *container = containerWindow(formWindow)) {
00091                         SetFormPropertyCommand *cmd = new SetFormPropertyCommand(formWindow);
00092                         cmd->init(object, name, value);
00093                         cmd->setOldValue(container->geometry());
00094                         formWindow->commandHistory()->push(cmd);
00095 
00096                         emit propertyChanged(formWindow, name, value);
00097                     }
00098 
00099                     return;
00100                 }
00101             }
00102 
00103             cursor->setProperty(name, value);
00104         } else if (propertyIndex != -1) {
00105             SetPropertyCommand *cmd = new SetPropertyCommand(formWindow);
00106             cmd->init(object, name, value);
00107             formWindow->commandHistory()->push(cmd);
00108         }
00109 
00110         if (name == QLatin1String("objectName") && core()->objectInspector()) {
00111             core()->objectInspector()->setFormWindow(formWindow);
00112         }
00113 
00114         emit propertyChanged(formWindow, name, value);
00115 
00116         core()->propertyEditor()->setPropertyValue(name, sheet->property(propertyIndex));
00117     }
00118 }
00119 
00120 void QDesignerIntegration::updateActiveFormWindow(QDesignerFormWindowInterface *formWindow)
00121 {
00122     Q_UNUSED(formWindow);
00123     updateSelection();
00124 }
00125 
00126 void QDesignerIntegration::setupFormWindow(QDesignerFormWindowInterface *formWindow)
00127 {
00128     connect(formWindow, SIGNAL(selectionChanged()), this, SLOT(updateSelection()));
00129     connect(formWindow, SIGNAL(activated(QWidget*)), this, SLOT(activateWidget(QWidget*)));
00130 }
00131 
00132 void QDesignerIntegration::updateGeometry()
00133 {
00134 }
00135 
00136 void QDesignerIntegration::updateSelection()
00137 {
00138     QDesignerFormWindowInterface *formWindow = core()->formWindowManager()->activeFormWindow();
00139     QWidget *selection = 0;
00140 
00141     if (formWindow)
00142         selection = formWindow->cursor()->selectedWidget(0);
00143 
00144     if (QDesignerActionEditorInterface *actionEditor = core()->actionEditor())
00145         actionEditor->setFormWindow(formWindow);
00146 
00147     if (QDesignerPropertyEditorInterface *propertyEditor = core()->propertyEditor()) {
00148         propertyEditor->setObject(selection);
00149         propertyEditor->setEnabled(formWindow && formWindow->cursor()->selectedWidgetCount() == 1);
00150     }
00151     if (QDesignerObjectInspectorInterface *objectInspector = core()->objectInspector())
00152         objectInspector->setFormWindow(formWindow);
00153 
00154 }
00155 
00156 void QDesignerIntegration::activateWidget(QWidget *widget)
00157 {
00158     Q_UNUSED(widget);
00159 }
00160 
00161 QWidget *QDesignerIntegration::containerWindow(QWidget *widget)
00162 {
00163     while (widget) {
00164         if (widget->isWindow())
00165             break;
00166         if (widget->parentWidget() && !qstrcmp(widget->parentWidget()->metaObject()->className(), "QWorkspaceChild"))
00167             break;
00168 
00169         widget = widget->parentWidget();
00170     }
00171 
00172     return widget;
00173 }
00174 
00175 
00176 } // namespace qdesigner_internal

Generated on Thu Mar 15 12:01:27 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1