1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Designer of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | // |
30 | // W A R N I N G |
31 | // ------------- |
32 | // |
33 | // This file is not part of the Qt API. It exists for the convenience |
34 | // of Qt Designer. This header |
35 | // file may change from version to version without notice, or even be removed. |
36 | // |
37 | // We mean it. |
38 | // |
39 | |
40 | |
41 | #ifndef WIDGETFACTORY_H |
42 | #define WIDGETFACTORY_H |
43 | |
44 | #include "shared_global_p.h" |
45 | #include "pluginmanager_p.h" |
46 | |
47 | #include <QtDesigner/abstractwidgetfactory.h> |
48 | |
49 | #include <QtCore/qmap.h> |
50 | #include <QtCore/qhash.h> |
51 | #include <QtCore/qvariant.h> |
52 | |
53 | QT_BEGIN_NAMESPACE |
54 | |
55 | class QObject; |
56 | class QWidget; |
57 | class QLayout; |
58 | class QDesignerFormEditorInterface; |
59 | class QDesignerCustomWidgetInterface; |
60 | class QDesignerFormWindowInterface; |
61 | class QStyle; |
62 | |
63 | namespace qdesigner_internal { |
64 | |
65 | class QDESIGNER_SHARED_EXPORT WidgetFactory: public QDesignerWidgetFactoryInterface |
66 | { |
67 | Q_OBJECT |
68 | public: |
69 | explicit WidgetFactory(QDesignerFormEditorInterface *core, QObject *parent = nullptr); |
70 | ~WidgetFactory(); |
71 | |
72 | QWidget* containerOfWidget(QWidget *widget) const override; |
73 | QWidget* widgetOfContainer(QWidget *widget) const override; |
74 | |
75 | QObject* createObject(const QString &className, QObject* parent) const; |
76 | |
77 | QWidget *createWidget(const QString &className, QWidget *parentWidget) const override; |
78 | QLayout *createLayout(QWidget *widget, QLayout *layout, int type) const override; |
79 | |
80 | bool isPassiveInteractor(QWidget *widget) override; |
81 | void initialize(QObject *object) const override; |
82 | void initializeCommon(QWidget *object) const; |
83 | void initializePreview(QWidget *object) const; |
84 | |
85 | |
86 | QDesignerFormEditorInterface *core() const override; |
87 | |
88 | static QString classNameOf(QDesignerFormEditorInterface *core, const QObject* o); |
89 | |
90 | QDesignerFormWindowInterface *currentFormWindow(QDesignerFormWindowInterface *fw); |
91 | |
92 | static QLayout *createUnmanagedLayout(QWidget *parentWidget, int type); |
93 | |
94 | // The widget factory maintains a cache of styles which it owns. |
95 | QString styleName() const; |
96 | void setStyleName(const QString &styleName); |
97 | |
98 | /* Return a cached style matching the name or QApplication's style if |
99 | * it is the default. */ |
100 | QStyle *getStyle(const QString &styleName); |
101 | // Return the current style used by the factory. This either a cached one |
102 | // or QApplication's style */ |
103 | QStyle *style() const; |
104 | |
105 | // Apply one of the cached styles or QApplication's style to a toplevel widget. |
106 | void applyStyleTopLevel(const QString &styleName, QWidget *w); |
107 | static void applyStyleToTopLevel(QStyle *style, QWidget *widget); |
108 | |
109 | // Return whether object was created by the factory for the form editor. |
110 | static bool isFormEditorObject(const QObject *o); |
111 | |
112 | // Boolean dynamic property to set on widgets to prevent custom |
113 | // styles from interfering |
114 | static const char *disableStyleCustomPaintingPropertyC; |
115 | |
116 | public slots: |
117 | void loadPlugins(); |
118 | void activeFormWindowChanged(QDesignerFormWindowInterface *formWindow); |
119 | void formWindowAdded(QDesignerFormWindowInterface *formWindow); |
120 | |
121 | private: |
122 | struct Strings { // Reduce string allocations by storing predefined strings |
123 | Strings(); |
124 | const QString m_alignment; |
125 | const QString m_bottomMargin; |
126 | const QString m_geometry; |
127 | const QString m_leftMargin; |
128 | const QString m_line; |
129 | const QString m_objectName; |
130 | const QString m_spacerName; |
131 | const QString m_orientation; |
132 | const QString m_qAction; |
133 | const QString m_qButtonGroup; |
134 | const QString m_qAxWidget; |
135 | const QString m_qDialog; |
136 | const QString m_qDockWidget; |
137 | const QString m_qLayoutWidget; |
138 | const QString ; |
139 | const QString ; |
140 | const QString m_qWidget; |
141 | const QString m_rightMargin; |
142 | const QString m_sizeHint; |
143 | const QString m_spacer; |
144 | const QString m_text; |
145 | const QString m_title; |
146 | const QString m_topMargin; |
147 | const QString m_windowIcon; |
148 | const QString m_windowTitle; |
149 | }; |
150 | |
151 | QWidget* createCustomWidget(const QString &className, QWidget *parentWidget, bool *creationError) const; |
152 | QDesignerFormWindowInterface *findFormWindow(QWidget *parentWidget) const; |
153 | void setFormWindowStyle(QDesignerFormWindowInterface *formWindow); |
154 | |
155 | const Strings m_strings; |
156 | QDesignerFormEditorInterface *m_core; |
157 | using CustomWidgetFactoryMap = QMap<QString, QDesignerCustomWidgetInterface*>; |
158 | CustomWidgetFactoryMap m_customFactory; |
159 | QDesignerFormWindowInterface *m_formWindow; |
160 | |
161 | // Points to the cached style or 0 if the default (qApp) is active |
162 | QStyle *m_currentStyle; |
163 | using StyleCache = QHash<QString, QStyle *>; |
164 | StyleCache m_styleCache; |
165 | }; |
166 | |
167 | } // namespace qdesigner_internal |
168 | |
169 | QT_END_NAMESPACE |
170 | |
171 | #endif // WIDGETFACTORY_H |
172 | |