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 <QtDesigner/QtDesigner>
00025
00026 #include "qdesigner_command_p.h"
00027 #include "qdesigner_utils_p.h"
00028 #include "layout_p.h"
00029 #include "qlayout_widget_p.h"
00030 #include "qdesigner_widget_p.h"
00031 #include "qdesigner_promotedwidget_p.h"
00032 #include "qdesigner_menu_p.h"
00033
00034 #include <QtCore/qdebug.h>
00035
00036 #include <QtGui/QMenuBar>
00037 #include <QtGui/QStatusBar>
00038 #include <QtGui/QToolBar>
00039 #include <QtGui/QToolBox>
00040 #include <QtGui/QStackedWidget>
00041 #include <QtGui/QTabWidget>
00042 #include <QtGui/QTableWidget>
00043 #include <QtGui/QTreeWidget>
00044 #include <QtGui/QListWidget>
00045 #include <QtGui/QComboBox>
00046 #include <QtGui/QSplitter>
00047 #include <QtGui/QDockWidget>
00048 #include <QtGui/QMainWindow>
00049 #include <QtGui/QApplication>
00050
00051 namespace qdesigner_internal {
00052
00053
00054 QDesignerFormEditorCommand::QDesignerFormEditorCommand(const QString &description, QDesignerFormEditorInterface *core)
00055 : QUndoCommand(description),
00056 m_core(core)
00057 {
00058 }
00059
00060 QDesignerFormEditorInterface *QDesignerFormEditorCommand::core() const
00061 {
00062 return m_core;
00063 }
00064
00065
00066 QDesignerFormWindowManagerCommand::QDesignerFormWindowManagerCommand(const QString &description, QDesignerFormWindowManagerInterface *formWindowManager)
00067 : QUndoCommand(description),
00068 m_formWindowManager(formWindowManager)
00069 {
00070 }
00071
00072 QDesignerFormWindowManagerInterface *QDesignerFormWindowManagerCommand::formWindowManager() const
00073 {
00074 return m_formWindowManager;
00075 }
00076
00077
00078 QDesignerFormWindowCommand::QDesignerFormWindowCommand(const QString &description, QDesignerFormWindowInterface *formWindow)
00079 : QUndoCommand(description),
00080 m_formWindow(formWindow)
00081 {
00082 }
00083
00084 QDesignerFormWindowInterface *QDesignerFormWindowCommand::formWindow() const
00085 {
00086 return m_formWindow;
00087 }
00088
00089 QDesignerFormEditorInterface *QDesignerFormWindowCommand::core() const
00090 {
00091 if (QDesignerFormWindowInterface *fw = formWindow())
00092 return fw->core();
00093
00094 return 0;
00095 }
00096
00097 void QDesignerFormWindowCommand::undo()
00098 {
00099 cheapUpdate();
00100 }
00101
00102 void QDesignerFormWindowCommand::redo()
00103 {
00104 cheapUpdate();
00105 }
00106
00107 void QDesignerFormWindowCommand::cheapUpdate()
00108 {
00109 if (core()->objectInspector())
00110 core()->objectInspector()->setFormWindow(formWindow());
00111
00112 if (core()->actionEditor())
00113 core()->actionEditor()->setFormWindow(formWindow());
00114 }
00115
00116 bool QDesignerFormWindowCommand::hasLayout(QWidget *widget) const
00117 {
00118 QDesignerFormEditorInterface *core = formWindow()->core();
00119 if (widget && LayoutInfo::layoutType(core, widget) != LayoutInfo::NoLayout) {
00120 QDesignerMetaDataBaseItemInterface *item = core->metaDataBase()->item(widget);
00121 return item != 0;
00122 }
00123
00124 return false;
00125 }
00126
00127 void QDesignerFormWindowCommand::checkObjectName(QObject *)
00128 {
00129 }
00130
00131 void QDesignerFormWindowCommand::updateBuddies(const QString &old_name,
00132 const QString &new_name)
00133 {
00134 QDesignerFormEditorInterface *core = formWindow()->core();
00135
00136 QList<QDesignerLabel*> label_list = qFindChildren<QDesignerLabel*>(formWindow());
00137 foreach (QDesignerLabel *label, label_list) {
00138 QDesignerPropertySheetExtension* propertySheet
00139 = qt_extension<QDesignerPropertySheetExtension*>
00140 (core->extensionManager(), label);
00141 if (propertySheet == 0)
00142 continue;
00143 int idx = propertySheet->indexOf(QLatin1String("buddy"));
00144 if (idx == -1)
00145 continue;
00146 if (propertySheet->property(idx).toString() == old_name)
00147 propertySheet->setProperty(idx, new_name);
00148 }
00149 }
00150
00151 void QDesignerFormWindowCommand::checkSelection(QWidget *widget)
00152 {
00153 Q_UNUSED(widget);
00154 }
00155
00156 void QDesignerFormWindowCommand::checkParent(QWidget *widget, QWidget *parentWidget)
00157 {
00158 Q_ASSERT(widget);
00159
00160 if (widget->parentWidget() != parentWidget)
00161 widget->setParent(parentWidget);
00162 }
00163
00164
00165 SetPropertyCommand::SetPropertyCommand(QDesignerFormWindowInterface *formWindow)
00166 : QDesignerFormWindowCommand(QString(), formWindow),
00167 m_index(-1),
00168 m_propertySheet(0),
00169 m_changed(false)
00170 {
00171 }
00172
00173 QObject *SetPropertyCommand::object() const
00174 {
00175 return m_object;
00176 }
00177
00178 QWidget *SetPropertyCommand::widget() const
00179 {
00180 return qobject_cast<QWidget*>(m_object);
00181 }
00182
00183 QWidget *SetPropertyCommand::parentWidget() const
00184 {
00185 if (QWidget *w = widget()) {
00186 return w->parentWidget();
00187 }
00188
00189 return 0;
00190 }
00191
00192 void SetPropertyCommand::init(QObject *object, const QString &propertyName, const QVariant &newValue)
00193 {
00194 Q_ASSERT(object);
00195
00196 m_object = object;
00197 m_parentWidget = parentWidget();
00198 m_propertyName = propertyName;
00199 m_newValue = newValue;
00200
00201 QDesignerFormEditorInterface *core = formWindow()->core();
00202 m_propertySheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), object);
00203 Q_ASSERT(m_propertySheet);
00204
00205 m_index = m_propertySheet->indexOf(m_propertyName);
00206 Q_ASSERT(m_index != -1);
00207
00208 m_changed = m_propertySheet->isChanged(m_index);
00209 m_oldValue = m_propertySheet->property(m_index);
00210
00211 setText(QApplication::translate("Command", "changed '%1' of '%2'").arg(m_propertyName).arg(object->objectName()));
00212 }
00213
00214 static QWidget *containerWindow(QWidget *widget)
00215 {
00216 while (widget) {
00217 if (widget->metaObject()->className() == QLatin1String("QDesignerFormWindow"))
00218 return widget;
00219
00220 widget = widget->parentWidget();
00221 }
00222 return 0;
00223 }
00224
00225 static QSize checkSize(const QSize &size)
00226 {
00227 QSize s = size;
00228 if (s.width() > 0xFFFFFF)
00229 s.setWidth(0xFFFFFF);
00230 if (s.height() > 0xFFFFFF)
00231 s.setHeight(0xFFFFFF);
00232 return s;
00233 }
00234
00235 static void setTopMinMaxSize(QDesignerFormWindowInterface *fw, QWidget *w, const QString &propertyName, const QVariant &value)
00236 {
00237 QDesignerFormWindowCursorInterface *cursor = fw->cursor();
00238 if (w && cursor->isWidgetSelected(w)) {
00239 if (cursor->isWidgetSelected(fw->mainContainer())) {
00240 if (propertyName == QLatin1String("minimumSize")) {
00241 if (QWidget *container = containerWindow(fw)) {
00242 if (container->parentWidget() && container->parentWidget()->metaObject()->className() == QLatin1String("QWorkspaceChild")) {
00243 QSize diff = container->parentWidget()->geometry().size() - container->geometry().size();
00244 container->parentWidget()->setMinimumSize(checkSize(value.toSize() + diff));
00245 }
00246 container->setMinimumSize(value.toSize());
00247 }
00248 } else if (propertyName == QLatin1String("maximumSize")) {
00249 if (QWidget *container = containerWindow(fw)) {
00250 if (container->parentWidget() && container->parentWidget()->metaObject()->className() == QLatin1String("QWorkspaceChild")) {
00251 QSize diff = container->parentWidget()->geometry().size() - container->geometry().size();
00252 container->parentWidget()->setMaximumSize(checkSize(value.toSize() + diff));
00253 }
00254 container->setMaximumSize(value.toSize());
00255 }
00256 }
00257 }
00258 }
00259 }
00260
00261 void SetPropertyCommand::redo()
00262 {
00263 Q_ASSERT(m_propertySheet);
00264 Q_ASSERT(m_index != -1);
00265
00266 m_propertySheet->setProperty(m_index, m_newValue);
00267 m_changed = m_propertySheet->isChanged(m_index);
00268 m_propertySheet->setChanged(m_index, true);
00269
00270 if (m_propertyName == QLatin1String("geometry") && widget()) {
00271 checkSelection(widget());
00272 checkParent(widget(), parentWidget());
00273 } else if (m_propertyName == QLatin1String("objectName")) {
00274 checkObjectName(m_object);
00275 updateBuddies(m_oldValue.toString(), m_newValue.toString());
00276 }
00277
00278 if (QDesignerPropertyEditorInterface *propertyEditor = formWindow()->core()->propertyEditor()) {
00279 if (propertyEditor->object() == object())
00280 propertyEditor->setPropertyValue(propertyName(), m_newValue, true);
00281 else
00282 propertyEditor->setObject(propertyEditor->object());
00283
00284
00285 }
00286
00287 setTopMinMaxSize(formWindow(), qobject_cast<QWidget *>(m_object), m_propertyName, m_newValue);
00288
00289 QAction *act = qobject_cast<QAction *>(m_object);
00290 if (m_propertyName == QLatin1String("objectName") ||
00291 m_propertyName == QLatin1String("icon") && act ||
00292 m_propertyName == QLatin1String("currentTabName")) {
00293 if (QDesignerObjectInspectorInterface *oi = formWindow()->core()->objectInspector())
00294 oi->setFormWindow(formWindow());
00295 }
00296
00297 if (m_propertyName == QLatin1String("objectName") && act) {
00298
00299 act->setData(QVariant(true));
00300 act->setData(QVariant(false));
00301 }
00302
00303 if (QDesignerPromotedWidget *promoted = qobject_cast<QDesignerPromotedWidget*>(m_object)) {
00304 if (m_propertyName == QLatin1String("minimumSize"))
00305 promoted->setMinimumSize(m_newValue.toSize());
00306 else if (m_propertyName == QLatin1String("maximumSize"))
00307 promoted->setMaximumSize(m_newValue.toSize());
00308 }
00309 }
00310
00311 void SetPropertyCommand::undo()
00312 {
00313 Q_ASSERT(m_propertySheet);
00314 Q_ASSERT(m_index != -1);
00315
00316 m_propertySheet->setProperty(m_index, m_oldValue);
00317 m_propertySheet->setChanged(m_index, m_changed);
00318
00319 if (m_propertyName == QLatin1String("geometry") && widget()) {
00320 checkSelection(widget());
00321 checkParent(widget(), parentWidget());
00322 } else if (m_propertyName == QLatin1String("objectName")) {
00323 checkObjectName(m_object);
00324 updateBuddies(m_newValue.toString(), m_oldValue.toString());
00325 }
00326
00327 if (QDesignerPropertyEditorInterface *propertyEditor = formWindow()->core()->propertyEditor()) {
00328 if (propertyEditor->object() == widget())
00329 propertyEditor->setPropertyValue(propertyName(), m_oldValue, m_changed);
00330 else
00331 propertyEditor->setObject(propertyEditor->object());
00332
00333
00334 }
00335
00336 setTopMinMaxSize(formWindow(), qobject_cast<QWidget *>(m_object), m_propertyName, m_oldValue);
00337
00338 QAction *act = qobject_cast<QAction *>(m_object);
00339 if (m_propertyName == QLatin1String("objectName") ||
00340 m_propertyName == QLatin1String("icon") && act ||
00341 m_propertyName == QLatin1String("currentTabName")) {
00342 if (QDesignerObjectInspectorInterface *oi = formWindow()->core()->objectInspector())
00343 oi->setFormWindow(formWindow());
00344 }
00345
00346 if (m_propertyName == QLatin1String("objectName") && act) {
00347
00348 act->setData(QVariant(true));
00349 act->setData(QVariant(false));
00350 }
00351
00352 if (QDesignerPromotedWidget *promoted = qobject_cast<QDesignerPromotedWidget*>(m_object)) {
00353 if (m_propertyName == QLatin1String("minimumSize"))
00354 promoted->setMinimumSize(m_oldValue.toSize());
00355 else if (m_propertyName == QLatin1String("maximumSize"))
00356 promoted->setMaximumSize(m_oldValue.toSize());
00357 }
00358 }
00359
00360 int SetPropertyCommand::id() const
00361 {
00362 return 1976;
00363 }
00364
00365 bool SetPropertyCommand::mergeWith(const QUndoCommand *other)
00366 {
00367 if (id() != other->id())
00368 return false;
00369
00370 if (const SetPropertyCommand *cmd = static_cast<const SetPropertyCommand*>(other)) {
00371 if (cmd->propertyName() == propertyName() && cmd->object() == object()) {
00372 if (!formWindow()->isDirty())
00373 return false;
00374
00375 m_newValue = cmd->newValue();
00376 return true;
00377 }
00378 }
00379
00380 return false;
00381 }
00382
00383
00384 SetFormPropertyCommand::SetFormPropertyCommand(QDesignerFormWindowInterface *formWindow)
00385 : QDesignerFormWindowCommand(QString(), formWindow),
00386 m_index(-1),
00387 m_changed(false),
00388 m_propertySheet(0)
00389 {
00390 }
00391
00392 void SetFormPropertyCommand::init(QObject *object, const QString &propertyName, const QVariant &newValue)
00393 {
00394 Q_ASSERT(object);
00395
00396 m_newValue = newValue;
00397 m_propertyName = propertyName;
00398
00399 QDesignerFormEditorInterface *core = formWindow()->core();
00400 m_propertySheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), object);
00401 Q_ASSERT(m_propertySheet);
00402
00403 m_index = m_propertySheet->indexOf(m_propertyName);
00404 Q_ASSERT(m_index != -1);
00405
00406 m_changed = m_propertySheet->isChanged(m_index);
00407 m_oldValue = m_propertySheet->property(m_index);
00408
00409 setText(QApplication::translate("Command", "changed '%1' of '%2'").arg(m_propertyName).arg(object->objectName()));
00410 }
00411
00412 void SetFormPropertyCommand::redo()
00413 {
00414 m_changed = m_propertySheet->isChanged(m_index);
00415 m_propertySheet->setChanged(m_index, true);
00416
00417 if (m_propertyName == QLatin1String("geometry"))
00418 updateFormWindowGeometry(m_newValue);
00419 }
00420
00421 void SetFormPropertyCommand::undo()
00422 {
00423 m_propertySheet->setChanged(m_index, m_changed);
00424
00425 if (m_propertyName == QLatin1String("geometry"))
00426 updateFormWindowGeometry(m_oldValue);
00427 }
00428
00429
00430 int SetFormPropertyCommand::id() const
00431 {
00432 return 1977;
00433 }
00434
00435 bool SetFormPropertyCommand::mergeWith(const QUndoCommand *other)
00436 {
00437 if (id() != other->id())
00438 return false;
00439
00440 if (const SetFormPropertyCommand *cmd = static_cast<const SetFormPropertyCommand*>(other)) {
00441 if (cmd->propertyName() == propertyName() && cmd->formWindow() == formWindow()) {
00442 m_newValue = cmd->newValue();
00443 return true;
00444 }
00445 }
00446
00447 return false;
00448 }
00449
00450 void SetFormPropertyCommand::updateFormWindowGeometry(const QVariant &value)
00451 {
00452 if (QWidget *container = containerWindow(formWindow())) {
00453 QRect r = container->geometry();
00454 if (container->parentWidget() && container->parentWidget()->metaObject()->className() == QLatin1String("QWorkspaceChild")) {
00455 QRect windowRect = container->parentWidget()->rect();
00456 QSize diff = windowRect.size() - r.size();
00457 windowRect.setSize(value.toRect().size() + diff);
00458 container->parentWidget()->setGeometry(windowRect);
00459 } else {
00460 r.setSize(value.toRect().size());
00461 container->setGeometry(r);
00462 }
00463 }
00464 }
00465
00466 QWidget *SetFormPropertyCommand::containerWindow(QWidget *widget)
00467 {
00468 while (widget) {
00469 if (widget->isWindow())
00470 break;
00471 if (widget->parentWidget() && !qstrcmp(widget->parentWidget()->metaObject()->className(), "QWorkspaceChild"))
00472 break;
00473
00474 widget = widget->parentWidget();
00475 }
00476
00477 return widget;
00478 }
00479
00480 ResetPropertyCommand::ResetPropertyCommand(QDesignerFormWindowInterface *formWindow)
00481 : QDesignerFormWindowCommand(QString(), formWindow),
00482 m_index(-1),
00483 m_propertySheet(0),
00484 m_changed(false)
00485 {
00486 }
00487
00488 QObject *ResetPropertyCommand::object() const
00489 {
00490 return m_object;
00491 }
00492
00493 QObject *ResetPropertyCommand::parentObject() const
00494 {
00495 return m_parentObject;
00496 }
00497
00498 void ResetPropertyCommand::init(QObject *object, const QString &propertyName)
00499 {
00500 Q_ASSERT(object);
00501
00502 m_object = object;
00503 m_parentObject = object->parent();
00504 m_propertyName = propertyName;
00505
00506 QDesignerFormEditorInterface *core = formWindow()->core();
00507 m_propertySheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), object);
00508 Q_ASSERT(m_propertySheet);
00509
00510 m_index = m_propertySheet->indexOf(m_propertyName);
00511 Q_ASSERT(m_index != -1);
00512
00513 m_changed = m_propertySheet->isChanged(m_index);
00514 m_oldValue = m_propertySheet->property(m_index);
00515
00516 setText(QApplication::translate("Command", "reset '%1' of '%2'").arg(m_propertyName).arg(m_object->objectName()));
00517 }
00518
00519 void ResetPropertyCommand::redo()
00520 {
00521 Q_ASSERT(m_propertySheet);
00522 Q_ASSERT(m_index != -1);
00523
00524 QObject *obj = m_object;
00525 QDesignerPromotedWidget *promoted = qobject_cast<QDesignerPromotedWidget*>(obj);
00526 if (promoted)
00527 obj = promoted->child();
00528
00529 QVariant new_value;
00530
00531 if (m_propertySheet->reset(m_index)) {
00532 new_value = m_propertySheet->property(m_index);
00533 } else {
00534 int item_idx = formWindow()->core()->widgetDataBase()->indexOfObject(obj);
00535 if (item_idx == -1) {
00536 new_value = m_oldValue;
00537 } else {
00538 QDesignerWidgetDataBaseItemInterface *item
00539 = formWindow()->core()->widgetDataBase()->item(item_idx);
00540 QList<QVariant> default_prop_values = item->defaultPropertyValues();
00541 if (m_index < default_prop_values.size())
00542 new_value = default_prop_values.at(m_index);
00543 else
00544 new_value = m_oldValue;
00545 }
00546
00547 m_propertySheet->setProperty(m_index, new_value);
00548 }
00549
00550 m_propertySheet->setChanged(m_index, false);
00551
00552 setTopMinMaxSize(formWindow(), qobject_cast<QWidget *>(m_object), m_propertyName, new_value);
00553
00554 QWidget *widget = qobject_cast<QWidget *>(m_object);
00555 QWidget *parentWidget = qobject_cast<QWidget *>(m_parentObject);
00556 if (m_propertyName == QLatin1String("geometry") && widget) {
00557 checkSelection(widget);
00558 checkParent(widget, parentWidget);
00559 } else if (m_propertyName == QLatin1String("objectName")) {
00560 checkObjectName(m_object);
00561 }
00562
00563 if (promoted) {
00564 if (m_propertyName == QLatin1String("minimumSize"))
00565 promoted->setMinimumSize(new_value.toSize());
00566 else if (m_propertyName == QLatin1String("maximumSize"))
00567 promoted->setMaximumSize(new_value.toSize());
00568 }
00569
00570 if (QDesignerPropertyEditorInterface *propertyEditor = formWindow()->core()->propertyEditor()) {
00571 if (propertyEditor->object() == object())
00572 propertyEditor->setPropertyValue(propertyName(), new_value, false);
00573 }
00574 }
00575
00576 void ResetPropertyCommand::undo()
00577 {
00578 Q_ASSERT(m_propertySheet);
00579 Q_ASSERT(m_index != -1);
00580
00581 m_propertySheet->setProperty(m_index, m_oldValue);
00582 m_propertySheet->setChanged(m_index, m_changed);
00583
00584 setTopMinMaxSize(formWindow(), qobject_cast<QWidget *>(m_object), m_propertyName, m_oldValue);
00585
00586 QWidget *widget = qobject_cast<QWidget *>(m_object);
00587 QWidget *parentWidget = qobject_cast<QWidget *>(m_parentObject);
00588 if (m_propertyName == QLatin1String("geometry") && widget) {
00589 checkSelection(widget);
00590 checkParent(widget, parentWidget);
00591 } else if (m_propertyName == QLatin1String("objectName")) {
00592 checkObjectName(m_object);
00593 }
00594
00595 if (QDesignerPropertyEditorInterface *propertyEditor = formWindow()->core()->propertyEditor()) {
00596 if (propertyEditor->object() == object())
00597 propertyEditor->setPropertyValue(propertyName(), m_oldValue, m_changed);
00598 }
00599
00600 if (QDesignerPromotedWidget *promoted = qobject_cast<QDesignerPromotedWidget*>(m_object)) {
00601 if (m_propertyName == QLatin1String("minimumSize"))
00602 promoted->setMinimumSize(m_oldValue.toSize());
00603 else if (m_propertyName == QLatin1String("maximumSize"))
00604 promoted->setMaximumSize(m_oldValue.toSize());
00605 }
00606 }
00607
00608
00609 InsertWidgetCommand::InsertWidgetCommand(QDesignerFormWindowInterface *formWindow)
00610 : QDesignerFormWindowCommand(QString(), formWindow)
00611 {
00612 }
00613
00614 void InsertWidgetCommand::init(QWidget *widget, bool already_in_form)
00615 {
00616 m_widget = widget;
00617
00618 setText(QApplication::translate("Command", "Insert '%1'").arg(widget->objectName()));
00619
00620 QWidget *parentWidget = m_widget->parentWidget();
00621 QDesignerFormEditorInterface *core = formWindow()->core();
00622 QDesignerLayoutDecorationExtension *deco = qt_extension<QDesignerLayoutDecorationExtension*>(core->extensionManager(), parentWidget);
00623
00624 m_insertMode = deco ? deco->currentInsertMode() : QDesignerLayoutDecorationExtension::InsertWidgetMode;
00625 m_cell = deco ? deco->currentCell() : qMakePair(0, 0);
00626 m_widgetWasManaged = already_in_form;
00627 }
00628
00629 static void recursiveUpdate(QWidget *w)
00630 {
00631 w->update();
00632
00633 const QObjectList &l = w->children();
00634 QObjectList::const_iterator it = l.begin();
00635 for (; it != l.end(); ++it) {
00636 if (QWidget *w = qobject_cast<QWidget*>(*it))
00637 recursiveUpdate(w);
00638 }
00639 }
00640
00641 void InsertWidgetCommand::redo()
00642 {
00643 checkObjectName(m_widget);
00644
00645 QWidget *parentWidget = m_widget->parentWidget();
00646 Q_ASSERT(parentWidget);
00647
00648 QDesignerFormEditorInterface *core = formWindow()->core();
00649 QDesignerLayoutDecorationExtension *deco = qt_extension<QDesignerLayoutDecorationExtension*>(core->extensionManager(), parentWidget);
00650
00651 if (deco != 0) {
00652 if (LayoutInfo::layoutType(core, parentWidget) == LayoutInfo::Grid) {
00653 switch (m_insertMode) {
00654 case QDesignerLayoutDecorationExtension::InsertRowMode: {
00655 deco->insertRow(m_cell.first);
00656 } break;
00657
00658 case QDesignerLayoutDecorationExtension::InsertColumnMode: {
00659 deco->insertColumn(m_cell.second);
00660 } break;
00661
00662 default: break;
00663 }
00664 }
00665 deco->insertWidget(m_widget, m_cell);
00666 }
00667
00668 if (!m_widgetWasManaged)
00669 formWindow()->manageWidget(m_widget);
00670 m_widget->show();
00671 formWindow()->emitSelectionChanged();
00672
00673 if (parentWidget && parentWidget->layout()) {
00674 recursiveUpdate(parentWidget);
00675 parentWidget->layout()->invalidate();
00676 }
00677
00678 QList<QDesignerLabel*> label_list = qFindChildren<QDesignerLabel*>(formWindow());
00679 foreach (QDesignerLabel *label, label_list) {
00680 QDesignerPropertySheetExtension* propertySheet
00681 = qt_extension<QDesignerPropertySheetExtension*>
00682 (core->extensionManager(), label);
00683 if (propertySheet == 0)
00684 continue;
00685 int idx = propertySheet->indexOf(QLatin1String("buddy"));
00686 if (idx == -1)
00687 continue;
00688 if (propertySheet->property(idx).toString() == m_widget->objectName())
00689 propertySheet->setProperty(idx, m_widget->objectName());
00690 }
00691 }
00692
00693 void InsertWidgetCommand::undo()
00694 {
00695 QWidget *parentWidget = m_widget->parentWidget();
00696
00697 QDesignerFormEditorInterface *core = formWindow()->core();
00698 QDesignerLayoutDecorationExtension *deco = qt_extension<QDesignerLayoutDecorationExtension*>(core->extensionManager(), parentWidget);
00699
00700 if (deco) {
00701 deco->removeWidget(m_widget);
00702 deco->simplify();
00703 }
00704
00705 if (!m_widgetWasManaged) {
00706 formWindow()->unmanageWidget(m_widget);
00707 m_widget->hide();
00708 }
00709 formWindow()->emitSelectionChanged();
00710
00711 QList<QDesignerLabel*> label_list = qFindChildren<QDesignerLabel*>(formWindow());
00712 foreach (QDesignerLabel *label, label_list) {
00713 QDesignerPropertySheetExtension* propertySheet
00714 = qt_extension<QDesignerPropertySheetExtension*>
00715 (core->extensionManager(), label);
00716 if (propertySheet == 0)
00717 continue;
00718 int idx = propertySheet->indexOf(QLatin1String("buddy"));
00719 if (idx == -1)
00720 continue;
00721 if (propertySheet->property(idx).toString() == m_widget->objectName())
00722 propertySheet->setProperty(idx, m_widget->objectName());
00723 }
00724 }
00725
00726
00727 RaiseWidgetCommand::RaiseWidgetCommand(QDesignerFormWindowInterface *formWindow)
00728 : QDesignerFormWindowCommand(QString(), formWindow)
00729 {
00730 }
00731
00732 void RaiseWidgetCommand::init(QWidget *widget)
00733 {
00734 m_widget = widget;
00735 setText(QApplication::translate("Command", "Raise '%1'").arg(widget->objectName()));
00736 }
00737
00738 void RaiseWidgetCommand::redo()
00739 {
00740 m_widget->raise();
00741 }
00742
00743 void RaiseWidgetCommand::undo()
00744 {
00745 }
00746
00747
00748 LowerWidgetCommand::LowerWidgetCommand(QDesignerFormWindowInterface *formWindow)
00749 : QDesignerFormWindowCommand(QString(), formWindow)
00750 {
00751 }
00752
00753 void LowerWidgetCommand::init(QWidget *widget)
00754 {
00755 m_widget = widget;
00756 setText(QApplication::translate("Command", "Lower '%1'").arg(widget->objectName()));
00757 }
00758
00759 void LowerWidgetCommand::redo()
00760 {
00761 m_widget->raise();
00762 }
00763
00764 void LowerWidgetCommand::undo()
00765 {
00766 }
00767
00768
00769 DeleteWidgetCommand::DeleteWidgetCommand(QDesignerFormWindowInterface *formWindow)
00770 : QDesignerFormWindowCommand(QString(), formWindow)
00771 {
00772 }
00773
00774 void DeleteWidgetCommand::init(QWidget *widget)
00775 {
00776 m_widget = widget;
00777 m_parentWidget = widget->parentWidget();
00778 m_geometry = widget->geometry();
00779
00780 m_layoutType = LayoutInfo::NoLayout;
00781 m_index = -1;
00782 if (hasLayout(m_parentWidget)) {
00783 m_layoutType = LayoutInfo::layoutType(formWindow()->core(), m_parentWidget);
00784
00785 switch (m_layoutType) {
00786 case LayoutInfo::VBox:
00787 m_index = static_cast<QVBoxLayout*>(m_parentWidget->layout())->indexOf(m_widget);
00788 break;
00789 case LayoutInfo::HBox:
00790 m_index = static_cast<QHBoxLayout*>(m_parentWidget->layout())->indexOf(m_widget);
00791 break;
00792 case LayoutInfo::Grid: {
00793 m_index = 0;
00794 while (QLayoutItem *item = m_parentWidget->layout()->itemAt(m_index)) {
00795 if (item->widget() == m_widget)
00796 break;
00797 ++m_index;
00798 }
00799
00800 static_cast<QGridLayout*>(m_parentWidget->layout())->getItemPosition(m_index, &m_row, &m_col, &m_rowspan, &m_colspan);
00801 } break;
00802
00803 default:
00804 break;
00805 }
00806 }
00807
00808 m_formItem = formWindow()->core()->metaDataBase()->item(formWindow());
00809 m_tabOrderIndex = m_formItem->tabOrder().indexOf(widget);
00810
00811
00812 m_managedChildren = QList<QPointer<QWidget> >();
00813 QList<QWidget *>children = qFindChildren<QWidget *>(m_widget);
00814 foreach (QPointer<QWidget> child, children) {
00815 if (formWindow()->isManaged(child))
00816 m_managedChildren.append(child);
00817 }
00818
00819 setText(QApplication::translate("Command", "Delete '%1'").arg(widget->objectName()));
00820 }
00821
00822 void DeleteWidgetCommand::redo()
00823 {
00824 QDesignerFormEditorInterface *core = formWindow()->core();
00825
00826 if (QDesignerContainerExtension *c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_parentWidget)) {
00827 for (int i=0; i<c->count(); ++i) {
00828 if (c->widget(i) == m_widget) {
00829 c->remove(i);
00830 formWindow()->emitSelectionChanged();
00831 return;
00832 }
00833 }
00834 }
00835
00836 if (QDesignerLayoutDecorationExtension *deco = qt_extension<QDesignerLayoutDecorationExtension*>(core->extensionManager(), m_parentWidget)) {
00837 deco->removeWidget(m_widget);
00838 }
00839
00840
00841 foreach (QWidget *child, m_managedChildren)
00842 formWindow()->unmanageWidget(child);
00843
00844 formWindow()->unmanageWidget(m_widget);
00845 m_widget->setParent(formWindow());
00846 m_widget->hide();
00847
00848 if (m_tabOrderIndex != -1) {
00849 QList<QWidget*> tab_order = m_formItem->tabOrder();
00850 tab_order.removeAt(m_tabOrderIndex);
00851 m_formItem->setTabOrder(tab_order);
00852 }
00853
00854 formWindow()->emitSelectionChanged();
00855 }
00856
00857 void DeleteWidgetCommand::undo()
00858 {
00859 QDesignerFormEditorInterface *core = formWindow()->core();
00860
00861 m_widget->setParent(m_parentWidget);
00862
00863 if (QDesignerContainerExtension *c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_parentWidget)) {
00864 c->addWidget(m_widget);
00865 formWindow()->emitSelectionChanged();
00866 return;
00867 }
00868
00869 m_widget->setGeometry(m_geometry);
00870 formWindow()->manageWidget(m_widget);
00871
00872
00873 foreach (QWidget *child, m_managedChildren)
00874 formWindow()->manageWidget(child);
00875
00876
00877 switch (m_layoutType) {
00878 case LayoutInfo::VBox: {
00879 QVBoxLayout *vbox = static_cast<QVBoxLayout*>(m_parentWidget->layout());
00880 insert_into_box_layout(vbox, m_index, m_widget);
00881 } break;
00882
00883 case LayoutInfo::HBox: {
00884 QHBoxLayout *hbox = static_cast<QHBoxLayout*>(m_parentWidget->layout());
00885 insert_into_box_layout(hbox, m_index, m_widget);
00886 } break;
00887
00888 case LayoutInfo::Grid: {
00889 QGridLayout *grid = static_cast<QGridLayout*>(m_parentWidget->layout());
00890 add_to_grid_layout(grid, m_widget, m_row, m_col, m_rowspan, m_colspan);
00891 } break;
00892
00893 default:
00894 break;
00895 }
00896
00897 m_widget->show();
00898
00899 if (m_tabOrderIndex != -1) {
00900 QList<QWidget*> tab_order = m_formItem->tabOrder();
00901 tab_order.insert(m_tabOrderIndex, m_widget);
00902 m_formItem->setTabOrder(tab_order);
00903 }
00904
00905 formWindow()->emitSelectionChanged();
00906 }
00907
00908
00909 ReparentWidgetCommand::ReparentWidgetCommand(QDesignerFormWindowInterface *formWindow)
00910 : QDesignerFormWindowCommand(QString(), formWindow)
00911 {
00912 }
00913
00914 void ReparentWidgetCommand::init(QWidget *widget, QWidget *parentWidget)
00915 {
00916 Q_ASSERT(widget);
00917
00918 m_widget = widget;
00919 m_oldParentWidget = widget->parentWidget();
00920 m_newParentWidget = parentWidget;
00921
00922 m_oldPos = m_widget->pos();
00923 m_newPos = m_newParentWidget->mapFromGlobal(m_oldParentWidget->mapToGlobal(m_oldPos));
00924
00925 setText(QApplication::translate("Command", "Reparent '%1'").arg(widget->objectName()));
00926 }
00927
00928 void ReparentWidgetCommand::redo()
00929 {
00930 m_widget->setParent(m_newParentWidget);
00931 m_widget->move(m_newPos);
00932
00933 m_widget->show();
00934 }
00935
00936 void ReparentWidgetCommand::undo()
00937 {
00938 m_widget->setParent(m_oldParentWidget);
00939 m_widget->move(m_oldPos);
00940
00941 m_widget->show();
00942 }
00943
00944
00945
00946 static void replace_widget_item(QDesignerFormWindowInterface *fw, QWidget *wgt, QWidget *promoted)
00947 {
00948 QDesignerFormEditorInterface *core = fw->core();
00949 QWidget *parent = wgt->parentWidget();
00950
00951 promoted->setMinimumSize(wgt->minimumSize());
00952 promoted->setMaximumSize(wgt->maximumSize());
00953
00954 QRect info;
00955 int splitter_idx = -1;
00956 if (QDesignerLayoutDecorationExtension *deco = qt_extension<QDesignerLayoutDecorationExtension*>(core->extensionManager(), parent)) {
00957 if (QSplitter *splitter = qobject_cast<QSplitter*>(parent)) {
00958 splitter_idx = splitter->indexOf(wgt);
00959 Q_ASSERT(splitter_idx != -1);
00960 wgt->setParent(0);
00961 } else {
00962 QLayout *layout = LayoutInfo::managedLayout(core, parent);
00963 Q_ASSERT(layout != 0);
00964
00965 int old_index = layout->indexOf(wgt);
00966 Q_ASSERT(old_index != -1);
00967
00968 info = deco->itemInfo(old_index);
00969
00970 QLayoutItem *item = layout->takeAt(old_index);
00971 delete item;
00972 layout->activate();
00973 }
00974 }
00975
00976 if (qt_extension<QDesignerLayoutDecorationExtension*>(core->extensionManager(), parent)) {
00977 if (QSplitter *splitter = qobject_cast<QSplitter*>(parent)) {
00978 splitter->insertWidget(splitter_idx, promoted);
00979 } else {
00980 QLayout *layout = LayoutInfo::managedLayout(core, parent);
00981 Q_ASSERT(layout != 0);
00982
00983
00984
00985 switch (LayoutInfo::layoutType(core, layout)) {
00986 default: Q_ASSERT(0); break;
00987
00988 case LayoutInfo::VBox:
00989 insert_into_box_layout(static_cast<QBoxLayout*>(layout), info.top(), promoted);
00990 break;
00991
00992 case LayoutInfo::HBox:
00993 insert_into_box_layout(static_cast<QBoxLayout*>(layout), info.left(), promoted);
00994 break;
00995
00996 case LayoutInfo::Grid:
00997 add_to_grid_layout(static_cast<QGridLayout*>(layout), promoted, info.top(), info.left(), info.height(), info.width());
00998 break;
00999 }
01000 }
01001 }
01002 }
01003
01004 PromoteToCustomWidgetCommand::PromoteToCustomWidgetCommand
01005 (QDesignerFormWindowInterface *formWindow)
01006 : QDesignerFormWindowCommand(QApplication::translate("Command", "Promote to custom widget"), formWindow)
01007 {
01008 m_widget = 0;
01009 m_promoted = 0;
01010 }
01011
01012 void PromoteToCustomWidgetCommand::init(QDesignerWidgetDataBaseItemInterface *item,
01013 QWidget *widget)
01014 {
01015 m_widget = widget;
01016 m_promoted = new QDesignerPromotedWidget(item, widget->parentWidget());
01017 }
01018
01019 void PromoteToCustomWidgetCommand::redo()
01020 {
01021 m_promoted->setObjectName(QLatin1String("__qt__promoted_") + m_widget->objectName());
01022 m_promoted->setGeometry(m_widget->geometry());
01023
01024 replace_widget_item(formWindow(), m_widget, m_promoted);
01025
01026 m_promoted->setChildWidget(m_widget);
01027 formWindow()->manageWidget(m_promoted);
01028
01029 formWindow()->clearSelection();
01030 formWindow()->selectWidget(m_promoted);
01031 m_promoted->show();
01032 }
01033
01034 void PromoteToCustomWidgetCommand::undo()
01035 {
01036 m_promoted->setChildWidget(0);
01037 m_widget->setParent(m_promoted->parentWidget());
01038 m_widget->setGeometry(m_promoted->geometry());
01039
01040 replace_widget_item(formWindow(), m_promoted, m_widget);
01041
01042 formWindow()->manageWidget(m_widget);
01043 formWindow()->unmanageWidget(m_promoted);
01044
01045 m_promoted->hide();
01046 m_widget->show();
01047
01048 formWindow()->clearSelection();
01049 formWindow()->selectWidget(m_promoted);
01050 }
01051
01052
01053
01054 DemoteFromCustomWidgetCommand::DemoteFromCustomWidgetCommand
01055 (QDesignerFormWindowInterface *formWindow)
01056 : QDesignerFormWindowCommand(QApplication::translate("Command", "Demote from custom widget"), formWindow)
01057 {
01058 m_promote_cmd = new PromoteToCustomWidgetCommand(formWindow);
01059 }
01060
01061 void DemoteFromCustomWidgetCommand::init(QDesignerPromotedWidget *promoted)
01062 {
01063 m_promote_cmd->m_widget = promoted->child();
01064 m_promote_cmd->m_promoted = promoted;
01065 }
01066
01067 void DemoteFromCustomWidgetCommand::redo()
01068 {
01069 m_promote_cmd->undo();
01070 m_promote_cmd->m_widget->show();
01071 }
01072
01073 void DemoteFromCustomWidgetCommand::undo()
01074 {
01075 m_promote_cmd->redo();
01076 }
01077
01078
01079 LayoutCommand::LayoutCommand(QDesignerFormWindowInterface *formWindow)
01080 : QDesignerFormWindowCommand(QString(), formWindow)
01081 {
01082 }
01083
01084 LayoutCommand::~LayoutCommand()
01085 {
01086 m_layout->deleteLater();
01087 }
01088
01089 void LayoutCommand::init(QWidget *parentWidget, const QList<QWidget*> &widgets, LayoutInfo::Type layoutType,
01090 QWidget *layoutBase, bool splitter)
01091 {
01092 m_parentWidget = parentWidget;
01093 m_widgets = widgets;
01094 formWindow()->simplifySelection(&m_widgets);
01095 QPoint grid = formWindow()->grid();
01096 QSize sz(qMax(5, grid.x()), qMax(5, grid.y()));
01097
01098 switch (layoutType) {
01099 case LayoutInfo::Grid:
01100 m_layout = new GridLayout(widgets, m_parentWidget, formWindow(), layoutBase, sz);
01101 setText(QApplication::translate("Command", "Lay out using grid"));
01102 break;
01103
01104 case LayoutInfo::VBox:
01105 m_layout = new VerticalLayout(widgets, m_parentWidget, formWindow(), layoutBase, splitter);
01106 setText(QApplication::translate("Command", "Lay out vertically"));
01107 break;
01108
01109 case LayoutInfo::HBox:
01110 m_layout = new HorizontalLayout(widgets, m_parentWidget, formWindow(), layoutBase, splitter);
01111 setText(QApplication::translate("Command", "Lay out horizontally"));
01112 break;
01113 default:
01114 Q_ASSERT(0);
01115 }
01116
01117 m_layout->setup();
01118 }
01119
01120 void LayoutCommand::redo()
01121 {
01122 m_layout->doLayout();
01123 checkSelection(m_parentWidget);
01124 }
01125
01126 void LayoutCommand::undo()
01127 {
01128 QDesignerFormEditorInterface *core = formWindow()->core();
01129
01130 QWidget *lb = m_layout->layoutBaseWidget();
01131 QDesignerLayoutDecorationExtension *deco = qt_extension<QDesignerLayoutDecorationExtension*>(core->extensionManager(), lb);
01132
01133 QWidget *p = m_layout->parentWidget();
01134 if (!deco && hasLayout(p)) {
01135 deco = qt_extension<QDesignerLayoutDecorationExtension*>(core->extensionManager(), p);
01136 }
01137
01138 m_layout->undoLayout();
01139 delete deco;
01140
01141
01142 if (!m_layoutBase && lb != 0 && !(qobject_cast<QLayoutWidget*>(lb) || qobject_cast<QSplitter*>(lb))) {
01143 core->metaDataBase()->add(lb);
01144 lb->show();
01145 }
01146
01147 checkSelection(m_parentWidget);
01148 }
01149
01150
01151 BreakLayoutCommand::BreakLayoutCommand(QDesignerFormWindowInterface *formWindow)
01152 : QDesignerFormWindowCommand(QApplication::translate("Command", "Break layout"), formWindow)
01153 {
01154 }
01155
01156 BreakLayoutCommand::~BreakLayoutCommand()
01157 {
01158 }
01159
01160 void BreakLayoutCommand::init(const QList<QWidget*> &widgets, QWidget *layoutBase)
01161 {
01162 QDesignerFormEditorInterface *core = formWindow()->core();
01163
01164 m_widgets = widgets;
01165 m_layoutBase = core->widgetFactory()->containerOfWidget(layoutBase);
01166 m_layout = 0;
01167
01168 QPoint grid = formWindow()->grid();
01169
01170 LayoutInfo::Type lay = LayoutInfo::layoutType(core, m_layoutBase);
01171 if (lay == LayoutInfo::HBox)
01172 m_layout = new HorizontalLayout(widgets, m_layoutBase, formWindow(), m_layoutBase, qobject_cast<QSplitter*>(m_layoutBase) != 0);
01173 else if (lay == LayoutInfo::VBox)
01174 m_layout = new VerticalLayout(widgets, m_layoutBase, formWindow(), m_layoutBase, qobject_cast<QSplitter*>(m_layoutBase) != 0);
01175 else if (lay == LayoutInfo::Grid)
01176 m_layout = new GridLayout(widgets, m_layoutBase, formWindow(), m_layoutBase, QSize(qMax(5, grid.x()), qMax(5, grid.y())));
01177
01178
01179 Q_ASSERT(m_layout != 0);
01180
01181 m_layout->sort();
01182
01183 m_margin = m_layout->margin();
01184 m_spacing = m_layout->spacing();
01185 }
01186
01187 void BreakLayoutCommand::redo()
01188 {
01189 if (!m_layout)
01190 return;
01191
01192 QDesignerFormEditorInterface *core = formWindow()->core();
01193 QWidget *lb = m_layout->layoutBaseWidget();
01194 QDesignerLayoutDecorationExtension *deco = qt_extension<QDesignerLayoutDecorationExtension*>(core->extensionManager(), lb);
01195 QWidget *p = m_layout->parentWidget();
01196 if (!deco && hasLayout(p))
01197 deco = qt_extension<QDesignerLayoutDecorationExtension*>(core->extensionManager(), p);
01198
01199 formWindow()->clearSelection(false);
01200 m_layout->breakLayout();
01201 delete deco;
01202
01203 foreach (QWidget *widget, m_widgets) {
01204 widget->resize(widget->size().expandedTo(QSize(16, 16)));
01205 }
01206 }
01207
01208 void BreakLayoutCommand::undo()
01209 {
01210 if (!m_layout)
01211 return;
01212
01213 formWindow()->clearSelection(false);
01214 m_layout->doLayout();
01215
01216 if (m_layoutBase && m_layoutBase->layout()) {
01217 m_layoutBase->layout()->setSpacing(m_spacing);
01218 m_layoutBase->layout()->setMargin(m_margin);
01219 }
01220 }
01221
01222
01223 ToolBoxCommand::ToolBoxCommand(QDesignerFormWindowInterface *formWindow)
01224 : QDesignerFormWindowCommand(QString(), formWindow)
01225 {
01226 }
01227
01228 ToolBoxCommand::~ToolBoxCommand()
01229 {
01230 }
01231
01232 void ToolBoxCommand::init(QToolBox *toolBox)
01233 {
01234 m_toolBox = toolBox;
01235 m_index = m_toolBox->currentIndex();
01236 m_widget = m_toolBox->widget(m_index);
01237 m_itemText = m_toolBox->itemText(m_index);
01238 m_itemIcon = m_toolBox->itemIcon(m_index);
01239 }
01240
01241 void ToolBoxCommand::removePage()
01242 {
01243 m_toolBox->removeItem(m_index);
01244
01245 m_widget->hide();
01246 m_widget->setParent(formWindow());
01247 }
01248
01249 void ToolBoxCommand::addPage()
01250 {
01251 m_widget->setParent(m_toolBox);
01252 m_toolBox->insertItem(m_index, m_widget, m_itemIcon, m_itemText);
01253 m_toolBox->setCurrentIndex(m_index);
01254
01255 m_widget->show();
01256 }
01257
01258
01259 MoveToolBoxPageCommand::MoveToolBoxPageCommand(QDesignerFormWindowInterface *formWindow)
01260 : ToolBoxCommand(formWindow)
01261 {
01262 }
01263
01264 MoveToolBoxPageCommand::~MoveToolBoxPageCommand()
01265 {
01266 }
01267
01268 void MoveToolBoxPageCommand::init(QToolBox *toolBox, QWidget *page, int newIndex)
01269 {
01270 ToolBoxCommand::init(toolBox);
01271 setText(QApplication::translate("Command", "Move Page"));
01272
01273 m_widget = page;
01274 m_oldIndex = m_toolBox->indexOf(m_widget);
01275 m_itemText = m_toolBox->itemText(m_oldIndex);
01276 m_itemIcon = m_toolBox->itemIcon(m_oldIndex);
01277 m_newIndex = newIndex;
01278 }
01279
01280 void MoveToolBoxPageCommand::redo()
01281 {
01282 m_toolBox->removeItem(m_oldIndex);
01283 m_toolBox->insertItem(m_newIndex, m_widget, m_itemIcon, m_itemText);
01284 }
01285
01286 void MoveToolBoxPageCommand::undo()
01287 {
01288 m_toolBox->removeItem(m_newIndex);
01289 m_toolBox->insertItem(m_oldIndex, m_widget, m_itemIcon, m_itemText);
01290 }
01291
01292
01293 DeleteToolBoxPageCommand::DeleteToolBoxPageCommand(QDesignerFormWindowInterface *formWindow)
01294 : ToolBoxCommand(formWindow)
01295 {
01296 }
01297
01298 DeleteToolBoxPageCommand::~DeleteToolBoxPageCommand()
01299 {
01300 }
01301
01302 void DeleteToolBoxPageCommand::init(QToolBox *toolBox)
01303 {
01304 ToolBoxCommand::init(toolBox);
01305 setText(QApplication::translate("Command", "Delete Page"));
01306 }
01307
01308 void DeleteToolBoxPageCommand::redo()
01309 {
01310 removePage();
01311 cheapUpdate();
01312 }
01313
01314 void DeleteToolBoxPageCommand::undo()
01315 {
01316 addPage();
01317 cheapUpdate();
01318 }
01319
01320
01321 AddToolBoxPageCommand::AddToolBoxPageCommand(QDesignerFormWindowInterface *formWindow)
01322 : ToolBoxCommand(formWindow)
01323 {
01324 }
01325
01326 AddToolBoxPageCommand::~AddToolBoxPageCommand()
01327 {
01328 }
01329
01330 void AddToolBoxPageCommand::init(QToolBox *toolBox)
01331 {
01332 init(toolBox, InsertBefore);
01333 }
01334
01335 void AddToolBoxPageCommand::init(QToolBox *toolBox, InsertionMode mode)
01336 {
01337 m_toolBox = toolBox;
01338
01339 m_index = m_toolBox->currentIndex();
01340 if (mode == InsertAfter)
01341 m_index++;
01342 m_widget = new QDesignerWidget(formWindow(), m_toolBox);
01343 m_itemText = QApplication::translate("Command", "Page");
01344 m_itemIcon = QIcon();
01345 m_widget->setObjectName(QApplication::translate("Command", "page"));
01346 formWindow()->ensureUniqueObjectName(m_widget);
01347
01348 setText(QApplication::translate("Command", "Insert Page"));
01349
01350 QDesignerFormEditorInterface *core = formWindow()->core();
01351 core->metaDataBase()->add(m_widget);
01352 }
01353
01354 void AddToolBoxPageCommand::redo()
01355 {
01356 addPage();
01357 cheapUpdate();
01358 }
01359
01360 void AddToolBoxPageCommand::undo()
01361 {
01362 removePage();
01363 cheapUpdate();
01364 }
01365
01366
01367 TabWidgetCommand::TabWidgetCommand(QDesignerFormWindowInterface *formWindow)
01368 : QDesignerFormWindowCommand(QString(), formWindow)
01369 {
01370 }
01371
01372 TabWidgetCommand::~TabWidgetCommand()
01373 {
01374 }
01375
01376 void TabWidgetCommand::init(QTabWidget *tabWidget)
01377 {
01378 m_tabWidget = tabWidget;
01379 m_index = m_tabWidget->currentIndex();
01380 m_widget = m_tabWidget->widget(m_index);
01381 m_itemText = m_tabWidget->tabText(m_index);
01382 m_itemIcon = m_tabWidget->tabIcon(m_index);
01383 }
01384
01385 void TabWidgetCommand::removePage()
01386 {
01387 m_tabWidget->removeTab(m_index);
01388
01389 m_widget->hide();
01390 m_widget->setParent(formWindow());
01391 m_tabWidget->setCurrentIndex(qMin(m_index, m_tabWidget->count()));
01392 }
01393
01394 void TabWidgetCommand::addPage()
01395 {
01396 m_widget->setParent(0);
01397 m_tabWidget->insertTab(m_index, m_widget, m_itemIcon, m_itemText);
01398 m_widget->show();
01399 m_tabWidget->setCurrentIndex(m_index);
01400 }
01401
01402
01403 DeleteTabPageCommand::DeleteTabPageCommand(QDesignerFormWindowInterface *formWindow)
01404 : TabWidgetCommand(formWindow)
01405 {
01406 }
01407
01408 DeleteTabPageCommand::~DeleteTabPageCommand()
01409 {
01410 }
01411
01412 void DeleteTabPageCommand::init(QTabWidget *tabWidget)
01413 {
01414 TabWidgetCommand::init(tabWidget);
01415 setText(QApplication::translate("Command", "Delete Page"));
01416 }
01417
01418 void DeleteTabPageCommand::redo()
01419 {
01420 removePage();
01421 cheapUpdate();
01422 }
01423
01424 void DeleteTabPageCommand::undo()
01425 {
01426 addPage();
01427 cheapUpdate();
01428 }
01429
01430
01431 AddTabPageCommand::AddTabPageCommand(QDesignerFormWindowInterface *formWindow)
01432 : TabWidgetCommand(formWindow)
01433 {
01434 }
01435
01436 AddTabPageCommand::~AddTabPageCommand()
01437 {
01438 }
01439
01440 void AddTabPageCommand::init(QTabWidget *tabWidget)
01441 {
01442 init(tabWidget, InsertBefore);
01443 }
01444
01445 void AddTabPageCommand::init(QTabWidget *tabWidget, InsertionMode mode)
01446 {
01447 m_tabWidget = tabWidget;
01448
01449 m_index = m_tabWidget->currentIndex();
01450 if (mode == InsertAfter)
01451 m_index++;
01452 m_widget = new QDesignerWidget(formWindow(), m_tabWidget);
01453 m_itemText = QApplication::translate("Command", "Page");
01454 m_itemIcon = QIcon();
01455 m_widget->setObjectName(QApplication::translate("Command", "tab"));
01456 formWindow()->ensureUniqueObjectName(m_widget);
01457
01458 setText(QApplication::translate("Command", "Insert Page"));
01459
01460 QDesignerFormEditorInterface *core = formWindow()->core();
01461 core->metaDataBase()->add(m_widget);
01462 }
01463
01464 void AddTabPageCommand::redo()
01465 {
01466 addPage();
01467 cheapUpdate();
01468 }
01469
01470 void AddTabPageCommand::undo()
01471 {
01472 removePage();
01473 cheapUpdate();
01474 }
01475
01476
01477 MoveTabPageCommand::MoveTabPageCommand(QDesignerFormWindowInterface *formWindow)
01478 : TabWidgetCommand(formWindow)
01479 {
01480 }
01481
01482 MoveTabPageCommand::~MoveTabPageCommand()
01483 {
01484 }
01485
01486 void MoveTabPageCommand::init(QTabWidget *tabWidget, QWidget *page,
01487 const QIcon &icon, const QString &label,
01488 int index, int newIndex)
01489 {
01490 TabWidgetCommand::init(tabWidget);
01491 setText(QApplication::translate("Command", "Move Page"));
01492
01493 m_page = page;
01494 m_newIndex = newIndex;
01495 m_oldIndex = index;
01496 m_label = label;
01497 m_icon = icon;
01498 }
01499
01500 void MoveTabPageCommand::redo()
01501 {
01502 m_tabWidget->removeTab(m_oldIndex);
01503 m_tabWidget->insertTab(m_newIndex, m_page, m_icon, m_label);
01504 m_tabWidget->setCurrentIndex(m_newIndex);
01505 }
01506
01507 void MoveTabPageCommand::undo()
01508 {
01509 m_tabWidget->removeTab(m_newIndex);
01510 m_tabWidget->insertTab(m_oldIndex, m_page, m_icon, m_label);
01511 m_tabWidget->setCurrentIndex(m_oldIndex);
01512 }
01513
01514
01515 StackedWidgetCommand::StackedWidgetCommand(QDesignerFormWindowInterface *formWindow)
01516 : QDesignerFormWindowCommand(QString(), formWindow)
01517 {
01518 }
01519
01520 StackedWidgetCommand::~StackedWidgetCommand()
01521 {
01522 }
01523
01524 void StackedWidgetCommand::init(QStackedWidget *stackedWidget)
01525 {
01526 m_stackedWidget = stackedWidget;
01527 m_index = m_stackedWidget->currentIndex();
01528 m_widget = m_stackedWidget->widget(m_index);
01529 }
01530
01531 void StackedWidgetCommand::removePage()
01532 {
01533 m_stackedWidget->removeWidget(m_stackedWidget->widget(m_index));
01534
01535 m_widget->hide();
01536 m_widget->setParent(formWindow());
01537 }
01538
01539 void StackedWidgetCommand::addPage()
01540 {
01541 m_stackedWidget->insertWidget(m_index, m_widget);
01542
01543 m_widget->show();
01544 m_stackedWidget->setCurrentIndex(m_index);
01545 }
01546
01547
01548 MoveStackedWidgetCommand::MoveStackedWidgetCommand(QDesignerFormWindowInterface *formWindow)
01549 : StackedWidgetCommand(formWindow)
01550 {
01551 }
01552
01553 MoveStackedWidgetCommand::~MoveStackedWidgetCommand()
01554 {
01555 }
01556
01557 void MoveStackedWidgetCommand::init(QStackedWidget *stackedWidget, QWidget *page, int newIndex)
01558 {
01559 StackedWidgetCommand::init(stackedWidget);
01560 setText(QApplication::translate("Command", "Move Page"));
01561
01562 m_widget = page;
01563 m_newIndex = newIndex;
01564 m_oldIndex = m_stackedWidget->indexOf(m_widget);
01565 }
01566
01567 void MoveStackedWidgetCommand::redo()
01568 {
01569 m_stackedWidget->removeWidget(m_widget);
01570 m_stackedWidget->insertWidget(m_newIndex, m_widget);
01571 }
01572
01573 void MoveStackedWidgetCommand::undo()
01574 {
01575 m_stackedWidget->removeWidget(m_widget);
01576 m_stackedWidget->insertWidget(m_oldIndex, m_widget);
01577 }
01578
01579
01580 DeleteStackedWidgetPageCommand::DeleteStackedWidgetPageCommand(QDesignerFormWindowInterface *formWindow)
01581 : StackedWidgetCommand(formWindow)
01582 {
01583 }
01584
01585 DeleteStackedWidgetPageCommand::~DeleteStackedWidgetPageCommand()
01586 {
01587 }
01588
01589 void DeleteStackedWidgetPageCommand::init(QStackedWidget *stackedWidget)
01590 {
01591 StackedWidgetCommand::init(stackedWidget);
01592 setText(QApplication::translate("Command", "Delete Page"));
01593 }
01594
01595 void DeleteStackedWidgetPageCommand::redo()
01596 {
01597 removePage();
01598 cheapUpdate();
01599 }
01600
01601 void DeleteStackedWidgetPageCommand::undo()
01602 {
01603 addPage();
01604 cheapUpdate();
01605 }
01606
01607
01608 AddStackedWidgetPageCommand::AddStackedWidgetPageCommand(QDesignerFormWindowInterface *formWindow)
01609 : StackedWidgetCommand(formWindow)
01610 {
01611 }
01612
01613 AddStackedWidgetPageCommand::~AddStackedWidgetPageCommand()
01614 {
01615 }
01616
01617 void AddStackedWidgetPageCommand::init(QStackedWidget *stackedWidget)
01618 {
01619 init(stackedWidget, InsertBefore);
01620 }
01621
01622 void AddStackedWidgetPageCommand::init(QStackedWidget *stackedWidget, InsertionMode mode)
01623 {
01624 m_stackedWidget = stackedWidget;
01625
01626 m_index = m_stackedWidget->currentIndex();
01627 if (mode == InsertAfter)
01628 m_index++;
01629 m_widget = new QDesignerWidget(formWindow(), m_stackedWidget);
01630 m_widget->setObjectName(QApplication::translate("Command", "page"));
01631 formWindow()->ensureUniqueObjectName(m_widget);
01632
01633 setText(QApplication::translate("Command", "Insert Page"));
01634
01635 QDesignerFormEditorInterface *core = formWindow()->core();
01636 core->metaDataBase()->add(m_widget);
01637 }
01638
01639 void AddStackedWidgetPageCommand::redo()
01640 {
01641 addPage();
01642 cheapUpdate();
01643 }
01644
01645 void AddStackedWidgetPageCommand::undo()
01646 {
01647 removePage();
01648 cheapUpdate();
01649 }
01650
01651
01652 TabOrderCommand::TabOrderCommand(QDesignerFormWindowInterface *formWindow)
01653 : QDesignerFormWindowCommand(QApplication::translate("Command", "Change Tab order"), formWindow),
01654 m_widgetItem(0)
01655 {
01656 }
01657
01658 void TabOrderCommand::init(const QList<QWidget*> &newTabOrder)
01659 {
01660 QDesignerFormEditorInterface *core = formWindow()->core();
01661 Q_ASSERT(core);
01662
01663 m_widgetItem = core->metaDataBase()->item(formWindow());
01664 Q_ASSERT(m_widgetItem);
01665 m_oldTabOrder = m_widgetItem->tabOrder();
01666 m_newTabOrder = newTabOrder;
01667 }
01668
01669 void TabOrderCommand::redo()
01670 {
01671 m_widgetItem->setTabOrder(m_newTabOrder);
01672 }
01673
01674 void TabOrderCommand::undo()
01675 {
01676 m_widgetItem->setTabOrder(m_oldTabOrder);
01677 }
01678
01679
01680 CreateMenuBarCommand::CreateMenuBarCommand(QDesignerFormWindowInterface *formWindow)
01681 : QDesignerFormWindowCommand(QApplication::translate("Command", "Create Menu Bar"), formWindow)
01682 {
01683 }
01684
01685 void CreateMenuBarCommand::init(QMainWindow *mainWindow)
01686 {
01687 m_mainWindow = mainWindow;
01688 QDesignerFormEditorInterface *core = formWindow()->core();
01689 m_menuBar = qobject_cast<QMenuBar*>(core->widgetFactory()->createWidget("QMenuBar", m_mainWindow));
01690 core->widgetFactory()->initialize(m_menuBar);
01691 }
01692
01693 void CreateMenuBarCommand::redo()
01694 {
01695 QDesignerFormEditorInterface *core = formWindow()->core();
01696 QDesignerContainerExtension *c;
01697 c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_mainWindow);
01698 c->addWidget(m_menuBar);
01699
01700 m_menuBar->setObjectName("menuBar");
01701 formWindow()->ensureUniqueObjectName(m_menuBar);
01702 core->metaDataBase()->add(m_menuBar);
01703 formWindow()->emitSelectionChanged();
01704 m_menuBar->setFocus();
01705 }
01706
01707 void CreateMenuBarCommand::undo()
01708 {
01709 QDesignerFormEditorInterface *core = formWindow()->core();
01710 QDesignerContainerExtension *c;
01711 c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_mainWindow);
01712 for (int i = 0; i < c->count(); ++i) {
01713 if (c->widget(i) == m_menuBar) {
01714 c->remove(i);
01715 break;
01716 }
01717 }
01718
01719 core->metaDataBase()->remove(m_menuBar);
01720 formWindow()->emitSelectionChanged();
01721 }
01722
01723
01724 DeleteMenuBarCommand::DeleteMenuBarCommand(QDesignerFormWindowInterface *formWindow)
01725 : QDesignerFormWindowCommand(QApplication::translate("Command", "Delete Menu Bar"), formWindow)
01726 {
01727 }
01728
01729 void DeleteMenuBarCommand::init(QMenuBar *menuBar)
01730 {
01731 m_menuBar = menuBar;
01732 m_mainWindow = qobject_cast<QMainWindow*>(menuBar->parentWidget());
01733 }
01734
01735 void DeleteMenuBarCommand::redo()
01736 {
01737 if (m_mainWindow) {
01738 QDesignerContainerExtension *c;
01739 c = qt_extension<QDesignerContainerExtension*>(core()->extensionManager(), m_mainWindow);
01740 Q_ASSERT(c != 0);
01741 for (int i=0; i<c->count(); ++i) {
01742 if (c->widget(i) == m_menuBar) {
01743 c->remove(i);
01744 break;
01745 }
01746 }
01747 }
01748
01749 core()->metaDataBase()->remove(m_menuBar);
01750 m_menuBar->hide();
01751 m_menuBar->setParent(formWindow());
01752 formWindow()->emitSelectionChanged();
01753 }
01754
01755 void DeleteMenuBarCommand::undo()
01756 {
01757 if (m_mainWindow) {
01758 m_menuBar->setParent(m_mainWindow);
01759 QDesignerContainerExtension *c;
01760 c = qt_extension<QDesignerContainerExtension*>(core()->extensionManager(), m_mainWindow);
01761
01762 c->addWidget(m_menuBar);
01763
01764 core()->metaDataBase()->add(m_menuBar);
01765 m_menuBar->show();
01766 formWindow()->emitSelectionChanged();
01767 }
01768 }
01769
01770
01771 CreateStatusBarCommand::CreateStatusBarCommand(QDesignerFormWindowInterface *formWindow)
01772 : QDesignerFormWindowCommand(QApplication::translate("Command", "Create Status Bar"), formWindow)
01773 {
01774 }
01775
01776 void CreateStatusBarCommand::init(QMainWindow *mainWindow)
01777 {
01778 m_mainWindow = mainWindow;
01779 QDesignerFormEditorInterface *core = formWindow()->core();
01780 m_statusBar = qobject_cast<QStatusBar*>(core->widgetFactory()->createWidget("QStatusBar", m_mainWindow));
01781 core->widgetFactory()->initialize(m_statusBar);
01782 }
01783
01784 void CreateStatusBarCommand::redo()
01785 {
01786 QDesignerFormEditorInterface *core = formWindow()->core();
01787 QDesignerContainerExtension *c;
01788 c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_mainWindow);
01789 c->addWidget(m_statusBar);
01790
01791 m_statusBar->setObjectName("statusBar");
01792 formWindow()->ensureUniqueObjectName(m_statusBar);
01793 core->metaDataBase()->add(m_statusBar);
01794 formWindow()->emitSelectionChanged();
01795 }
01796
01797 void CreateStatusBarCommand::undo()
01798 {
01799 QDesignerFormEditorInterface *core = formWindow()->core();
01800 QDesignerContainerExtension *c;
01801 c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_mainWindow);
01802 for (int i = 0; i < c->count(); ++i) {
01803 if (c->widget(i) == m_statusBar) {
01804 c->remove(i);
01805 break;
01806 }
01807 }
01808
01809 core->metaDataBase()->remove(m_statusBar);
01810 formWindow()->emitSelectionChanged();
01811 }
01812
01813
01814 DeleteStatusBarCommand::DeleteStatusBarCommand(QDesignerFormWindowInterface *formWindow)
01815 : QDesignerFormWindowCommand(QApplication::translate("Command", "Delete Status Bar"), formWindow)
01816 {
01817 }
01818
01819 void DeleteStatusBarCommand::init(QStatusBar *statusBar)
01820 {
01821 m_statusBar = statusBar;
01822 m_mainWindow = qobject_cast<QMainWindow*>(statusBar->parentWidget());
01823 }
01824
01825 void DeleteStatusBarCommand::redo()
01826 {
01827 if (m_mainWindow) {
01828 QDesignerContainerExtension *c;
01829 c = qt_extension<QDesignerContainerExtension*>(core()->extensionManager(), m_mainWindow);
01830 Q_ASSERT(c != 0);
01831 for (int i=0; i<c->count(); ++i) {
01832 if (c->widget(i) == m_statusBar) {
01833 c->remove(i);
01834 break;
01835 }
01836 }
01837 }
01838
01839 core()->metaDataBase()->remove(m_statusBar);
01840 m_statusBar->hide();
01841 m_statusBar->setParent(formWindow());
01842 formWindow()->emitSelectionChanged();
01843 }
01844
01845 void DeleteStatusBarCommand::undo()
01846 {
01847 if (m_mainWindow) {
01848 m_statusBar->setParent(m_mainWindow);
01849 QDesignerContainerExtension *c;
01850 c = qt_extension<QDesignerContainerExtension*>(core()->extensionManager(), m_mainWindow);
01851
01852 c->addWidget(m_statusBar);
01853
01854 core()->metaDataBase()->add(m_statusBar);
01855 m_statusBar->show();
01856 formWindow()->emitSelectionChanged();
01857 }
01858 }
01859
01860
01861 AddToolBarCommand::AddToolBarCommand(QDesignerFormWindowInterface *formWindow)
01862 : QDesignerFormWindowCommand(QApplication::translate("Command", "Add Tool Bar"), formWindow)
01863 {
01864 }
01865
01866 void AddToolBarCommand::init(QMainWindow *mainWindow)
01867 {
01868 m_mainWindow = mainWindow;
01869 QDesignerFormEditorInterface *core = formWindow()->core();
01870 m_toolBar = qobject_cast<QToolBar*>(core->widgetFactory()->createWidget("QToolBar", m_mainWindow));
01871 m_toolBar->hide();
01872 }
01873
01874 void AddToolBarCommand::redo()
01875 {
01876 QDesignerFormEditorInterface *core = formWindow()->core();
01877 core->metaDataBase()->add(m_toolBar);
01878
01879 QDesignerContainerExtension *c;
01880 c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_mainWindow);
01881 c->addWidget(m_toolBar);
01882
01883 m_toolBar->setObjectName("toolBar");
01884 formWindow()->ensureUniqueObjectName(m_toolBar);
01885 formWindow()->emitSelectionChanged();
01886 }
01887
01888 void AddToolBarCommand::undo()
01889 {
01890 QDesignerFormEditorInterface *core = formWindow()->core();
01891 core->metaDataBase()->remove(m_toolBar);
01892 QDesignerContainerExtension *c;
01893 c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_mainWindow);
01894 for (int i = 0; i < c->count(); ++i) {
01895 if (c->widget(i) == m_toolBar) {
01896 c->remove(i);
01897 break;
01898 }
01899 }
01900 formWindow()->emitSelectionChanged();
01901 }
01902
01903
01904 DockWidgetCommand::DockWidgetCommand(const QString &description, QDesignerFormWindowInterface *formWindow)
01905 : QDesignerFormWindowCommand(description, formWindow)
01906 {
01907 }
01908
01909 DockWidgetCommand::~DockWidgetCommand()
01910 {
01911 }
01912
01913 void DockWidgetCommand::init(QDockWidget *dockWidget)
01914 {
01915 m_dockWidget = dockWidget;
01916 }
01917
01918
01919 SetDockWidgetCommand::SetDockWidgetCommand(QDesignerFormWindowInterface *formWindow)
01920 : DockWidgetCommand(QApplication::translate("Command", "Set Dock Window Widget"), formWindow)
01921 {
01922 }
01923
01924 void SetDockWidgetCommand::init(QDockWidget *dockWidget, QWidget *widget)
01925 {
01926 DockWidgetCommand::init(dockWidget);
01927 m_widget = widget;
01928 m_oldWidget = dockWidget->widget();
01929 }
01930
01931 void SetDockWidgetCommand::undo()
01932 {
01933 m_dockWidget->setWidget(m_oldWidget);
01934 }
01935
01936 void SetDockWidgetCommand::redo()
01937 {
01938 formWindow()->unmanageWidget(m_widget);
01939 formWindow()->core()->metaDataBase()->add(m_widget);
01940 m_dockWidget->setWidget(m_widget);
01941 }
01942
01943
01944 AddDockWidgetCommand::AddDockWidgetCommand(QDesignerFormWindowInterface *formWindow)
01945 : QDesignerFormWindowCommand(QApplication::translate("Command", "Add Dock Window"), formWindow)
01946 {
01947 }
01948
01949 void AddDockWidgetCommand::init(QMainWindow *mainWindow, QDockWidget *dockWidget)
01950 {
01951 m_mainWindow = mainWindow;
01952 m_dockWidget = dockWidget;
01953 }
01954
01955 void AddDockWidgetCommand::init(QMainWindow *mainWindow)
01956 {
01957 m_mainWindow = mainWindow;
01958 QDesignerFormEditorInterface *core = formWindow()->core();
01959 m_dockWidget = qobject_cast<QDockWidget*>(core->widgetFactory()->createWidget("QDockWidget", m_mainWindow));
01960 }
01961
01962 void AddDockWidgetCommand::redo()
01963 {
01964 QDesignerFormEditorInterface *core = formWindow()->core();
01965 QDesignerContainerExtension *c;
01966 c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_mainWindow);
01967 c->addWidget(m_dockWidget);
01968
01969 m_dockWidget->setObjectName("dockWidget");
01970 formWindow()->ensureUniqueObjectName(m_dockWidget);
01971 formWindow()->manageWidget(m_dockWidget);
01972 formWindow()->emitSelectionChanged();
01973 }
01974
01975 void AddDockWidgetCommand::undo()
01976 {
01977 QDesignerFormEditorInterface *core = formWindow()->core();
01978 QDesignerContainerExtension *c;
01979 c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_mainWindow);
01980 for (int i = 0; i < c->count(); ++i) {
01981 if (c->widget(i) == m_dockWidget) {
01982 c->remove(i);
01983 break;
01984 }
01985 }
01986
01987 formWindow()->unmanageWidget(m_dockWidget);
01988 formWindow()->emitSelectionChanged();
01989 }
01990
01991
01992 AdjustWidgetSizeCommand::AdjustWidgetSizeCommand(QDesignerFormWindowInterface *formWindow)
01993 : QDesignerFormWindowCommand(QString(), formWindow)
01994 {
01995 }
01996
01997 void AdjustWidgetSizeCommand::init(QWidget *widget)
01998 {
01999 m_widget = widget;
02000 setText(QApplication::translate("Command", "Adjust Size of '%1'").arg(widget->objectName()));
02001 m_geometry = m_widget->geometry();
02002 }
02003
02004 void AdjustWidgetSizeCommand::redo()
02005 {
02006 QWidget *widget = m_widget;
02007 if (Utils::isCentralWidget(formWindow(), widget) && formWindow()->parentWidget())
02008 widget = formWindow()->parentWidget();
02009
02010 m_geometry = widget->geometry();
02011 if (widget != m_widget && widget->parentWidget()) {
02012 QApplication::processEvents();
02013 widget->parentWidget()->adjustSize();
02014 }
02015 QApplication::processEvents();
02016 widget->adjustSize();
02017
02018 if (QDesignerPropertyEditorInterface *propertyEditor = formWindow()->core()->propertyEditor()) {
02019 if (propertyEditor->object() == m_widget)
02020 propertyEditor->setPropertyValue(QLatin1String("geometry"), m_widget->geometry(), true);
02021 }
02022 }
02023
02024 void AdjustWidgetSizeCommand::undo()
02025 {
02026 if (formWindow()->mainContainer() == m_widget && formWindow()->parentWidget()) {
02027 formWindow()->parentWidget()->resize(m_geometry.width(), m_geometry.height());
02028 QWidget *widget = formWindow()->parentWidget();
02029 if (widget->parentWidget()) {
02030 widget->parentWidget()->setGeometry(m_geometry);
02031 }
02032 } else {
02033 m_widget->setGeometry(m_geometry);
02034 }
02035
02036 if (QDesignerPropertyEditorInterface *propertyEditor = formWindow()->core()->propertyEditor()) {
02037 if (propertyEditor->object() == m_widget)
02038 propertyEditor->setPropertyValue(QLatin1String("geometry"), m_widget->geometry(), true);
02039 }
02040 }
02041
02042
02043 ChangeLayoutItemGeometry::ChangeLayoutItemGeometry(QDesignerFormWindowInterface *formWindow)
02044 : QDesignerFormWindowCommand(QApplication::translate("Command", "Change Layout Item Geometry"), formWindow)
02045 {
02046 }
02047
02048 void ChangeLayoutItemGeometry::init(QWidget *widget, int row, int column, int rowspan, int colspan)
02049 {
02050 m_widget = widget;
02051 Q_ASSERT(m_widget->parentWidget() != 0);
02052
02053 QLayout *layout = LayoutInfo::managedLayout(formWindow()->core(), m_widget->parentWidget());
02054 Q_ASSERT(layout != 0);
02055
02056 QGridLayout *grid = qobject_cast<QGridLayout*>(layout);
02057 Q_ASSERT(grid != 0);
02058
02059 int itemIndex = grid->indexOf(m_widget);
02060 Q_ASSERT(itemIndex != -1);
02061
02062 int current_row, current_column, current_rowspan, current_colspan;
02063 grid->getItemPosition(itemIndex, ¤t_row, ¤t_column, ¤t_rowspan, ¤t_colspan);
02064
02065 m_oldInfo.setRect(current_column, current_row, current_colspan, current_rowspan);
02066 m_newInfo.setRect(column, row, colspan, rowspan);
02067 }
02068
02069 void ChangeLayoutItemGeometry::changeItemPosition(const QRect &g)
02070 {
02071 QLayout *layout = LayoutInfo::managedLayout(formWindow()->core(), m_widget->parentWidget());
02072 Q_ASSERT(layout != 0);
02073
02074 QGridLayout *grid = qobject_cast<QGridLayout*>(layout);
02075 Q_ASSERT(grid != 0);
02076
02077 int itemIndex = grid->indexOf(m_widget);
02078 Q_ASSERT(itemIndex != -1);
02079
02080 QLayoutItem *item = grid->takeAt(itemIndex);
02081 delete item;
02082
02083 add_to_grid_layout(grid, m_widget, g.top(), g.left(), g.height(), g.width());
02084
02085 grid->invalidate();
02086 grid->activate();
02087
02088 QLayoutSupport::createEmptyCells(grid);
02089
02090 formWindow()->clearSelection(false);
02091 formWindow()->selectWidget(m_widget, true);
02092 }
02093
02094 void ChangeLayoutItemGeometry::redo()
02095 {
02096 changeItemPosition(m_newInfo);
02097 }
02098
02099 void ChangeLayoutItemGeometry::undo()
02100 {
02101 changeItemPosition(m_oldInfo);
02102 }
02103
02104
02105 InsertRowCommand::InsertRowCommand(QDesignerFormWindowInterface *formWindow)
02106 : QDesignerFormWindowCommand(QApplication::translate("Command", "Insert Row"), formWindow)
02107 {
02108 }
02109
02110 void InsertRowCommand::init(QWidget *widget, int row)
02111 {
02112 m_widget = widget;
02113 m_row = row;
02114 }
02115
02116 void InsertRowCommand::redo()
02117 {
02118 }
02119
02120 void InsertRowCommand::undo()
02121 {
02122 }
02123
02124
02125
02126
02127 ContainerWidgetCommand::ContainerWidgetCommand(QDesignerFormWindowInterface *formWindow)
02128 : QDesignerFormWindowCommand(QString(), formWindow)
02129 {
02130 }
02131
02132 ContainerWidgetCommand::~ContainerWidgetCommand()
02133 {
02134 }
02135
02136 QDesignerContainerExtension *ContainerWidgetCommand::containerExtension() const
02137 {
02138 QExtensionManager *mgr = core()->extensionManager();
02139 return qt_extension<QDesignerContainerExtension*>(mgr, m_containerWidget);
02140 }
02141
02142 void ContainerWidgetCommand::init(QWidget *containerWidget)
02143 {
02144 m_containerWidget = containerWidget;
02145
02146 if (QDesignerContainerExtension *c = containerExtension()) {
02147 m_index = c->currentIndex();
02148 m_widget = c->widget(m_index);
02149 }
02150 }
02151
02152 void ContainerWidgetCommand::removePage()
02153 {
02154 if (QDesignerContainerExtension *c = containerExtension()) {
02155 c->remove(m_index);
02156
02157 m_widget->hide();
02158 m_widget->setParent(formWindow());
02159 }
02160 }
02161
02162 void ContainerWidgetCommand::addPage()
02163 {
02164 if (QDesignerContainerExtension *c = containerExtension()) {
02165 c->insertWidget(m_index, m_widget);
02166
02167 m_widget->show();
02168 c->setCurrentIndex(m_index);
02169 }
02170 }
02171
02172
02173 DeleteContainerWidgetPageCommand::DeleteContainerWidgetPageCommand(QDesignerFormWindowInterface *formWindow)
02174 : ContainerWidgetCommand(formWindow)
02175 {
02176 }
02177
02178 DeleteContainerWidgetPageCommand::~DeleteContainerWidgetPageCommand()
02179 {
02180 }
02181
02182 void DeleteContainerWidgetPageCommand::init(QWidget *containerWidget)
02183 {
02184 ContainerWidgetCommand::init(containerWidget);
02185 setText(QApplication::translate("Command", "Delete Page"));
02186 }
02187
02188 void DeleteContainerWidgetPageCommand::redo()
02189 {
02190 removePage();
02191 cheapUpdate();
02192 }
02193
02194 void DeleteContainerWidgetPageCommand::undo()
02195 {
02196 addPage();
02197 cheapUpdate();
02198 }
02199
02200
02201 AddContainerWidgetPageCommand::AddContainerWidgetPageCommand(QDesignerFormWindowInterface *formWindow)
02202 : ContainerWidgetCommand(formWindow)
02203 {
02204 }
02205
02206 AddContainerWidgetPageCommand::~AddContainerWidgetPageCommand()
02207 {
02208 }
02209
02210 void AddContainerWidgetPageCommand::init(QWidget *containerWidget)
02211 {
02212 init(containerWidget, InsertBefore);
02213 }
02214
02215 void AddContainerWidgetPageCommand::init(QWidget *containerWidget, InsertionMode mode)
02216 {
02217 m_containerWidget = containerWidget;
02218
02219 if (QDesignerContainerExtension *c = containerExtension()) {
02220 m_index = c->currentIndex();
02221 if (mode == InsertAfter)
02222 m_index++;
02223 m_widget = new QDesignerWidget(formWindow(), m_containerWidget);
02224 m_widget->setObjectName(QApplication::translate("Command", "page"));
02225 formWindow()->ensureUniqueObjectName(m_widget);
02226
02227 setText(QApplication::translate("Command", "Insert Page"));
02228
02229 QDesignerFormEditorInterface *core = formWindow()->core();
02230 core->metaDataBase()->add(m_widget);
02231 }
02232 }
02233
02234 void AddContainerWidgetPageCommand::redo()
02235 {
02236 addPage();
02237 cheapUpdate();
02238 }
02239
02240 void AddContainerWidgetPageCommand::undo()
02241 {
02242 removePage();
02243 cheapUpdate();
02244 }
02245
02246
02247 ChangeTableContentsCommand::ChangeTableContentsCommand(QDesignerFormWindowInterface *formWindow)
02248 : QDesignerFormWindowCommand(QApplication::translate("Command", "Change Table Contents"), formWindow),
02249 m_oldColumnCount(0),
02250 m_newColumnCount(0),
02251 m_oldRowCount(0),
02252 m_newRowCount(0)
02253 {
02254
02255 }
02256
02257 void ChangeTableContentsCommand::init(QTableWidget *tableWidget, QTableWidget *fromTableWidget)
02258 {
02259 m_tableWidget = tableWidget;
02260
02261 m_oldItemsState.clear();
02262 m_newItemsState.clear();
02263 m_oldHorizontalHeaderState.clear();
02264 m_newHorizontalHeaderState.clear();
02265 m_oldVerticalHeaderState.clear();
02266 m_newVerticalHeaderState.clear();
02267
02268 m_oldColumnCount = tableWidget->columnCount();
02269 m_oldRowCount = tableWidget->rowCount();
02270 m_newColumnCount = fromTableWidget->columnCount();
02271 m_newRowCount = fromTableWidget->rowCount();
02272
02273 for (int col = 0; col < m_oldColumnCount; col++) {
02274 QTableWidgetItem *item = tableWidget->horizontalHeaderItem(col);
02275 if (item) {
02276 QString text = item->text();
02277 QIcon icon = item->icon();
02278 if (!text.isEmpty() || !icon.isNull()) {
02279 m_oldHorizontalHeaderState[col] =
02280 qMakePair<QString, QIcon>(text, icon);
02281 }
02282 }
02283 }
02284
02285 for (int row = 0; row < m_oldRowCount; row++) {
02286 QTableWidgetItem *item = tableWidget->verticalHeaderItem(row);
02287 if (item) {
02288 QString text = item->text();
02289 QIcon icon = item->icon();
02290 if (!text.isEmpty() || !icon.isNull()) {
02291 m_oldVerticalHeaderState[row] =
02292 qMakePair<QString, QIcon>(text, icon);
02293 }
02294 }
02295 }
02296
02297 for (int col = 0; col < m_oldColumnCount; col++) {
02298 for (int row = 0; row < m_oldRowCount; row++) {
02299 QTableWidgetItem *item = tableWidget->item(row, col);
02300 if (item) {
02301 QString text = item->text();
02302 QIcon icon = item->icon();
02303 if (!text.isEmpty() || !icon.isNull()) {
02304 m_oldItemsState[qMakePair<int, int>(row, col)] =
02305 qMakePair<QString, QIcon>(text, icon);
02306 }
02307 }
02308 }
02309 }
02310
02311
02312 for (int col = 0; col < m_newColumnCount; col++) {
02313 QTableWidgetItem *item = fromTableWidget->horizontalHeaderItem(col);
02314 if (item) {
02315 QString text = item->text();
02316 QIcon icon = item->icon();
02317 if (!text.isEmpty() || !icon.isNull()) {
02318 m_newHorizontalHeaderState[col] =
02319 qMakePair<QString, QIcon>(text, icon);
02320 }
02321 }
02322 }
02323
02324 for (int row = 0; row < m_newRowCount; row++) {
02325 QTableWidgetItem *item = fromTableWidget->verticalHeaderItem(row);
02326 if (item) {
02327 QString text = item->text();
02328 QIcon icon = item->icon();
02329 if (!text.isEmpty() || !icon.isNull()) {
02330 m_newVerticalHeaderState[row] =
02331 qMakePair<QString, QIcon>(text, icon);
02332 }
02333 }
02334 }
02335
02336 for (int col = 0; col < m_newColumnCount; col++) {
02337 for (int row = 0; row < m_newRowCount; row++) {
02338 QTableWidgetItem *item = fromTableWidget->item(row, col);
02339 if (item) {
02340 QString text = item->text();
02341 QIcon icon = item->icon();
02342 if (!text.isEmpty() || !icon.isNull()) {
02343 m_newItemsState[qMakePair<int, int>(row, col)] =
02344 qMakePair<QString, QIcon>(text, icon);
02345 }
02346 }
02347 }
02348 }
02349 }
02350
02351 void ChangeTableContentsCommand::changeContents(QTableWidget *tableWidget,
02352 int rowCount, int columnCount,
02353 const QMap<int, QPair<QString, QIcon> > &horizontalHeaderState,
02354 const QMap<int, QPair<QString, QIcon> > &verticalHeaderState,
02355 const QMap<QPair<int, int>, QPair<QString, QIcon> > &itemsState) const
02356 {
02357 tableWidget->clear();
02358
02359 tableWidget->setColumnCount(columnCount);
02360 QMap<int, QPair<QString, QIcon> >::ConstIterator itColumn =
02361 horizontalHeaderState.constBegin();
02362 while (itColumn != horizontalHeaderState.constEnd()) {
02363 int column = itColumn.key();
02364 QString text = itColumn.value().first;
02365 QIcon icon = itColumn.value().second;
02366 QTableWidgetItem *item = new QTableWidgetItem;
02367 item->setText(text);
02368 item->setIcon(icon);
02369 tableWidget->setHorizontalHeaderItem(column, item);
02370
02371 itColumn++;
02372 }
02373
02374 tableWidget->setRowCount(rowCount);
02375 QMap<int, QPair<QString, QIcon> >::ConstIterator itRow =
02376 verticalHeaderState.constBegin();
02377 while (itRow != verticalHeaderState.constEnd()) {
02378 int row = itRow.key();
02379 QString text = itRow.value().first;
02380 QIcon icon = itRow.value().second;
02381 QTableWidgetItem *item = new QTableWidgetItem;
02382 item->setText(text);
02383 item->setIcon(icon);
02384 tableWidget->setVerticalHeaderItem(row, item);
02385
02386 itRow++;
02387 }
02388
02389 QMap<QPair<int, int>, QPair<QString, QIcon> >::ConstIterator itItem =
02390 itemsState.constBegin();
02391 while (itItem != itemsState.constEnd()) {
02392 int row = itItem.key().first;
02393 int column = itItem.key().second;
02394 QString text = itItem.value().first;
02395 QIcon icon = itItem.value().second;
02396 QTableWidgetItem *item = new QTableWidgetItem;
02397 item->setText(text);
02398 item->setIcon(icon);
02399 tableWidget->setItem(row, column, item);
02400
02401 itItem++;
02402 }
02403 }
02404
02405 void ChangeTableContentsCommand::redo()
02406 {
02407 changeContents(m_tableWidget, m_newRowCount, m_newColumnCount,
02408 m_newHorizontalHeaderState, m_newVerticalHeaderState, m_newItemsState);
02409 }
02410
02411 void ChangeTableContentsCommand::undo()
02412 {
02413 changeContents(m_tableWidget, m_oldRowCount, m_oldColumnCount,
02414 m_oldHorizontalHeaderState, m_oldVerticalHeaderState, m_oldItemsState);
02415 }
02416
02417
02418 ChangeTreeContentsCommand::ChangeTreeContentsCommand(QDesignerFormWindowInterface *formWindow)
02419 : QDesignerFormWindowCommand(QApplication::translate("Command", "Change Tree Contents"), formWindow),
02420 m_oldHeaderItemState(0),
02421 m_newHeaderItemState(0),
02422 m_oldColumnCount(0),
02423 m_newColumnCount(0)
02424 {
02425
02426 }
02427
02428 ChangeTreeContentsCommand::~ChangeTreeContentsCommand()
02429 {
02430 clearState(m_oldItemsState, m_oldHeaderItemState);
02431 clearState(m_newItemsState, m_newHeaderItemState);
02432 }
02433
02434 void ChangeTreeContentsCommand::init(QTreeWidget *treeWidget, QTreeWidget *fromTreeWidget)
02435 {
02436 m_treeWidget = treeWidget;
02437 m_oldColumnCount = treeWidget->columnCount();
02438 m_newColumnCount = fromTreeWidget->columnCount();
02439
02440 initState(m_oldItemsState, m_oldHeaderItemState, treeWidget);
02441 initState(m_newItemsState, m_newHeaderItemState, fromTreeWidget);
02442 }
02443
02444 void ChangeTreeContentsCommand::redo()
02445 {
02446 changeContents(m_treeWidget, m_newColumnCount, m_newItemsState, m_newHeaderItemState);
02447 }
02448
02449 void ChangeTreeContentsCommand::undo()
02450 {
02451 changeContents(m_treeWidget, m_oldColumnCount, m_oldItemsState, m_oldHeaderItemState);
02452 }
02453
02454 void ChangeTreeContentsCommand::initState(QList<QTreeWidgetItem *> &itemsState,
02455 QTreeWidgetItem *&headerItemState, QTreeWidget *fromTreeWidget) const
02456 {
02457 clearState(itemsState, headerItemState);
02458
02459 for (int i = 0; i < fromTreeWidget->topLevelItemCount(); i++)
02460 itemsState.append(fromTreeWidget->topLevelItem(i)->clone());
02461
02462 headerItemState = fromTreeWidget->headerItem()->clone();
02463 }
02464
02465 void ChangeTreeContentsCommand::changeContents(QTreeWidget *treeWidget, int columnCount,
02466 const QList<QTreeWidgetItem *> &itemsState, const QTreeWidgetItem *headerItemState) const
02467 {
02468 treeWidget->clear();
02469 treeWidget->setColumnCount(columnCount);
02470
02471 treeWidget->setHeaderItem(headerItemState->clone());
02472
02473 if (!columnCount)
02474 return;
02475
02476 foreach (QTreeWidgetItem *item, itemsState)
02477 treeWidget->addTopLevelItem(item->clone());
02478 }
02479
02480 void ChangeTreeContentsCommand::clearState(QList<QTreeWidgetItem *> &itemsState,
02481 QTreeWidgetItem *&headerItemState) const
02482 {
02483 QListIterator<QTreeWidgetItem *> it(itemsState);
02484 while (it.hasNext())
02485 delete it.next();
02486 itemsState.clear();
02487 if (headerItemState)
02488 delete headerItemState;
02489 headerItemState = 0;
02490 }
02491
02492
02493 ChangeListContentsCommand::ChangeListContentsCommand(QDesignerFormWindowInterface *formWindow)
02494 : QDesignerFormWindowCommand(QString(), formWindow)
02495 {
02496
02497 }
02498
02499 void ChangeListContentsCommand::init(QListWidget *listWidget,
02500 const QList<QPair<QString, QIcon> > &items)
02501 {
02502 m_listWidget = listWidget;
02503 m_comboBox = 0;
02504
02505 m_newItemsState = items;
02506 m_oldItemsState.clear();
02507
02508 for (int i = 0; i < listWidget->count(); i++) {
02509 QListWidgetItem *item = listWidget->item(i);
02510 QString text = item->text();
02511 QIcon icon = item->icon();
02512
02513 m_oldItemsState.append(qMakePair<QString, QIcon>(text, icon));
02514 }
02515 }
02516
02517 void ChangeListContentsCommand::init(QComboBox *comboBox,
02518 const QList<QPair<QString, QIcon> > &items)
02519 {
02520 m_listWidget = 0;
02521 m_comboBox = comboBox;
02522
02523 m_newItemsState = items;
02524 m_oldItemsState.clear();
02525
02526 for (int i = 0; i < comboBox->count(); i++) {
02527 QString text = comboBox->itemText(i);
02528 QIcon icon = comboBox->itemIcon(i);
02529
02530 m_oldItemsState.append(qMakePair<QString, QIcon>(text, icon));
02531 }
02532 }
02533
02534 void ChangeListContentsCommand::redo()
02535 {
02536 if (m_listWidget)
02537 changeContents(m_listWidget, m_newItemsState);
02538 else if (m_comboBox)
02539 changeContents(m_comboBox, m_newItemsState);
02540 }
02541
02542 void ChangeListContentsCommand::undo()
02543 {
02544 if (m_listWidget)
02545 changeContents(m_listWidget, m_oldItemsState);
02546 else if (m_comboBox)
02547 changeContents(m_comboBox, m_oldItemsState);
02548 }
02549
02550 void ChangeListContentsCommand::changeContents(QListWidget *listWidget,
02551 const QList<QPair<QString, QIcon> > &itemsState) const
02552 {
02553 listWidget->clear();
02554 QListIterator<QPair<QString, QIcon> > it(itemsState);
02555 while (it.hasNext()) {
02556 QPair<QString, QIcon> pair = it.next();
02557 QListWidgetItem *item = new QListWidgetItem(pair.second, pair.first);
02558 listWidget->addItem(item);
02559 }
02560 }
02561
02562 void ChangeListContentsCommand::changeContents(QComboBox *comboBox,
02563 const QList<QPair<QString, QIcon> > &itemsState) const
02564 {
02565 comboBox->clear();
02566 QListIterator<QPair<QString, QIcon> > it(itemsState);
02567 while (it.hasNext()) {
02568 QPair<QString, QIcon> pair = it.next();
02569 comboBox->addItem(pair.second, pair.first);
02570 comboBox->setItemData(comboBox->count() - 1, pair.second);
02571 }
02572 }
02573
02574
02575
02576 AddActionCommand::AddActionCommand(QDesignerFormWindowInterface *formWindow)
02577 : QDesignerFormWindowCommand(QLatin1String("Add action"), formWindow)
02578 {
02579 m_action = 0;
02580 }
02581
02582 void AddActionCommand::init(QAction *action)
02583 {
02584 Q_ASSERT(m_action == 0);
02585 m_action = action;
02586 }
02587
02588 void AddActionCommand::redo()
02589 {
02590 core()->actionEditor()->setFormWindow(formWindow());
02591 core()->actionEditor()->manageAction(m_action);
02592 }
02593
02594 void AddActionCommand::undo()
02595 {
02596 core()->actionEditor()->setFormWindow(formWindow());
02597 core()->actionEditor()->unmanageAction(m_action);
02598 }
02599
02600
02601
02602 RemoveActionCommand::RemoveActionCommand(QDesignerFormWindowInterface *formWindow)
02603 : QDesignerFormWindowCommand(QLatin1String("Remove action"), formWindow)
02604 {
02605 m_action = 0;
02606 }
02607
02608 template <typename T>
02609 static RemoveActionCommand::ActionData findActionIn(QDesignerFormWindowInterface *formWindow,
02610 QAction *action)
02611 {
02612 RemoveActionCommand::ActionData result;
02613
02614 QList<T*> widgetList = qFindChildren<T*>(formWindow->mainContainer());
02615 foreach (QWidget *widget, widgetList) {
02616 QList<QAction*> actionList = widget->actions();
02617 for (int i = 0; i < actionList.size(); ++i) {
02618 if (actionList.at(i) == action) {
02619 QAction *before = 0;
02620 if (i + 1 < actionList.size())
02621 before = actionList.at(i + 1);
02622 result.append(RemoveActionCommand::ActionDataItem(before, widget));
02623 break;
02624 }
02625 }
02626 }
02627
02628 return result;
02629 }
02630
02631 void RemoveActionCommand::init(QAction *action)
02632 {
02633 Q_ASSERT(m_action == 0);
02634 m_action = action;
02635
02636 m_actionData = findActionIn<QMenu>(formWindow(), action);
02637 m_actionData += findActionIn<QToolBar>(formWindow(), action);
02638 }
02639
02640 void RemoveActionCommand::redo()
02641 {
02642 foreach (const ActionDataItem &item, m_actionData) {
02643 item.widget->removeAction(m_action);
02644 }
02645 core()->actionEditor()->setFormWindow(formWindow());
02646 core()->