00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "qdesigner_integration_p.h"
00025 #include "qdesigner_command_p.h"
00026
00027
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
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 }