14#include <widgetdatabase_p.h>
15#include <iconloader_p.h>
16#include <connectionedit_p.h>
17#include <qtresourcemodel_p.h>
18#include <qdesigner_dnditem_p.h>
19#include <qdesigner_command_p.h>
20#include <qdesigner_command2_p.h>
21#include <layoutinfo_p.h>
22#include <qlayout_widget_p.h>
23#include <qdesigner_objectinspector_p.h>
24#include <actioneditor_p.h>
25#include <shared_settings_p.h>
26#include <previewmanager_p.h>
27#include <abstractdialoggui_p.h>
28#include <widgetfactory_p.h>
29#include <spacer_widget_p.h>
32#include <QtDesigner/qextensionmanager.h>
33#include <QtDesigner/abstractlanguage.h>
34#include <QtDesigner/container.h>
35#include <QtDesigner/abstractwidgetbox.h>
36#include <QtDesigner/abstractintegration.h>
38#include <QtWidgets/qapplication.h>
39#include <QtWidgets/qsizegrip.h>
40#include <QtWidgets/qmdiarea.h>
41#include <QtWidgets/qmdisubwindow.h>
42#include <QtWidgets/qmessagebox.h>
43#include <QtWidgets/qsplitter.h>
45#include <QtGui/qaction.h>
46#if QT_CONFIG(clipboard)
47# include <QtGui/qclipboard.h>
49#include <QtGui/qevent.h>
50#include <QtGui/qundogroup.h>
52#include <QtCore/qdebug.h>
56using namespace Qt::StringLiterals;
59 enum { debugFWM = 0 };
67template <
class Iterator>
70 for (;it != end; ++it) {
71 if (w->isAncestorOf(*it))
80 QDesignerFormWindowManager(parent),
82 m_activeFormWindow(
nullptr),
83 m_previewManager(
new PreviewManager(PreviewManager::SingleFormNonModalPreview,
this)),
84 m_createLayoutContext(LayoutContainer),
85 m_morphLayoutContainer(
nullptr),
86 m_actionGroupPreviewInStyle(
nullptr),
87 m_actionShowFormWindowSettingsDialog(
nullptr)
90 qApp->installEventFilter(
this);
95 qDeleteAll(m_formWindows);
105 return m_activeFormWindow;
110 return m_formWindows.size();
115 return m_formWindows.at(index);
120 if (!o->isWidgetType())
124 const QEvent::Type eventType = e->type();
125 if (m_activeFormWindow ==
nullptr && eventType != QEvent::WindowActivate)
130 case QEvent::Destroy:
131 case QEvent::ActionAdded:
132 case QEvent::ActionChanged:
133 case QEvent::ActionRemoved:
134 case QEvent::ChildAdded:
135 case QEvent::ChildPolished:
136 case QEvent::ChildRemoved:
137#if QT_CONFIG(clipboard)
138 case QEvent::Clipboard:
140 case QEvent::ContentsRectChange:
141 case QEvent::DeferredDelete:
142 case QEvent::FileOpen:
143 case QEvent::LanguageChange:
144 case QEvent::MetaCall:
145 case QEvent::ModifiedChange:
147 case QEvent::PaletteChange:
148 case QEvent::ParentAboutToChange:
149 case QEvent::ParentChange:
151 case QEvent::PolishRequest:
152 case QEvent::QueryWhatsThis:
153 case QEvent::StatusTip:
154 case QEvent::StyleChange:
156 case QEvent::ToolBarChange:
157 case QEvent::ToolTip:
158 case QEvent::WhatsThis:
159 case QEvent::WhatsThisClicked:
160 case QEvent::WinIdChange:
161 case QEvent::DynamicPropertyChange:
162 case QEvent::HoverEnter:
163 case QEvent::HoverLeave:
164 case QEvent::HoverMove:
165 case QEvent::AcceptDropsChange:
171 QWidget *widget =
static_cast<QWidget*>(o);
182 if (
QWidget *managedWidget = findManagedWidget(fw, widget)) {
184 if (managedWidget != widget && eventType == QEvent::Close) {
189 case QEvent::LayoutRequest:
192 if (fw->handleOperation() == FormWindow::ChangeLayoutSpanHandleOperation) {
198 case QEvent::WindowActivate: {
199 if (fw->parentWidget()->isWindow() && fw->isMainContainer(managedWidget) && activeFormWindow() != fw) {
200 setActiveFormWindow(fw);
204 case QEvent::WindowDeactivate: {
205 if (o == fw && o == activeFormWindow())
209 case QEvent::KeyPress: {
210 QKeyEvent *ke =
static_cast<QKeyEvent*>(e);
211 if (ke->key() == Qt::Key_Escape) {
221 if (activeFormWindow() != fw)
222 setActiveFormWindow(fw);
225 if (fw->handleEvent(widget, managedWidget, e)) {
239 if (!formWindow || m_formWindows.contains(formWindow))
242 connect(formWindow, &QDesignerFormWindowInterface::selectionChanged,
243 this, &FormWindowManager::slotUpdateActions);
244 connect(formWindow->commandHistory(), &QUndoStack::indexChanged,
245 this, &FormWindowManager::slotUpdateActions);
246 connect(formWindow, &QDesignerFormWindowInterface::toolChanged,
247 this, &FormWindowManager::slotUpdateActions);
249 if (ActionEditor *ae = qobject_cast<ActionEditor *>(m_core->actionEditor())) {
250 connect(w, &QDesignerFormWindowInterface::mainContainerChanged,
251 ae, &ActionEditor::mainContainerChanged);
253 if (QDesignerObjectInspector *oi = qobject_cast<QDesignerObjectInspector *>(m_core->objectInspector()))
254 connect(w, &QDesignerFormWindowInterface::mainContainerChanged,
255 oi, &QDesignerObjectInspector::mainContainerChanged);
257 m_formWindows.append(formWindow);
258 emit formWindowAdded(formWindow);
265 int idx = m_formWindows.indexOf(formWindow);
266 if (!formWindow || idx == -1)
269 formWindow->disconnect(
this);
270 m_formWindows.removeAt(idx);
271 emit formWindowRemoved(formWindow);
273 if (formWindow == m_activeFormWindow)
274 setActiveFormWindow(
nullptr);
277 if (m_formWindows.isEmpty() && m_core->widgetBox())
278 m_core->widgetBox()->setEnabled(
true);
286 if (formWindow == m_activeFormWindow)
291 m_activeFormWindow = formWindow;
293 QtResourceSet *resourceSet =
nullptr;
295 resourceSet = formWindow->resourceSet();
296 m_core->resourceModel()->setCurrentResourceSet(resourceSet);
300 if (m_activeFormWindow) {
306 emit activeFormWindowChanged(m_activeFormWindow);
308 if (m_activeFormWindow) {
310 m_activeFormWindow->commandHistory()->setActive();
312 QMdiSubWindow *mdiSubWindow =
nullptr;
313 if (
QWidget *formwindow = m_activeFormWindow->parentWidget()) {
314 mdiSubWindow = qobject_cast<QMdiSubWindow *>(formwindow->parentWidget());
317 for (
QWidget *parent = mdiSubWindow->parentWidget(); parent; parent = parent->parentWidget()) {
318 if (QMdiArea *mdiArea = qobject_cast<QMdiArea*>(parent)) {
319 mdiArea->setActiveSubWindow(mdiSubWindow);
329 m_previewManager->closeAllPreviews();
334 while (w && w != fw) {
337 w = w->parentWidget();
344#if QT_CONFIG(clipboard)
345 const QIcon cutIcon = createIconSet(QIcon::ThemeIcon::EditCut,
347 m_actionCut =
new QAction(cutIcon, tr(
"Cu&t"),
this);
348 m_actionCut->setObjectName(u"__qt_cut_action"_s);
349 m_actionCut->setShortcut(QKeySequence::Cut);
350 m_actionCut->setStatusTip(tr(
"Cuts the selected widgets and puts them on the clipboard"));
351 m_actionCut->setWhatsThis(whatsThisFrom(u"Edit|Cut"_s));
352 connect(m_actionCut, &QAction::triggered,
this, &FormWindowManager::slotActionCutActivated);
353 m_actionCut->setEnabled(
false);
355 const QIcon copyIcon = createIconSet(QIcon::ThemeIcon::EditCopy,
"editcopy.png"_L1);
356 m_actionCopy =
new QAction(copyIcon, tr(
"&Copy"),
this);
357 m_actionCopy->setObjectName(u"__qt_copy_action"_s);
358 m_actionCopy->setShortcut(QKeySequence::Copy);
359 m_actionCopy->setStatusTip(tr(
"Copies the selected widgets to the clipboard"));
360 m_actionCopy->setWhatsThis(whatsThisFrom(u"Edit|Copy"_s));
361 connect(m_actionCopy, &QAction::triggered,
this, &FormWindowManager::slotActionCopyActivated);
362 m_actionCopy->setEnabled(
false);
364 const QIcon pasteIcon = createIconSet(QIcon::ThemeIcon::EditPaste,
"editpaste.png"_L1);
365 m_actionPaste =
new QAction(pasteIcon, tr(
"&Paste"),
this);
366 m_actionPaste->setObjectName(u"__qt_paste_action"_s);
367 m_actionPaste->setShortcut(QKeySequence::Paste);
368 m_actionPaste->setStatusTip(tr(
"Pastes the clipboard's contents"));
369 m_actionPaste->setWhatsThis(whatsThisFrom(u"Edit|Paste"_s));
370 connect(m_actionPaste, &QAction::triggered,
this, &FormWindowManager::slotActionPasteActivated);
371 m_actionPaste->setEnabled(
false);
374 m_actionDelete =
new QAction(QIcon::fromTheme(QIcon::ThemeIcon::EditDelete),
375 tr(
"&Delete"),
this);
376 m_actionDelete->setObjectName(u"__qt_delete_action"_s);
377 m_actionDelete->setStatusTip(tr(
"Deletes the selected widgets"));
378 m_actionDelete->setWhatsThis(whatsThisFrom(u"Edit|Delete"_s));
379 connect(m_actionDelete, &QAction::triggered,
this, &FormWindowManager::slotActionDeleteActivated);
380 m_actionDelete->setEnabled(
false);
382 m_actionSelectAll =
new QAction(tr(
"Select &All"),
this);
383 m_actionSelectAll->setObjectName(u"__qt_select_all_action"_s);
384 m_actionSelectAll->setShortcut(QKeySequence::SelectAll);
385 m_actionSelectAll->setStatusTip(tr(
"Selects all widgets"));
386 m_actionSelectAll->setWhatsThis(whatsThisFrom(u"Edit|Select All"_s));
387 connect(m_actionSelectAll, &QAction::triggered,
this, &FormWindowManager::slotActionSelectAllActivated);
388 m_actionSelectAll->setEnabled(
false);
390 m_actionRaise =
new QAction(createIconSet(
"editraise.png"_L1),
391 tr(
"Bring to &Front"),
this);
392 m_actionRaise->setObjectName(u"__qt_raise_action"_s);
393 m_actionRaise->setShortcut(Qt::CTRL | Qt::Key_L);
394 m_actionRaise->setStatusTip(tr(
"Raises the selected widgets"));
395 m_actionRaise->setWhatsThis(tr(
"Raises the selected widgets"));
396 connect(m_actionRaise, &QAction::triggered,
this, &FormWindowManager::slotActionRaiseActivated);
397 m_actionRaise->setEnabled(
false);
399 m_actionLower =
new QAction(createIconSet(
"editlower.png"_L1),
400 tr(
"Send to &Back"),
this);
401 m_actionLower->setObjectName(u"__qt_lower_action"_s);
402 m_actionLower->setShortcut(Qt::CTRL | Qt::Key_K);
403 m_actionLower->setStatusTip(tr(
"Lowers the selected widgets"));
404 m_actionLower->setWhatsThis(tr(
"Lowers the selected widgets"));
405 connect(m_actionLower, &QAction::triggered,
this, &FormWindowManager::slotActionLowerActivated);
406 m_actionLower->setEnabled(
false);
408 m_actionAdjustSize =
new QAction(createIconSet(
"adjustsize.png"_L1),
409 tr(
"Adjust &Size"),
this);
410 m_actionAdjustSize->setObjectName(u"__qt_adjust_size_action"_s);
411 m_actionAdjustSize->setShortcut(Qt::CTRL | Qt::Key_J);
412 m_actionAdjustSize->setStatusTip(tr(
"Adjusts the size of the selected widget"));
413 m_actionAdjustSize->setWhatsThis(whatsThisFrom(u"Layout|Adjust Size"_s));
414 connect(m_actionAdjustSize, &QAction::triggered,
this, &FormWindowManager::slotActionAdjustSizeActivated);
415 m_actionAdjustSize->setEnabled(
false);
418 m_actionHorizontalLayout =
new QAction(createIconSet(
"edithlayout.png"_L1),
419 tr(
"Lay Out &Horizontally"),
this);
420 m_actionHorizontalLayout->setObjectName(u"__qt_horizontal_layout_action"_s);
421 m_actionHorizontalLayout->setShortcut(Qt::CTRL | Qt::Key_1);
422 m_actionHorizontalLayout->setStatusTip(tr(
"Lays out the selected widgets horizontally"));
423 m_actionHorizontalLayout->setWhatsThis(whatsThisFrom(u"Layout|Lay Out Horizontally"_s));
424 m_actionHorizontalLayout->setData(LayoutInfo::HBox);
425 m_actionHorizontalLayout->setEnabled(
false);
426 connect(m_actionHorizontalLayout, &QAction::triggered,
this, &FormWindowManager::createLayout);
428 m_actionVerticalLayout =
new QAction(createIconSet(
"editvlayout.png"_L1),
429 tr(
"Lay Out &Vertically"),
this);
430 m_actionVerticalLayout->setObjectName(u"__qt_vertical_layout_action"_s);
431 m_actionVerticalLayout->setShortcut(Qt::CTRL | Qt::Key_2);
432 m_actionVerticalLayout->setStatusTip(tr(
"Lays out the selected widgets vertically"));
433 m_actionVerticalLayout->setWhatsThis(whatsThisFrom(u"Layout|Lay Out Vertically"_s));
434 m_actionVerticalLayout->setData(LayoutInfo::VBox);
435 m_actionVerticalLayout->setEnabled(
false);
436 connect(m_actionVerticalLayout, &QAction::triggered,
this, &FormWindowManager::createLayout);
438 QIcon formIcon = QIcon::fromTheme(u"designer-form-layout"_s,
439 createIconSet(
"editform.png"_L1));
440 m_actionFormLayout =
new QAction(formIcon, tr(
"Lay Out in a &Form Layout"),
this);
441 m_actionFormLayout->setObjectName(u"__qt_form_layout_action"_s);
442 m_actionFormLayout->setShortcut(Qt::CTRL | Qt::Key_6);
443 m_actionFormLayout->setStatusTip(tr(
"Lays out the selected widgets in a form layout"));
444 m_actionFormLayout->setWhatsThis(whatsThisFrom(u"Layout|Lay Out in a Form"_s));
445 m_actionFormLayout->setData(LayoutInfo::Form);
446 m_actionFormLayout->setEnabled(
false);
447 connect(m_actionFormLayout, &QAction::triggered,
this, &FormWindowManager::createLayout);
449 m_actionGridLayout =
new QAction(createIconSet(
"editgrid.png"_L1),
450 tr(
"Lay Out in a &Grid"),
this);
451 m_actionGridLayout->setObjectName(u"__qt_grid_layout_action"_s);
452 m_actionGridLayout->setShortcut(Qt::CTRL | Qt::Key_5);
453 m_actionGridLayout->setStatusTip(tr(
"Lays out the selected widgets in a grid"));
454 m_actionGridLayout->setWhatsThis(whatsThisFrom(u"Layout|Lay Out in a Grid"_s));
455 m_actionGridLayout->setData(LayoutInfo::Grid);
456 m_actionGridLayout->setEnabled(
false);
457 connect(m_actionGridLayout, &QAction::triggered,
this, &FormWindowManager::createLayout);
459 m_actionSplitHorizontal =
new QAction(createIconSet(
"edithlayoutsplit.png"_L1),
460 tr(
"Lay Out Horizontally in S&plitter"),
this);
461 m_actionSplitHorizontal->setObjectName(u"__qt_split_horizontal_action"_s);
462 m_actionSplitHorizontal->setShortcut(Qt::CTRL | Qt::Key_3);
463 m_actionSplitHorizontal->setStatusTip(tr(
"Lays out the selected widgets horizontally in a splitter"));
464 m_actionSplitHorizontal->setWhatsThis(whatsThisFrom(u"Layout|Lay Out Horizontally in Splitter"_s));
465 m_actionSplitHorizontal->setData(LayoutInfo::HSplitter);
466 m_actionSplitHorizontal->setEnabled(
false);
467 connect(m_actionSplitHorizontal, &QAction::triggered,
this, &FormWindowManager::createLayout);
469 m_actionSplitVertical =
new QAction(createIconSet(
"editvlayoutsplit.png"_L1),
470 tr(
"Lay Out Vertically in Sp&litter"),
this);
471 m_actionSplitVertical->setObjectName(u"__qt_split_vertical_action"_s);
472 m_actionSplitVertical->setShortcut(Qt::CTRL | Qt::Key_4);
473 m_actionSplitVertical->setStatusTip(tr(
"Lays out the selected widgets vertically in a splitter"));
474 m_actionSplitVertical->setWhatsThis(whatsThisFrom(u"Layout|Lay Out Vertically in Splitter"_s));
475 connect(m_actionSplitVertical, &QAction::triggered,
this, &FormWindowManager::createLayout);
476 m_actionSplitVertical->setData(LayoutInfo::VSplitter);
478 m_actionSplitVertical->setEnabled(
false);
480 m_actionBreakLayout =
new QAction(createIconSet(
"editbreaklayout.png"_L1),
481 tr(
"&Break Layout"),
this);
482 m_actionBreakLayout->setObjectName(u"__qt_break_layout_action"_s);
483 m_actionBreakLayout->setShortcut(Qt::CTRL | Qt::Key_0);
484 m_actionBreakLayout->setStatusTip(tr(
"Breaks the selected layout"));
485 m_actionBreakLayout->setWhatsThis(whatsThisFrom(u"Layout|Break Layout"_s));
486 connect(m_actionBreakLayout, &QAction::triggered,
this, &FormWindowManager::slotActionBreakLayoutActivated);
487 m_actionBreakLayout->setEnabled(
false);
489 m_actionSimplifyLayout =
new QAction(tr(
"Si&mplify Grid Layout"),
this);
490 m_actionSimplifyLayout->setObjectName(u"__qt_simplify_layout_action"_s);
491 m_actionSimplifyLayout->setStatusTip(tr(
"Removes empty columns and rows"));
492 m_actionSimplifyLayout->setWhatsThis(whatsThisFrom(u"Layout|Simplify Layout"_s));
493 connect(m_actionSimplifyLayout, &QAction::triggered,
this, &FormWindowManager::slotActionSimplifyLayoutActivated);
494 m_actionSimplifyLayout->setEnabled(
false);
496 m_actionDefaultPreview =
new QAction(tr(
"&Preview..."),
this);
497 m_actionDefaultPreview->setObjectName(u"__qt_default_preview_action"_s);
498 m_actionDefaultPreview->setStatusTip(tr(
"Preview current form"));
499 m_actionDefaultPreview->setWhatsThis(whatsThisFrom(u"Form|Preview"_s));
500 connect(m_actionDefaultPreview, &QAction::triggered,
501 this, &FormWindowManager::showPreview);
503 m_undoGroup =
new QUndoGroup(
this);
505 m_actionUndo = m_undoGroup->createUndoAction(
this);
506 m_actionUndo->setEnabled(
false);
508 m_actionUndo->setIcon(createIconSet(QIcon::ThemeIcon::EditUndo,
"undo.png"_L1));
509 m_actionRedo = m_undoGroup->createRedoAction(
this);
510 m_actionRedo->setEnabled(
false);
511 m_actionRedo->setIcon(createIconSet(QIcon::ThemeIcon::EditRedo,
"redo.png"_L1));
513 m_actionShowFormWindowSettingsDialog =
new QAction(tr(
"Form &Settings..."),
this);
514 m_actionShowFormWindowSettingsDialog->setObjectName(u"__qt_form_settings_action"_s);
515 connect(m_actionShowFormWindowSettingsDialog, &QAction::triggered,
516 this, &FormWindowManager::slotActionShowFormWindowSettingsDialog);
517 m_actionShowFormWindowSettingsDialog->setEnabled(
false);
520#if QT_CONFIG(clipboard)
540 m_activeFormWindow->deleteWidgets();
555 QWidgetList l(fw->selectedWidgets());
556 fw->simplifySelection(&l);
562 QAction *a = qobject_cast<QAction *>(sender());
565 const int type = a->data().toInt();
566 switch (m_createLayoutContext) {
567 case LayoutContainer:
569 if (type != LayoutInfo::HSplitter && type != LayoutInfo::VSplitter)
572 case LayoutSelection:
576 m_activeFormWindow->morphLayout(m_morphLayoutContainer, type);
583 const QWidgetList layouts = layoutsToBeBroken();
584 if (layouts.isEmpty())
588 qDebug() <<
"slotActionBreakLayoutActivated: " << layouts.size();
589 for (
const QWidget *w : layouts)
593 m_activeFormWindow->beginCommand(tr(
"Break Layout"));
594 for (QWidget *layout : layouts)
595 m_activeFormWindow->breakLayout(layout);
601 Q_ASSERT(m_activeFormWindow !=
nullptr);
602 QWidgetList selectedWidgets = m_activeFormWindow->selectedWidgets();
603 m_activeFormWindow->simplifySelection(&selectedWidgets);
604 if (selectedWidgets.size() != 1)
606 SimplifyLayoutCommand *cmd =
new SimplifyLayoutCommand(m_activeFormWindow);
607 if (cmd->init(selectedWidgets.constFirst())) {
608 m_activeFormWindow->commandHistory()->push(cmd);
616 Q_ASSERT(m_activeFormWindow !=
nullptr);
618 m_activeFormWindow->beginCommand(tr(
"Adjust Size"));
620 QWidgetList selectedWidgets = m_activeFormWindow->selectedWidgets();
621 m_activeFormWindow->simplifySelection(&selectedWidgets);
623 if (selectedWidgets.isEmpty()) {
629 for (QWidget *widget : std::as_const(selectedWidgets)) {
630 bool unlaidout = LayoutInfo::layoutType(core(), widget->parentWidget()) == LayoutInfo::NoLayout;
631 bool isMainContainer = m_activeFormWindow->isMainContainer(widget);
633 if (unlaidout || isMainContainer) {
634 AdjustWidgetSizeCommand *cmd =
new AdjustWidgetSizeCommand(m_activeFormWindow);
636 m_activeFormWindow->commandHistory()->push(cmd);
650 slotActionGroupPreviewInStyle(QString(), -1);
653void FormWindowManager::slotActionGroupPreviewInStyle(
const QString &style,
int deviceProfileIndex)
655 QDesignerFormWindowInterface *fw = activeFormWindow();
659 QString errorMessage;
660 if (!m_previewManager->showPreview(fw, style, deviceProfileIndex, &errorMessage)) {
661 const QString title = tr(
"Could not create form preview",
"Title of warning message box");
662 core()->dialogGui()->message(fw, QDesignerDialogGuiInterface::FormEditorMessage, QMessageBox::Warning,
663 title, errorMessage);
671 return QWidgetList();
674 qDebug() <<
"layoutsToBeBroken: " << w;
676 QWidget *parent = w->parentWidget();
680 QWidget *widget =
core()->widgetFactory()->containerOfWidget(w);
683 const QDesignerWidgetDataBaseInterface *db = m_core->widgetDataBase();
684 const QDesignerWidgetDataBaseItemInterface *item = db->item(db->indexOfObject(widget));
687 qDebug() <<
"layoutsToBeBroken: Don't have an item, recursing for parent";
688 return layoutsToBeBroken(parent);
691 const bool layoutContainer = (item->isContainer() || m_activeFormWindow
->isMainContainer(widget
));
693 if (!layoutContainer) {
695 qDebug() <<
"layoutsToBeBroken: Not a container, recursing for parent";
696 return layoutsToBeBroken(parent);
699 QLayout *widgetLayout = widget->layout();
700 QLayout *managedLayout = LayoutInfo::managedLayout(m_core, widgetLayout);
701 if (!managedLayout) {
702 if (qobject_cast<
const QSplitter *>(widget)) {
704 qDebug() <<
"layoutsToBeBroken: Splitter special";
705 QWidgetList list = layoutsToBeBroken(parent);
710 qDebug() <<
"layoutsToBeBroken: Is a container but doesn't have a managed layout (has an internal layout), returning 0";
711 return QWidgetList();
717 qDebug() <<
"layoutsToBeBroken: Is a container and has a layout";
718 if (qobject_cast<
const QLayoutWidget *>(widget)) {
720 qDebug() <<
"layoutsToBeBroken: red layout special case";
721 list = layoutsToBeBroken(parent);
727 qDebug() <<
"layoutsToBeBroken: Is a container but doesn't have a layout at all, returning 0";
728 return QWidgetList();
732QSet<QWidget *>
FormWindowManager::getUnsortedLayoutsToBeBroken(
bool firstOnly)
const
735 QSet<QWidget *> layouts;
737 QWidgetList selection = m_activeFormWindow->selectedWidgets();
741 for (QWidget *selectedWidget : std::as_const(selection)) {
743 const QWidgetList &list = layoutsToBeBroken(selectedWidget);
744 if (!list.isEmpty()) {
745 for (QWidget *widget : list)
746 layouts.insert(widget);
757 return !getUnsortedLayoutsToBeBroken(
true).isEmpty();
764 const QSet<QWidget *> unsortedLayouts = getUnsortedLayoutsToBeBroken(
false);
766 QWidgetList orderedLayoutList;
767 for (QWidget *wToBeInserted : unsortedLayouts) {
768 if (!orderedLayoutList.contains(wToBeInserted)) {
770 const auto firstChildPos = findFirstChildOf(orderedLayoutList.begin(), orderedLayoutList.end(), wToBeInserted);
771 if (firstChildPos == orderedLayoutList.end()) {
772 orderedLayoutList.push_back(wToBeInserted);
774 orderedLayoutList.insert(firstChildPos, wToBeInserted);
778 return orderedLayoutList;
783 if (
const QLayout *ml = LayoutInfo::managedLayout(core, w)) {
785 const int count = ml->count();
786 for (
int i = 0; i < count; i++)
787 if (!LayoutInfo::isEmptyItem(ml->itemAt(i)))
795 m_createLayoutContext = LayoutSelection;
796 m_morphLayoutContainer =
nullptr;
797 bool canMorphIntoVBoxLayout =
false;
798 bool canMorphIntoHBoxLayout =
false;
799 bool canMorphIntoGridLayout =
false;
800 bool canMorphIntoFormLayout =
false;
801 bool hasSelectedWidgets =
false;
802 int unlaidoutWidgetCount = 0;
803#if QT_CONFIG(clipboard)
804 bool pasteAvailable =
false;
806 bool layoutAvailable =
false;
807 bool breakAvailable =
false;
808 bool simplifyAvailable =
false;
809 bool layoutContainer =
false;
810 bool canChangeZOrder =
true;
813 if (m_activeFormWindow ==
nullptr || m_activeFormWindow
->currentTool() != 0)
816 breakAvailable = hasLayoutsToBeBroken();
818 QWidgetList simplifiedSelection = m_activeFormWindow->selectedWidgets();
820 hasSelectedWidgets = !simplifiedSelection.isEmpty();
821#if QT_CONFIG(clipboard)
822 pasteAvailable = qApp->clipboard()->mimeData() && qApp->clipboard()->mimeData()->hasText();
825 m_activeFormWindow->simplifySelection(&simplifiedSelection);
827 if (simplifiedSelection.isEmpty() && mainContainer)
828 simplifiedSelection.append(mainContainer);
831 for (
auto *w : std::as_const(simplifiedSelection)) {
832 if (w == mainContainer || !LayoutInfo::isWidgetLaidout(m_core, w))
833 ++unlaidoutWidgetCount;
835 if (qobject_cast<
const QLayoutWidget *>(w) || qobject_cast<
const Spacer *>(w))
836 canChangeZOrder =
false;
840 if (simplifiedSelection.size() != 1) {
841 layoutAvailable = unlaidoutWidgetCount > 1;
846 m_createLayoutContext = LayoutSelection;
847 QWidget *widget =
core()->widgetFactory()->containerOfWidget(simplifiedSelection.first());
848 if (widget ==
nullptr)
851 const QDesignerWidgetDataBaseInterface *db = m_core->widgetDataBase();
852 const QDesignerWidgetDataBaseItemInterface *item = db->item(db->indexOfObject(widget));
856 QLayout *widgetLayout = LayoutInfo::internalLayout(widget);
857 QLayout *managedLayout = LayoutInfo::managedLayout(m_core, widgetLayout);
859 if (widgetLayout && !managedLayout)
864 layoutAvailable = layoutContainer && m_activeFormWindow
->hasInsertedChildren(widget
) && managedLayout ==
nullptr;
865 simplifyAvailable = SimplifyLayoutCommand::canSimplify(m_core, widget);
866 if (layoutAvailable) {
867 m_createLayoutContext = LayoutContainer;
870
871
872
873 if (breakAvailable && simplifiedSelection.size() == 1
876 m_morphLayoutContainer = widget;
877 m_createLayoutContext = MorphLayout;
878 if (MorphLayoutCommand::canMorph(m_activeFormWindow, m_morphLayoutContainer, &type)) {
879 canMorphIntoVBoxLayout = type != LayoutInfo::VBox;
880 canMorphIntoHBoxLayout = type != LayoutInfo::HBox;
881 canMorphIntoGridLayout = type != LayoutInfo::Grid;
882 canMorphIntoFormLayout = type != LayoutInfo::Form;
888#if QT_CONFIG(clipboard)
889 m_actionCut->setEnabled(hasSelectedWidgets);
890 m_actionCopy->setEnabled(hasSelectedWidgets);
891 m_actionPaste->setEnabled(pasteAvailable);
893 m_actionDelete->setEnabled(hasSelectedWidgets);
894 m_actionLower->setEnabled(canChangeZOrder && hasSelectedWidgets);
895 m_actionRaise->setEnabled(canChangeZOrder && hasSelectedWidgets);
898 m_actionSelectAll->setEnabled(m_activeFormWindow !=
nullptr);
900 m_actionAdjustSize->setEnabled(unlaidoutWidgetCount > 0);
902 m_actionHorizontalLayout->setEnabled(layoutAvailable || canMorphIntoHBoxLayout);
903 m_actionVerticalLayout->setEnabled(layoutAvailable || canMorphIntoVBoxLayout);
904 m_actionSplitHorizontal->setEnabled(layoutAvailable && !layoutContainer);
905 m_actionSplitVertical->setEnabled(layoutAvailable && !layoutContainer);
906 m_actionFormLayout->setEnabled(layoutAvailable || canMorphIntoFormLayout);
907 m_actionGridLayout->setEnabled(layoutAvailable || canMorphIntoGridLayout);
909 m_actionBreakLayout->setEnabled(breakAvailable);
910 m_actionSimplifyLayout->setEnabled(simplifyAvailable);
911 m_actionShowFormWindowSettingsDialog->setEnabled(m_activeFormWindow !=
nullptr);
917 formWindow->setProperty(WidgetFactory::disableStyleCustomPaintingPropertyC, QVariant(
true));
918 addFormWindow(formWindow);
924 const QDesignerFormWindowInterface *fw = activeFormWindow();
927 QString errorMessage;
928 const QPixmap pix = m_previewManager->createPreviewPixmap(fw, QString(), &errorMessage);
929 if (pix.isNull() && !errorMessage.isEmpty())
930 qWarning(
"Preview pixmap creation failed: %s", qPrintable(errorMessage));
936 if (m_actionGroupPreviewInStyle)
937 m_actionGroupPreviewInStyle->updateDeviceProfiles();
944 QDesignerMimeData::execDrag(item_list, m_core->topLevel());
954 QDesignerFormWindowInterface *fw = activeFormWindow();
958 QDialog *settingsDialog =
nullptr;
959 const bool wasDirty = fw->isDirty();
962 if (QDesignerLanguageExtension *lang = qt_extension<QDesignerLanguageExtension*>(m_core->extensionManager(), m_core))
963 settingsDialog = lang->createFormWindowSettingsDialog(fw,
nullptr);
966 settingsDialog =
new FormWindowSettings(fw);
968 QString title = QFileInfo(fw->fileName()).fileName();
970 if (
const QWidget *window = m_core->integration()->containerWindow(fw))
971 title = window->windowTitle();
973 settingsDialog->setWindowTitle(tr(
"Form Settings - %1").arg(title));
974 if (settingsDialog->exec())
975 if (fw->isDirty() != wasDirty)
976 emit formWindowSettingsChanged(fw);
978 delete settingsDialog;
984#if QT_CONFIG(clipboard)
985 case QDesignerFormWindowManagerInterface::CutAction:
987 case QDesignerFormWindowManagerInterface::CopyAction:
989 case QDesignerFormWindowManagerInterface::PasteAction:
990 return m_actionPaste;
992 case QDesignerFormWindowManagerInterface::DeleteAction:
993 return m_actionDelete;
994 case QDesignerFormWindowManagerInterface::SelectAllAction:
995 return m_actionSelectAll;
996 case QDesignerFormWindowManagerInterface::LowerAction:
997 return m_actionLower;
998 case QDesignerFormWindowManagerInterface::RaiseAction:
999 return m_actionRaise;
1000 case QDesignerFormWindowManagerInterface::UndoAction:
1001 return m_actionUndo;
1002 case QDesignerFormWindowManagerInterface::RedoAction:
1003 return m_actionRedo;
1004 case QDesignerFormWindowManagerInterface::HorizontalLayoutAction:
1005 return m_actionHorizontalLayout;
1006 case QDesignerFormWindowManagerInterface::VerticalLayoutAction:
1007 return m_actionVerticalLayout;
1008 case QDesignerFormWindowManagerInterface::SplitHorizontalAction:
1009 return m_actionSplitHorizontal;
1010 case QDesignerFormWindowManagerInterface::SplitVerticalAction:
1011 return m_actionSplitVertical;
1012 case QDesignerFormWindowManagerInterface::GridLayoutAction:
1013 return m_actionGridLayout;
1014 case QDesignerFormWindowManagerInterface::FormLayoutAction:
1015 return m_actionFormLayout;
1016 case QDesignerFormWindowManagerInterface::BreakLayoutAction:
1017 return m_actionBreakLayout;
1018 case QDesignerFormWindowManagerInterface::AdjustSizeAction:
1019 return m_actionAdjustSize;
1020 case QDesignerFormWindowManagerInterface::SimplifyLayoutAction:
1021 return m_actionSimplifyLayout;
1022 case QDesignerFormWindowManagerInterface::DefaultPreviewAction:
1023 return m_actionDefaultPreview;
1024 case QDesignerFormWindowManagerInterface::FormWindowSettingsDialogAction:
1025 return m_actionShowFormWindowSettingsDialog;
1027 qWarning(
"FormWindowManager::action: Unhanded enumeration value %d", action);
1033 switch (actionGroup) {
1034 case QDesignerFormWindowManagerInterface::StyledPreviewActionGroup:
1035 if (m_actionGroupPreviewInStyle ==
nullptr) {
1038 m_actionGroupPreviewInStyle =
new PreviewActionGroup(m_core, parent);
1039 connect(m_actionGroupPreviewInStyle, &PreviewActionGroup::preview,
1040 this, &FormWindowManager::slotActionGroupPreviewInStyle);
1042 return m_actionGroupPreviewInStyle;
1044 qWarning(
"FormWindowManager::actionGroup: Unhanded enumeration value %d", actionGroup);
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.
static QWidget * findLayoutContainer(const FormWindow *fw)
static bool hasManagedLayoutItems(const QDesignerFormEditorInterface *core, QWidget *w)