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#ifndef QDESIGNER_FORMBUILDER_H
41#define QDESIGNER_FORMBUILDER_H
42
43#include "shared_global_p.h"
44#include "deviceprofile_p.h"
45
46#include <QtDesigner/formbuilder.h>
47
48#include <QtCore/qmap.h>
49#include <QtCore/qset.h>
50
51QT_BEGIN_NAMESPACE
52
53class QDesignerFormEditorInterface;
54class QDesignerFormWindowInterface;
55
56class QPixmap;
57class QtResourceSet;
58
59namespace qdesigner_internal {
60
61class DesignerPixmapCache;
62class DesignerIconCache;
63
64/* Form builder used for previewing forms and widget box.
65 * It applies the system settings to its toplevel window. */
66
67class QDESIGNER_SHARED_EXPORT QDesignerFormBuilder: public QFormBuilder
68{
69public:
70 QDesignerFormBuilder(QDesignerFormEditorInterface *core,
71 const DeviceProfile &deviceProfile = DeviceProfile());
72
73 virtual QWidget *createWidget(DomWidget *ui_widget, QWidget *parentWidget = nullptr)
74 { return QFormBuilder::create(ui_widget, parentWidget); }
75
76 inline QDesignerFormEditorInterface *core() const
77 { return m_core; }
78
79 QString systemStyle() const;
80
81 // Create a preview widget (for integrations) or return 0. The widget has to be embedded into a main window.
82 // Experimental, depending on script support.
83 static QWidget *createPreview(const QDesignerFormWindowInterface *fw, const QString &styleName /* ="" */,
84 const QString &appStyleSheet /* ="" */,
85 const DeviceProfile &deviceProfile,
86 QString *errorMessage);
87 // Convenience that pops up message boxes in case of failures.
88 static QWidget *createPreview(const QDesignerFormWindowInterface *fw, const QString &styleName = QString());
89 // Create a preview widget (for integrations) or return 0. The widget has to be embedded into a main window.
90 static QWidget *createPreview(const QDesignerFormWindowInterface *fw, const QString &styleName, const QString &appStyleSheet, QString *errorMessage);
91 // Convenience that pops up message boxes in case of failures.
92 static QWidget *createPreview(const QDesignerFormWindowInterface *fw, const QString &styleName, const QString &appStyleSheet);
93
94 // Create a preview image
95 static QPixmap createPreviewPixmap(const QDesignerFormWindowInterface *fw, const QString &styleName = QString(), const QString &appStyleSheet = QString());
96
97protected:
98 using QFormBuilder::createDom;
99 using QFormBuilder::create;
100
101 QWidget *create(DomUI *ui, QWidget *parentWidget) override;
102 DomWidget *createDom(QWidget *widget, DomWidget *ui_parentWidget, bool recursive = true) override;
103 QWidget *create(DomWidget *ui_widget, QWidget *parentWidget) override;
104 QLayout *create(DomLayout *ui_layout, QLayout *layout, QWidget *parentWidget) override;
105 void createResources(DomResources *resources) override;
106
107 QWidget *createWidget(const QString &widgetName, QWidget *parentWidget, const QString &name) override;
108 bool addItem(DomWidget *ui_widget, QWidget *widget, QWidget *parentWidget) override;
109 bool addItem(DomLayoutItem *ui_item, QLayoutItem *item, QLayout *layout) override;
110
111 virtual QIcon nameToIcon(const QString &filePath, const QString &qrcPath);
112 virtual QPixmap nameToPixmap(const QString &filePath, const QString &qrcPath);
113
114 void applyProperties(QObject *o, const QList<DomProperty*> &properties) override;
115
116 void loadExtraInfo(DomWidget *ui_widget, QWidget *widget, QWidget *parentWidget) override;
117
118 QtResourceSet *internalResourceSet() const { return m_tempResourceSet; }
119
120 DeviceProfile deviceProfile() const { return m_deviceProfile; }
121
122private:
123 QDesignerFormEditorInterface *m_core;
124
125 using WidgetSet = QSet<QWidget *>;
126 WidgetSet m_customWidgetsWithScript;
127
128 const DeviceProfile m_deviceProfile;
129
130 DesignerPixmapCache *m_pixmapCache;
131 DesignerIconCache *m_iconCache;
132 bool m_ignoreCreateResources;
133 QtResourceSet *m_tempResourceSet;
134 bool m_mainWidget;
135};
136
137// Form builder for a new form widget (preview). To allow for promoted
138// widgets in the template, it implements the handling of custom widgets
139// (adding of them to the widget database).
140
141class QDESIGNER_SHARED_EXPORT NewFormWidgetFormBuilder: public QDesignerFormBuilder {
142public:
143 NewFormWidgetFormBuilder(QDesignerFormEditorInterface *core,
144 const DeviceProfile &deviceProfile = DeviceProfile());
145
146protected:
147 void createCustomWidgets(DomCustomWidgets *) override;
148};
149
150
151} // namespace qdesigner_internal
152
153QT_END_NAMESPACE
154
155#endif // QDESIGNER_FORMBUILDER_H
156

source code of qttools/src/designer/src/lib/shared/qdesigner_formbuilder_p.h