void QStackedWidgetEventFilter::changeOrder() { QDesignerFormWindowInterface *fw = QDesignerFormWindowInterface::findFormWindow(stackedWidget()); if (!fw) return; const QWidgetList oldPages = qdesigner_internal::OrderDialog::pagesOfContainer(fw->core(), stackedWidget()); const int pageCount = oldPages.size(); if (pageCount < 2) return; qdesigner_internal::OrderDialog dlg(fw); dlg.setPageList(oldPages); if (dlg.exec() == QDialog::Rejected) return; const QWidgetList newPages = dlg.pageList(); if (newPages == oldPages) return; fw->beginCommand(tr("Change Page Order")); for(int i=0; i < pageCount; ++i) { if (newPages.at(i) == stackedWidget()->widget(i)) continue; qdesigner_internal::MoveStackedWidgetCommand *cmd = new qdesigner_internal::MoveStackedWidgetCommand(fw); cmd->init(stackedWidget(), newPages.at(i), i); fw->commandHistory()->push(cmd); } fw->endCommand(); }
void ActionEditor::editAction(QAction *action) { if (!action) return; NewActionDialog dlg(this); dlg.setWindowTitle(tr("Edit action")); ActionData oldActionData; QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension*>(core()->extensionManager(), action); oldActionData.name = action->objectName(); oldActionData.text = action->text(); oldActionData.toolTip = textPropertyValue(sheet, QLatin1String(toolTipPropertyC)); oldActionData.icon = qvariant_cast<PropertySheetIconValue>(sheet->property(sheet->indexOf(QLatin1String(iconPropertyC)))); oldActionData.keysequence = ActionModel::actionShortCut(sheet); oldActionData.checkable = action->isCheckable(); dlg.setActionData(oldActionData); if (!dlg.exec()) return; // figure out changes and whether to start a macro const ActionData newActionData = dlg.actionData(); const unsigned changeMask = newActionData.compare(oldActionData); if (changeMask == 0u) return; const bool severalChanges = (changeMask != ActionData::TextChanged) && (changeMask != ActionData::NameChanged) && (changeMask != ActionData::ToolTipChanged) && (changeMask != ActionData::IconChanged) && (changeMask != ActionData::CheckableChanged) && (changeMask != ActionData::KeysequenceChanged); QDesignerFormWindowInterface *fw = formWindow(); QUndoStack *undoStack = fw->commandHistory(); if (severalChanges) fw->beginCommand(QStringLiteral("Edit action")); if (changeMask & ActionData::NameChanged) undoStack->push(createTextPropertyCommand(QLatin1String(objectNamePropertyC), newActionData.name, action, fw)); if (changeMask & ActionData::TextChanged) undoStack->push(createTextPropertyCommand(QLatin1String(textPropertyC), newActionData.text, action, fw)); if (changeMask & ActionData::ToolTipChanged) undoStack->push(createTextPropertyCommand(QLatin1String(toolTipPropertyC), newActionData.toolTip, action, fw)); if (changeMask & ActionData::IconChanged) undoStack->push(setIconPropertyCommand(newActionData.icon, action, fw)); if (changeMask & ActionData::CheckableChanged) undoStack->push(setPropertyCommand(QLatin1String(checkablePropertyC), newActionData.checkable, false, action, fw)); if (changeMask & ActionData::KeysequenceChanged) undoStack->push(setKeySequencePropertyCommand(newActionData.keysequence, action, fw)); if (severalChanges) fw->endCommand(); }
void ToolBarEventFilter::slotInsertSeparator() { QDesignerFormWindowInterface *fw = formWindow(); QAction *theSender = qobject_cast<QAction*>(sender()); QAction *previous = qvariant_cast<QAction *>(theSender->data()); fw->beginCommand(tr("Insert Separator")); QAction *action = createAction(fw, QLatin1String("separator"), true); InsertActionIntoCommand *cmd = new InsertActionIntoCommand(fw); cmd->init(m_toolBar, action, previous); fw->commandHistory()->push(cmd); fw->endCommand(); }
bool QDesignerMenuBar::swapActions(int a, int b) { const int left = qMin(a, b); int right = qMax(a, b); QAction *action_a = safeActionAt(left); QAction *action_b = safeActionAt(right); if (action_a == action_b || !action_a || !action_b || qobject_cast<SpecialMenuAction*>(action_a) || qobject_cast<SpecialMenuAction*>(action_b)) return false; // nothing to do right = qMin(right, realActionCount()); if (right < 0) return false; // nothing to do formWindow()->beginCommand(QApplication::translate("Command", "Move action")); QAction *action_b_before = safeActionAt(right + 1); QDesignerFormWindowInterface *fw = formWindow(); RemoveActionFromCommand *cmd1 = new RemoveActionFromCommand(fw); cmd1->init(this, action_b, action_b_before, false); fw->commandHistory()->push(cmd1); QAction *action_a_before = safeActionAt(left + 1); InsertActionIntoCommand *cmd2 = new InsertActionIntoCommand(fw); cmd2->init(this, action_b, action_a_before, false); fw->commandHistory()->push(cmd2); RemoveActionFromCommand *cmd3 = new RemoveActionFromCommand(fw); cmd3->init(this, action_a, action_b, false); fw->commandHistory()->push(cmd3); InsertActionIntoCommand *cmd4 = new InsertActionIntoCommand(fw); cmd4->init(this, action_a, action_b_before, true); fw->commandHistory()->push(cmd4); fw->endCommand(); return true; }
void QDesignerMenuBar::leaveEditMode(LeaveEditMode mode) { m_editor->releaseKeyboard(); if (mode == Default) return; if (m_editor->text().isEmpty()) return; QAction *action = 0; QDesignerFormWindowInterface *fw = formWindow(); Q_ASSERT(fw); if (m_currentIndex >= 0 && m_currentIndex < realActionCount()) { action = safeActionAt(m_currentIndex); fw->beginCommand(QApplication::translate("Command", "Change Title")); } else { fw->beginCommand(QApplication::translate("Command", "Insert Menu")); const QString niceObjectName = ActionEditor::actionTextToName(m_editor->text(), QStringLiteral("menu")); QMenu *menu = qobject_cast<QMenu*>(fw->core()->widgetFactory()->createWidget(QStringLiteral("QMenu"), this)); fw->core()->widgetFactory()->initialize(menu); menu->setObjectName(niceObjectName); menu->setTitle(tr("Menu")); fw->ensureUniqueObjectName(menu); action = menu->menuAction(); AddMenuActionCommand *cmd = new AddMenuActionCommand(fw); cmd->init(action, m_addMenu, this, this); fw->commandHistory()->push(cmd); } SetPropertyCommand *cmd = new SetPropertyCommand(fw); cmd->init(action, QStringLiteral("text"), m_editor->text()); fw->commandHistory()->push(cmd); fw->endCommand(); }