Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
formwindow.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#ifndef FORMWINDOW_H
5#define FORMWINDOW_H
6
8#include <formwindowbase_p.h>
9
10// Qt
11#include <QtGui/qundostack.h>
12#include <QtCore/qhash.h>
13#include <QtCore/qlist.h>
14#include <QtCore/qset.h>
15#include <QtCore/qpointer.h>
16
17#include <utility>
18
19QT_BEGIN_NAMESPACE
20
21class QDesignerDnDItemInterface;
22class QDesignerTaskMenuExtension;
23class DomConnections;
24class DomUI;
25
26class QWidget;
27class QAction;
28class QLabel;
29class QTimer;
30class QAction;
31class QMenu;
32class QRubberBand;
33
34namespace qdesigner_internal {
35
36class FormEditor;
42class SetPropertyCommand;
43
45{
47
48public:
55
56 explicit FormWindow(FormEditor *core, QWidget *parent = nullptr, Qt::WindowFlags flags = {});
58
59 QDesignerFormEditorInterface *core() const override;
60
62
63 // Overwritten: FormWindowBase
65
66 int toolCount() const override;
67 int currentTool() const override;
68 void setCurrentTool(int index) override;
69 QDesignerFormWindowToolInterface *tool(int index) const override;
70 void registerTool(QDesignerFormWindowToolInterface *tool) override;
71
72 QString author() const override;
73 void setAuthor(const QString &author) override;
74
75 QString comment() const override;
76 void setComment(const QString &comment) override;
77
78 void layoutDefault(int *margin, int *spacing) override;
79 void setLayoutDefault(int margin, int spacing) override;
80
81 void layoutFunction(QString *margin, QString *spacing) override;
82 void setLayoutFunction(const QString &margin, const QString &spacing) override;
83
84 QString pixmapFunction() const override;
85 void setPixmapFunction(const QString &pixmapFunction) override;
86
87 QString exportMacro() const override;
88 void setExportMacro(const QString &exportMacro) override;
89
90 QStringList includeHints() const override;
91 void setIncludeHints(const QStringList &includeHints) override;
92
93 QString fileName() const override;
94 void setFileName(const QString &fileName) override;
95
96 QString contents() const override;
97 bool setContents(QIODevice *dev, QString *errorMessage = nullptr) override;
98 bool setContents(const QString &) override;
99
100 QDir absoluteDir() const override;
101
102 void simplifySelection(QWidgetList *sel) const override;
103
104 void ensureUniqueObjectName(QObject *object) override;
105
107 void setMainContainer(QWidget *mainContainer) override;
108 bool isMainContainer(const QWidget *w) const;
109
110 QWidget *currentWidget() const;
111
112 bool hasInsertedChildren(QWidget *w) const;
113
115 void clearSelection(bool changePropertyDisplay = true) override;
116 bool isWidgetSelected(QWidget *w) const;
117 void selectWidget(QWidget *w, bool select = true) override;
118
119 void selectWidgets();
120 void repaintSelection();
121 void updateSelection(QWidget *w);
124 void raiseSelection(QWidget *w);
125
126 inline const QWidgetList& widgets() const { return m_widgets; }
127 inline int widgetCount() const { return m_widgets.size(); }
128 inline QWidget *widgetAt(int index) const { return m_widgets.at(index); }
129
130 QWidgetList widgets(QWidget *widget) const;
131
132 QWidget *createWidget(DomUI *ui, QRect rect, QWidget *target);
133
134 bool isManaged(QWidget *w) const override;
135
138
139 QUndoStack *commandHistory() const override;
140 void beginCommand(const QString &description) override;
141 void endCommand() override;
142
143 bool blockSelectionChanged(bool blocked) override;
145
146 bool unify(QObject *w, QString &s, bool changeIt);
147
148 bool isDirty() const override;
149 void setDirty(bool dirty) override;
150
152
153 virtual QWidget *containerAt(const QPoint &pos);
154 QWidget *widgetAt(const QPoint &pos) override;
155 void highlightWidget(QWidget *w, const QPoint &pos, HighlightMode mode = Highlight) override;
156
158
159 bool handleEvent(QWidget *widget, QWidget *managedWidget, QEvent *event);
160
161 QStringList resourceFiles() const override;
162 void addResourceFile(const QString &path) override;
163 void removeResourceFile(const QString &path) override;
164
165 void resizeWidget(QWidget *widget, QRect geometry);
166
167 bool dropDockWidget(QDesignerDnDItemInterface *item, QPoint global_mouse_pos);
168 bool dropWidgets(const QList<QDesignerDnDItemInterface*> &item_list, QWidget *target,
169 const QPoint &global_mouse_pos) override;
170
171 QWidget *findContainer(QWidget *w, bool excludeLayout) const override;
172 // for WidgetSelection only.
173 QWidget *designerWidget(QWidget *w) const;
174
175 // Initialize and return a popup menu for a managed widget
176 QMenu *initializePopupMenu(QWidget *managedWidget) override;
177
178#if QT_CONFIG(clipboard)
180#endif
181 QEditorFormBuilder *createFormBuilder() override;
182
183 bool eventFilter(QObject *watched, QEvent *event) override;
184
185 HandleOperation handleOperation() const { return m_handleOperation; }
186 void setHandleOperation(HandleOperation o) { m_handleOperation = o; }
187
188signals:
190
191public slots:
192 void deleteWidgets();
193 void raiseWidgets();
194 void lowerWidgets();
195#if QT_CONFIG(clipboard)
196 void copy();
197 void cut();
198 void paste();
199#endif
200 void selectAll();
201
202 void createLayout(int type, QWidget *container = nullptr);
203 void morphLayout(QWidget *container, int newType);
204 void breakLayout(QWidget *w);
205
206 void editContents();
207
208protected:
209 virtual QMenu *createPopupMenu(QWidget *w);
210 void resizeEvent(QResizeEvent *e) override;
211
212 void insertWidget(QWidget *w, QRect rect, QWidget *target, bool already_in_form = false);
213
214private slots:
216 void checkSelection();
217 void checkSelectionNow();
218 void slotSelectWidget(QAction *);
219 void slotCleanChanged(bool);
220
221private:
222 enum MouseState {
223 NoMouseState,
224 // Double click received
225 MouseDoubleClicked,
226 // Drawing selection rubber band rectangle
227 MouseDrawRubber,
228 // Started a move operation
229 MouseMoveDrag,
230 // Click on a widget whose parent is selected. Defer selection to release
231 MouseDeferredSelection
232 };
233 MouseState m_mouseState;
234 QPointer<QWidget> m_lastClickedWidget;
235
236 void init();
237 void initializeCoreTools();
238
239 int getValue(QRect rect, int key, bool size) const;
240 int calcValue(int val, bool forward, bool snap, int snapOffset) const;
241 void handleClickSelection(QWidget *managedWidget, unsigned mouseFlags);
242
243 bool frameNeeded(QWidget *w) const;
244
245 enum RectType { Insert, Rubber };
246
247 void startRectDraw(QPoint global, QWidget *, RectType t);
248 void continueRectDraw(QPoint global, QWidget *, RectType t);
249 void endRectDraw();
250
251 QWidget *containerAt(QPoint pos, QWidget *notParentOf);
252
253 void checkPreviewGeometry(QRect &r);
254
255 bool handleContextMenu(QWidget *widget, QWidget *managedWidget, QContextMenuEvent *e);
256 bool handleMouseButtonDblClickEvent(QWidget *widget, QWidget *managedWidget, QMouseEvent *e);
257 bool handleMousePressEvent(QWidget *widget, QWidget *managedWidget, QMouseEvent *e);
258 bool handleMouseMoveEvent(QWidget *widget, QWidget *managedWidget, QMouseEvent *e);
259 bool handleMouseReleaseEvent(QWidget *widget, QWidget *managedWidget, QMouseEvent *e);
260 bool handleKeyPressEvent(QWidget *widget, QWidget *managedWidget, QKeyEvent *e);
261 bool handleKeyReleaseEvent(QWidget *widget, QWidget *managedWidget, QKeyEvent *e);
262
263 bool isCentralWidget(QWidget *w) const;
264
265 bool setCurrentWidget(QWidget *currentWidget);
266 bool trySelectWidget(QWidget *w, bool select);
267
268 void dragWidgetWithinForm(QWidget *widget, QRect targetGeometry, QWidget *targetContainer);
269
270 void setCursorToAll(const QCursor &c, QWidget *start);
271
272 QPoint mapToForm(const QWidget *w, QPoint pos) const;
273 bool canBeBuddy(QWidget *w) const;
274
275 QWidget *findTargetContainer(QWidget *widget) const;
276
277 void clearMainContainer();
278
279 static int widgetDepth(const QWidget *w);
280 static bool isChildOf(const QWidget *c, const QWidget *p);
281
282 void editWidgets() override;
283
284 void updateWidgets();
285
286 void handleArrowKeyEvent(int key, Qt::KeyboardModifiers modifiers);
287
288 void layoutSelection(int type);
289 void layoutContainer(QWidget *w, int type);
290
291private:
292 QWidget *innerContainer(QWidget *outerContainer) const;
293 QWidget *containerForPaste() const;
294 QAction *createSelectAncestorSubMenu(QWidget *w);
295 void selectSingleWidget(QWidget *w);
296
297 FormEditor *m_core;
298 FormWindowCursor *m_cursor;
299 QWidget *m_mainContainer = nullptr;
300 QWidget *m_currentWidget = nullptr;
301
302 bool m_blockSelectionChanged = false;
303
304 QPoint m_rectAnchor;
305 QRect m_currRect;
306
307 QWidgetList m_widgets;
308 QSet<QWidget*> m_insertedWidgets;
309
310 class Selection;
311 Selection *m_selection;
312
313 QPoint m_startPos;
314
315 QUndoStack m_undoStack;
316
317 QString m_fileName;
318
319 using PaletteAndFill = std::pair<QPalette, bool>;
320 QHash<QWidget *, PaletteAndFill> m_palettesBeforeHighlight;
321
322 QRubberBand *m_rubberBand = nullptr;
323
324 QTimer *m_selectionChangedTimer = nullptr;
325 QTimer *m_checkSelectionTimer = nullptr;
326 QTimer *m_geometryChangedTimer = nullptr;
327
328 FormWindowWidgetStack *m_widgetStack;
329 WidgetEditorTool *m_widgetEditor = nullptr;
330
331 QStringList m_resourceFiles;
332
333 QString m_comment;
334 QString m_author;
335 QString m_pixmapFunction;
336 int m_defaultMargin, m_defaultSpacing;
337 QString m_marginFunction, m_spacingFunction;
338 QString m_exportMacro;
339 QStringList m_includeHints;
340
341 QPoint m_contextMenuPosition;
342 HandleOperation m_handleOperation = NoHandleOperation;
343
344private:
345 friend class WidgetEditorTool;
346};
347
348} // namespace qdesigner_internal
349
350QT_END_NAMESPACE
351
352#endif // FORMWINDOW_H
friend class QWidget
Definition qpainter.h:421
void raiseList(const QWidgetList &l)
WidgetSelection * addWidget(FormWindow *fw, QWidget *w)
static FormWindow * findFormWindow(QWidget *w)
void layoutFunction(QString *margin, QString *spacing) override
Fills in the current margin and spacing for the form's layout in the margin and spacing variables spe...
QWidgetList widgets(QWidget *widget) const
void simplifySelection(QWidgetList *sel) const override
Simplifies the selection of widgets specified by widgets.
void removeResourceFile(const QString &path) override
Removes the resource file at the specified path from the list of those used by the form.
QDesignerFormEditorInterface * core() const override
Returns a pointer to \QD's current QDesignerFormEditorInterface object.
void setPixmapFunction(const QString &pixmapFunction) override
Sets the function used to load pixmaps into the form window to the given pixmapFunction.
void editWidgets() override
Switches the form window into editing mode.
QMenu * initializePopupMenu(QWidget *managedWidget) override
void insertWidget(QWidget *w, QRect rect, QWidget *target, bool already_in_form=false)
HandleOperation handleOperation() const
Definition formwindow.h:185
bool setContents(const QString &) override
Sets the contents of the form using data read from the specified contents string and returns whether ...
void setLayoutDefault(int margin, int spacing) override
Sets the default margin and spacing for the form's layout.
QWidget * createWidget(DomUI *ui, QRect rect, QWidget *target)
QString pixmapFunction() const override
Returns the name of the function used to load pixmaps into the form window.
void setMainContainer(QWidget *mainContainer) override
Sets the main container widget on the form to the specified mainContainer.
void beginCommand(const QString &description) override
Begins execution of a command with the given description.
void setHandleOperation(HandleOperation o)
Definition formwindow.h:186
void highlightWidget(QWidget *w, const QPoint &pos, HighlightMode mode=Highlight) override
void resizeEvent(QResizeEvent *e) override
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
void layoutDefault(int *margin, int *spacing) override
Fills in the default margin and spacing for the form's default layout in the margin and spacing varia...
const QWidgetList & widgets() const
Definition formwindow.h:126
void createLayout(int type, QWidget *container=nullptr)
bool eventFilter(QObject *watched, QEvent *event) override
Filters events if this object has been installed as an event filter for the watched object.
QWidget * mainContainer() const override
Returns the main container widget for the form window.
QWidget * designerWidget(QWidget *w) const
bool isDirty() const override
Returns true if the form window is "dirty" (modified but not saved); otherwise returns false.
QDir absoluteDir() const override
Returns the absolute location of the directory containing the form shown in the form window.
void unmanageWidget(QWidget *w) override
Instructs the form window not to manage the specified widget.
QUndoStack * commandHistory() const override
Returns an object that can be used to obtain the commands used so far in the construction of the form...
QEditorFormBuilder * createFormBuilder() override
QStringList resourceFiles() const override
Returns a list of paths to resource files that are currently being used by the form window.
void setLayoutFunction(const QString &margin, const QString &spacing) override
Sets the margin and spacing for the form's layout.
QWidget * currentWidget() const
void endCommand() override
Ends execution of the current command.
QStringList includeHints() const override
Returns a list of the header files that will be included in the form window's associated UI file.
bool handleEvent(QWidget *widget, QWidget *managedWidget, QEvent *event)
QString contents() const override
Returns details of the contents of the form currently being displayed in the window.
bool blockSelectionChanged(bool blocked) override
QString exportMacro() const override
Returns the export macro associated with the form currently being displayed in the window.
void clearSelection(bool changePropertyDisplay=true) override
Clears the current selection in the form window.
void addResourceFile(const QString &path) override
Adds the resource file at the given path to those used by the form.
void manageWidget(QWidget *w) override
Instructs the form window to manage the specified widget.
void ensureUniqueObjectName(QObject *object) override
Ensures that the specified object has a unique name amongst the other objects on the form.
QWidgetList selectedWidgets() const
FormWindow(FormEditor *core, QWidget *parent=nullptr, Qt::WindowFlags flags={})
int toolCount() const override
Returns the number of tools available.
void raiseChildSelections(QWidget *w)
QWidget * widgetAt(int index) const
Definition formwindow.h:128
bool setContents(QIODevice *dev, QString *errorMessage=nullptr) override
Sets the form's contents using data obtained from the given device and returns whether loading succee...
void setExportMacro(const QString &exportMacro) override
Sets the form window's export macro to exportMacro.
void registerTool(QDesignerFormWindowToolInterface *tool) override
Registers the given tool with the form window.
void setComment(const QString &comment) override
Sets the information about the form to the comment specified.
bool isMainContainer(const QWidget *w) const
QWidget * formContainer() const override
Returns the form the widget containing the main container widget.
int currentTool() const override
Returns the index of the current tool in use.
virtual QWidget * containerAt(const QPoint &pos)
void setAuthor(const QString &author) override
Sets the details for the author or creator of the form to the author specified.
void setIncludeHints(const QStringList &includeHints) override
Sets the header files that will be included in the form window's associated UI file to the specified ...
void selectWidget(QWidget *w, bool select=true) override
If select is true, the given widget is selected; otherwise the widget is deselected.
void setDirty(bool dirty) override
If dirty is true, the form window is marked as dirty, meaning that it is modified but not saved.
bool unify(QObject *w, QString &s, bool changeIt)
virtual QMenu * createPopupMenu(QWidget *w)
bool dropWidgets(const QList< QDesignerDnDItemInterface * > &item_list, QWidget *target, const QPoint &global_mouse_pos) override
QWidget * widgetAt(const QPoint &pos) override
void emitSelectionChanged() override
Emits the selectionChanged() signal.
QDesignerFormWindowCursorInterface * cursor() const override
Returns the cursor interface used by the form window.
QWidget * findContainer(QWidget *w, bool excludeLayout) const override
bool isWidgetSelected(QWidget *w) const
void updateChildSelections(QWidget *w)
QString author() const override
Returns details of the author or creator of the form currently being displayed in the window.
void setFileName(const QString &fileName) override
Sets the file name for the form to the given fileName.
bool hasInsertedChildren(QWidget *w) const
bool isManaged(QWidget *w) const override
Returns true if the specified widget is managed by the form window; otherwise returns false.
QDesignerFormWindowToolInterface * tool(int index) const override
Returns an interface to the tool with the given index.
bool dropDockWidget(QDesignerDnDItemInterface *item, QPoint global_mouse_pos)
void morphLayout(QWidget *container, int newType)
QString comment() const override
Returns comments about the form currently being displayed in the window.
void resizeWidget(QWidget *widget, QRect geometry)
void setCurrentTool(int index) override
Sets the current tool to be the one with the given index.
QString fileName() const override
Returns the file name of the UI file that describes the form currently being shown.
#define QT_FORMEDITOR_EXPORT
Auxiliary methods to store/retrieve settings.
static unsigned mouseFlags(Qt::KeyboardModifiers mod)
static void insertNames(const QDesignerMetaDataBaseInterface *metaDataBase, Iterator it, const Iterator &end, QObject *excludedObject, QSet< QString > &nameSet)
static void clearObjectInspectorSelection(const QDesignerFormEditorInterface *core)
static bool canDragWidgetInLayout(const QDesignerFormEditorInterface *core, QWidget *w)
static bool isDescendant(const QWidget *parent, const QWidget *child)
static QSet< QString > languageKeywords()
static QWidget * findSelectedParent(QDesignerFormWindowInterface *fw, const QWidget *w, bool selected)