Mercurial > projects > qtd
comparison tools/duic/d/dwriteinitialization.h @ 1:e78566595089
initial import
author | mandel |
---|---|
date | Mon, 11 May 2009 16:01:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:36fb74dc547d | 1:e78566595089 |
---|---|
1 /**************************************************************************** | |
2 ** | |
3 ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). | |
4 ** Contact: Qt Software Information (qt-info@nokia.com) | |
5 ** | |
6 ** This file is part of the tools applications of the Qt Toolkit. | |
7 ** | |
8 ** Commercial Usage | |
9 ** Licensees holding valid Qt Commercial licenses may use this file in | |
10 ** accordance with the Qt Commercial License Agreement provided with the | |
11 ** Software or, alternatively, in accordance with the terms contained in | |
12 ** a written agreement between you and Nokia. | |
13 ** | |
14 ** | |
15 ** GNU General Public License Usage | |
16 ** Alternatively, this file may be used under the terms of the GNU | |
17 ** General Public License versions 2.0 or 3.0 as published by the Free | |
18 ** Software Foundation and appearing in the file LICENSE.GPL included in | |
19 ** the packaging of this file. Please review the following information | |
20 ** to ensure GNU General Public Licensing requirements will be met: | |
21 ** http://www.fsf.org/licensing/licenses/info/GPLv2.html and | |
22 ** http://www.gnu.org/copyleft/gpl.html. In addition, as a special | |
23 ** exception, Nokia gives you certain additional rights. These rights | |
24 ** are described in the Nokia Qt GPL Exception version 1.3, included in | |
25 ** the file GPL_EXCEPTION.txt in this package. | |
26 ** | |
27 ** Qt for Windows(R) Licensees | |
28 ** As a special exception, Nokia, as the sole copyright holder for Qt | |
29 ** Designer, grants users of the Qt/Eclipse Integration plug-in the | |
30 ** right for the Qt/Eclipse Integration to link to functionality | |
31 ** provided by Qt Designer and its related libraries. | |
32 ** | |
33 ** If you are unsure which license is appropriate for your use, please | |
34 ** contact the sales department at qt-sales@nokia.com. | |
35 ** | |
36 ****************************************************************************/ | |
37 | |
38 #ifndef DWRITEINITIALIZATION_H | |
39 #define DWRITEINITIALIZATION_H | |
40 | |
41 #include "treewalker.h" | |
42 #include <QtCore/QPair> | |
43 #include <QtCore/QHash> | |
44 #include <QtCore/QMap> | |
45 #include <QtCore/QStack> | |
46 #include <QtCore/QTextStream> | |
47 | |
48 QT_BEGIN_NAMESPACE | |
49 | |
50 class Driver; | |
51 class Uic; | |
52 class DomBrush; | |
53 class DomFont; | |
54 class DomResourceIcon; | |
55 class DomSizePolicy; | |
56 struct Option; | |
57 | |
58 namespace D { | |
59 // Handle for a flat DOM font to get comparison functionality required for maps | |
60 class FontHandle { | |
61 public: | |
62 FontHandle(const DomFont *domFont); | |
63 int compare(const FontHandle &) const; | |
64 private: | |
65 const DomFont *m_domFont; | |
66 #if defined(Q_OS_MAC) && defined(Q_CC_GNU) && (__GNUC__ == 3 && __GNUC_MINOR__ == 3) | |
67 friend uint qHash(const FontHandle &); | |
68 #endif | |
69 }; | |
70 inline bool operator ==(const FontHandle &f1, const FontHandle &f2) { return f1.compare(f2) == 0; } | |
71 inline bool operator <(const FontHandle &f1, const FontHandle &f2) { return f1.compare(f2) < 0; } | |
72 | |
73 // Handle for a flat DOM icon to get comparison functionality required for maps | |
74 class IconHandle { | |
75 public: | |
76 IconHandle(const DomResourceIcon *domIcon); | |
77 int compare(const IconHandle &) const; | |
78 private: | |
79 const DomResourceIcon *m_domIcon; | |
80 #if defined(Q_OS_MAC) && defined(Q_CC_GNU) && (__GNUC__ == 3 && __GNUC_MINOR__ == 3) | |
81 friend uint qHash(const IconHandle &); | |
82 #endif | |
83 }; | |
84 inline bool operator ==(const IconHandle &i1, const IconHandle &i2) { return i1.compare(i2) == 0; } | |
85 inline bool operator <(const IconHandle &i1, const IconHandle &i2) { return i1.compare(i2) < 0; } | |
86 | |
87 // Handle for a flat DOM size policy to get comparison functionality required for maps | |
88 class SizePolicyHandle { | |
89 public: | |
90 SizePolicyHandle(const DomSizePolicy *domSizePolicy); | |
91 int compare(const SizePolicyHandle &) const; | |
92 private: | |
93 const DomSizePolicy *m_domSizePolicy; | |
94 #if defined(Q_OS_MAC) && defined(Q_CC_GNU) && (__GNUC__ == 3 && __GNUC_MINOR__ == 3) | |
95 friend uint qHash(const SizePolicyHandle &); | |
96 #endif | |
97 }; | |
98 inline bool operator ==(const SizePolicyHandle &f1, const SizePolicyHandle &f2) { return f1.compare(f2) == 0; } | |
99 #if !(defined(Q_OS_MAC) && defined(Q_CC_GNU) && (__GNUC__ == 3 && __GNUC_MINOR__ == 3)) | |
100 inline bool operator <(const SizePolicyHandle &f1, const SizePolicyHandle &f2) { return f1.compare(f2) < 0; } | |
101 #endif | |
102 | |
103 | |
104 | |
105 struct WriteInitialization : public TreeWalker | |
106 { | |
107 typedef QList<DomProperty*> DomPropertyList; | |
108 typedef QHash<QString, DomProperty*> DomPropertyMap; | |
109 | |
110 WriteInitialization(Uic *uic, bool activateScripts); | |
111 | |
112 // | |
113 // widgets | |
114 // | |
115 void acceptUI(DomUI *node); | |
116 void acceptWidget(DomWidget *node); | |
117 void acceptWidgetScripts(const DomScripts &, DomWidget *node, const DomWidgets &childWidgets); | |
118 | |
119 void acceptLayout(DomLayout *node); | |
120 void acceptSpacer(DomSpacer *node); | |
121 void acceptLayoutItem(DomLayoutItem *node); | |
122 | |
123 // | |
124 // actions | |
125 // | |
126 void acceptActionGroup(DomActionGroup *node); | |
127 void acceptAction(DomAction *node); | |
128 void acceptActionRef(DomActionRef *node); | |
129 | |
130 // | |
131 // tab stops | |
132 // | |
133 void acceptTabStops(DomTabStops *tabStops); | |
134 | |
135 // | |
136 // custom widgets | |
137 // | |
138 void acceptCustomWidgets(DomCustomWidgets *node); | |
139 void acceptCustomWidget(DomCustomWidget *node); | |
140 | |
141 // | |
142 // layout defaults/functions | |
143 // | |
144 void acceptLayoutDefault(DomLayoutDefault *node) { m_LayoutDefaultHandler.acceptLayoutDefault(node); } | |
145 void acceptLayoutFunction(DomLayoutFunction *node) { m_LayoutDefaultHandler.acceptLayoutFunction(node); } | |
146 | |
147 // | |
148 // signal/slot connections | |
149 // | |
150 void acceptConnection(DomConnection *connection); | |
151 | |
152 // | |
153 // images | |
154 // | |
155 void acceptImage(DomImage *image); | |
156 | |
157 enum { | |
158 Use43UiFile = 0, | |
159 TopLevelMargin, | |
160 ChildMargin, | |
161 SubLayoutMargin | |
162 }; | |
163 | |
164 private: | |
165 static QString domColor2QString(const DomColor *c); | |
166 | |
167 QString iconCall(const DomProperty *prop); | |
168 QString pixCall(const DomProperty *prop) const; | |
169 QString pixCall(const QString &type, const QString &text) const; | |
170 QString trCall(const QString &str, const QString &comment = QString()) const; | |
171 QString trCall(DomString *str) const; | |
172 | |
173 enum { WritePropertyIgnoreMargin = 1, WritePropertyIgnoreSpacing = 2 }; | |
174 void writeProperties(const QString &varName, const QString &className, const DomPropertyList &lst, unsigned flags = 0); | |
175 void writeColorGroup(DomColorGroup *colorGroup, const QString &group, const QString &paletteName); | |
176 void writeBrush(const DomBrush *brush, const QString &brushName); | |
177 | |
178 // | |
179 // special initialization | |
180 // | |
181 void initializeMenu(DomWidget *w, const QString &parentWidget); | |
182 void initializeComboBox(DomWidget *w); | |
183 void initializeListWidget(DomWidget *w); | |
184 void initializeTreeWidget(DomWidget *w); | |
185 void initializeTreeWidgetItems(const QString &className, const QString &varName, const QList<DomItem *> &items, const QString &parentPath); | |
186 void initializeTableWidget(DomWidget *w); | |
187 | |
188 QString disableSorting(DomWidget *w, const QString &varName); | |
189 void enableSorting(DomWidget *w, const QString &varName, const QString &tempName); | |
190 | |
191 // | |
192 // special initialization for the Q3 support classes | |
193 // | |
194 void initializeQ3ListBox(DomWidget *w); | |
195 void initializeQ3IconView(DomWidget *w); | |
196 void initializeQ3ListView(DomWidget *w); | |
197 void initializeQ3ListViewItems(const QString &className, const QString &varName, const QList<DomItem*> &items); | |
198 void initializeQ3Table(DomWidget *w); | |
199 void initializeQ3TableItems(const QString &className, const QString &varName, const QList<DomItem*> &items); | |
200 | |
201 // | |
202 // Sql | |
203 // | |
204 void initializeQ3SqlDataTable(DomWidget *w); | |
205 void initializeQ3SqlDataBrowser(DomWidget *w); | |
206 | |
207 QString findDeclaration(const QString &name); | |
208 DomWidget *findWidget(const QString &widgetClass); | |
209 DomImage *findImage(const QString &name) const; | |
210 | |
211 bool isValidObject(const QString &name) const; | |
212 | |
213 private: | |
214 QString writeFontProperties(const DomFont *f); | |
215 QString writeIconProperties(const DomResourceIcon *i); | |
216 QString writeSizePolicy(const DomSizePolicy *sp); | |
217 QString writeBrushInitialization(const DomBrush *brush); | |
218 | |
219 const Uic *m_uic; | |
220 Driver *m_driver; | |
221 QTextStream &m_output; | |
222 const Option &m_option; | |
223 bool m_stdsetdef; | |
224 | |
225 struct Buddy | |
226 { | |
227 Buddy(const QString &oN, const QString &b) | |
228 : objName(oN), buddy(b) {} | |
229 QString objName; | |
230 QString buddy; | |
231 }; | |
232 | |
233 QStack<DomWidget*> m_widgetChain; | |
234 QStack<DomLayout*> m_layoutChain; | |
235 QStack<DomActionGroup*> m_actionGroupChain; | |
236 QList<Buddy> m_buddies; | |
237 | |
238 QHash<QString, QString> m_buttonGroups; | |
239 QHash<QString, DomWidget*> m_registeredWidgets; | |
240 QHash<QString, DomImage*> m_registeredImages; | |
241 QHash<QString, DomAction*> m_registeredActions; | |
242 typedef QHash<uint, QString> ColorBrushHash; | |
243 ColorBrushHash m_colorBrushHash; | |
244 // Map from font properties to font variable name for reuse | |
245 // Map from size policy to variable for reuse | |
246 #if defined(Q_OS_MAC) && defined(Q_CC_GNU) && (__GNUC__ == 3 && __GNUC_MINOR__ == 3) | |
247 typedef QHash<FontHandle, QString> FontPropertiesNameMap; | |
248 typedef QHash<IconHandle, QString> IconPropertiesNameMap; | |
249 typedef QHash<SizePolicyHandle, QString> SizePolicyNameMap; | |
250 #else | |
251 typedef QMap<FontHandle, QString> FontPropertiesNameMap; | |
252 typedef QMap<IconHandle, QString> IconPropertiesNameMap; | |
253 typedef QMap<SizePolicyHandle, QString> SizePolicyNameMap; | |
254 #endif | |
255 FontPropertiesNameMap m_fontPropertiesNameMap; | |
256 IconPropertiesNameMap m_iconPropertiesNameMap; | |
257 SizePolicyNameMap m_sizePolicyNameMap; | |
258 | |
259 class LayoutDefaultHandler { | |
260 public: | |
261 LayoutDefaultHandler(); | |
262 void acceptLayoutDefault(DomLayoutDefault *node); | |
263 void acceptLayoutFunction(DomLayoutFunction *node); | |
264 | |
265 // Write out the layout margin and spacing properties applying the defaults. | |
266 void writeProperties(const QString &indent, const QString &varName, | |
267 const DomPropertyMap &pm, int marginType, | |
268 bool suppressMarginDefault, QTextStream &str) const; | |
269 private: | |
270 void writeProperty(int p, const QString &indent, const QString &objectName, const DomPropertyMap &pm, | |
271 const QString &propertyName, const QString &setter, int defaultStyleValue, | |
272 bool suppressDefault, QTextStream &str) const; | |
273 | |
274 enum Properties { Margin, Spacing, NumProperties }; | |
275 enum StateFlags { HasDefaultValue = 1, HasDefaultFunction = 2}; | |
276 unsigned m_state[NumProperties]; | |
277 int m_defaultValues[NumProperties]; | |
278 QString m_functions[NumProperties]; | |
279 }; | |
280 | |
281 // layout defaults | |
282 LayoutDefaultHandler m_LayoutDefaultHandler; | |
283 int m_layoutMarginType; | |
284 | |
285 QString m_generatedClass; | |
286 | |
287 QString m_delayedInitialization; | |
288 QTextStream m_delayedOut; | |
289 | |
290 QString m_refreshInitialization; | |
291 QTextStream m_refreshOut; | |
292 | |
293 QString m_delayedActionInitialization; | |
294 QTextStream m_actionOut; | |
295 const bool m_activateScripts; | |
296 | |
297 bool m_layoutWidget; | |
298 }; | |
299 | |
300 } // namespace D | |
301 | |
302 QT_END_NAMESPACE | |
303 | |
304 #endif // DWRITEINITIALIZATION_H |