| author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
| Wed, 18 Aug 2010 10:37:55 +0300 | |
| changeset 33 | 3e2da88830cd |
| parent 30 | 5dc02b23752f |
| permissions | -rw-r--r-- |
| 0 | 1 |
/**************************************************************************** |
2 |
** |
|
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
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 "brushpropertymanager.h" |
|
43 |
#include "qtpropertymanager.h" |
|
44 |
#include "qtvariantproperty.h" |
|
45 |
#include "qtpropertybrowserutils_p.h" |
|
46 |
||
47 |
#include <QtCore/QCoreApplication> |
|
48 |
#include <QtCore/QVariant> |
|
49 |
#include <QtCore/QString> |
|
50 |
||
51 |
static const char *brushStyles[] = {
|
|
52 |
QT_TRANSLATE_NOOP("BrushPropertyManager", "No brush"),
|
|
53 |
QT_TRANSLATE_NOOP("BrushPropertyManager", "Solid"),
|
|
54 |
QT_TRANSLATE_NOOP("BrushPropertyManager", "Dense 1"),
|
|
55 |
QT_TRANSLATE_NOOP("BrushPropertyManager", "Dense 2"),
|
|
56 |
QT_TRANSLATE_NOOP("BrushPropertyManager", "Dense 3"),
|
|
57 |
QT_TRANSLATE_NOOP("BrushPropertyManager", "Dense 4"),
|
|
58 |
QT_TRANSLATE_NOOP("BrushPropertyManager", "Dense 5"),
|
|
59 |
QT_TRANSLATE_NOOP("BrushPropertyManager", "Dense 6"),
|
|
60 |
QT_TRANSLATE_NOOP("BrushPropertyManager", "Dense 7"),
|
|
61 |
QT_TRANSLATE_NOOP("BrushPropertyManager", "Horizontal"),
|
|
62 |
QT_TRANSLATE_NOOP("BrushPropertyManager", "Vertical"),
|
|
63 |
QT_TRANSLATE_NOOP("BrushPropertyManager", "Cross"),
|
|
64 |
QT_TRANSLATE_NOOP("BrushPropertyManager", "Backward diagonal"),
|
|
65 |
QT_TRANSLATE_NOOP("BrushPropertyManager", "Forward diagonal"),
|
|
66 |
QT_TRANSLATE_NOOP("BrushPropertyManager", "Crossing diagonal"),
|
|
67 |
}; |
|
68 |
||
69 |
QT_BEGIN_NAMESPACE |
|
70 |
||
71 |
namespace qdesigner_internal {
|
|
72 |
||
73 |
BrushPropertyManager::BrushPropertyManager() |
|
74 |
{
|
|
75 |
} |
|
76 |
||
77 |
int BrushPropertyManager::brushStyleToIndex(Qt::BrushStyle st) |
|
78 |
{
|
|
79 |
switch (st) {
|
|
80 |
case Qt::NoBrush: return 0; |
|
81 |
case Qt::SolidPattern: return 1; |
|
82 |
case Qt::Dense1Pattern: return 2; |
|
83 |
case Qt::Dense2Pattern: return 3; |
|
84 |
case Qt::Dense3Pattern: return 4; |
|
85 |
case Qt::Dense4Pattern: return 5; |
|
86 |
case Qt::Dense5Pattern: return 6; |
|
87 |
case Qt::Dense6Pattern: return 7; |
|
88 |
case Qt::Dense7Pattern: return 8; |
|
89 |
case Qt::HorPattern: return 9; |
|
90 |
case Qt::VerPattern: return 10; |
|
91 |
case Qt::CrossPattern: return 11; |
|
92 |
case Qt::BDiagPattern: return 12; |
|
93 |
case Qt::FDiagPattern: return 13; |
|
94 |
case Qt::DiagCrossPattern: return 14; |
|
95 |
default: break; |
|
96 |
} |
|
97 |
return 0; |
|
98 |
} |
|
99 |
||
100 |
Qt::BrushStyle BrushPropertyManager::brushStyleIndexToStyle(int brushStyleIndex) |
|
101 |
{
|
|
102 |
switch (brushStyleIndex) {
|
|
103 |
case 0: return Qt::NoBrush; |
|
104 |
case 1: return Qt::SolidPattern; |
|
105 |
case 2: return Qt::Dense1Pattern; |
|
106 |
case 3: return Qt::Dense2Pattern; |
|
107 |
case 4: return Qt::Dense3Pattern; |
|
108 |
case 5: return Qt::Dense4Pattern; |
|
109 |
case 6: return Qt::Dense5Pattern; |
|
110 |
case 7: return Qt::Dense6Pattern; |
|
111 |
case 8: return Qt::Dense7Pattern; |
|
112 |
case 9: return Qt::HorPattern; |
|
113 |
case 10: return Qt::VerPattern; |
|
114 |
case 11: return Qt::CrossPattern; |
|
115 |
case 12: return Qt::BDiagPattern; |
|
116 |
case 13: return Qt::FDiagPattern; |
|
117 |
case 14: return Qt::DiagCrossPattern; |
|
118 |
} |
|
119 |
return Qt::NoBrush; |
|
120 |
} |
|
121 |
||
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
122 |
|
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
123 |
typedef QMap<int, QIcon> EnumIndexIconMap; |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
124 |
|
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
125 |
static void clearBrushIcons(); |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
126 |
Q_GLOBAL_STATIC_WITH_INITIALIZER(EnumIndexIconMap, brushIcons, qAddPostRoutine(clearBrushIcons)) |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
127 |
|
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
128 |
static void clearBrushIcons() |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
129 |
{
|
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
130 |
brushIcons()->clear(); |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
131 |
} |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
132 |
|
| 0 | 133 |
const BrushPropertyManager::EnumIndexIconMap &BrushPropertyManager::brushStyleIcons() |
134 |
{
|
|
135 |
// Create a map of icons for the brush style editor |
|
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
136 |
if (brushIcons()->empty()) {
|
| 0 | 137 |
const int brushStyleCount = sizeof(brushStyles)/sizeof(const char *); |
138 |
QBrush brush(Qt::black); |
|
139 |
const QIcon solidIcon = QtPropertyBrowserUtils::brushValueIcon(brush); |
|
140 |
for (int i = 0; i < brushStyleCount; i++) {
|
|
141 |
const Qt::BrushStyle style = brushStyleIndexToStyle(i); |
|
142 |
brush.setStyle(style); |
|
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
143 |
brushIcons()->insert(i, QtPropertyBrowserUtils::brushValueIcon(brush)); |
| 0 | 144 |
} |
145 |
} |
|
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
146 |
return *(brushIcons()); |
| 0 | 147 |
} |
148 |
||
149 |
QString BrushPropertyManager::brushStyleIndexToString(int brushStyleIndex) |
|
150 |
{
|
|
151 |
const int brushStyleCount = sizeof(brushStyles)/sizeof(const char *); |
|
152 |
return brushStyleIndex < brushStyleCount ? QCoreApplication::translate("BrushPropertyManager", brushStyles[brushStyleIndex]) : QString();
|
|
153 |
} |
|
154 |
||
155 |
void BrushPropertyManager::initializeProperty(QtVariantPropertyManager *vm, QtProperty *property, int enumTypeId) |
|
156 |
{
|
|
157 |
m_brushValues.insert(property, QBrush()); |
|
158 |
// style |
|
159 |
QtVariantProperty *styleSubProperty = vm->addProperty(enumTypeId, QCoreApplication::translate("BrushPropertyManager", "Style"));
|
|
160 |
property->addSubProperty(styleSubProperty); |
|
161 |
QStringList styles; |
|
162 |
const int brushStyleCount = sizeof(brushStyles)/sizeof(const char *); |
|
163 |
for (int i = 0; i < brushStyleCount; i++) |
|
164 |
styles.push_back(QCoreApplication::translate("BrushPropertyManager", brushStyles[i]));
|
|
165 |
styleSubProperty->setAttribute(QLatin1String("enumNames"), styles);
|
|
166 |
styleSubProperty->setAttribute(QLatin1String("enumIcons"), qVariantFromValue(brushStyleIcons()));
|
|
167 |
m_brushPropertyToStyleSubProperty.insert(property, styleSubProperty); |
|
168 |
m_brushStyleSubPropertyToProperty.insert(styleSubProperty, property); |
|
169 |
// color |
|
170 |
QtVariantProperty *colorSubProperty = vm->addProperty(QVariant::Color, QCoreApplication::translate("BrushPropertyManager", "Color"));
|
|
171 |
property->addSubProperty(colorSubProperty); |
|
172 |
m_brushPropertyToColorSubProperty.insert(property, colorSubProperty); |
|
173 |
m_brushColorSubPropertyToProperty.insert(colorSubProperty, property); |
|
174 |
} |
|
175 |
||
176 |
bool BrushPropertyManager::uninitializeProperty(QtProperty *property) |
|
177 |
{
|
|
178 |
const PropertyBrushMap::iterator brit = m_brushValues.find(property); // Brushes |
|
179 |
if (brit == m_brushValues.end()) |
|
180 |
return false; |
|
181 |
m_brushValues.erase(brit); |
|
182 |
// style |
|
183 |
PropertyToPropertyMap::iterator subit = m_brushPropertyToStyleSubProperty.find(property); |
|
184 |
if (subit != m_brushPropertyToStyleSubProperty.end()) {
|
|
185 |
QtProperty *styleProp = subit.value(); |
|
186 |
m_brushStyleSubPropertyToProperty.remove(styleProp); |
|
187 |
m_brushPropertyToStyleSubProperty.erase(subit); |
|
188 |
delete styleProp; |
|
189 |
} |
|
190 |
// color |
|
191 |
subit = m_brushPropertyToColorSubProperty.find(property); |
|
192 |
if (subit != m_brushPropertyToColorSubProperty.end()) {
|
|
193 |
QtProperty *colorProp = subit.value(); |
|
194 |
m_brushColorSubPropertyToProperty.remove(colorProp); |
|
195 |
m_brushPropertyToColorSubProperty.erase(subit); |
|
196 |
delete colorProp; |
|
197 |
} |
|
198 |
return true; |
|
199 |
} |
|
200 |
||
201 |
void BrushPropertyManager::slotPropertyDestroyed(QtProperty *property) |
|
202 |
{
|
|
203 |
PropertyToPropertyMap::iterator subit = m_brushStyleSubPropertyToProperty.find(property); |
|
204 |
if (subit != m_brushStyleSubPropertyToProperty.end()) {
|
|
205 |
m_brushPropertyToStyleSubProperty[subit.value()] = 0; |
|
206 |
m_brushStyleSubPropertyToProperty.erase(subit); |
|
207 |
} |
|
208 |
subit = m_brushColorSubPropertyToProperty.find(property); |
|
209 |
if (subit != m_brushColorSubPropertyToProperty.end()) {
|
|
210 |
m_brushPropertyToColorSubProperty[subit.value()] = 0; |
|
211 |
m_brushColorSubPropertyToProperty.erase(subit); |
|
212 |
} |
|
213 |
} |
|
214 |
||
215 |
||
216 |
BrushPropertyManager::ValueChangedResult BrushPropertyManager::valueChanged(QtVariantPropertyManager *vm, QtProperty *property, const QVariant &value) |
|
217 |
{
|
|
218 |
switch (value.type()) {
|
|
219 |
case QVariant::Int: // Style subproperty? |
|
220 |
if (QtProperty *brushProperty = m_brushStyleSubPropertyToProperty.value(property, 0)) {
|
|
221 |
const QBrush oldValue = m_brushValues.value(brushProperty); |
|
222 |
QBrush newBrush = oldValue; |
|
223 |
const int index = value.toInt(); |
|
224 |
newBrush.setStyle(brushStyleIndexToStyle(index)); |
|
225 |
if (newBrush == oldValue) |
|
226 |
return Unchanged; |
|
227 |
vm->variantProperty(brushProperty)->setValue(newBrush); |
|
228 |
return Changed; |
|
229 |
} |
|
230 |
break; |
|
231 |
case QVariant::Color: // Color subproperty? |
|
232 |
if (QtProperty *brushProperty = m_brushColorSubPropertyToProperty.value(property, 0)) {
|
|
233 |
const QBrush oldValue = m_brushValues.value(brushProperty); |
|
234 |
QBrush newBrush = oldValue; |
|
235 |
newBrush.setColor(qvariant_cast<QColor>(value)); |
|
236 |
if (newBrush == oldValue) |
|
237 |
return Unchanged; |
|
238 |
vm->variantProperty(brushProperty)->setValue(newBrush); |
|
239 |
return Changed; |
|
240 |
} |
|
241 |
break; |
|
242 |
default: |
|
243 |
break; |
|
244 |
} |
|
245 |
return NoMatch; |
|
246 |
} |
|
247 |
||
248 |
BrushPropertyManager::ValueChangedResult BrushPropertyManager::setValue(QtVariantPropertyManager *vm, QtProperty *property, const QVariant &value) |
|
249 |
{
|
|
250 |
if (value.type() != QVariant::Brush) |
|
251 |
return NoMatch; |
|
252 |
const PropertyBrushMap::iterator brit = m_brushValues.find(property); |
|
253 |
if (brit == m_brushValues.end()) |
|
254 |
return NoMatch; |
|
255 |
||
256 |
const QBrush newBrush = qvariant_cast<QBrush>(value); |
|
257 |
if (newBrush == brit.value()) |
|
258 |
return Unchanged; |
|
259 |
brit.value() = newBrush; |
|
260 |
if (QtProperty *styleProperty = m_brushPropertyToStyleSubProperty.value(property)) |
|
261 |
vm->variantProperty(styleProperty)->setValue(brushStyleToIndex(newBrush.style())); |
|
262 |
if (QtProperty *colorProperty = m_brushPropertyToColorSubProperty.value(property)) |
|
263 |
vm->variantProperty(colorProperty)->setValue(newBrush.color()); |
|
264 |
||
265 |
return Changed; |
|
266 |
} |
|
267 |
||
268 |
bool BrushPropertyManager::valueText(const QtProperty *property, QString *text) const |
|
269 |
{
|
|
270 |
const PropertyBrushMap::const_iterator brit = m_brushValues.constFind(const_cast<QtProperty *>(property)); |
|
271 |
if (brit == m_brushValues.constEnd()) |
|
272 |
return false; |
|
273 |
const QBrush &brush = brit.value(); |
|
274 |
const QString styleName = brushStyleIndexToString(brushStyleToIndex(brush.style())); |
|
275 |
*text = QCoreApplication::translate("BrushPropertyManager", "[%1, %2]").arg(styleName).arg(QtPropertyBrowserUtils::colorValueText(brush.color()));
|
|
276 |
return true; |
|
277 |
} |
|
278 |
||
279 |
bool BrushPropertyManager::valueIcon(const QtProperty *property, QIcon *icon) const |
|
280 |
{
|
|
281 |
const PropertyBrushMap::const_iterator brit = m_brushValues.constFind(const_cast<QtProperty *>(property)); |
|
282 |
if (brit == m_brushValues.constEnd()) |
|
283 |
return false; |
|
284 |
*icon = QtPropertyBrowserUtils::brushValueIcon(brit.value()); |
|
285 |
return true; |
|
286 |
} |
|
287 |
||
288 |
bool BrushPropertyManager::value(const QtProperty *property, QVariant *v) const |
|
289 |
{
|
|
290 |
const PropertyBrushMap::const_iterator brit = m_brushValues.constFind(const_cast<QtProperty *>(property)); |
|
291 |
if (brit == m_brushValues.constEnd()) |
|
292 |
return false; |
|
293 |
qVariantSetValue(*v, brit.value()); |
|
294 |
return true; |
|
295 |
} |
|
296 |
} |
|
297 |
||
298 |
QT_END_NAMESPACE |