📄 qdesigner_command.cpp
字号:
m_widget->setGeometry(m_geometry); formWindow()->manageWidget(m_widget); // Manage the managed children foreach (QWidget *child, m_managedChildren) formWindow()->manageWidget(child); // ### set up alignment switch (m_layoutType) { case LayoutInfo::VBox: { QVBoxLayout *vbox = static_cast<QVBoxLayout*>(m_parentWidget->layout()); insert_into_box_layout(vbox, m_index, m_widget); } break; case LayoutInfo::HBox: { QHBoxLayout *hbox = static_cast<QHBoxLayout*>(m_parentWidget->layout()); insert_into_box_layout(hbox, m_index, m_widget); } break; case LayoutInfo::Grid: { QGridLayout *grid = static_cast<QGridLayout*>(m_parentWidget->layout()); add_to_grid_layout(grid, m_widget, m_row, m_col, m_rowspan, m_colspan); } break; default: break; } // end switch m_widget->show(); if (m_tabOrderIndex != -1) { QList<QWidget*> tab_order = m_formItem->tabOrder(); tab_order.insert(m_tabOrderIndex, m_widget); m_formItem->setTabOrder(tab_order); } formWindow()->emitSelectionChanged();}// ---- ReparentWidgetCommand ----ReparentWidgetCommand::ReparentWidgetCommand(QDesignerFormWindowInterface *formWindow) : QDesignerFormWindowCommand(QString(), formWindow){}void ReparentWidgetCommand::init(QWidget *widget, QWidget *parentWidget){ Q_ASSERT(widget); m_widget = widget; m_oldParentWidget = widget->parentWidget(); m_newParentWidget = parentWidget; m_oldPos = m_widget->pos(); m_newPos = m_newParentWidget->mapFromGlobal(m_oldParentWidget->mapToGlobal(m_oldPos)); setText(QApplication::translate("Command", "Reparent '%1'").arg(widget->objectName()));}void ReparentWidgetCommand::redo(){ m_widget->setParent(m_newParentWidget); m_widget->move(m_newPos); m_widget->show();}void ReparentWidgetCommand::undo(){ m_widget->setParent(m_oldParentWidget); m_widget->move(m_oldPos); m_widget->show();}// ---- PromoteToCustomWidgetCommand ----static void replace_widget_item(QDesignerFormWindowInterface *fw, QWidget *wgt, QWidget *promoted){ QDesignerFormEditorInterface *core = fw->core(); QWidget *parent = wgt->parentWidget(); promoted->setMinimumSize(wgt->minimumSize()); promoted->setMaximumSize(wgt->maximumSize()); QRect info; int splitter_idx = -1; if (QDesignerLayoutDecorationExtension *deco = qt_extension<QDesignerLayoutDecorationExtension*>(core->extensionManager(), parent)) { if (QSplitter *splitter = qobject_cast<QSplitter*>(parent)) { splitter_idx = splitter->indexOf(wgt); Q_ASSERT(splitter_idx != -1); wgt->setParent(0); } else { QLayout *layout = LayoutInfo::managedLayout(core, parent); Q_ASSERT(layout != 0); int old_index = layout->indexOf(wgt); Q_ASSERT(old_index != -1); info = deco->itemInfo(old_index); QLayoutItem *item = layout->takeAt(old_index); delete item; layout->activate(); } } if (qt_extension<QDesignerLayoutDecorationExtension*>(core->extensionManager(), parent)) { if (QSplitter *splitter = qobject_cast<QSplitter*>(parent)) { splitter->insertWidget(splitter_idx, promoted); } else { QLayout *layout = LayoutInfo::managedLayout(core, parent); Q_ASSERT(layout != 0); // ### check if `info' is valid! switch (LayoutInfo::layoutType(core, layout)) { default: Q_ASSERT(0); break; case LayoutInfo::VBox: insert_into_box_layout(static_cast<QBoxLayout*>(layout), info.top(), promoted); break; case LayoutInfo::HBox: insert_into_box_layout(static_cast<QBoxLayout*>(layout), info.left(), promoted); break; case LayoutInfo::Grid: add_to_grid_layout(static_cast<QGridLayout*>(layout), promoted, info.top(), info.left(), info.height(), info.width()); break; } } }}PromoteToCustomWidgetCommand::PromoteToCustomWidgetCommand (QDesignerFormWindowInterface *formWindow) : QDesignerFormWindowCommand(QApplication::translate("Command", "Promote to custom widget"), formWindow){ m_widget = 0; m_promoted = 0;}void PromoteToCustomWidgetCommand::init(QDesignerWidgetDataBaseItemInterface *item, QWidget *widget){ m_widget = widget; m_promoted = new QDesignerPromotedWidget(item, widget->parentWidget());}void PromoteToCustomWidgetCommand::redo(){ m_promoted->setObjectName(QLatin1String("__qt__promoted_") + m_widget->objectName()); m_promoted->setGeometry(m_widget->geometry()); replace_widget_item(formWindow(), m_widget, m_promoted); m_promoted->setChildWidget(m_widget); formWindow()->manageWidget(m_promoted); formWindow()->clearSelection(); formWindow()->selectWidget(m_promoted); m_promoted->show();}void PromoteToCustomWidgetCommand::undo(){ m_promoted->setChildWidget(0); m_widget->setParent(m_promoted->parentWidget()); m_widget->setGeometry(m_promoted->geometry()); replace_widget_item(formWindow(), m_promoted, m_widget); formWindow()->manageWidget(m_widget); formWindow()->unmanageWidget(m_promoted); m_promoted->hide(); m_widget->show(); formWindow()->clearSelection(); formWindow()->selectWidget(m_promoted);}// ---- DemoteFromCustomWidgetCommand ----DemoteFromCustomWidgetCommand::DemoteFromCustomWidgetCommand (QDesignerFormWindowInterface *formWindow) : QDesignerFormWindowCommand(QApplication::translate("Command", "Demote from custom widget"), formWindow){ m_promote_cmd = new PromoteToCustomWidgetCommand(formWindow);}void DemoteFromCustomWidgetCommand::init(QDesignerPromotedWidget *promoted){ m_promote_cmd->m_widget = promoted->child(); m_promote_cmd->m_promoted = promoted;}void DemoteFromCustomWidgetCommand::redo(){ m_promote_cmd->undo(); m_promote_cmd->m_widget->show();}void DemoteFromCustomWidgetCommand::undo(){ m_promote_cmd->redo();}// ---- LayoutCommand ----LayoutCommand::LayoutCommand(QDesignerFormWindowInterface *formWindow) : QDesignerFormWindowCommand(QString(), formWindow){}LayoutCommand::~LayoutCommand(){ m_layout->deleteLater();}void LayoutCommand::init(QWidget *parentWidget, const QList<QWidget*> &widgets, LayoutInfo::Type layoutType, QWidget *layoutBase, bool splitter){ m_parentWidget = parentWidget; m_widgets = widgets; formWindow()->simplifySelection(&m_widgets); QPoint grid = formWindow()->grid(); QSize sz(qMax(5, grid.x()), qMax(5, grid.y())); switch (layoutType) { case LayoutInfo::Grid: m_layout = new GridLayout(widgets, m_parentWidget, formWindow(), layoutBase, sz); setText(QApplication::translate("Command", "Lay out using grid")); break; case LayoutInfo::VBox: m_layout = new VerticalLayout(widgets, m_parentWidget, formWindow(), layoutBase, splitter); setText(QApplication::translate("Command", "Lay out vertically")); break; case LayoutInfo::HBox: m_layout = new HorizontalLayout(widgets, m_parentWidget, formWindow(), layoutBase, splitter); setText(QApplication::translate("Command", "Lay out horizontally")); break; default: Q_ASSERT(0); } m_layout->setup();}void LayoutCommand::redo(){ m_layout->doLayout(); checkSelection(m_parentWidget);}void LayoutCommand::undo(){ QDesignerFormEditorInterface *core = formWindow()->core(); QWidget *lb = m_layout->layoutBaseWidget(); QDesignerLayoutDecorationExtension *deco = qt_extension<QDesignerLayoutDecorationExtension*>(core->extensionManager(), lb); QWidget *p = m_layout->parentWidget(); if (!deco && hasLayout(p)) { deco = qt_extension<QDesignerLayoutDecorationExtension*>(core->extensionManager(), p); } m_layout->undoLayout(); delete deco; // release the extension // ### generalize (put in function) if (!m_layoutBase && lb != 0 && !(qobject_cast<QLayoutWidget*>(lb) || qobject_cast<QSplitter*>(lb))) { core->metaDataBase()->add(lb); lb->show(); } checkSelection(m_parentWidget);}// ---- BreakLayoutCommand ----BreakLayoutCommand::BreakLayoutCommand(QDesignerFormWindowInterface *formWindow) : QDesignerFormWindowCommand(QApplication::translate("Command", "Break layout"), formWindow){}BreakLayoutCommand::~BreakLayoutCommand(){}void BreakLayoutCommand::init(const QList<QWidget*> &widgets, QWidget *layoutBase){ QDesignerFormEditorInterface *core = formWindow()->core(); m_widgets = widgets; m_layoutBase = core->widgetFactory()->containerOfWidget(layoutBase); m_layout = 0; QPoint grid = formWindow()->grid(); LayoutInfo::Type lay = LayoutInfo::layoutType(core, m_layoutBase); if (lay == LayoutInfo::HBox) m_layout = new HorizontalLayout(widgets, m_layoutBase, formWindow(), m_layoutBase, qobject_cast<QSplitter*>(m_layoutBase) != 0); else if (lay == LayoutInfo::VBox) m_layout = new VerticalLayout(widgets, m_layoutBase, formWindow(), m_layoutBase, qobject_cast<QSplitter*>(m_layoutBase) != 0); else if (lay == LayoutInfo::Grid) m_layout = new GridLayout(widgets, m_layoutBase, formWindow(), m_layoutBase, QSize(qMax(5, grid.x()), qMax(5, grid.y()))); // ### StackedLayout Q_ASSERT(m_layout != 0); m_layout->sort(); m_margin = m_layout->margin(); m_spacing = m_layout->spacing();}void BreakLayoutCommand::redo(){ if (!m_layout) return; QDesignerFormEditorInterface *core = formWindow()->core(); QWidget *lb = m_layout->layoutBaseWidget(); QDesignerLayoutDecorationExtension *deco = qt_extension<QDesignerLayoutDecorationExtension*>(core->extensionManager(), lb); QWidget *p = m_layout->parentWidget(); if (!deco && hasLayout(p)) deco = qt_extension<QDesignerLayoutDecorationExtension*>(core->extensionManager(), p); formWindow()->clearSelection(false); m_layout->breakLayout(); delete deco; // release the extension foreach (QWidget *widget, m_widgets) { widget->resize(widget->size().expandedTo(QSize(16, 16))); }}void BreakLayoutCommand::undo(){ if (!m_layout) return; formWindow()->clearSelection(false); m_layout->doLayout(); if (m_layoutBase && m_layoutBase->layout()) { m_layoutBase->layout()->setSpacing(m_spacing); m_layoutBase->layout()->setMargin(m_margin); }}// ---- ToolBoxCommand ----ToolBoxCommand::ToolBoxCommand(QDesignerFormWindowInterface *formWindow) : QDesignerFormWindowCommand(QString(), formWindow){}ToolBoxCommand::~ToolBoxCommand(){}void ToolBoxCommand::init(QToolBox *toolBox){ m_toolBox = toolBox; m_index = m_toolBox->currentIndex(); m_widget = m_toolBox->widget(m_index); m_itemText = m_toolBox->itemText(m_index); m_itemIcon = m_toolBox->itemIcon(m_index);}void ToolBoxCommand::removePage(){ m_toolBox->removeItem(m_index); m_widget->hide(); m_widget->setParent(formWindow());}void ToolBoxCommand::addPage(){ m_widget->setParent(m_toolBox); m_toolBox->insertItem(m_index, m_widget, m_itemIcon, m_itemText); m_toolBox->setCurrentIndex(m_index); m_widget->show();}// ---- MoveToolBoxPageCommand ----MoveToolBoxPageCommand::MoveToolBoxPageCommand(QDesignerFormWindowInterface *formWindow) : ToolBoxCommand(formWindow){}MoveToolBoxPageCommand::~MoveToolBoxPageCommand(){}void MoveToolBoxPageCommand::init(QToolBox *toolBox, QWidget *page, int newIndex){ ToolBoxCommand::init(toolBox); setText(QApplication::translate("Command", "Move Page")); m_widget = page; m_oldIndex = m_toolBox->indexOf(m_widget); m_itemText = m_toolBox->itemText(m_oldIndex); m_itemIcon = m_toolBox->itemIcon(m_oldIndex); m_newIndex = newIndex;}void MoveToolBoxPageCommand::redo(){ m_toolBox->removeItem(m_oldIndex); m_toolBox->insertItem(m_newIndex, m_widget, m_itemIcon, m_itemText);}void MoveToolBoxPageCommand::undo(){ m_toolBox->removeItem(m_newIndex); m_toolBox->insertItem(m_oldIndex, m_widget, m_itemIcon, m_itemText);}// ---- DeleteToolBoxPageCommand ----DeleteToolBoxPageCommand::DeleteToolBoxPageCommand(QDesignerFormWindowInterface *formWindow) : ToolBoxCommand(formWindow){}DeleteToolBoxPageCommand::~DeleteToolBoxPageCommand(){}void DeleteToolBoxPageCommand::init(QToolBox *toolBox)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -