|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Designer of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 // |
|
43 // W A R N I N G |
|
44 // ------------- |
|
45 // |
|
46 // This file is not part of the Qt API. It exists for the convenience |
|
47 // of Qt Designer. This header |
|
48 // file may change from version to version without notice, or even be removed. |
|
49 // |
|
50 // We mean it. |
|
51 // |
|
52 |
|
53 #ifndef QSIMPLERESOURCE_H |
|
54 #define QSIMPLERESOURCE_H |
|
55 |
|
56 #include "shared_global_p.h" |
|
57 #include "abstractformbuilder.h" |
|
58 #include <QtCore/QStringList> |
|
59 |
|
60 QT_BEGIN_NAMESPACE |
|
61 |
|
62 class DomScript; |
|
63 class DomCustomWidgets; |
|
64 class DomCustomWidget; |
|
65 class DomSlots; |
|
66 |
|
67 class QDesignerFormEditorInterface; |
|
68 |
|
69 namespace qdesigner_internal { |
|
70 |
|
71 class WidgetDataBaseItem; |
|
72 |
|
73 class QDESIGNER_SHARED_EXPORT QSimpleResource : public QAbstractFormBuilder |
|
74 { |
|
75 public: |
|
76 explicit QSimpleResource(QDesignerFormEditorInterface *core); |
|
77 virtual ~QSimpleResource(); |
|
78 |
|
79 QBrush setupBrush(DomBrush *brush); |
|
80 DomBrush *saveBrush(const QBrush &brush); |
|
81 |
|
82 inline QDesignerFormEditorInterface *core() const |
|
83 { return m_core; } |
|
84 |
|
85 // Query extensions for additional data |
|
86 static void addExtensionDataToDOM(QAbstractFormBuilder *afb, |
|
87 QDesignerFormEditorInterface *core, |
|
88 DomWidget *ui_widget, QWidget *widget); |
|
89 static void applyExtensionDataFromDOM(QAbstractFormBuilder *afb, |
|
90 QDesignerFormEditorInterface *core, |
|
91 DomWidget *ui_widget, QWidget *widget, |
|
92 bool applyState); |
|
93 // Enable warnings while saving. Turn off for backups. |
|
94 static bool setWarningsEnabled(bool warningsEnabled); |
|
95 static bool warningsEnabled(); |
|
96 // Return the script returned by the CustomWidget codeTemplate API |
|
97 static QString customWidgetScript(QDesignerFormEditorInterface *core, QObject *object); |
|
98 static QString customWidgetScript(QDesignerFormEditorInterface *core, const QString &className); |
|
99 static bool hasCustomWidgetScript(QDesignerFormEditorInterface *core, QObject *object); |
|
100 |
|
101 // Implementation for FormBuilder::createDomCustomWidgets() that adds |
|
102 // the custom widgets to the widget database |
|
103 static void handleDomCustomWidgets(const QDesignerFormEditorInterface *core, |
|
104 const DomCustomWidgets *dom_custom_widgets); |
|
105 |
|
106 protected: |
|
107 virtual QIcon nameToIcon(const QString &filePath, const QString &qrcPath); |
|
108 virtual QString iconToFilePath(const QIcon &pm) const; |
|
109 virtual QString iconToQrcPath(const QIcon &pm) const; |
|
110 virtual QPixmap nameToPixmap(const QString &filePath, const QString &qrcPath); |
|
111 virtual QString pixmapToFilePath(const QPixmap &pm) const; |
|
112 virtual QString pixmapToQrcPath(const QPixmap &pm) const; |
|
113 |
|
114 enum ScriptSource { ScriptDesigner, ScriptExtension, ScriptCustomWidgetPlugin }; |
|
115 static DomScript*createScript(const QString &script, ScriptSource source); |
|
116 typedef QList<DomScript*> DomScripts; |
|
117 static void addScript(const QString &script, ScriptSource source, DomScripts &domScripts); |
|
118 |
|
119 static bool addFakeMethods(const DomSlots *domSlots, QStringList &fakeSlots, QStringList &fakeSignals); |
|
120 |
|
121 private: |
|
122 static void addCustomWidgetsToWidgetDatabase(const QDesignerFormEditorInterface *core, |
|
123 QList<DomCustomWidget*>& custom_widget_list); |
|
124 static void addFakeMethodsToWidgetDataBase(const DomCustomWidget *domCustomWidget, WidgetDataBaseItem *item); |
|
125 |
|
126 static bool m_warningsEnabled; |
|
127 QDesignerFormEditorInterface *m_core; |
|
128 }; |
|
129 |
|
130 // Contents of clipboard for formbuilder copy and paste operations |
|
131 // (Actions and widgets) |
|
132 struct QDESIGNER_SHARED_EXPORT FormBuilderClipboard { |
|
133 typedef QList<QAction*> ActionList; |
|
134 |
|
135 FormBuilderClipboard() {} |
|
136 FormBuilderClipboard(QWidget *w); |
|
137 |
|
138 bool empty() const; |
|
139 |
|
140 QWidgetList m_widgets; |
|
141 ActionList m_actions; |
|
142 }; |
|
143 |
|
144 // Base class for a form builder used in the editor that |
|
145 // provides copy and paste.(move into base interface) |
|
146 class QDESIGNER_SHARED_EXPORT QEditorFormBuilder : public QSimpleResource |
|
147 { |
|
148 public: |
|
149 explicit QEditorFormBuilder(QDesignerFormEditorInterface *core) : QSimpleResource(core) {} |
|
150 |
|
151 virtual bool copy(QIODevice *dev, const FormBuilderClipboard &selection) = 0; |
|
152 virtual DomUI *copy(const FormBuilderClipboard &selection) = 0; |
|
153 |
|
154 // A widget parent needs to be specified, otherwise, the widget factory cannot locate the form window via parent |
|
155 // and thus is not able to construct special widgets (QLayoutWidget). |
|
156 virtual FormBuilderClipboard paste(DomUI *ui, QWidget *widgetParent, QObject *actionParent = 0) = 0; |
|
157 virtual FormBuilderClipboard paste(QIODevice *dev, QWidget *widgetParent, QObject *actionParent = 0) = 0; |
|
158 }; |
|
159 |
|
160 } // namespace qdesigner_internal |
|
161 |
|
162 QT_END_NAMESPACE |
|
163 |
|
164 #endif |