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// Qt-Security score:significant reason:default
4
5#ifndef FORMWINDOW_H
6#define FORMWINDOW_H
7
9#include <formwindowbase_p.h>
10
11// Qt
12#include <QtGui/qundostack.h>
13#include <QtCore/qhash.h>
14#include <QtCore/qlist.h>
15#include <QtCore/qset.h>
16#include <QtCore/qpointer.h>
17
18#include <utility>
19
20QT_BEGIN_NAMESPACE
21
22class QDesignerDnDItemInterface;
23class QDesignerTaskMenuExtension;
24class DomConnections;
25class DomUI;
26
27class QWidget;
28class QAction;
29class QLabel;
30class QTimer;
31class QAction;
32class QMenu;
33class QRubberBand;
34
35namespace qdesigner_internal {
36
37class FormEditor;
43class SetPropertyCommand;
44
46{
48
49public:
56
57 explicit FormWindow(FormEditor *core, QWidget *parent = nullptr, Qt::WindowFlags flags = {});
59
60 QDesignerFormEditorInterface *core() const override;
61
63
64 // Overwritten: FormWindowBase
66
67 int toolCount() const override;
68 int currentTool() const override;
69 void setCurrentTool(int index) override;
70 QDesignerFormWindowToolInterface *tool(int index) const override;
71 void registerTool(QDesignerFormWindowToolInterface *tool) override;
72
73 QString author() const override;
74 void setAuthor(const QString &author) override;
75
76 QString comment() const override;
77 void setComment(const QString &comment) override;
78
79 void layoutDefault(int *margin, int *spacing) override;
80 void setLayoutDefault(int margin, int spacing) override;
81
82 void layoutFunction(QString *margin, QString *spacing) override;
83 void setLayoutFunction(const QString &margin, const QString &spacing) override;
84
85 QString pixmapFunction() const override;
86 void setPixmapFunction(const QString &pixmapFunction) override;
87
88 QString exportMacro() const override;
89 void setExportMacro(const QString &exportMacro) override;
90
91 QStringList includeHints() const override;
92 void setIncludeHints(const QStringList &includeHints) override;
93
94 QString fileName() const override;
95 void setFileName(const QString &fileName) override;
96
97 QString contents() const override;
98 bool setContents(QIODevice *dev, QString *errorMessage = nullptr) override;
99 bool setContents(const QString &) override;
100
101 QDir absoluteDir() const override;
102
103 void simplifySelection(QWidgetList *sel) const override;
104
105 void ensureUniqueObjectName(QObject *object) override;
106
108 void setMainContainer(QWidget *mainContainer) override;
109 bool isMainContainer(const QWidget *w) const;
110
111 QWidget *currentWidget() const;
112
113 bool hasInsertedChildren(QWidget *w) const;
114
116 void clearSelection(bool changePropertyDisplay = true) override;
117 bool isWidgetSelected(QWidget *w) const;
118 void selectWidget(QWidget *w, bool select = true) override;
119
120 void selectWidgets();
121 void repaintSelection();
122 void updateSelection(QWidget *w);
125 void raiseSelection(QWidget *w);
126
127 const QWidgetList& widgets() const { return m_widgets; }
128 int widgetCount() const { return m_widgets.size(); }
129 QWidget *widgetAt(int index) const { return m_widgets.at(index); }
130
131 QWidgetList widgets(QWidget *widget) const;
132
133 QWidget *createWidget(DomUI *ui, QRect rect, QWidget *target);
134
135 bool isManaged(QWidget *w) const override;
136
139
140 QUndoStack *commandHistory() const override;
141 void beginCommand(const QString &description) override;
142 void endCommand() override;
143
144 bool blockSelectionChanged(bool blocked) override;
146
147 bool unify(QObject *w, QString &s, bool changeIt);
148
149 bool isDirty() const override;
150 void setDirty(bool dirty) override;
151
153
154 virtual QWidget *containerAt(const QPoint &pos);
155 QWidget *widgetAt(const QPoint &pos) override;
156 void highlightWidget(QWidget *w, const QPoint &pos, HighlightMode mode = Highlight) override;
157
159
160 bool handleEvent(QWidget *widget, QWidget *managedWidget, QEvent *event);
161
162 QStringList resourceFiles() const override;
163 void addResourceFile(const QString &path) override;
164 void removeResourceFile(const QString &path) override;
165
166 void resizeWidget(QWidget *widget, QRect geometry);
167
168 bool dropDockWidget(QDesignerDnDItemInterface *item, QPoint global_mouse_pos);
169 bool dropWidgets(const QList<QDesignerDnDItemInterface*> &item_list, QWidget *target,
170 const QPoint &global_mouse_pos) override;
171
172 QWidget *findContainer(QWidget *w, bool excludeLayout) const override;
173 // for WidgetSelection only.
174 QWidget *designerWidget(QWidget *w) const;
175
176 // Initialize and return a popup menu for a managed widget
177 QMenu *initializePopupMenu(QWidget *managedWidget) override;
178
179#if QT_CONFIG(clipboard)
181#endif
182 QEditorFormBuilder *createFormBuilder() override;
183
184 bool eventFilter(QObject *watched, QEvent *event) override;
185
186 HandleOperation handleOperation() const { return m_handleOperation; }
187 void setHandleOperation(HandleOperation o) { m_handleOperation = o; }
188
189signals:
191
192public slots:
193 void deleteWidgets();
194 void raiseWidgets();
195 void lowerWidgets();
196#if QT_CONFIG(clipboard)
197 void copy();
198 void cut();
199 void paste();
200#endif
201 void selectAll();
202
203 void createLayout(int type, QWidget *container = nullptr);
204 void morphLayout(QWidget *container, int newType);
205 void breakLayout(QWidget *w);
206
207 void editContents();
208
209protected:
210 virtual QMenu *createPopupMenu(QWidget *w);
211 void resizeEvent(QResizeEvent *e) override;
212
213 void insertWidget(QWidget *w, QRect rect, QWidget *target, bool already_in_form = false);
214
215private slots:
217 void checkSelection();
218 void checkSelectionNow();
219 void slotSelectWidget(QAction *);
220 void slotCleanChanged(bool);
221
222private:
223 enum MouseState {
224 NoMouseState,
225 // Double click received
226 MouseDoubleClicked,
227 // Drawing selection rubber band rectangle
228 MouseDrawRubber,
229 // Started a move operation
230 MouseMoveDrag,
231 // Click on a widget whose parent is selected. Defer selection to release
232 MouseDeferredSelection
233 };
234 MouseState m_mouseState;
235 QPointer<QWidget> m_lastClickedWidget;
236
237 void init();
238 void initializeCoreTools();
239
240 int getValue(QRect rect, int key, bool size) const;
241 int calcValue(int val, bool forward, bool snap, int snapOffset) const;
242 void handleClickSelection(QWidget *managedWidget, unsigned mouseFlags);
243
244 bool frameNeeded(QWidget *w) const;
245
246 enum RectType { Insert, Rubber };
247
248 void startRectDraw(QPoint global, QWidget *, RectType t);
249 void continueRectDraw(QPoint global, QWidget *, RectType t);
250 void endRectDraw();
251
252 QWidget *containerAt(QPoint pos, QWidget *notParentOf);
253
254 void checkPreviewGeometry(QRect &r);
255
256 bool handleContextMenu(QWidget *widget, QWidget *managedWidget, QContextMenuEvent *e);
257 bool handleMouseButtonDblClickEvent(QWidget *widget, QWidget *managedWidget, QMouseEvent *e);
258 bool handleMousePressEvent(QWidget *widget, QWidget *managedWidget, QMouseEvent *e);
259 bool handleMouseMoveEvent(QWidget *widget, QWidget *managedWidget, QMouseEvent *e);
260 bool handleMouseReleaseEvent(QWidget *widget, QWidget *managedWidget, QMouseEvent *e);
261 bool handleKeyPressEvent(QWidget *widget, QWidget *managedWidget, QKeyEvent *e);
262 bool handleKeyReleaseEvent(QWidget *widget, QWidget *managedWidget, QKeyEvent *e);
263
264 bool isCentralWidget(QWidget *w) const;
265
266 bool setCurrentWidget(QWidget *currentWidget);
267 bool trySelectWidget(QWidget *w, bool select);
268
269 void dragWidgetWithinForm(QWidget *widget, QRect targetGeometry, QWidget *targetContainer);
270
271 void setCursorToAll(const QCursor &c, QWidget *start);
272
273 QPoint mapToForm(const QWidget *w, QPoint pos) const;
274 bool canBeBuddy(QWidget *w) const;
275
276 QWidget *findTargetContainer(QWidget *widget) const;
277
278 void clearMainContainer();
279
280 static int widgetDepth(const QWidget *w);
281 static bool isChildOf(const QWidget *c, const QWidget *p);
282
283 void editWidgets() override;
284
285 void updateWidgets();
286
287 void handleArrowKeyEvent(int key, Qt::KeyboardModifiers modifiers);
288
289 void layoutSelection(int type);
290 void layoutContainer(QWidget *w, int type);
291
292private:
293 QWidget *innerContainer(QWidget *outerContainer) const;
294 QWidget *containerForPaste() const;
295 QAction *createSelectAncestorSubMenu(QWidget *w);
296 void selectSingleWidget(QWidget *w);
297
298 FormEditor *m_core;
299 FormWindowCursor *m_cursor;
300 QWidget *m_mainContainer = nullptr;
301 QWidget *m_currentWidget = nullptr;
302
303 bool m_blockSelectionChanged = false;
304
305 QPoint m_rectAnchor;
306 QRect m_currRect;
307
308 QWidgetList m_widgets;
309 QSet<QWidget*> m_insertedWidgets;
310
311 class Selection;
312 Selection *m_selection;
313
314 QPoint m_startPos;
315
316 QUndoStack m_undoStack;
317
318 QString m_fileName;
319
320 using PaletteAndFill = std::pair<QPalette, bool>;
321 QHash<QWidget *, PaletteAndFill> m_palettesBeforeHighlight;
322
323 QRubberBand *m_rubberBand = nullptr;
324
325 QTimer *m_selectionChangedTimer = nullptr;
326 QTimer *m_checkSelectionTimer = nullptr;
327 QTimer *m_geometryChangedTimer = nullptr;
328
329 FormWindowWidgetStack *m_widgetStack;
330 WidgetEditorTool *m_widgetEditor = nullptr;
331
332 QStringList m_resourceFiles;
333
334 QString m_comment;
335 QString m_author;
336 QString m_pixmapFunction;
337 int m_defaultMargin, m_defaultSpacing;
338 QString m_marginFunction, m_spacingFunction;
339 QString m_exportMacro;
340 QStringList m_includeHints;
341
342 QPoint m_contextMenuPosition;
343 HandleOperation m_handleOperation = NoHandleOperation;
344
345private:
346 friend class WidgetEditorTool;
347};
348
349} // namespace qdesigner_internal
350
351QT_END_NAMESPACE
352
353#endif // FORMWINDOW_H
friend class QWidget
Definition qpainter.h:432
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:186
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:187
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:127
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:129
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)