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 m_actionFormLayout =
new QAction(createIconSet(
"editform.png"_L1),
439 tr(
"Lay Out in a &Form Layout"),
this);
440 m_actionFormLayout->setObjectName(u"__qt_form_layout_action"_s);
441 m_actionFormLayout->setShortcut(Qt::CTRL | Qt::Key_6);
442 m_actionFormLayout->setStatusTip(tr(
"Lays out the selected widgets in a form layout"));
443 m_actionFormLayout->setWhatsThis(whatsThisFrom(u"Layout|Lay Out in a Form"_s));
444 m_actionFormLayout->setData(LayoutInfo::Form);
445 m_actionFormLayout->setEnabled(
false);
446 connect(m_actionFormLayout, &QAction::triggered,
this, &FormWindowManager::createLayout);
448 m_actionGridLayout =
new QAction(createIconSet(
"editgrid.png"_L1),
449 tr(
"Lay Out in a &Grid"),
this);
450 m_actionGridLayout->setObjectName(u"__qt_grid_layout_action"_s);
451 m_actionGridLayout->setShortcut(Qt::CTRL | Qt::Key_5);
452 m_actionGridLayout->setStatusTip(tr(
"Lays out the selected widgets in a grid"));
453 m_actionGridLayout->setWhatsThis(whatsThisFrom(u"Layout|Lay Out in a Grid"_s));
454 m_actionGridLayout->setData(LayoutInfo::Grid);
455 m_actionGridLayout->setEnabled(
false);
456 connect(m_actionGridLayout, &QAction::triggered,
this, &FormWindowManager::createLayout);
458 m_actionSplitHorizontal =
new QAction(createIconSet(
"edithlayoutsplit.png"_L1),
459 tr(
"Lay Out Horizontally in S&plitter"),
this);
460 m_actionSplitHorizontal->setObjectName(u"__qt_split_horizontal_action"_s);
461 m_actionSplitHorizontal->setShortcut(Qt::CTRL | Qt::Key_3);
462 m_actionSplitHorizontal->setStatusTip(tr(
"Lays out the selected widgets horizontally in a splitter"));
463 m_actionSplitHorizontal->setWhatsThis(whatsThisFrom(u"Layout|Lay Out Horizontally in Splitter"_s));
464 m_actionSplitHorizontal->setData(LayoutInfo::HSplitter);
465 m_actionSplitHorizontal->setEnabled(
false);
466 connect(m_actionSplitHorizontal, &QAction::triggered,
this, &FormWindowManager::createLayout);
468 m_actionSplitVertical =
new QAction(createIconSet(
"editvlayoutsplit.png"_L1),
469 tr(
"Lay Out Vertically in Sp&litter"),
this);
470 m_actionSplitVertical->setObjectName(u"__qt_split_vertical_action"_s);
471 m_actionSplitVertical->setShortcut(Qt::CTRL | Qt::Key_4);
472 m_actionSplitVertical->setStatusTip(tr(
"Lays out the selected widgets vertically in a splitter"));
473 m_actionSplitVertical->setWhatsThis(whatsThisFrom(u"Layout|Lay Out Vertically in Splitter"_s));
474 connect(m_actionSplitVertical, &QAction::triggered,
this, &FormWindowManager::createLayout);
475 m_actionSplitVertical->setData(LayoutInfo::VSplitter);
477 m_actionSplitVertical->setEnabled(
false);
479 m_actionBreakLayout =
new QAction(createIconSet(
"editbreaklayout.png"_L1),
480 tr(
"&Break Layout"),
this);
481 m_actionBreakLayout->setObjectName(u"__qt_break_layout_action"_s);
482 m_actionBreakLayout->setShortcut(Qt::CTRL | Qt::Key_0);
483 m_actionBreakLayout->setStatusTip(tr(
"Breaks the selected layout"));
484 m_actionBreakLayout->setWhatsThis(whatsThisFrom(u"Layout|Break Layout"_s));
485 connect(m_actionBreakLayout, &QAction::triggered,
this, &FormWindowManager::slotActionBreakLayoutActivated);
486 m_actionBreakLayout->setEnabled(
false);
488 m_actionSimplifyLayout =
new QAction(tr(
"Si&mplify Grid Layout"),
this);
489 m_actionSimplifyLayout->setObjectName(u"__qt_simplify_layout_action"_s);
490 m_actionSimplifyLayout->setStatusTip(tr(
"Removes empty columns and rows"));
491 m_actionSimplifyLayout->setWhatsThis(whatsThisFrom(u"Layout|Simplify Layout"_s));
492 connect(m_actionSimplifyLayout, &QAction::triggered,
this, &FormWindowManager::slotActionSimplifyLayoutActivated);
493 m_actionSimplifyLayout->setEnabled(
false);
495 m_actionDefaultPreview =
new QAction(tr(
"&Preview..."),
this);
496 m_actionDefaultPreview->setObjectName(u"__qt_default_preview_action"_s);
497 m_actionDefaultPreview->setStatusTip(tr(
"Preview current form"));
498 m_actionDefaultPreview->setWhatsThis(whatsThisFrom(u"Form|Preview"_s));
499 connect(m_actionDefaultPreview, &QAction::triggered,
500 this, &FormWindowManager::showPreview);
502 m_undoGroup =
new QUndoGroup(
this);
504 m_actionUndo = m_undoGroup->createUndoAction(
this);
505 m_actionUndo->setEnabled(
false);
507 m_actionUndo->setIcon(createIconSet(QIcon::ThemeIcon::EditUndo,
"undo.png"_L1));
508 m_actionRedo = m_undoGroup->createRedoAction(
this);
509 m_actionRedo->setEnabled(
false);
510 m_actionRedo->setIcon(createIconSet(QIcon::ThemeIcon::EditRedo,
"redo.png"_L1));
512 m_actionShowFormWindowSettingsDialog =
new QAction(tr(
"Form &Settings..."),
this);
513 m_actionShowFormWindowSettingsDialog->setObjectName(u"__qt_form_settings_action"_s);
514 connect(m_actionShowFormWindowSettingsDialog, &QAction::triggered,
515 this, &FormWindowManager::slotActionShowFormWindowSettingsDialog);
516 m_actionShowFormWindowSettingsDialog->setEnabled(
false);
519#if QT_CONFIG(clipboard)
539 m_activeFormWindow->deleteWidgets();
554 QWidgetList l(fw->selectedWidgets());
555 fw->simplifySelection(&l);
561 QAction *a = qobject_cast<QAction *>(sender());
564 const int type = a->data().toInt();
565 switch (m_createLayoutContext) {
566 case LayoutContainer:
568 if (type != LayoutInfo::HSplitter && type != LayoutInfo::VSplitter)
571 case LayoutSelection:
575 m_activeFormWindow->morphLayout(m_morphLayoutContainer, type);
582 const QWidgetList layouts = layoutsToBeBroken();
583 if (layouts.isEmpty())
587 qDebug() <<
"slotActionBreakLayoutActivated: " << layouts.size();
588 for (
const QWidget *w : layouts)
592 m_activeFormWindow->beginCommand(tr(
"Break Layout"));
593 for (QWidget *layout : layouts)
594 m_activeFormWindow->breakLayout(layout);
600 Q_ASSERT(m_activeFormWindow !=
nullptr);
601 QWidgetList selectedWidgets = m_activeFormWindow->selectedWidgets();
602 m_activeFormWindow->simplifySelection(&selectedWidgets);
603 if (selectedWidgets.size() != 1)
605 SimplifyLayoutCommand *cmd =
new SimplifyLayoutCommand(m_activeFormWindow);
606 if (cmd->init(selectedWidgets.constFirst())) {
607 m_activeFormWindow->commandHistory()->push(cmd);
615 Q_ASSERT(m_activeFormWindow !=
nullptr);
617 m_activeFormWindow->beginCommand(tr(
"Adjust Size"));
619 QWidgetList selectedWidgets = m_activeFormWindow->selectedWidgets();
620 m_activeFormWindow->simplifySelection(&selectedWidgets);
622 if (selectedWidgets.isEmpty()) {
628 for (QWidget *widget : std::as_const(selectedWidgets)) {
629 bool unlaidout = LayoutInfo::layoutType(core(), widget->parentWidget()) == LayoutInfo::NoLayout;
630 bool isMainContainer = m_activeFormWindow->isMainContainer(widget);
632 if (unlaidout || isMainContainer) {
633 AdjustWidgetSizeCommand *cmd =
new AdjustWidgetSizeCommand(m_activeFormWindow);
635 m_activeFormWindow->commandHistory()->push(cmd);
649 slotActionGroupPreviewInStyle(QString(), -1);
652void FormWindowManager::slotActionGroupPreviewInStyle(
const QString &style,
int deviceProfileIndex)
654 QDesignerFormWindowInterface *fw = activeFormWindow();
658 QString errorMessage;
659 if (!m_previewManager->showPreview(fw, style, deviceProfileIndex, &errorMessage)) {
660 const QString title = tr(
"Could not create form preview",
"Title of warning message box");
661 core()->dialogGui()->message(fw, QDesignerDialogGuiInterface::FormEditorMessage, QMessageBox::Warning,
662 title, errorMessage);
670 return QWidgetList();
673 qDebug() <<
"layoutsToBeBroken: " << w;
675 QWidget *parent = w->parentWidget();
679 QWidget *widget =
core()->widgetFactory()->containerOfWidget(w);
682 const QDesignerWidgetDataBaseInterface *db = m_core->widgetDataBase();
683 const QDesignerWidgetDataBaseItemInterface *item = db->item(db->indexOfObject(widget));
686 qDebug() <<
"layoutsToBeBroken: Don't have an item, recursing for parent";
687 return layoutsToBeBroken(parent);
690 const bool layoutContainer = (item->isContainer() || m_activeFormWindow
->isMainContainer(widget
));
692 if (!layoutContainer) {
694 qDebug() <<
"layoutsToBeBroken: Not a container, recursing for parent";
695 return layoutsToBeBroken(parent);
698 QLayout *widgetLayout = widget->layout();
699 QLayout *managedLayout = LayoutInfo::managedLayout(m_core, widgetLayout);
700 if (!managedLayout) {
701 if (qobject_cast<
const QSplitter *>(widget)) {
703 qDebug() <<
"layoutsToBeBroken: Splitter special";
704 QWidgetList list = layoutsToBeBroken(parent);
709 qDebug() <<
"layoutsToBeBroken: Is a container but doesn't have a managed layout (has an internal layout), returning 0";
710 return QWidgetList();
716 qDebug() <<
"layoutsToBeBroken: Is a container and has a layout";
717 if (qobject_cast<
const QLayoutWidget *>(widget)) {
719 qDebug() <<
"layoutsToBeBroken: red layout special case";
720 list = layoutsToBeBroken(parent);
726 qDebug() <<
"layoutsToBeBroken: Is a container but doesn't have a layout at all, returning 0";
727 return QWidgetList();
731QSet<QWidget *>
FormWindowManager::getUnsortedLayoutsToBeBroken(
bool firstOnly)
const
734 QSet<QWidget *> layouts;
736 QWidgetList selection = m_activeFormWindow->selectedWidgets();
740 for (QWidget *selectedWidget : std::as_const(selection)) {
742 const QWidgetList &list = layoutsToBeBroken(selectedWidget);
743 if (!list.isEmpty()) {
744 for (QWidget *widget : list)
745 layouts.insert(widget);
756 return !getUnsortedLayoutsToBeBroken(
true).isEmpty();
763 const QSet<QWidget *> unsortedLayouts = getUnsortedLayoutsToBeBroken(
false);
765 QWidgetList orderedLayoutList;
766 for (QWidget *wToBeInserted : unsortedLayouts) {
767 if (!orderedLayoutList.contains(wToBeInserted)) {
769 const auto firstChildPos = findFirstChildOf(orderedLayoutList.begin(), orderedLayoutList.end(), wToBeInserted);
770 if (firstChildPos == orderedLayoutList.end()) {
771 orderedLayoutList.push_back(wToBeInserted);
773 orderedLayoutList.insert(firstChildPos, wToBeInserted);
777 return orderedLayoutList;
782 if (
const QLayout *ml = LayoutInfo::managedLayout(core, w)) {
784 const int count = ml->count();
785 for (
int i = 0; i < count; i++)
786 if (!LayoutInfo::isEmptyItem(ml->itemAt(i)))
794 m_createLayoutContext = LayoutSelection;
795 m_morphLayoutContainer =
nullptr;
796 bool canMorphIntoVBoxLayout =
false;
797 bool canMorphIntoHBoxLayout =
false;
798 bool canMorphIntoGridLayout =
false;
799 bool canMorphIntoFormLayout =
false;
800 bool hasSelectedWidgets =
false;
801 int unlaidoutWidgetCount = 0;
802#if QT_CONFIG(clipboard)
803 bool pasteAvailable =
false;
805 bool layoutAvailable =
false;
806 bool breakAvailable =
false;
807 bool simplifyAvailable =
false;
808 bool layoutContainer =
false;
809 bool canChangeZOrder =
true;
812 if (m_activeFormWindow ==
nullptr || m_activeFormWindow
->currentTool() != 0)
815 breakAvailable = hasLayoutsToBeBroken();
817 QWidgetList simplifiedSelection = m_activeFormWindow->selectedWidgets();
819 hasSelectedWidgets = !simplifiedSelection.isEmpty();
820#if QT_CONFIG(clipboard)
821 pasteAvailable = qApp->clipboard()->mimeData() && qApp->clipboard()->mimeData()->hasText();
824 m_activeFormWindow->simplifySelection(&simplifiedSelection);
826 if (simplifiedSelection.isEmpty() && mainContainer)
827 simplifiedSelection.append(mainContainer);
830 for (
auto *w : std::as_const(simplifiedSelection)) {
831 if (w == mainContainer || !LayoutInfo::isWidgetLaidout(m_core, w))
832 ++unlaidoutWidgetCount;
834 if (qobject_cast<
const QLayoutWidget *>(w) || qobject_cast<
const Spacer *>(w))
835 canChangeZOrder =
false;
839 if (simplifiedSelection.size() != 1) {
840 layoutAvailable = unlaidoutWidgetCount > 1;
845 m_createLayoutContext = LayoutSelection;
846 QWidget *widget =
core()->widgetFactory()->containerOfWidget(simplifiedSelection.first());
847 if (widget ==
nullptr)
850 const QDesignerWidgetDataBaseInterface *db = m_core->widgetDataBase();
851 const QDesignerWidgetDataBaseItemInterface *item = db->item(db->indexOfObject(widget));
855 QLayout *widgetLayout = LayoutInfo::internalLayout(widget);
856 QLayout *managedLayout = LayoutInfo::managedLayout(m_core, widgetLayout);
858 if (widgetLayout && !managedLayout)
863 layoutAvailable = layoutContainer && m_activeFormWindow
->hasInsertedChildren(widget
) && managedLayout ==
nullptr;
864 simplifyAvailable = SimplifyLayoutCommand::canSimplify(m_core, widget);
865 if (layoutAvailable) {
866 m_createLayoutContext = LayoutContainer;
869
870
871
872 if (breakAvailable && simplifiedSelection.size() == 1
875 m_morphLayoutContainer = widget;
876 m_createLayoutContext = MorphLayout;
877 if (MorphLayoutCommand::canMorph(m_activeFormWindow, m_morphLayoutContainer, &type)) {
878 canMorphIntoVBoxLayout = type != LayoutInfo::VBox;
879 canMorphIntoHBoxLayout = type != LayoutInfo::HBox;
880 canMorphIntoGridLayout = type != LayoutInfo::Grid;
881 canMorphIntoFormLayout = type != LayoutInfo::Form;
887#if QT_CONFIG(clipboard)
888 m_actionCut->setEnabled(hasSelectedWidgets);
889 m_actionCopy->setEnabled(hasSelectedWidgets);
890 m_actionPaste->setEnabled(pasteAvailable);
892 m_actionDelete->setEnabled(hasSelectedWidgets);
893 m_actionLower->setEnabled(canChangeZOrder && hasSelectedWidgets);
894 m_actionRaise->setEnabled(canChangeZOrder && hasSelectedWidgets);
897 m_actionSelectAll->setEnabled(m_activeFormWindow !=
nullptr);
899 m_actionAdjustSize->setEnabled(unlaidoutWidgetCount > 0);
901 m_actionHorizontalLayout->setEnabled(layoutAvailable || canMorphIntoHBoxLayout);
902 m_actionVerticalLayout->setEnabled(layoutAvailable || canMorphIntoVBoxLayout);
903 m_actionSplitHorizontal->setEnabled(layoutAvailable && !layoutContainer);
904 m_actionSplitVertical->setEnabled(layoutAvailable && !layoutContainer);
905 m_actionFormLayout->setEnabled(layoutAvailable || canMorphIntoFormLayout);
906 m_actionGridLayout->setEnabled(layoutAvailable || canMorphIntoGridLayout);
908 m_actionBreakLayout->setEnabled(breakAvailable);
909 m_actionSimplifyLayout->setEnabled(simplifyAvailable);
910 m_actionShowFormWindowSettingsDialog->setEnabled(m_activeFormWindow !=
nullptr);
916 formWindow->setProperty(WidgetFactory::disableStyleCustomPaintingPropertyC, QVariant(
true));
917 addFormWindow(formWindow);
923 const QDesignerFormWindowInterface *fw = activeFormWindow();
926 QString errorMessage;
927 const QPixmap pix = m_previewManager->createPreviewPixmap(fw, QString(), &errorMessage);
928 if (pix.isNull() && !errorMessage.isEmpty())
929 qWarning(
"Preview pixmap creation failed: %s", qPrintable(errorMessage));
935 if (m_actionGroupPreviewInStyle)
936 m_actionGroupPreviewInStyle->updateDeviceProfiles();
943 QDesignerMimeData::execDrag(item_list, m_core->topLevel());
953 QDesignerFormWindowInterface *fw = activeFormWindow();
957 QDialog *settingsDialog =
nullptr;
958 const bool wasDirty = fw->isDirty();
961 if (QDesignerLanguageExtension *lang = qt_extension<QDesignerLanguageExtension*>(m_core->extensionManager(), m_core))
962 settingsDialog = lang->createFormWindowSettingsDialog(fw,
nullptr);
965 settingsDialog =
new FormWindowSettings(fw);
967 QString title = QFileInfo(fw->fileName()).fileName();
969 if (
const QWidget *window = m_core->integration()->containerWindow(fw))
970 title = window->windowTitle();
972 settingsDialog->setWindowTitle(tr(
"Form Settings - %1").arg(title));
973 if (settingsDialog->exec())
974 if (fw->isDirty() != wasDirty)
975 emit formWindowSettingsChanged(fw);
977 delete settingsDialog;
983#if QT_CONFIG(clipboard)
984 case QDesignerFormWindowManagerInterface::CutAction:
986 case QDesignerFormWindowManagerInterface::CopyAction:
988 case QDesignerFormWindowManagerInterface::PasteAction:
989 return m_actionPaste;
991 case QDesignerFormWindowManagerInterface::DeleteAction:
992 return m_actionDelete;
993 case QDesignerFormWindowManagerInterface::SelectAllAction:
994 return m_actionSelectAll;
995 case QDesignerFormWindowManagerInterface::LowerAction:
996 return m_actionLower;
997 case QDesignerFormWindowManagerInterface::RaiseAction:
998 return m_actionRaise;
999 case QDesignerFormWindowManagerInterface::UndoAction:
1000 return m_actionUndo;
1001 case QDesignerFormWindowManagerInterface::RedoAction:
1002 return m_actionRedo;
1003 case QDesignerFormWindowManagerInterface::HorizontalLayoutAction:
1004 return m_actionHorizontalLayout;
1005 case QDesignerFormWindowManagerInterface::VerticalLayoutAction:
1006 return m_actionVerticalLayout;
1007 case QDesignerFormWindowManagerInterface::SplitHorizontalAction:
1008 return m_actionSplitHorizontal;
1009 case QDesignerFormWindowManagerInterface::SplitVerticalAction:
1010 return m_actionSplitVertical;
1011 case QDesignerFormWindowManagerInterface::GridLayoutAction:
1012 return m_actionGridLayout;
1013 case QDesignerFormWindowManagerInterface::FormLayoutAction:
1014 return m_actionFormLayout;
1015 case QDesignerFormWindowManagerInterface::BreakLayoutAction:
1016 return m_actionBreakLayout;
1017 case QDesignerFormWindowManagerInterface::AdjustSizeAction:
1018 return m_actionAdjustSize;
1019 case QDesignerFormWindowManagerInterface::SimplifyLayoutAction:
1020 return m_actionSimplifyLayout;
1021 case QDesignerFormWindowManagerInterface::DefaultPreviewAction:
1022 return m_actionDefaultPreview;
1023 case QDesignerFormWindowManagerInterface::FormWindowSettingsDialogAction:
1024 return m_actionShowFormWindowSettingsDialog;
1026 qWarning(
"FormWindowManager::action: Unhanded enumeration value %d", action);
1032 switch (actionGroup) {
1033 case QDesignerFormWindowManagerInterface::StyledPreviewActionGroup:
1034 if (m_actionGroupPreviewInStyle ==
nullptr) {
1037 m_actionGroupPreviewInStyle =
new PreviewActionGroup(m_core, parent);
1038 connect(m_actionGroupPreviewInStyle, &PreviewActionGroup::preview,
1039 this, &FormWindowManager::slotActionGroupPreviewInStyle);
1041 return m_actionGroupPreviewInStyle;
1043 qWarning(
"FormWindowManager::actionGroup: Unhanded enumeration value %d", actionGroup);
Auxiliary methods to store/retrieve settings.
static QWidget * findLayoutContainer(const FormWindow *fw)
static bool hasManagedLayoutItems(const QDesignerFormEditorInterface *core, QWidget *w)