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
qlayout_widget_p.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//
5// W A R N I N G
6// -------------
7//
8// This file is not part of the Qt API. It exists for the convenience
9// of Qt Designer. This header
10// file may change from version to version without notice, or even be removed.
11//
12// We mean it.
13//
14
15#ifndef QLAYOUT_WIDGET_H
16#define QLAYOUT_WIDGET_H
17
19
20#include <QtDesigner/layoutdecoration.h>
21
22#include <QtCore/qpointer.h>
23#include <QtCore/qvariant.h>
24#include <QtWidgets/qwidget.h>
25#include <QtWidgets/qlayout.h>
26
28
29class QDesignerFormWindowInterface;
30class QDesignerFormEditorInterface;
31class QGridLayout;
32class QFormLayout;
33
34namespace qdesigner_internal {
35// ---- LayoutProperties: Helper struct that stores all layout-relevant properties
36// with functions to retrieve and apply to property sheets. Can be used to store the state
37// for undo commands and while rebuilding layouts.
39{
41 void clear();
42
45
55
56 // return a PropertyMask of visible properties
57 static int visibleProperties(const QLayout *layout);
58
59 // Retrieve from /apply to sheet: A property mask is returned indicating the properties found in the sheet
60 int fromPropertySheet(const QDesignerFormEditorInterface *core, QLayout *l, int mask = AllProperties);
61 int toPropertySheet(const QDesignerFormEditorInterface *core, QLayout *l, int mask = AllProperties, bool applyChanged = true) const;
62
65
68
69 QVariant m_objectName; // receives a PropertySheetStringValue
73
82
85
88
91
94
97};
98
99// -- LayoutHelper: For use with the 'insert widget'/'delete widget' command,
100// able to store and restore states.
101// This could become part of 'QDesignerLayoutDecorationExtensionV2',
102// but to keep any existing old extensions working, it is provided as
103// separate class with a factory function.
105protected:
107
108public:
110
111 virtual ~LayoutHelper();
112
113 static LayoutHelper *createLayoutHelper(int type);
114
115 static int indexOf(const QLayout *lt, const QWidget *widget);
116
117 // Return area of an item (x == columns)
118 QRect itemInfo(QLayout *lt, const QWidget *widget) const;
119
120 virtual QRect itemInfo(QLayout *lt, int index) const = 0;
121 virtual void insertWidget(QLayout *lt, const QRect &info, QWidget *w) = 0;
122 virtual void removeWidget(QLayout *lt, QWidget *widget) = 0;
123 // Since 4.5: The 'morphing' feature requires an API for replacing widgets on layouts.
124 virtual void replaceWidget(QLayout *lt, QWidget *before, QWidget *after) = 0;
125
126 // Simplify a grid, remove empty columns, rows within the rectangle
127 // The DeleteWidget command restricts the area to be simplified.
128 virtual bool canSimplify(const QDesignerFormEditorInterface *core, const QWidget *widgetWithManagedLayout, const QRect &restrictionArea) const = 0;
129 virtual void simplify(const QDesignerFormEditorInterface *core, QWidget *widgetWithManagedLayout, const QRect &restrictionArea) = 0;
130
131 // Push and pop a state. Can be used for implementing undo for
132 // simplify/row, column insertion commands, provided that
133 // the widgets remain the same.
134 virtual void pushState(const QDesignerFormEditorInterface *core, const QWidget *widgetWithManagedLayout) = 0;
135 virtual void popState(const QDesignerFormEditorInterface *core, QWidget *widgetWithManagedLayout) = 0;
136};
137
138// Base class for layout decoration extensions.
139class QDESIGNER_SHARED_EXPORT QLayoutSupport: public QObject, public QDesignerLayoutDecorationExtension
140{
141 Q_OBJECT
142 Q_INTERFACES(QDesignerLayoutDecorationExtension)
143
144protected:
145 QLayoutSupport(QDesignerFormWindowInterface *formWindow, QWidget *widget, LayoutHelper *helper, QObject *parent = nullptr);
146
147public:
148 ~QLayoutSupport() override;
149
150 inline QDesignerFormWindowInterface *formWindow() const { return m_formWindow; }
151
152 // DecorationExtension V2
153 LayoutHelper* helper() const { return m_helper; }
154
155 // DecorationExtension
156 int currentIndex() const override { return m_currentIndex; }
157
158 InsertMode currentInsertMode() const override { return m_currentInsertMode; }
159
160 std::pair<int, int> currentCell() const override { return m_currentCell; }
161
162 int findItemAt(const QPoint &pos) const override;
163 int indexOf(QWidget *widget) const override;
164 int indexOf(QLayoutItem *item) const override;
165
166 void adjustIndicator(const QPoint &pos, int index) override;
167
168 QWidgetList widgets(QLayout *layout) const override;
169
170 // Pad empty cells with dummy spacers. Called by layouting commands.
171 static void createEmptyCells(QGridLayout *gridLayout);
172 // remove dummy spacers in the area. Returns false if there are non-empty items in the way
173 static bool removeEmptyCells(QGridLayout *gridLayout, const QRect &area);
174 static void createEmptyCells(QFormLayout *formLayout); // ditto.
175 static bool removeEmptyCells(QFormLayout *formLayout, const QRect &area);
176
177 // grid helpers: find item index
178 static int findItemAt(QGridLayout *, int row, int column);
179 using QDesignerLayoutDecorationExtension::findItemAt;
180 // grid helpers: Quick check whether simplify should be enabled for grids. May return false positives.
181 static bool canSimplifyQuickCheck(const QGridLayout *);
182 static bool canSimplifyQuickCheck(const QFormLayout *fl);
183 // Factory function, create layout support according to layout type of widget
184 static QLayoutSupport *createLayoutSupport(QDesignerFormWindowInterface *formWindow, QWidget *widget, QObject *parent = nullptr);
185
186protected:
187 // figure out insertion position and mode from indicator on empty cell if supported
188 virtual void setCurrentCellFromIndicatorOnEmptyCell(int index) = 0;
189 // figure out insertion position and mode from indicator
190 virtual void setCurrentCellFromIndicator(Qt::Orientation indicatorOrientation, int index, int increment) = 0;
191
192 // Overwrite to return the extended geometry of an item, that is,
193 // if it is a border item, include the widget border for the indicator to work correctly
194 virtual QRect extendedGeometry(int index) const = 0;
195 virtual bool supportsIndicatorOrientation(Qt::Orientation indicatorOrientation) const = 0;
196
197 QRect itemInfo(int index) const override;
198 QLayout *layout() const;
199 QGridLayout *gridLayout() const;
200 QWidget *widget() const { return m_widget; }
201
202 void setInsertMode(InsertMode im);
203 void setCurrentCell(const std::pair<int, int> &cell);
204
205private:
206 enum Indicator { LeftIndicator, TopIndicator, RightIndicator, BottomIndicator, NumIndicators };
207
208 void hideIndicator(Indicator i);
209 void showIndicator(Indicator i, const QRect &geometry, const QPalette &);
210
211 QDesignerFormWindowInterface *m_formWindow;
212 LayoutHelper* m_helper;
213
214 QPointer<QWidget> m_widget;
215 QPointer<QWidget> m_indicators[NumIndicators];
216 int m_currentIndex;
217 InsertMode m_currentInsertMode;
218 std::pair<int, int> m_currentCell;
219};
220} // namespace qdesigner_internal
221
222// Red layout widget.
224{
225 Q_OBJECT
226public:
227 explicit QLayoutWidget(QDesignerFormWindowInterface *formWindow, QWidget *parent = nullptr);
228
229 int layoutLeftMargin() const;
230 void setLayoutLeftMargin(int layoutMargin);
231
232 int layoutTopMargin() const;
233 void setLayoutTopMargin(int layoutMargin);
234
235 int layoutRightMargin() const;
236 void setLayoutRightMargin(int layoutMargin);
237
238 int layoutBottomMargin() const;
239 void setLayoutBottomMargin(int layoutMargin);
240
241 inline QDesignerFormWindowInterface *formWindow() const { return m_formWindow; }
242
243protected:
244 bool event(QEvent *e) override;
245 void paintEvent(QPaintEvent *e) override;
246
247private:
248 QDesignerFormWindowInterface *m_formWindow;
249 int m_leftMargin;
250 int m_topMargin;
251 int m_rightMargin;
252 int m_bottomMargin;
253};
254
255QT_END_NAMESPACE
256
257#endif // QDESIGNER_WIDGET_H
static bool canBeBuddy(QWidget *w, QDesignerFormWindowInterface *form)
static QString buddy(QLabel *label, QDesignerFormEditorInterface *core)
static constexpr auto buddyPropertyC
#define QT_BUDDYEDITOR_EXPORT
The QDesignerMetaDataBaseItemInterface class provides an interface to individual items in \QD's meta ...
friend class QWidget
Definition qpainter.h:421
void init(QWidget *parentWidget, QAction *action, QAction *beforeAction=nullptr, bool update=true)
ActionInsertionCommand(const QString &text, QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
AddMenuActionCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
AddStackedWidgetPageCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void init(QStackedWidget *stackedWidget, InsertionMode mode)
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
void init(QTabWidget *tabWidget, InsertionMode mode)
AddTabPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
AddToolBarCommand(QDesignerFormWindowInterface *formWindow)
void init(QMainWindow *mainWindow, Qt::ToolBarArea area)
void undo() override
Reverts a change to the document.
AddToolBoxPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void init(QToolBox *toolBox, InsertionMode mode)
void undo() override
Reverts a change to the document.
void setBackground(QWidget *background) override
QDesignerFormWindowInterface * formWindow() const
void endConnection(QWidget *target, const QPoint &pos) override
void widgetRemoved(QWidget *w) override
QWidget * widgetAt(const QPoint &pos) const override
Connection * createConnection(QWidget *source, QWidget *destination) override
void createContextMenu(QMenu &menu) override
CreateMenuBarCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
CreateStatusBarCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void init(QDesignerMenu *menu, QAction *action, QObject *m_objectToSelect=nullptr)
CreateSubmenuCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void restore(QDesignerFormWindowInterface *formWindow) const
void save(const QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
DeleteMenuBarCommand(QDesignerFormWindowInterface *formWindow)
DeleteStackedWidgetPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
DeleteTabPageCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
DeleteToolBarCommand(QDesignerFormWindowInterface *formWindow)
DeleteToolBoxPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
DockWidgetCommand(const QString &description, QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
InsertActionIntoCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
static LayoutHelper * createLayoutHelper(int type)
void init(QAction *action, QAction *actionBefore, QWidget *associatedWidget, QWidget *objectToSelect)
MenuActionCommand(const QString &text, QDesignerFormWindowInterface *formWindow)
const KeyToValueMap & keyToValueMap() const
const QStringList & keys() const
const QString & scope() const
void addKey(IntType value, const QString &name)
const QString & enumName() const
IntType keyToValue(QStringView key, bool *ok=nullptr) const
void appendQualifiedName(const QString &key, SerializationMode sm, QString &target) const
const QString & separator() const
QString valueToKey(IntType value, bool *ok=nullptr) const
MetaEnum(const QString &enumName, const QString &scope, const QString &separator)
void init(QStackedWidget *stackedWidget, QWidget *page, int newIndex)
MoveStackedWidgetCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
MoveTabPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void init(QTabWidget *tabWidget, QWidget *page, const QIcon &icon, const QString &label, int index, int newIndex)
MoveToolBoxPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void init(QToolBox *toolBox, QWidget *page, int newIndex)
void undo() override
Reverts a change to the document.
QDesignerIntegration * integration(QDesignerFormWindowInterface *fw) const
PropertyHelper(QObject *object, SpecialProperty specialProperty, QDesignerPropertySheetExtension *sheet, int index)
void setOldValue(const QVariant &oldValue)
Value restoreDefaultValue(QDesignerFormWindowInterface *fw)
Value restoreOldValue(QDesignerFormWindowInterface *fw)
bool canMerge(const PropertyHelper &other) const
virtual Value setValue(QDesignerFormWindowInterface *fw, const QVariant &value, bool changed, quint64 subPropertyMask)
RemoveActionFromCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
RemoveMenuActionCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
StackedWidgetCommand(QDesignerFormWindowInterface *formWindow)
void init(QStackedWidget *stackedWidget)
TabWidgetCommand(QDesignerFormWindowInterface *formWindow)
ToolBoxCommand(QDesignerFormWindowInterface *formWindow)
Combined button and popup list for selecting options.
int valueOf(const QVariant &value, bool *ok=nullptr)
bool isObjectAncestorOf(QObject *ancestor, QObject *child)
bool isCentralWidget(QDesignerFormWindowInterface *fw, QWidget *widget)
Auxiliary methods to store/retrieve settings.
QDESIGNER_SHARED_EXPORT void getFormLayoutItemPosition(const QFormLayout *formLayout, int index, int *rowPtr, int *columnPtr=nullptr, int *rowspanPtr=nullptr, int *colspanPtr=nullptr)
QDESIGNER_SHARED_EXPORT QDebug operator<<(QDebug, const PropertySheetIconValue &)
static QUndoCommand * createBuddyCommand(QDesignerFormWindowInterface *fw, QLabel *label, QWidget *buddy)
QDESIGNER_SHARED_EXPORT void formLayoutAddWidget(QFormLayout *formLayout, QWidget *w, const QRect &r, bool insert)
QDESIGNER_SHARED_EXPORT void designerWarning(const QString &message)
QDESIGNER_SHARED_EXPORT void reloadIconResources(DesignerIconCache *iconCache, QObject *object)
QDESIGNER_SHARED_EXPORT bool runUIC(const QString &fileName, UicLanguage language, QByteArray &ba, QString &errorMessage)
#define QDESIGNER_SHARED_EXPORT