1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the examples of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:LGPL$
9
** Commercial License Usage
10
** Licensees holding valid commercial Qt licenses may use this file in
11
** accordance with the commercial license agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
17
** GNU Lesser General Public License Usage
18
** Alternatively, this file may be used under the terms of the GNU Lesser
19
** General Public License version 2.1 as published by the Free Software
20
** Foundation and appearing in the file LICENSE.LGPL included in the
21
** packaging of this file. Please review the following information to
22
** ensure the GNU Lesser General Public License version 2.1 requirements
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
** In addition, as a special exception, Digia gives you certain additional
26
** rights. These rights are described in the Digia Qt LGPL Exception
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
** GNU General Public License Usage
30
** Alternatively, this file may be used under the terms of the GNU
31
** General Public License version 3.0 as published by the Free Software
32
** Foundation and appearing in the file LICENSE.GPL included in the
33
** packaging of this file. Please review the following information to
34
** ensure the GNU General Public License version 3.0 requirements will be
35
** met: http://www.gnu.org/copyleft/gpl.html.
40
****************************************************************************/
44
#include <QPixmapCache>
45
#include <QSvgRenderer>
49
Q_DECLARE_METATYPE(Theme::Themes*)
51
Theme::Theme(QObject *parent)
57
, m_listItemBackgroundBrushEven()
58
, m_listItemBackgroundOpacityEven()
59
, m_listItemBackgroundBrushOdd()
60
, m_listItemBackgroundOpacityOdd()
61
, m_listItemBorderPen(QPen())
62
, m_listItemRounding()
63
, m_iconOpacityEffectEnabled()
65
, m_iconSmoothTransformation()
67
m_availableThemes << "Blue" << "Lime";
69
// Set blue theme as a default theme without emiting themeChanged() signal
83
void Theme::setTheme(const QString theme)
85
if (theme.compare("blue", Qt::CaseInsensitive) == 0)
87
setTheme(Theme::Blue);
89
else if (theme.compare("lime", Qt::CaseInsensitive) == 0)
91
setTheme(Theme::Lime);
95
qDebug() << "Unknown theme";
99
void Theme::setTheme(const Themes theme)
101
if (m_currentTheme == theme)
118
void Theme::setBlueTheme()
120
m_currentTheme = Theme::Blue;
122
m_fonts[ContactName].setFamily("Arial");
123
m_fonts[ContactName].setPixelSize(16);
124
m_fonts[ContactName].setStyle(QFont::StyleNormal);
125
m_fonts[ContactName].setWeight(QFont::Normal);
127
m_fonts[ContactNumber].setFamily("Arial");
128
m_fonts[ContactNumber].setPixelSize(14);
129
m_fonts[ContactNumber].setStyle(QFont::StyleNormal);
131
m_fonts[ContactEmail].setFamily("Arial");
132
m_fonts[ContactEmail].setPixelSize(14);
133
m_fonts[ContactEmail].setStyle(QFont::StyleNormal);
135
m_fonts[TitleBar].setFamily("Arial");
136
m_fonts[TitleBar].setPixelSize(36);
137
m_fonts[TitleBar].setStyle(QFont::StyleNormal);
139
m_fonts[StatusBar].setFamily("Arial");
140
m_fonts[StatusBar].setPixelSize(16);
141
m_fonts[StatusBar].setStyle(QFont::StyleNormal);
143
m_fonts[MenuItem].setFamily("Arial");
144
m_fonts[MenuItem].setPixelSize(14);
145
m_fonts[MenuItem].setStyle(QFont::StyleNormal);
147
m_pixmapPath = ":/themes/blue/";
149
m_listItemBackgroundBrushEven = QBrush(Qt::NoBrush);
150
m_listItemBackgroundOpacityEven = 1.0;
151
m_listItemBackgroundBrushOdd = QBrush(QColor(44,214,250), Qt::SolidPattern);
152
m_listItemBackgroundOpacityOdd = 1.0;
154
m_listItemBorderPen = QPen(Qt::NoPen);
155
m_listItemRounding = QSize(0.0, 0.0);
157
m_iconOpacityEffectEnabled[ListItem::LeftIcon] = false;
158
m_iconOpacityEffectEnabled[ListItem::RightIcon] = false;
160
m_iconRotation[ListItem::LeftIcon] = 0.0;
161
m_iconRotation[ListItem::RightIcon] = 0.0;
163
m_iconSmoothTransformation[ListItem::LeftIcon] = false;
164
m_iconSmoothTransformation[ListItem::RightIcon] = false;
167
void Theme::setLimeTheme()
169
m_currentTheme = Theme::Lime;
171
m_fonts[ContactName].setFamily("Arial");
172
m_fonts[ContactName].setPixelSize(16);
173
m_fonts[ContactName].setStyle(QFont::StyleItalic);
174
m_fonts[ContactName].setWeight(QFont::Bold);
176
m_fonts[ContactNumber].setFamily("Arial");
177
m_fonts[ContactNumber].setPixelSize(14);
178
m_fonts[ContactNumber].setStyle(QFont::StyleItalic);
180
m_fonts[ContactEmail].setFamily("Arial");
181
m_fonts[ContactEmail].setPixelSize(14);
182
m_fonts[ContactEmail].setStyle(QFont::StyleItalic);
184
m_fonts[TitleBar].setFamily("Arial");
185
m_fonts[TitleBar].setPixelSize(36);
186
m_fonts[TitleBar].setStyle(QFont::StyleItalic);
188
m_fonts[StatusBar].setFamily("Arial");
189
m_fonts[StatusBar].setPixelSize(16);
190
m_fonts[StatusBar].setStyle(QFont::StyleItalic);
192
m_fonts[MenuItem].setFamily("Arial");
193
m_fonts[MenuItem].setPixelSize(14);
194
m_fonts[MenuItem].setStyle(QFont::StyleItalic);
196
m_pixmapPath = ":/themes/lime/";
198
m_listItemBackgroundBrushEven = QBrush(QPixmap(":/avatars/avatar_014.png"));
199
m_listItemBackgroundOpacityEven = 0.05;
201
m_listItemBackgroundBrushOdd = QBrush(QPixmap(":/avatars/avatar_012.png"));
202
m_listItemBackgroundOpacityOdd = 0.15;
204
m_listItemBorderPen = QPen(QColor(0,0,0,55), 3, Qt::SolidLine);
205
m_listItemRounding = QSize(12.0, 12.0);
207
m_iconOpacityEffectEnabled[ListItem::LeftIcon] = true;
208
m_iconOpacityEffectEnabled[ListItem::RightIcon] = false;
210
m_iconRotation[ListItem::LeftIcon] = -4.0;
211
m_iconRotation[ListItem::RightIcon] = 0.0;
213
m_iconSmoothTransformation[ListItem::LeftIcon] = true;
214
m_iconSmoothTransformation[ListItem::RightIcon] = false;
217
QPixmap Theme::pixmap(const QString filename, QSize size)
219
if (filename.endsWith(".svg", Qt::CaseInsensitive))
221
QSvgRenderer doc(m_pixmapPath+filename);
222
if (size == QSize(0,0))
223
size = doc.defaultSize();
224
QPixmap pix(size.width(),size.height());
225
pix.fill(Qt::transparent);
226
QPainter painter(&pix);
227
painter.setViewport(0, 0, size.width(), size.height());
228
doc.render(&painter);
233
QPixmap pix(m_pixmapPath+filename);
234
return pix.scaled(size);