1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
/****************************************************************************
**
** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
** This file is part of the $MODULE$ of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the either Technology Preview License Agreement or the
** Beta Release License Agreement.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qs60style.h"
#include "qs60style_p.h"
#include "qfile.h"
#include "qhash.h"
#include "qapplication.h"
#include "qpainter.h"
#include "qpicture.h"
#include "qstyleoption.h"
#include "qtransform.h"
#include "qlayout.h"
#include "qpixmapcache.h"
#include "qmetaobject.h"
#if !defined(QT_NO_STYLE_S60) || defined(QT_PLUGIN)
QT_BEGIN_NAMESPACE
class QS60StyleModeSpecifics
{
public:
static QPixmap skinnedGraphics(QS60StyleEnums::SkinParts stylepart,
const QSize &size, QS60StylePrivate::SkinElementFlags flags);
static QHash<QString, QPicture> m_partPictures;
static QHash<QPair<QString , int>, QColor> m_colors;
};
QHash<QString, QPicture> QS60StyleModeSpecifics::m_partPictures;
QHash<QPair<QString , int>, QColor> QS60StyleModeSpecifics::m_colors;
QS60StylePrivate::QS60StylePrivate()
{
setCurrentLayout(0);
}
QColor QS60StylePrivate::s60Color(QS60StyleEnums::ColorLists list,
int index, const QStyleOption *option)
{
const QString listKey = QS60Style::colorListKeys().at(list);
return QS60StylePrivate::stateColor(
QS60StyleModeSpecifics::m_colors.value(QPair<QString, int>(listKey, index)),
option
);
}
QPixmap QS60StylePrivate::part(QS60StyleEnums::SkinParts part, const QSize &size,
QS60StylePrivate::SkinElementFlags flags)
{
const QString partKey = QS60Style::partKeys().at(part);
const QPicture partPicture = QS60StyleModeSpecifics::m_partPictures.value(partKey);
QSize partSize(partPicture.boundingRect().size());
if (flags & (SF_PointEast | SF_PointWest)) {
const int temp = partSize.width();
partSize.setWidth(partSize.height());
partSize.setHeight(temp);
}
const qreal scaleX = size.width() / (qreal)partSize.width();
const qreal scaleY = size.height() / (qreal)partSize.height();
QImage partImage(size, QImage::Format_ARGB32);
partImage.fill(Qt::transparent);
QPainter resultPainter(&partImage);
QTransform t;
if (flags & SF_PointEast)
t.translate(size.width(), 0);
else if (flags & SF_PointSouth)
t.translate(size.width(), size.height());
else if (flags & SF_PointWest)
t.translate(0, size.height());
t.scale(scaleX, scaleY);
if (flags & SF_PointEast)
t.rotate(90);
else if (flags & SF_PointSouth)
t.rotate(180);
else if (flags & SF_PointWest)
t.rotate(270);
resultPainter.setTransform(t, true);
const_cast<QPicture *>(&partPicture)->play(&resultPainter);
resultPainter.end();
QPixmap result = QPixmap::fromImage(partImage);
if (flags & SF_StateDisabled) {
// TODO: fix this
QStyleOption opt;
// opt.palette = q->standardPalette();
result = QApplication::style()->generatedIconPixmap(QIcon::Disabled, result, &opt);
}
return result;
}
QPixmap QS60StylePrivate::frame(SkinFrameElements frame, const QSize &size,
SkinElementFlags flags)
{
const QS60StyleEnums::SkinParts center = m_frameElementsData[frame].center;
const QS60StyleEnums::SkinParts topLeft = QS60StyleEnums::SkinParts(center - 8);
const QS60StyleEnums::SkinParts topRight = QS60StyleEnums::SkinParts(center - 7);
const QS60StyleEnums::SkinParts bottomLeft = QS60StyleEnums::SkinParts(center - 6);
const QS60StyleEnums::SkinParts bottomRight = QS60StyleEnums::SkinParts(center - 5);
const QS60StyleEnums::SkinParts top = QS60StyleEnums::SkinParts(center - 4);
const QS60StyleEnums::SkinParts bottom = QS60StyleEnums::SkinParts(center - 3);
const QS60StyleEnums::SkinParts left = QS60StyleEnums::SkinParts(center - 2);
const QS60StyleEnums::SkinParts right = QS60StyleEnums::SkinParts(center - 1);
// The size of topLeft defines all other sizes
const QSize cornerSize(partSize(topLeft));
// if frame is so small that corners would cover it completely, draw only center piece
const bool drawOnlyCenter =
2 * cornerSize.width() + 1 >= size.width() || 2 * cornerSize.height() + 1 >= size.height();
const int cornerWidth = cornerSize.width();
const int cornerHeight = cornerSize.height();
const int rectWidth = size.width();
const int rectHeight = size.height();
const QRect rect(QPoint(), size);
const QRect topLeftRect = QRect(rect.topLeft(), cornerSize);
const QRect topRect = rect.adjusted(cornerWidth, 0, -cornerWidth, -(rectHeight - cornerHeight));
const QRect topRightRect = topLeftRect.translated(rectWidth - cornerWidth, 0);
const QRect rightRect = rect.adjusted(rectWidth - cornerWidth, cornerHeight, 0, -cornerHeight);
const QRect bottomRightRect = topRightRect.translated(0, rectHeight - cornerHeight);
const QRect bottomRect = topRect.translated(0, rectHeight - cornerHeight);
const QRect bottomLeftRect = topLeftRect.translated(0, rectHeight - cornerHeight);
const QRect leftRect = rightRect.translated(cornerWidth - rectWidth, 0);
const QRect centerRect = drawOnlyCenter ? rect : rect.adjusted(cornerWidth, cornerWidth, -cornerWidth, -cornerWidth);
QImage result(size, QImage::Format_ARGB32);
QPainter painter(&result);
#if 0
painter.save();
painter.setOpacity(.3);
painter.fillRect(topLeftRect, Qt::red);
painter.fillRect(topRect, Qt::green);
painter.fillRect(topRightRect, Qt::blue);
painter.fillRect(rightRect, Qt::green);
painter.fillRect(bottomRightRect, Qt::red);
painter.fillRect(bottomRect, Qt::blue);
painter.fillRect(bottomLeftRect, Qt::green);
painter.fillRect(leftRect, Qt::blue);
painter.fillRect(centerRect, Qt::red);
painter.restore();
#else
drawPart(topLeft, &painter, topLeftRect, flags);
drawPart(top, &painter, topRect, flags);
drawPart(topRight, &painter, topRightRect, flags);
drawPart(right, &painter, rightRect, flags);
drawPart(bottomRight, &painter, bottomRightRect, flags);
drawPart(bottom, &painter, bottomRect, flags);
drawPart(bottomLeft, &painter, bottomLeftRect, flags);
drawPart(left, &painter, leftRect, flags);
drawPart(center, &painter, centerRect, flags);
#endif
return QPixmap::fromImage(result);
}
void QS60StylePrivate::setStyleProperty_specific(const char *name, const QVariant &value)
{
setStyleProperty(name, value);
}
QVariant QS60StylePrivate::styleProperty_specific(const char *name) const
{
return styleProperty(name);
}
QPixmap QS60StylePrivate::backgroundTexture()
{
if (!m_background) {
const QSize size = QApplication::desktop()->screen()->size();
QPixmap background = part(QS60StyleEnums::SP_QsnBgScreen, size);
m_background = new QPixmap(background);
}
return *m_background;
}
bool QS60StylePrivate::isTouchSupported()
{
#ifdef QT_KEYPAD_NAVIGATION
return !QApplication::keypadNavigationEnabled();
#else
return true;
#endif
}
bool QS60StylePrivate::isToolBarBackground()
{
return true;
}
QFont QS60StylePrivate::s60Font_specific(QS60StyleEnums::FontCategories fontCategory, int pointSize)
{
QFont result;
result.setPointSize(pointSize);
switch (fontCategory) {
case QS60StyleEnums::FC_Primary:
result.setBold(true);
break;
case QS60StyleEnums::FC_Secondary:
case QS60StyleEnums::FC_Title:
case QS60StyleEnums::FC_PrimarySmall:
case QS60StyleEnums::FC_Digital:
case QS60StyleEnums::FC_Undefined:
default:
break;
}
return result;
}
Q_GLOBAL_STATIC_WITH_INITIALIZER(QStringList, enumPartKeys, {
const int enumIndex = QS60StyleEnums::staticMetaObject.indexOfEnumerator("SkinParts");
Q_ASSERT(enumIndex >= 0);
const QMetaEnum metaEnum = QS60StyleEnums::staticMetaObject.enumerator(enumIndex);
for (int i = 0; i < metaEnum.keyCount(); ++i) {
const QString enumKey = QString::fromLatin1(metaEnum.key(i));
QString partKey;
// Following loop does following conversions: "SP_QgnNoteInfo" to "qgn_note_info"...
for (int charPosition = 3; charPosition < enumKey.length(); charPosition++) {
if (charPosition > 3 && enumKey[charPosition].isUpper())
partKey.append(QChar::fromLatin1('_'));
partKey.append(enumKey[charPosition].toLower());
}
x->append(partKey);
}
})
QStringList QS60Style::partKeys()
{
return *enumPartKeys();
}
Q_GLOBAL_STATIC_WITH_INITIALIZER(QStringList, enumColorListKeys, {
const int enumIndex = QS60StyleEnums::staticMetaObject.indexOfEnumerator("ColorLists");
Q_ASSERT(enumIndex >= 0);
const QMetaEnum metaEnum = QS60StyleEnums::staticMetaObject.enumerator(enumIndex);
for (int i = 0; i < metaEnum.keyCount(); i++) {
const QString enumKey = QString::fromLatin1(metaEnum.key(i));
// Following line does following conversions: CL_QsnTextColors to "text"...
x->append(enumKey.mid(6, enumKey.length() - 12).toLower());
}
})
QStringList QS60Style::colorListKeys()
{
return *enumColorListKeys();
}
void QS60Style::setS60Theme(const QHash<QString, QPicture> &parts,
const QHash<QPair<QString , int>, QColor> &colors)
{
Q_D(QS60Style);
QS60StyleModeSpecifics::m_partPictures = parts;
QS60StyleModeSpecifics::m_colors = colors;
d->clearCaches(QS60StylePrivate::CC_ThemeChange);
d->setBackgroundTexture(qApp);
}
QPoint qt_s60_fill_background_offset(const QWidget *targetWidget)
{
Q_UNUSED(targetWidget)
return QPoint();
}
QT_END_NAMESPACE
#endif // QT_NO_STYLE_S60 || QT_PLUGIN
|