|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
5 ** |
|
6 ** This file is part of the examples of the Qt Toolkit. |
|
7 ** |
|
8 ** $QT_BEGIN_LICENSE:LGPL$ |
|
9 ** No Commercial Usage |
|
10 ** This file contains pre-release code and may not be distributed. |
|
11 ** You may use this file in accordance with the terms and conditions |
|
12 ** contained in the either Technology Preview License Agreement or the |
|
13 ** Beta Release License Agreement. |
|
14 ** |
|
15 ** GNU Lesser General Public License Usage |
|
16 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
17 ** General Public License version 2.1 as published by the Free Software |
|
18 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
19 ** packaging of this file. Please review the following information to |
|
20 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
21 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
22 ** |
|
23 ** In addition, as a special exception, Nokia gives you certain |
|
24 ** additional rights. These rights are described in the Nokia Qt LGPL |
|
25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this |
|
26 ** package. |
|
27 ** |
|
28 ** GNU General Public License Usage |
|
29 ** Alternatively, this file may be used under the terms of the GNU |
|
30 ** General Public License version 3.0 as published by the Free Software |
|
31 ** Foundation and appearing in the file LICENSE.GPL included in the |
|
32 ** packaging of this file. Please review the following information to |
|
33 ** ensure the GNU General Public License version 3.0 requirements will be |
|
34 ** met: http://www.gnu.org/copyleft/gpl.html. |
|
35 ** |
|
36 ** If you are unsure which license is appropriate for your use, please |
|
37 ** contact the sales department at http://qt.nokia.com/contact. |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <QDebug> |
|
43 #include <QPainter> |
|
44 #include <QPixmapCache> |
|
45 #include <QSvgRenderer> |
|
46 |
|
47 #include "theme.h" |
|
48 |
|
49 Q_DECLARE_METATYPE(Theme::Themes*) |
|
50 |
|
51 Theme::Theme(QObject *parent) |
|
52 : QObject(parent) |
|
53 , m_currentTheme() |
|
54 , m_availableThemes() |
|
55 , m_fonts() |
|
56 , m_pixmapPath() |
|
57 , m_listItemBackgroundBrushEven() |
|
58 , m_listItemBackgroundOpacityEven() |
|
59 , m_listItemBackgroundBrushOdd() |
|
60 , m_listItemBackgroundOpacityOdd() |
|
61 , m_listItemBorderPen(QPen()) |
|
62 , m_listItemRounding() |
|
63 #if (QT_VERSION >= 0x040600) |
|
64 , m_iconOpacityEffectEnabled() |
|
65 #endif |
|
66 , m_iconRotation() |
|
67 , m_iconSmoothTransformation() |
|
68 { |
|
69 m_availableThemes << "Blue" << "Lime"; |
|
70 |
|
71 // Set blue theme as a default theme without emiting themeChanged() signal |
|
72 setBlueTheme(); |
|
73 } |
|
74 |
|
75 Theme::~Theme() |
|
76 { |
|
77 } |
|
78 |
|
79 Theme* Theme::p() |
|
80 { |
|
81 static Theme t; |
|
82 return &t; |
|
83 } |
|
84 |
|
85 void Theme::setTheme(const QString theme) |
|
86 { |
|
87 if (theme.compare("blue", Qt::CaseInsensitive) == 0) |
|
88 { |
|
89 setTheme(Theme::Blue); |
|
90 } |
|
91 else if (theme.compare("lime", Qt::CaseInsensitive) == 0) |
|
92 { |
|
93 setTheme(Theme::Lime); |
|
94 } |
|
95 else |
|
96 { |
|
97 qDebug() << "Unknown theme"; |
|
98 } |
|
99 } |
|
100 |
|
101 void Theme::setTheme(const Themes theme) |
|
102 { |
|
103 if (m_currentTheme == theme) |
|
104 return; |
|
105 |
|
106 switch (theme) |
|
107 { |
|
108 case Theme::Blue: |
|
109 setBlueTheme(); |
|
110 emit themeChanged(); |
|
111 break; |
|
112 |
|
113 case Theme::Lime: |
|
114 setLimeTheme(); |
|
115 emit themeChanged(); |
|
116 break; |
|
117 } |
|
118 } |
|
119 |
|
120 void Theme::setBlueTheme() |
|
121 { |
|
122 m_currentTheme = Theme::Blue; |
|
123 |
|
124 m_fonts[ContactName].setFamily("Arial"); |
|
125 m_fonts[ContactName].setPixelSize(16); |
|
126 m_fonts[ContactName].setStyle(QFont::StyleNormal); |
|
127 m_fonts[ContactName].setWeight(QFont::Normal); |
|
128 |
|
129 m_fonts[ContactNumber].setFamily("Arial"); |
|
130 m_fonts[ContactNumber].setPixelSize(14); |
|
131 m_fonts[ContactNumber].setStyle(QFont::StyleNormal); |
|
132 |
|
133 m_fonts[ContactEmail].setFamily("Arial"); |
|
134 m_fonts[ContactEmail].setPixelSize(14); |
|
135 m_fonts[ContactEmail].setStyle(QFont::StyleNormal); |
|
136 |
|
137 m_fonts[TitleBar].setFamily("Arial"); |
|
138 m_fonts[TitleBar].setPixelSize(36); |
|
139 m_fonts[TitleBar].setStyle(QFont::StyleNormal); |
|
140 |
|
141 m_fonts[StatusBar].setFamily("Arial"); |
|
142 m_fonts[StatusBar].setPixelSize(16); |
|
143 m_fonts[StatusBar].setStyle(QFont::StyleNormal); |
|
144 |
|
145 m_fonts[MenuItem].setFamily("Arial"); |
|
146 m_fonts[MenuItem].setPixelSize(14); |
|
147 m_fonts[MenuItem].setStyle(QFont::StyleNormal); |
|
148 |
|
149 m_pixmapPath = ":/themes/blue/"; |
|
150 |
|
151 m_listItemBackgroundBrushEven = QBrush(Qt::NoBrush); |
|
152 m_listItemBackgroundOpacityEven = 1.0; |
|
153 m_listItemBackgroundBrushOdd = QBrush(QColor(44,214,250), Qt::SolidPattern); |
|
154 m_listItemBackgroundOpacityOdd = 1.0; |
|
155 |
|
156 m_listItemBorderPen = QPen(Qt::NoPen); |
|
157 m_listItemRounding = QSize(0.0, 0.0); |
|
158 |
|
159 #if (QT_VERSION >= 0x040600) |
|
160 m_iconOpacityEffectEnabled[ListItem::LeftIcon] = false; |
|
161 m_iconOpacityEffectEnabled[ListItem::RightIcon] = false; |
|
162 #endif |
|
163 m_iconRotation[ListItem::LeftIcon] = 0.0; |
|
164 m_iconRotation[ListItem::RightIcon] = 0.0; |
|
165 |
|
166 m_iconSmoothTransformation[ListItem::LeftIcon] = false; |
|
167 m_iconSmoothTransformation[ListItem::RightIcon] = false; |
|
168 } |
|
169 |
|
170 void Theme::setLimeTheme() |
|
171 { |
|
172 m_currentTheme = Theme::Lime; |
|
173 |
|
174 m_fonts[ContactName].setFamily("Arial"); |
|
175 m_fonts[ContactName].setPixelSize(16); |
|
176 m_fonts[ContactName].setStyle(QFont::StyleItalic); |
|
177 m_fonts[ContactName].setWeight(QFont::Bold); |
|
178 |
|
179 m_fonts[ContactNumber].setFamily("Arial"); |
|
180 m_fonts[ContactNumber].setPixelSize(14); |
|
181 m_fonts[ContactNumber].setStyle(QFont::StyleItalic); |
|
182 |
|
183 m_fonts[ContactEmail].setFamily("Arial"); |
|
184 m_fonts[ContactEmail].setPixelSize(14); |
|
185 m_fonts[ContactEmail].setStyle(QFont::StyleItalic); |
|
186 |
|
187 m_fonts[TitleBar].setFamily("Arial"); |
|
188 m_fonts[TitleBar].setPixelSize(36); |
|
189 m_fonts[TitleBar].setStyle(QFont::StyleItalic); |
|
190 |
|
191 m_fonts[StatusBar].setFamily("Arial"); |
|
192 m_fonts[StatusBar].setPixelSize(16); |
|
193 m_fonts[StatusBar].setStyle(QFont::StyleItalic); |
|
194 |
|
195 m_fonts[MenuItem].setFamily("Arial"); |
|
196 m_fonts[MenuItem].setPixelSize(14); |
|
197 m_fonts[MenuItem].setStyle(QFont::StyleItalic); |
|
198 |
|
199 m_pixmapPath = ":/themes/lime/"; |
|
200 |
|
201 m_listItemBackgroundBrushEven = QBrush(QPixmap(":/avatars/avatar_014.png")); |
|
202 m_listItemBackgroundOpacityEven = 0.05; |
|
203 |
|
204 m_listItemBackgroundBrushOdd = QBrush(QPixmap(":/avatars/avatar_012.png")); |
|
205 m_listItemBackgroundOpacityOdd = 0.15; |
|
206 |
|
207 m_listItemBorderPen = QPen(QColor(0,0,0,55), 3, Qt::SolidLine); |
|
208 m_listItemRounding = QSize(12.0, 12.0); |
|
209 |
|
210 #if (QT_VERSION >= 0x040600) |
|
211 m_iconOpacityEffectEnabled[ListItem::LeftIcon] = true; |
|
212 m_iconOpacityEffectEnabled[ListItem::RightIcon] = false; |
|
213 #endif |
|
214 m_iconRotation[ListItem::LeftIcon] = -4.0; |
|
215 m_iconRotation[ListItem::RightIcon] = 0.0; |
|
216 |
|
217 m_iconSmoothTransformation[ListItem::LeftIcon] = true; |
|
218 m_iconSmoothTransformation[ListItem::RightIcon] = false; |
|
219 } |
|
220 |
|
221 QPixmap Theme::pixmap(const QString filename, QSize size) |
|
222 { |
|
223 if (filename.endsWith(".svg", Qt::CaseInsensitive)) |
|
224 { |
|
225 QSvgRenderer doc(m_pixmapPath+filename); |
|
226 if (size == QSize(0,0)) |
|
227 size = doc.defaultSize(); |
|
228 QPixmap pix(size.width(),size.height()); |
|
229 pix.fill(Qt::transparent); |
|
230 QPainter painter(&pix); |
|
231 painter.setViewport(0, 0, size.width(), size.height()); |
|
232 doc.render(&painter); |
|
233 return pix; |
|
234 } |
|
235 else |
|
236 { |
|
237 QPixmap pix(m_pixmapPath+filename); |
|
238 return pix.scaled(size); |
|
239 } |
|
240 } |