qdesigner_command.cpp
来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 2,136 行 · 第 1/5 页
CPP
2,136 行
} } } core()->metaDataBase()->remove(m_statusBar); m_statusBar->hide(); m_statusBar->setParent(formWindow()); formWindow()->emitSelectionChanged();}void DeleteStatusBarCommand::undo(){ if (m_mainWindow) { m_statusBar->setParent(m_mainWindow); QDesignerContainerExtension *c = qt_extension<QDesignerContainerExtension*>(core()->extensionManager(), m_mainWindow); c->addWidget(m_statusBar); core()->metaDataBase()->add(m_statusBar); m_statusBar->show(); formWindow()->emitSelectionChanged(); }}// ---- AddToolBarCommand ----AddToolBarCommand::AddToolBarCommand(QDesignerFormWindowInterface *formWindow) : QDesignerFormWindowCommand(QApplication::translate("Command", "Add Tool Bar"), formWindow){}void AddToolBarCommand::init(QMainWindow *mainWindow){ m_mainWindow = mainWindow; QDesignerFormEditorInterface *core = formWindow()->core(); m_toolBar = qobject_cast<QToolBar*>(core->widgetFactory()->createWidget(QLatin1String("QToolBar"), m_mainWindow)); m_toolBar->hide();}void AddToolBarCommand::redo(){ QDesignerFormEditorInterface *core = formWindow()->core(); core->metaDataBase()->add(m_toolBar); QDesignerContainerExtension *c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_mainWindow); c->addWidget(m_toolBar); m_toolBar->setObjectName(QLatin1String("toolBar")); formWindow()->ensureUniqueObjectName(m_toolBar); QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core->extensionManager(), m_toolBar); if (sheet) { int idx = sheet->indexOf(QLatin1String("windowTitle")); if (idx != -1) { sheet->setProperty(idx, m_toolBar->objectName()); sheet->setChanged(idx, true); } } formWindow()->emitSelectionChanged();}void AddToolBarCommand::undo(){ QDesignerFormEditorInterface *core = formWindow()->core(); core->metaDataBase()->remove(m_toolBar); QDesignerContainerExtension *c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_mainWindow); for (int i = 0; i < c->count(); ++i) { if (c->widget(i) == m_toolBar) { c->remove(i); break; } } formWindow()->emitSelectionChanged();}// ---- DockWidgetCommand:: ----DockWidgetCommand::DockWidgetCommand(const QString &description, QDesignerFormWindowInterface *formWindow) : QDesignerFormWindowCommand(description, formWindow){}DockWidgetCommand::~DockWidgetCommand(){}void DockWidgetCommand::init(QDockWidget *dockWidget){ m_dockWidget = dockWidget;}// ---- SetDockWidgetCommand ----SetDockWidgetCommand::SetDockWidgetCommand(QDesignerFormWindowInterface *formWindow) : DockWidgetCommand(QApplication::translate("Command", "Set Dock Window Widget"), formWindow){}void SetDockWidgetCommand::init(QDockWidget *dockWidget, QWidget *widget){ DockWidgetCommand::init(dockWidget); m_widget = widget; m_oldWidget = dockWidget->widget();}void SetDockWidgetCommand::undo(){ m_dockWidget->setWidget(m_oldWidget);}void SetDockWidgetCommand::redo(){ formWindow()->unmanageWidget(m_widget); formWindow()->core()->metaDataBase()->add(m_widget); m_dockWidget->setWidget(m_widget);}// ---- AddDockWidgetCommand ----AddDockWidgetCommand::AddDockWidgetCommand(QDesignerFormWindowInterface *formWindow) : QDesignerFormWindowCommand(QApplication::translate("Command", "Add Dock Window"), formWindow){}void AddDockWidgetCommand::init(QMainWindow *mainWindow, QDockWidget *dockWidget){ m_mainWindow = mainWindow; m_dockWidget = dockWidget;}void AddDockWidgetCommand::init(QMainWindow *mainWindow){ m_mainWindow = mainWindow; QDesignerFormEditorInterface *core = formWindow()->core(); m_dockWidget = qobject_cast<QDockWidget*>(core->widgetFactory()->createWidget(QLatin1String("QDockWidget"), m_mainWindow));}void AddDockWidgetCommand::redo(){ QDesignerFormEditorInterface *core = formWindow()->core(); QDesignerContainerExtension *c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_mainWindow); c->addWidget(m_dockWidget); m_dockWidget->setObjectName(QLatin1String("dockWidget")); formWindow()->ensureUniqueObjectName(m_dockWidget); formWindow()->manageWidget(m_dockWidget); formWindow()->emitSelectionChanged();}void AddDockWidgetCommand::undo(){ QDesignerFormEditorInterface *core = formWindow()->core(); QDesignerContainerExtension *c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_mainWindow); for (int i = 0; i < c->count(); ++i) { if (c->widget(i) == m_dockWidget) { c->remove(i); break; } } formWindow()->unmanageWidget(m_dockWidget); formWindow()->emitSelectionChanged();}// ---- AdjustWidgetSizeCommand ----AdjustWidgetSizeCommand::AdjustWidgetSizeCommand(QDesignerFormWindowInterface *formWindow) : QDesignerFormWindowCommand(QString(), formWindow){}void AdjustWidgetSizeCommand::init(QWidget *widget){ m_widget = widget; setText(QApplication::translate("Command", "Adjust Size of '%1'").arg(widget->objectName())); m_geometry = m_widget->geometry();}void AdjustWidgetSizeCommand::redo(){ QWidget *widget = m_widget; if (Utils::isCentralWidget(formWindow(), widget) && formWindow()->parentWidget()) widget = formWindow()->parentWidget(); m_geometry = widget->geometry(); if (widget != m_widget && widget->parentWidget()) { QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); widget->parentWidget()->adjustSize(); } QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); widget->adjustSize(); if (QDesignerPropertyEditorInterface *propertyEditor = formWindow()->core()->propertyEditor()) { if (propertyEditor->object() == m_widget) propertyEditor->setPropertyValue(QLatin1String("geometry"), m_widget->geometry(), true); }}void AdjustWidgetSizeCommand::undo(){ if (formWindow()->mainContainer() == m_widget && formWindow()->parentWidget()) { formWindow()->parentWidget()->resize(m_geometry.width(), m_geometry.height()); QWidget *widget = formWindow()->parentWidget(); if (widget->parentWidget()) { widget->parentWidget()->setGeometry(m_geometry); } } else { m_widget->setGeometry(m_geometry); } if (QDesignerPropertyEditorInterface *propertyEditor = formWindow()->core()->propertyEditor()) { if (propertyEditor->object() == m_widget) propertyEditor->setPropertyValue(QLatin1String("geometry"), m_widget->geometry(), true); }}// ---- ChangeLayoutItemGeometry ----ChangeLayoutItemGeometry::ChangeLayoutItemGeometry(QDesignerFormWindowInterface *formWindow) : QDesignerFormWindowCommand(QApplication::translate("Command", "Change Layout Item Geometry"), formWindow){}void ChangeLayoutItemGeometry::init(QWidget *widget, int row, int column, int rowspan, int colspan){ m_widget = widget; Q_ASSERT(m_widget->parentWidget() != 0); QLayout *layout = LayoutInfo::managedLayout(formWindow()->core(), m_widget->parentWidget()); Q_ASSERT(layout != 0); QGridLayout *grid = qobject_cast<QGridLayout*>(layout); Q_ASSERT(grid != 0); const int itemIndex = grid->indexOf(m_widget); Q_ASSERT(itemIndex != -1); int current_row, current_column, current_rowspan, current_colspan; grid->getItemPosition(itemIndex, ¤t_row, ¤t_column, ¤t_rowspan, ¤t_colspan); m_oldInfo.setRect(current_column, current_row, current_colspan, current_rowspan); m_newInfo.setRect(column, row, colspan, rowspan);}void ChangeLayoutItemGeometry::changeItemPosition(const QRect &g){ QLayout *layout = LayoutInfo::managedLayout(formWindow()->core(), m_widget->parentWidget()); Q_ASSERT(layout != 0); QGridLayout *grid = qobject_cast<QGridLayout*>(layout); Q_ASSERT(grid != 0); const int itemIndex = grid->indexOf(m_widget); Q_ASSERT(itemIndex != -1); QLayoutItem *item = grid->takeAt(itemIndex); delete item; add_to_grid_layout(grid, m_widget, g.top(), g.left(), g.height(), g.width()); grid->invalidate(); grid->activate(); QLayoutSupport::createEmptyCells(grid); formWindow()->clearSelection(false); formWindow()->selectWidget(m_widget, true);}void ChangeLayoutItemGeometry::redo(){ changeItemPosition(m_newInfo);}void ChangeLayoutItemGeometry::undo(){ changeItemPosition(m_oldInfo);}// ---- InsertRowCommand ----InsertRowCommand::InsertRowCommand(QDesignerFormWindowInterface *formWindow) : QDesignerFormWindowCommand(QApplication::translate("Command", "Insert Row"), formWindow){}void InsertRowCommand::init(QWidget *widget, int row){ m_widget = widget; m_row = row;}void InsertRowCommand::redo(){}void InsertRowCommand::undo(){}// ---- ContainerWidgetCommand ----ContainerWidgetCommand::ContainerWidgetCommand(QDesignerFormWindowInterface *formWindow) : QDesignerFormWindowCommand(QString(), formWindow){}ContainerWidgetCommand::~ContainerWidgetCommand(){}QDesignerContainerExtension *ContainerWidgetCommand::containerExtension() const{ QExtensionManager *mgr = core()->extensionManager(); return qt_extension<QDesignerContainerExtension*>(mgr, m_containerWidget);}void ContainerWidgetCommand::init(QWidget *containerWidget){ m_containerWidget = containerWidget; if (QDesignerContainerExtension *c = containerExtension()) { m_index = c->currentIndex(); m_widget = c->widget(m_index); }}void ContainerWidgetCommand::removePage(){ if (QDesignerContainerExtension *c = containerExtension()) { c->remove(m_index); m_widget->hide(); m_widget->setParent(formWindow()); }}void ContainerWidgetCommand::addPage(){ if (QDesignerContainerExtension *c = containerExtension()) { c->insertWidget(m_index, m_widget); m_widget->show(); c->setCurrentIndex(m_index); }}// ---- DeleteContainerWidgetPageCommand ----DeleteContainerWidgetPageCommand::DeleteContainerWidgetPageCommand(QDesignerFormWindowInterface *formWindow) : ContainerWidgetCommand(formWindow){}DeleteContainerWidgetPageCommand::~DeleteContainerWidgetPageCommand(){}void DeleteContainerWidgetPageCommand::init(QWidget *containerWidget){ ContainerWidgetCommand::init(containerWidget); setText(QApplication::translate("Command", "Delete Page"));}void DeleteContainerWidgetPageCommand::redo(){ removePage(); cheapUpdate();}void DeleteContainerWidgetPageCommand::undo(){ addPage(); cheapUpdate();}// ---- AddContainerWidgetPageCommand ----AddContainerWidgetPageCommand::AddContainerWidgetPageCommand(QDesignerFormWindowInterface *formWindow) : ContainerWidgetCommand(formWindow){}AddContainerWidgetPageCommand::~AddContainerWidgetPageCommand(){}void AddContainerWidgetPageCommand::init(QWidget *containerWidget){ init(containerWidget, InsertBefore);}void AddContainerWidgetPageCommand::init(QWidget *containerWidget, InsertionMode mode){ m_containerWidget = containerWidget; if (QDesignerContainerExtension *c = containerExtension()) { m_index = c->currentIndex(); if (mode == InsertAfter) m_index++; m_widget = new QDesignerWidget(formWindow(), m_containerWidget); 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 AddContainerWidgetPageCommand::redo(){ addPage(); cheapUpdate();}void AddContainerWidgetPageCommand::undo(){ removePage(); cheapUpdate();}// ---- ChangeTableContentsCommand ----ChangeTableContentsCommand::ChangeTableContentsCommand(QDesignerFormWindowInterface *formWindow) : QDesignerFormWindowCommand(QApplication::translate("Command", "Change Table Contents"), formWindow), m_oldColumnCount(0), m_newColumnCount(0), m_oldRowCount(0), m_newRowCount(0){}static void insertHeaderItem(const QString &text, const QIcon &icon, int i, QMap<int, QPair<QString, QIcon> > *headerMap){ if (icon.isNull()) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?