qdesigner_command.cpp
来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 2,136 行 · 第 1/5 页
CPP
2,136 行
QWidgetList newList = qVariantValue<QWidgetList>(m_newParentWidget->property("_q_widgetOrder")); newList.removeAll(m_widget); qVariantSetValue(v, newList); m_newParentWidget->setProperty("_q_widgetOrder", v); m_widget->show();}PromoteToCustomWidgetCommand::PromoteToCustomWidgetCommand (QDesignerFormWindowInterface *formWindow) : QDesignerFormWindowCommand(QApplication::translate("Command", "Promote to custom widget"), formWindow){}void PromoteToCustomWidgetCommand::init(const WidgetList &widgets,const QString &customClassName){ m_widgets = widgets; m_customClassName = customClassName;}void PromoteToCustomWidgetCommand::redo(){ foreach (QWidget *w, m_widgets) { if (w) promoteWidget(core(), w, m_customClassName); } updateSelection();}void PromoteToCustomWidgetCommand::updateSelection() { // force update of properties, class name, etc. formWindow()->clearSelection(); foreach (QWidget *w, m_widgets) { if (w) formWindow()->selectWidget(w); }}void PromoteToCustomWidgetCommand::undo(){ foreach (QWidget *w, m_widgets) { if (w) demoteWidget(core(), w); } updateSelection();}// ---- DemoteFromCustomWidgetCommand ----DemoteFromCustomWidgetCommand::DemoteFromCustomWidgetCommand (QDesignerFormWindowInterface *formWindow) : QDesignerFormWindowCommand(QApplication::translate("Command", "Demote from custom widget"), formWindow), m_promote_cmd(formWindow){}void DemoteFromCustomWidgetCommand::init(const WidgetList &promoted){ m_promote_cmd.init(promoted, promotedCustomClassName(core(), promoted.front()));}void DemoteFromCustomWidgetCommand::redo(){ m_promote_cmd.undo();}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); const QPoint grid = formWindow()->grid(); const 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();}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(); }}// ---- 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; const QPoint grid = formWindow()->grid(); const 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(); QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), LayoutInfo::internalLayout(m_layoutBase)); if (sheet) { m_leftMargin = sheet->property(sheet->indexOf("leftMargin")).toInt(); m_topMargin = sheet->property(sheet->indexOf("topMargin")).toInt(); m_rightMargin = sheet->property(sheet->indexOf("rightMargin")).toInt(); m_bottomMargin = sheet->property(sheet->indexOf("bottomMargin")).toInt(); m_spacing = sheet->property(sheet->indexOf("spacing")).toInt(); m_horizSpacing = sheet->property(sheet->indexOf("horizontalSpacing")).toInt(); m_vertSpacing = sheet->property(sheet->indexOf("verticalSpacing")).toInt(); m_leftMarginChanged = sheet->isChanged(sheet->indexOf(QLatin1String("leftMargin"))); m_topMarginChanged = sheet->isChanged(sheet->indexOf(QLatin1String("topMargin"))); m_rightMarginChanged = sheet->isChanged(sheet->indexOf(QLatin1String("rightMargin"))); m_bottomMarginChanged = sheet->isChanged(sheet->indexOf(QLatin1String("bottomMargin"))); m_spacingChanged = sheet->isChanged(sheet->indexOf(QLatin1String("spacing"))); m_horizSpacingChanged = sheet->isChanged(sheet->indexOf(QLatin1String("horizontalSpacing"))); m_vertSpacingChanged = sheet->isChanged(sheet->indexOf(QLatin1String("verticalSpacing"))); }}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()) { QDesignerFormEditorInterface *core = formWindow()->core(); QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), LayoutInfo::internalLayout(m_layoutBase)); if (sheet) { sheet->setProperty(sheet->indexOf("leftMargin"), m_leftMargin); sheet->setChanged(sheet->indexOf("leftMargin"), m_leftMarginChanged); sheet->setProperty(sheet->indexOf("topMargin"), m_topMargin); sheet->setChanged(sheet->indexOf("topMargin"), m_topMarginChanged); sheet->setProperty(sheet->indexOf("rightMargin"), m_rightMargin); sheet->setChanged(sheet->indexOf("rightMargin"), m_rightMarginChanged); sheet->setProperty(sheet->indexOf("bottomMargin"), m_bottomMargin); sheet->setChanged(sheet->indexOf("bottomMargin"), m_bottomMarginChanged); sheet->setProperty(sheet->indexOf("spacing"), m_spacing); sheet->setChanged(sheet->indexOf("spacing"), m_spacingChanged); sheet->setProperty(sheet->indexOf("horizontalSpacing"), m_horizSpacing); sheet->setChanged(sheet->indexOf("horizontalSpacing"), m_horizSpacingChanged); sheet->setProperty(sheet->indexOf("verticalSpacing"), m_vertSpacing); sheet->setChanged(sheet->indexOf("verticalSpacing"), m_vertSpacingChanged); } }}// ---- 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){ ToolBoxCommand::init(toolBox); setText(QApplication::translate("Command", "Delete Page"));}void DeleteToolBoxPageCommand::redo(){ removePage(); cheapUpdate();}void DeleteToolBoxPageCommand::undo(){ addPage(); cheapUpdate();}// ---- AddToolBoxPageCommand ----AddToolBoxPageCommand::AddToolBoxPageCommand(QDesignerFormWindowInterface *formWindow) : ToolBoxCommand(formWindow){}AddToolBoxPageCommand::~AddToolBoxPageCommand(){}void AddToolBoxPageCommand::init(QToolBox *toolBox){ init(toolBox, InsertBefore);}void AddToolBoxPageCommand::init(QToolBox *toolBox, InsertionMode mode){ m_toolBox = toolBox; m_index = m_toolBox->currentIndex(); if (mode == InsertAfter) m_index++; m_widget = new QDesignerWidget(formWindow(), m_toolBox); m_itemText = QApplication::translate("Command", "Page"); m_itemIcon = QIcon(); m_widget->setObjectName(QApplication::translate("Command", "page")); formWindow()->ensureUniqueObjectName(m_widget); setText(QApplication::translate("Command", "Insert Page")); QDesignerFormEditorInterface *core = formWindow()->core(); core->metaDataBase()->add(m_widget);}void AddToolBoxPageCommand::redo(){ addPage(); cheapUpdate();}void AddToolBoxPageCommand::undo(){ removePage(); cheapUpdate();}// ---- TabWidgetCommand ----TabWidgetCommand::TabWidgetCommand(QDesignerFormWindowInterface *formWindow) : QDesignerFormWindowCommand(QString(), formWindow){}TabWidgetCommand::~TabWidgetCommand(){}void TabWidgetCommand::init(QTabWidget *tabWidget){ m_tabWidget = tabWidget; m_index = m_tabWidget->currentIndex(); m_widget = m_tabWidget->widget(m_index); m_itemText = m_tabWidget->tabText(m_index); m_itemIcon = m_tabWidget->tabIcon(m_index);}void TabWidgetCommand::removePage(){ m_tabWidget->removeTab(m_index); m_widget->hide(); m_widget->setParent(formWindow()); m_tabWidget->setCurrentIndex(qMin(m_index, m_tabWidget->count()));}void TabWidgetCommand::addPage(){ m_widget->setParent(0); m_tabWidget->insertTab(m_index, m_widget, m_itemIcon, m_itemText); m_widget->show(); m_tabWidget->setCurrentIndex(m_index);}// ---- DeleteTabPageCommand ----DeleteTabPageCommand::DeleteTabPageCommand(QDesignerFormWindowInterface *formWindow) : TabWidgetCommand(formWindow)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?