author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 15 Mar 2010 12:43:09 +0200 | |
branch | RCL_3 |
changeset 6 | dee5afe5301f |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
#include "formbuilderextra_p.h" |
|
43 |
#include "abstractformbuilder.h" |
|
44 |
#include "resourcebuilder_p.h" |
|
45 |
#include "textbuilder_p.h" |
|
46 |
#include "ui4_p.h" |
|
47 |
||
48 |
#include <QtGui/QLabel> |
|
49 |
#include <QtGui/QBoxLayout> |
|
50 |
#include <QtGui/QGridLayout> |
|
51 |
||
52 |
#include <QtCore/QVariant> |
|
53 |
#include <QtCore/qdebug.h> |
|
54 |
#include <QtCore/QTextStream> |
|
55 |
#include <QtCore/QStringList> |
|
56 |
#include <QtCore/QCoreApplication> |
|
57 |
||
58 |
QT_BEGIN_NAMESPACE |
|
59 |
||
60 |
#ifdef QFORMINTERNAL_NAMESPACE |
|
61 |
namespace QFormInternal { |
|
62 |
#endif |
|
63 |
||
64 |
void uiLibWarning(const QString &message) { |
|
65 |
qWarning("Designer: %s", qPrintable(message)); |
|
66 |
} |
|
67 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
68 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
69 |
QFormBuilderExtra::CustomWidgetData::CustomWidgetData() : |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
70 |
isContainer(false) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
71 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
72 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
73 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
74 |
QFormBuilderExtra::CustomWidgetData::CustomWidgetData(const DomCustomWidget *dcw) : |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
75 |
addPageMethod(dcw->elementAddPageMethod()), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
76 |
baseClass(dcw->elementExtends()), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
77 |
isContainer(dcw->hasElementContainer() && dcw->elementContainer() != 0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
78 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
79 |
#ifndef QT_FORMBUILDER_NO_SCRIPT |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
80 |
if (const DomScript *domScript = dcw->elementScript()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
81 |
script = domScript->text(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
82 |
#endif |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
83 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
84 |
|
0 | 85 |
QFormBuilderExtra::QFormBuilderExtra() : |
86 |
m_layoutWidget(false), |
|
87 |
m_resourceBuilder(0), |
|
88 |
m_textBuilder(0) |
|
89 |
{ |
|
90 |
} |
|
91 |
||
92 |
QFormBuilderExtra::~QFormBuilderExtra() |
|
93 |
{ |
|
94 |
clearResourceBuilder(); |
|
95 |
clearTextBuilder(); |
|
96 |
} |
|
97 |
||
98 |
void QFormBuilderExtra::clear() |
|
99 |
{ |
|
100 |
m_buddies.clear(); |
|
101 |
m_parentWidget = 0; |
|
102 |
m_parentWidgetIsSet = false; |
|
103 |
#ifndef QT_FORMBUILDER_NO_SCRIPT |
|
104 |
m_FormScriptRunner.clearErrors(); |
|
105 |
#endif |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
106 |
m_customWidgetDataHash.clear(); |
0 | 107 |
m_buttonGroups.clear(); |
108 |
} |
|
109 |
||
110 |
||
111 |
bool QFormBuilderExtra::applyPropertyInternally(QObject *o, const QString &propertyName, const QVariant &value) |
|
112 |
{ |
|
113 |
// Store buddies and apply them later on as the widgets might not exist yet. |
|
114 |
QLabel *label = qobject_cast<QLabel*>(o); |
|
115 |
if (!label || propertyName != QFormBuilderStrings::instance().buddyProperty) |
|
116 |
return false; |
|
117 |
||
118 |
m_buddies.insert(label, value.toString()); |
|
119 |
return true; |
|
120 |
} |
|
121 |
||
122 |
void QFormBuilderExtra::applyInternalProperties() const |
|
123 |
{ |
|
124 |
if (m_buddies.empty()) |
|
125 |
return; |
|
126 |
||
127 |
const BuddyHash::const_iterator cend = m_buddies.constEnd(); |
|
128 |
for (BuddyHash::const_iterator it = m_buddies.constBegin(); it != cend; ++it ) |
|
129 |
applyBuddy(it.value(), BuddyApplyAll, it.key()); |
|
130 |
} |
|
131 |
||
132 |
bool QFormBuilderExtra::applyBuddy(const QString &buddyName, BuddyMode applyMode, QLabel *label) |
|
133 |
{ |
|
134 |
if (buddyName.isEmpty()) { |
|
135 |
label->setBuddy(0); |
|
136 |
return false; |
|
137 |
} |
|
138 |
||
139 |
const QWidgetList widgets = qFindChildren<QWidget*>(label->topLevelWidget(), buddyName); |
|
140 |
if (widgets.empty()) { |
|
141 |
label->setBuddy(0); |
|
142 |
return false; |
|
143 |
} |
|
144 |
||
145 |
const QWidgetList::const_iterator cend = widgets.constEnd(); |
|
146 |
for ( QWidgetList::const_iterator it = widgets.constBegin(); it != cend; ++it) { |
|
147 |
if (applyMode == BuddyApplyAll || !(*it)->isHidden()) { |
|
148 |
label->setBuddy(*it); |
|
149 |
return true; |
|
150 |
} |
|
151 |
} |
|
152 |
||
153 |
label->setBuddy(0); |
|
154 |
return false; |
|
155 |
} |
|
156 |
||
157 |
const QPointer<QWidget> &QFormBuilderExtra::parentWidget() const |
|
158 |
{ |
|
159 |
return m_parentWidget; |
|
160 |
} |
|
161 |
||
162 |
bool QFormBuilderExtra::parentWidgetIsSet() const |
|
163 |
{ |
|
164 |
return m_parentWidgetIsSet; |
|
165 |
} |
|
166 |
||
167 |
void QFormBuilderExtra::setParentWidget(const QPointer<QWidget> &w) |
|
168 |
{ |
|
169 |
// Parent widget requires special handling of the geometry property. |
|
170 |
m_parentWidget = w; |
|
171 |
m_parentWidgetIsSet = true; |
|
172 |
} |
|
173 |
||
174 |
#ifndef QT_FORMBUILDER_NO_SCRIPT |
|
175 |
QFormScriptRunner &QFormBuilderExtra::formScriptRunner() |
|
176 |
{ |
|
177 |
return m_FormScriptRunner; |
|
178 |
} |
|
179 |
||
180 |
QString QFormBuilderExtra::customWidgetScript(const QString &className) const |
|
181 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
182 |
const QHash<QString, CustomWidgetData>::const_iterator it = m_customWidgetDataHash.constFind(className); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
183 |
if (it != m_customWidgetDataHash.constEnd()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
184 |
return it.value().script; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
185 |
return QString(); |
0 | 186 |
} |
187 |
||
188 |
#endif |
|
189 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
190 |
void QFormBuilderExtra::storeCustomWidgetData(const QString &className, const DomCustomWidget *d) |
0 | 191 |
{ |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
192 |
if (d) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
193 |
m_customWidgetDataHash.insert(className, CustomWidgetData(d)); |
0 | 194 |
} |
195 |
||
196 |
QString QFormBuilderExtra::customWidgetBaseClass(const QString &className) const |
|
197 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
198 |
const QHash<QString, CustomWidgetData>::const_iterator it = m_customWidgetDataHash.constFind(className); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
199 |
if (it != m_customWidgetDataHash.constEnd()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
200 |
return it.value().baseClass; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
201 |
return QString(); |
0 | 202 |
} |
203 |
||
204 |
QString QFormBuilderExtra::customWidgetAddPageMethod(const QString &className) const |
|
205 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
206 |
const QHash<QString, CustomWidgetData>::const_iterator it = m_customWidgetDataHash.constFind(className); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
207 |
if (it != m_customWidgetDataHash.constEnd()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
208 |
return it.value().addPageMethod; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
209 |
return QString(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
210 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
211 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
212 |
bool QFormBuilderExtra::isCustomWidgetContainer(const QString &className) const |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
213 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
214 |
const QHash<QString, CustomWidgetData>::const_iterator it = m_customWidgetDataHash.constFind(className); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
215 |
if (it != m_customWidgetDataHash.constEnd()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
216 |
return it.value().isContainer; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
217 |
return false; |
0 | 218 |
} |
219 |
||
220 |
namespace { |
|
221 |
typedef QHash<const QAbstractFormBuilder *, QFormBuilderExtra *> FormBuilderPrivateHash; |
|
222 |
} |
|
223 |
||
224 |
Q_GLOBAL_STATIC(FormBuilderPrivateHash, g_FormBuilderPrivateHash) |
|
225 |
||
226 |
QFormBuilderExtra *QFormBuilderExtra::instance(const QAbstractFormBuilder *afb) |
|
227 |
{ |
|
228 |
FormBuilderPrivateHash &fbHash = *g_FormBuilderPrivateHash(); |
|
229 |
||
230 |
FormBuilderPrivateHash::iterator it = fbHash.find(afb); |
|
231 |
if (it == fbHash.end()) |
|
232 |
it = fbHash.insert(afb, new QFormBuilderExtra); |
|
233 |
return it.value(); |
|
234 |
} |
|
235 |
||
236 |
void QFormBuilderExtra::removeInstance(const QAbstractFormBuilder *afb) |
|
237 |
{ |
|
238 |
FormBuilderPrivateHash &fbHash = *g_FormBuilderPrivateHash(); |
|
239 |
||
240 |
FormBuilderPrivateHash::iterator it = fbHash.find(afb); |
|
241 |
if (it != fbHash.end()) { |
|
242 |
delete it.value(); |
|
243 |
fbHash.erase(it); |
|
244 |
} |
|
245 |
} |
|
246 |
||
247 |
void QFormBuilderExtra::setProcessingLayoutWidget(bool processing) |
|
248 |
{ |
|
249 |
m_layoutWidget = processing; |
|
250 |
} |
|
251 |
||
252 |
bool QFormBuilderExtra::processingLayoutWidget() const |
|
253 |
{ |
|
254 |
return m_layoutWidget; |
|
255 |
} |
|
256 |
void QFormBuilderExtra::setResourceBuilder(QResourceBuilder *builder) |
|
257 |
{ |
|
258 |
if (m_resourceBuilder == builder) |
|
259 |
return; |
|
260 |
clearResourceBuilder(); |
|
261 |
m_resourceBuilder = builder; |
|
262 |
} |
|
263 |
||
264 |
QResourceBuilder *QFormBuilderExtra::resourceBuilder() const |
|
265 |
{ |
|
266 |
return m_resourceBuilder; |
|
267 |
} |
|
268 |
||
269 |
void QFormBuilderExtra::clearResourceBuilder() |
|
270 |
{ |
|
271 |
if (m_resourceBuilder) { |
|
272 |
delete m_resourceBuilder; |
|
273 |
m_resourceBuilder = 0; |
|
274 |
} |
|
275 |
} |
|
276 |
||
277 |
void QFormBuilderExtra::setTextBuilder(QTextBuilder *builder) |
|
278 |
{ |
|
279 |
if (m_textBuilder == builder) |
|
280 |
return; |
|
281 |
clearTextBuilder(); |
|
282 |
m_textBuilder = builder; |
|
283 |
} |
|
284 |
||
285 |
QTextBuilder *QFormBuilderExtra::textBuilder() const |
|
286 |
{ |
|
287 |
return m_textBuilder; |
|
288 |
} |
|
289 |
||
290 |
void QFormBuilderExtra::clearTextBuilder() |
|
291 |
{ |
|
292 |
if (m_textBuilder) { |
|
293 |
delete m_textBuilder; |
|
294 |
m_textBuilder = 0; |
|
295 |
} |
|
296 |
} |
|
297 |
||
298 |
void QFormBuilderExtra::registerButtonGroups(const DomButtonGroups *domGroups) |
|
299 |
{ |
|
300 |
typedef QList<DomButtonGroup*> DomButtonGroupList; |
|
301 |
const DomButtonGroupList domGroupList = domGroups->elementButtonGroup(); |
|
302 |
const DomButtonGroupList::const_iterator cend = domGroupList.constEnd(); |
|
303 |
for (DomButtonGroupList::const_iterator it = domGroupList.constBegin(); it != cend; ++it) { |
|
304 |
DomButtonGroup *domGroup = *it; |
|
305 |
m_buttonGroups.insert(domGroup->attributeName(), ButtonGroupEntry(domGroup, 0)); |
|
306 |
} |
|
307 |
} |
|
308 |
||
309 |
// Utilities for parsing per-cell integer properties that have setters and |
|
310 |
// getters of the form 'setX(int idx, int value)' and 'x(int index)' |
|
311 |
// (converting them to comma-separated string lists and back). |
|
312 |
// Used for layout stretch and grid per-row/column properties. |
|
313 |
||
314 |
// Format a list of cell-properties of one dimension as a ','-separated list |
|
315 |
template <class Layout> |
|
316 |
inline QString perCellPropertyToString(const Layout *l, int count, int (Layout::*getter)(int) const) |
|
317 |
{ |
|
318 |
if (count == 0) |
|
319 |
return QString(); |
|
320 |
QString rc; |
|
321 |
{ |
|
322 |
QTextStream str(&rc); |
|
323 |
for (int i = 0; i < count; i++) { |
|
324 |
if (i) |
|
325 |
str << QLatin1Char(','); |
|
326 |
str << (l->*getter)(i); |
|
327 |
} |
|
328 |
} |
|
329 |
return rc; |
|
330 |
} |
|
331 |
||
332 |
// Clear the property, set all cells to 0 |
|
333 |
||
334 |
template <class Layout> |
|
335 |
inline void clearPerCellValue(Layout *l, int count, void (Layout::*setter)(int,int), int value = 0) |
|
336 |
{ |
|
337 |
for (int i = 0; i < count; i++) |
|
338 |
(l->*setter)(i, value); |
|
339 |
} |
|
340 |
||
341 |
// Parse and set the property from a comma-separated list |
|
342 |
||
343 |
template <class Layout> |
|
344 |
inline bool parsePerCellProperty(Layout *l, int count, void (Layout::*setter)(int,int), const QString &s, int defaultValue = 0) |
|
345 |
{ |
|
346 |
if (s.isEmpty()) { |
|
347 |
clearPerCellValue(l, count, setter, defaultValue); |
|
348 |
return true; |
|
349 |
} |
|
350 |
const QStringList list = s.split(QLatin1Char(',')); |
|
351 |
if (list.empty()) { |
|
352 |
clearPerCellValue(l, count, setter, defaultValue); |
|
353 |
return true; |
|
354 |
} |
|
355 |
// Apply all values contained in list |
|
356 |
const int ac = qMin(count, list.size()); |
|
357 |
bool ok; |
|
358 |
int i = 0; |
|
359 |
for ( ; i < ac; i++) { |
|
360 |
const int value = list.at(i).toInt(&ok); |
|
361 |
if (!ok || value < 0) |
|
362 |
return false; |
|
363 |
(l->*setter)(i, value); |
|
364 |
} |
|
365 |
// Clear rest |
|
366 |
for ( ; i < count; i++) |
|
367 |
(l->*setter)(i, defaultValue); |
|
368 |
return true; |
|
369 |
} |
|
370 |
||
371 |
// Read and write stretch |
|
372 |
static QString msgInvalidStretch(const QString &objectName, const QString &stretch) |
|
373 |
{ |
|
374 |
//: Parsing layout stretch values |
|
375 |
return QCoreApplication::translate("FormBuilder", "Invalid stretch value for '%1': '%2'").arg(objectName, stretch); |
|
376 |
} |
|
377 |
||
378 |
QString QFormBuilderExtra::boxLayoutStretch(const QBoxLayout *box) |
|
379 |
{ |
|
380 |
return perCellPropertyToString(box, box->count(), &QBoxLayout::stretch); |
|
381 |
} |
|
382 |
||
383 |
bool QFormBuilderExtra::setBoxLayoutStretch(const QString &s, QBoxLayout *box) |
|
384 |
{ |
|
385 |
const bool rc = parsePerCellProperty(box, box->count(), &QBoxLayout::setStretch, s); |
|
386 |
if (!rc) |
|
387 |
uiLibWarning(msgInvalidStretch(box->objectName(), s)); |
|
388 |
return rc; |
|
389 |
} |
|
390 |
||
391 |
void QFormBuilderExtra::clearBoxLayoutStretch(QBoxLayout *box) |
|
392 |
{ |
|
393 |
clearPerCellValue(box, box->count(), &QBoxLayout::setStretch); |
|
394 |
} |
|
395 |
||
396 |
QString QFormBuilderExtra::gridLayoutRowStretch(const QGridLayout *grid) |
|
397 |
{ |
|
398 |
return perCellPropertyToString(grid, grid->rowCount(), &QGridLayout::rowStretch); |
|
399 |
} |
|
400 |
||
401 |
bool QFormBuilderExtra::setGridLayoutRowStretch(const QString &s, QGridLayout *grid) |
|
402 |
{ |
|
403 |
const bool rc = parsePerCellProperty(grid, grid->rowCount(), &QGridLayout::setRowStretch, s); |
|
404 |
if (!rc) |
|
405 |
uiLibWarning(msgInvalidStretch(grid->objectName(), s)); |
|
406 |
return rc; |
|
407 |
} |
|
408 |
||
409 |
void QFormBuilderExtra::clearGridLayoutRowStretch(QGridLayout *grid) |
|
410 |
{ |
|
411 |
clearPerCellValue(grid, grid->rowCount(), &QGridLayout::setRowStretch); |
|
412 |
} |
|
413 |
||
414 |
QString QFormBuilderExtra::gridLayoutColumnStretch(const QGridLayout *grid) |
|
415 |
{ |
|
416 |
return perCellPropertyToString(grid, grid->columnCount(), &QGridLayout::columnStretch); |
|
417 |
} |
|
418 |
||
419 |
bool QFormBuilderExtra::setGridLayoutColumnStretch(const QString &s, QGridLayout *grid) |
|
420 |
{ |
|
421 |
const bool rc = parsePerCellProperty(grid, grid->columnCount(), &QGridLayout::setColumnStretch, s); |
|
422 |
if (!rc) |
|
423 |
uiLibWarning(msgInvalidStretch(grid->objectName(), s)); |
|
424 |
return rc; |
|
425 |
} |
|
426 |
||
427 |
void QFormBuilderExtra::clearGridLayoutColumnStretch(QGridLayout *grid) |
|
428 |
{ |
|
429 |
clearPerCellValue(grid, grid->columnCount(), &QGridLayout::setColumnStretch); |
|
430 |
} |
|
431 |
||
432 |
// Read and write grid layout row/column size limits |
|
433 |
||
434 |
static QString msgInvalidMinimumSize(const QString &objectName, const QString &ms) |
|
435 |
{ |
|
436 |
//: Parsing grid layout minimum size values |
|
437 |
return QCoreApplication::translate("FormBuilder", "Invalid minimum size for '%1': '%2'").arg(objectName, ms); |
|
438 |
} |
|
439 |
||
440 |
QString QFormBuilderExtra::gridLayoutRowMinimumHeight(const QGridLayout *grid) |
|
441 |
{ |
|
442 |
return perCellPropertyToString(grid, grid->rowCount(), &QGridLayout::rowMinimumHeight); |
|
443 |
} |
|
444 |
||
445 |
bool QFormBuilderExtra::setGridLayoutRowMinimumHeight(const QString &s, QGridLayout *grid) |
|
446 |
{ |
|
447 |
const bool rc = parsePerCellProperty(grid, grid->rowCount(), &QGridLayout::setRowMinimumHeight, s); |
|
448 |
if (!rc) |
|
449 |
uiLibWarning(msgInvalidMinimumSize(grid->objectName(), s)); |
|
450 |
return rc; |
|
451 |
} |
|
452 |
||
453 |
void QFormBuilderExtra::clearGridLayoutRowMinimumHeight(QGridLayout *grid) |
|
454 |
{ |
|
455 |
clearPerCellValue(grid, grid->rowCount(), &QGridLayout::setRowMinimumHeight); |
|
456 |
} |
|
457 |
||
458 |
QString QFormBuilderExtra::gridLayoutColumnMinimumWidth(const QGridLayout *grid) |
|
459 |
{ |
|
460 |
return perCellPropertyToString(grid, grid->columnCount(), &QGridLayout::columnMinimumWidth); |
|
461 |
} |
|
462 |
||
463 |
bool QFormBuilderExtra::setGridLayoutColumnMinimumWidth(const QString &s, QGridLayout *grid) |
|
464 |
{ |
|
465 |
const bool rc = parsePerCellProperty(grid, grid->columnCount(), &QGridLayout::setColumnMinimumWidth, s); |
|
466 |
if (!rc) |
|
467 |
uiLibWarning(msgInvalidMinimumSize(grid->objectName(), s)); |
|
468 |
return rc; |
|
469 |
} |
|
470 |
||
471 |
void QFormBuilderExtra::clearGridLayoutColumnMinimumWidth(QGridLayout *grid) |
|
472 |
{ |
|
473 |
clearPerCellValue(grid, grid->columnCount(), &QGridLayout::setColumnMinimumWidth); |
|
474 |
} |
|
475 |
||
476 |
// ------------ QFormBuilderStrings |
|
477 |
||
478 |
QFormBuilderStrings::QFormBuilderStrings() : |
|
479 |
buddyProperty(QLatin1String("buddy")), |
|
480 |
cursorProperty(QLatin1String("cursor")), |
|
481 |
objectNameProperty(QLatin1String("objectName")), |
|
482 |
trueValue(QLatin1String("true")), |
|
483 |
falseValue(QLatin1String("false")), |
|
484 |
horizontalPostFix(QLatin1String("Horizontal")), |
|
485 |
separator(QLatin1String("separator")), |
|
486 |
defaultTitle(QLatin1String("Page")), |
|
487 |
titleAttribute(QLatin1String("title")), |
|
488 |
labelAttribute(QLatin1String("label")), |
|
489 |
toolTipAttribute(QLatin1String("toolTip")), |
|
490 |
whatsThisAttribute(QLatin1String("whatsThis")), |
|
491 |
flagsAttribute(QLatin1String("flags")), |
|
492 |
iconAttribute(QLatin1String("icon")), |
|
493 |
pixmapAttribute(QLatin1String("pixmap")), |
|
494 |
textAttribute(QLatin1String("text")), |
|
495 |
currentIndexProperty(QLatin1String("currentIndex")), |
|
496 |
toolBarAreaAttribute(QLatin1String("toolBarArea")), |
|
497 |
toolBarBreakAttribute(QLatin1String("toolBarBreak")), |
|
498 |
dockWidgetAreaAttribute(QLatin1String("dockWidgetArea")), |
|
499 |
marginProperty(QLatin1String("margin")), |
|
500 |
spacingProperty(QLatin1String("spacing")), |
|
501 |
leftMarginProperty(QLatin1String("leftMargin")), |
|
502 |
topMarginProperty(QLatin1String("topMargin")), |
|
503 |
rightMarginProperty(QLatin1String("rightMargin")), |
|
504 |
bottomMarginProperty(QLatin1String("bottomMargin")), |
|
505 |
horizontalSpacingProperty(QLatin1String("horizontalSpacing")), |
|
506 |
verticalSpacingProperty(QLatin1String("verticalSpacing")), |
|
507 |
sizeHintProperty(QLatin1String("sizeHint")), |
|
508 |
sizeTypeProperty(QLatin1String("sizeType")), |
|
509 |
orientationProperty(QLatin1String("orientation")), |
|
510 |
styleSheetProperty(QLatin1String("styleSheet")), |
|
511 |
qtHorizontal(QLatin1String("Qt::Horizontal")), |
|
512 |
qtVertical(QLatin1String("Qt::Vertical")), |
|
513 |
currentRowProperty(QLatin1String("currentRow")), |
|
514 |
tabSpacingProperty(QLatin1String("tabSpacing")), |
|
515 |
qWidgetClass(QLatin1String("QWidget")), |
|
516 |
lineClass(QLatin1String("Line")), |
|
517 |
geometryProperty(QLatin1String("geometry")), |
|
518 |
scriptWidgetVariable(QLatin1String("widget")), |
|
519 |
scriptChildWidgetsVariable(QLatin1String("childWidgets")) |
|
520 |
{ |
|
521 |
itemRoles.append(qMakePair(Qt::FontRole, QString::fromLatin1("font"))); |
|
522 |
itemRoles.append(qMakePair(Qt::TextAlignmentRole, QString::fromLatin1("textAlignment"))); |
|
523 |
itemRoles.append(qMakePair(Qt::BackgroundRole, QString::fromLatin1("background"))); |
|
524 |
itemRoles.append(qMakePair(Qt::ForegroundRole, QString::fromLatin1("foreground"))); |
|
525 |
itemRoles.append(qMakePair(Qt::CheckStateRole, QString::fromLatin1("checkState"))); |
|
526 |
||
527 |
foreach (const RoleNName &it, itemRoles) |
|
528 |
treeItemRoleHash.insert(it.second, it.first); |
|
529 |
||
530 |
itemTextRoles.append(qMakePair(qMakePair(Qt::EditRole, Qt::DisplayPropertyRole), |
|
531 |
textAttribute)); // This must be first for the loop below |
|
532 |
itemTextRoles.append(qMakePair(qMakePair(Qt::ToolTipRole, Qt::ToolTipPropertyRole), |
|
533 |
toolTipAttribute)); |
|
534 |
itemTextRoles.append(qMakePair(qMakePair(Qt::StatusTipRole, Qt::StatusTipPropertyRole), |
|
535 |
QString::fromLatin1("statusTip"))); |
|
536 |
itemTextRoles.append(qMakePair(qMakePair(Qt::WhatsThisRole, Qt::WhatsThisPropertyRole), |
|
537 |
whatsThisAttribute)); |
|
538 |
||
539 |
// Note: this skips the first item! |
|
540 |
QList<TextRoleNName>::const_iterator it = itemTextRoles.constBegin(), end = itemTextRoles.constEnd(); |
|
541 |
while (++it != end) |
|
542 |
treeItemTextRoleHash.insert(it->second, it->first); |
|
543 |
} |
|
544 |
||
545 |
const QFormBuilderStrings &QFormBuilderStrings::instance() |
|
546 |
{ |
|
547 |
static const QFormBuilderStrings rc; |
|
548 |
return rc; |
|
549 |
} |
|
550 |
||
551 |
#ifdef QFORMINTERNAL_NAMESPACE |
|
552 |
} // namespace QFormInternal |
|
553 |
#endif |
|
554 |
||
555 |
QT_END_NAMESPACE |