⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qdesigner_command.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
void DeleteStackedWidgetPageCommand::redo(){    removePage();    cheapUpdate();}void DeleteStackedWidgetPageCommand::undo(){    addPage();    cheapUpdate();}// ---- AddStackedWidgetPageCommand ----AddStackedWidgetPageCommand::AddStackedWidgetPageCommand(QDesignerFormWindowInterface *formWindow)    : StackedWidgetCommand(formWindow){}AddStackedWidgetPageCommand::~AddStackedWidgetPageCommand(){}void AddStackedWidgetPageCommand::init(QStackedWidget *stackedWidget){    init(stackedWidget, InsertBefore);}void AddStackedWidgetPageCommand::init(QStackedWidget *stackedWidget, InsertionMode mode){    m_stackedWidget = stackedWidget;    m_index = m_stackedWidget->currentIndex();    if (mode == InsertAfter)        m_index++;    m_widget = new QDesignerWidget(formWindow(), m_stackedWidget);    m_widget->setObjectName(tr("page"));    formWindow()->ensureUniqueObjectName(m_widget);    setDescription(tr("Insert Page"));    QDesignerFormEditorInterface *core = formWindow()->core();    core->metaDataBase()->add(m_widget);}void AddStackedWidgetPageCommand::redo(){    addPage();    cheapUpdate();}void AddStackedWidgetPageCommand::undo(){    removePage();    cheapUpdate();}// ---- TabOrderCommand ----TabOrderCommand::TabOrderCommand(QDesignerFormWindowInterface *formWindow)    : QDesignerFormWindowCommand(tr("Change Tab order"), formWindow),      m_widgetItem(0){}void TabOrderCommand::init(const QList<QWidget*> &newTabOrder){    QDesignerFormEditorInterface *core = formWindow()->core();    Q_ASSERT(core);    m_widgetItem = core->metaDataBase()->item(formWindow());    Q_ASSERT(m_widgetItem);    m_oldTabOrder = m_widgetItem->tabOrder();    m_newTabOrder = newTabOrder;}void TabOrderCommand::redo(){    m_widgetItem->setTabOrder(m_newTabOrder);}void TabOrderCommand::undo(){    m_widgetItem->setTabOrder(m_oldTabOrder);}// ---- CreateMenuBarCommand ----CreateMenuBarCommand::CreateMenuBarCommand(QDesignerFormWindowInterface *formWindow)    : QDesignerFormWindowCommand(tr("Create Menu Bar"), formWindow){}void CreateMenuBarCommand::init(QMainWindow *mainWindow){    m_mainWindow = mainWindow;    QDesignerFormEditorInterface *core = formWindow()->core();    m_menuBar = qobject_cast<QMenuBar*>(core->widgetFactory()->createWidget("QMenuBar", m_mainWindow));    core->widgetFactory()->initialize(m_menuBar);}void CreateMenuBarCommand::redo(){    QDesignerFormEditorInterface *core = formWindow()->core();    QDesignerContainerExtension *c;    c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_mainWindow);    c->addWidget(m_menuBar);    m_menuBar->setObjectName("menuBar");    formWindow()->ensureUniqueObjectName(m_menuBar);    core->metaDataBase()->add(m_menuBar);    formWindow()->emitSelectionChanged();    m_menuBar->setFocus();}void CreateMenuBarCommand::undo(){    QDesignerFormEditorInterface *core = formWindow()->core();    QDesignerContainerExtension *c;    c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_mainWindow);    for (int i = 0; i < c->count(); ++i) {        if (c->widget(i) == m_menuBar) {            c->remove(i);            break;        }    }    core->metaDataBase()->remove(m_menuBar);    formWindow()->emitSelectionChanged();}// ---- DeleteMenuBarCommand ----DeleteMenuBarCommand::DeleteMenuBarCommand(QDesignerFormWindowInterface *formWindow)    : QDesignerFormWindowCommand(tr("Delete Menu Bar"), formWindow){}void DeleteMenuBarCommand::init(QMenuBar *menuBar){    m_menuBar = menuBar;    m_mainWindow = qobject_cast<QMainWindow*>(menuBar->parentWidget());}void DeleteMenuBarCommand::redo(){    if (m_mainWindow) {        QDesignerContainerExtension *c;        c = qt_extension<QDesignerContainerExtension*>(core()->extensionManager(), m_mainWindow);        Q_ASSERT(c != 0);        for (int i=0; i<c->count(); ++i) {            if (c->widget(i) == m_menuBar) {                c->remove(i);                break;            }        }    }    core()->metaDataBase()->remove(m_menuBar);    m_menuBar->hide();    m_menuBar->setParent(formWindow());    formWindow()->emitSelectionChanged();}void DeleteMenuBarCommand::undo(){    if (m_mainWindow) {        m_menuBar->setParent(m_mainWindow);        QDesignerContainerExtension *c;        c = qt_extension<QDesignerContainerExtension*>(core()->extensionManager(), m_mainWindow);        c->addWidget(m_menuBar);        core()->metaDataBase()->add(m_menuBar);        m_menuBar->show();        formWindow()->emitSelectionChanged();    }}// ---- CreateStatusBarCommand ----CreateStatusBarCommand::CreateStatusBarCommand(QDesignerFormWindowInterface *formWindow)    : QDesignerFormWindowCommand(tr("Create Status Bar"), formWindow){}void CreateStatusBarCommand::init(QMainWindow *mainWindow){    m_mainWindow = mainWindow;    QDesignerFormEditorInterface *core = formWindow()->core();    m_statusBar = qobject_cast<QStatusBar*>(core->widgetFactory()->createWidget("QStatusBar", m_mainWindow));}void CreateStatusBarCommand::redo(){    QDesignerFormEditorInterface *core = formWindow()->core();    QDesignerContainerExtension *c;    c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_mainWindow);    c->addWidget(m_statusBar);    m_statusBar->setObjectName("statusBar");    formWindow()->ensureUniqueObjectName(m_statusBar);    formWindow()->manageWidget(m_statusBar);    formWindow()->emitSelectionChanged();}void CreateStatusBarCommand::undo(){    QDesignerFormEditorInterface *core = formWindow()->core();    QDesignerContainerExtension *c;    c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_mainWindow);    for (int i = 0; i < c->count(); ++i) {        if (c->widget(i) == m_statusBar) {            c->remove(i);            break;        }    }    formWindow()->unmanageWidget(m_statusBar);    formWindow()->emitSelectionChanged();}// ---- AddToolBarCommand ----AddToolBarCommand::AddToolBarCommand(QDesignerFormWindowInterface *formWindow)    : QDesignerFormWindowCommand(tr("Add Tool Bar"), formWindow){}void AddToolBarCommand::init(QMainWindow *mainWindow){    m_mainWindow = mainWindow;    QDesignerFormEditorInterface *core = formWindow()->core();    m_toolBar = qobject_cast<QToolBar*>(core->widgetFactory()->createWidget("QToolBar", m_mainWindow));    m_toolBar->hide();}void AddToolBarCommand::redo(){    QDesignerFormEditorInterface *core = formWindow()->core();    core->metaDataBase()->add(m_toolBar);    QDesignerContainerExtension *c;    c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_mainWindow);    c->addWidget(m_toolBar);    m_toolBar->setObjectName("toolBar");    formWindow()->ensureUniqueObjectName(m_toolBar);    formWindow()->emitSelectionChanged();}void AddToolBarCommand::undo(){    QDesignerFormEditorInterface *core = formWindow()->core();    core->metaDataBase()->remove(m_toolBar);    QDesignerContainerExtension *c;    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(tr("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(tr("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("QDockWidget", m_mainWindow));}void AddDockWidgetCommand::redo(){    QDesignerFormEditorInterface *core = formWindow()->core();    QDesignerContainerExtension *c;    c = qt_extension<QDesignerContainerExtension*>(core->extensionManager(), m_mainWindow);    c->addWidget(m_dockWidget);    m_dockWidget->setObjectName("dockWidget");    formWindow()->ensureUniqueObjectName(m_dockWidget);    formWindow()->manageWidget(m_dockWidget);    formWindow()->emitSelectionChanged();}void AddDockWidgetCommand::undo(){    QDesignerFormEditorInterface *core = formWindow()->core();    QDesignerContainerExtension *c;    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;    setDescription(tr("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();    QApplication::processEvents();    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());    } 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(tr("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);    int itemIndex = grid->indexOf(m_widget);    Q_ASSERT(itemIndex != -1);    int current_row, current_column, current_rowspan, current_colspan;    grid->getItemPosition(itemIndex, &current_row, &current_column, &current_rowspan, &current_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);    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);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -