~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/theme.cpp

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the examples of the Qt Toolkit.
 
7
**
 
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.
 
16
**
 
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.
 
24
**
 
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.
 
28
**
 
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.
 
36
**
 
37
**
 
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
  , m_iconOpacityEffectEnabled()
 
64
  , m_iconRotation()
 
65
  , m_iconSmoothTransformation()
 
66
{
 
67
    m_availableThemes << "Blue" << "Lime";
 
68
 
 
69
    // Set blue theme as a default theme without emiting themeChanged() signal
 
70
    setBlueTheme();
 
71
}
 
72
 
 
73
Theme::~Theme()
 
74
{
 
75
}
 
76
 
 
77
Theme* Theme::p()
 
78
{
 
79
    static Theme t;
 
80
    return &t;
 
81
}
 
82
 
 
83
void Theme::setTheme(const QString theme)
 
84
{
 
85
    if (theme.compare("blue", Qt::CaseInsensitive) == 0)
 
86
    {
 
87
        setTheme(Theme::Blue);
 
88
    }
 
89
    else if (theme.compare("lime", Qt::CaseInsensitive) == 0)
 
90
    {
 
91
        setTheme(Theme::Lime);
 
92
    }
 
93
    else
 
94
    {
 
95
        qDebug() << "Unknown theme";
 
96
    }
 
97
}
 
98
 
 
99
void Theme::setTheme(const Themes theme)
 
100
{
 
101
    if (m_currentTheme == theme)
 
102
        return;
 
103
 
 
104
    switch (theme)
 
105
    {
 
106
        case Theme::Blue:
 
107
            setBlueTheme();
 
108
            emit themeChanged();
 
109
            break;
 
110
 
 
111
        case Theme::Lime:
 
112
            setLimeTheme();
 
113
            emit themeChanged();
 
114
            break;
 
115
    }
 
116
}
 
117
 
 
118
void Theme::setBlueTheme()
 
119
{
 
120
    m_currentTheme = Theme::Blue;
 
121
 
 
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);
 
126
 
 
127
    m_fonts[ContactNumber].setFamily("Arial");
 
128
    m_fonts[ContactNumber].setPixelSize(14);
 
129
    m_fonts[ContactNumber].setStyle(QFont::StyleNormal);
 
130
 
 
131
    m_fonts[ContactEmail].setFamily("Arial");
 
132
    m_fonts[ContactEmail].setPixelSize(14);
 
133
    m_fonts[ContactEmail].setStyle(QFont::StyleNormal);
 
134
 
 
135
    m_fonts[TitleBar].setFamily("Arial");
 
136
    m_fonts[TitleBar].setPixelSize(36);
 
137
    m_fonts[TitleBar].setStyle(QFont::StyleNormal);
 
138
 
 
139
    m_fonts[StatusBar].setFamily("Arial");
 
140
    m_fonts[StatusBar].setPixelSize(16);
 
141
    m_fonts[StatusBar].setStyle(QFont::StyleNormal);
 
142
 
 
143
    m_fonts[MenuItem].setFamily("Arial");
 
144
    m_fonts[MenuItem].setPixelSize(14);
 
145
    m_fonts[MenuItem].setStyle(QFont::StyleNormal);
 
146
 
 
147
    m_pixmapPath = ":/themes/blue/";
 
148
 
 
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;
 
153
 
 
154
    m_listItemBorderPen = QPen(Qt::NoPen);
 
155
    m_listItemRounding = QSize(0.0, 0.0);
 
156
 
 
157
    m_iconOpacityEffectEnabled[ListItem::LeftIcon] = false;
 
158
    m_iconOpacityEffectEnabled[ListItem::RightIcon] = false;
 
159
 
 
160
    m_iconRotation[ListItem::LeftIcon] =  0.0;
 
161
    m_iconRotation[ListItem::RightIcon] = 0.0;
 
162
 
 
163
    m_iconSmoothTransformation[ListItem::LeftIcon] = false;
 
164
    m_iconSmoothTransformation[ListItem::RightIcon] = false;
 
165
}
 
166
 
 
167
void Theme::setLimeTheme()
 
168
{
 
169
    m_currentTheme = Theme::Lime;
 
170
 
 
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);
 
175
 
 
176
    m_fonts[ContactNumber].setFamily("Arial");
 
177
    m_fonts[ContactNumber].setPixelSize(14);
 
178
    m_fonts[ContactNumber].setStyle(QFont::StyleItalic);
 
179
 
 
180
    m_fonts[ContactEmail].setFamily("Arial");
 
181
    m_fonts[ContactEmail].setPixelSize(14);
 
182
    m_fonts[ContactEmail].setStyle(QFont::StyleItalic);
 
183
 
 
184
    m_fonts[TitleBar].setFamily("Arial");
 
185
    m_fonts[TitleBar].setPixelSize(36);
 
186
    m_fonts[TitleBar].setStyle(QFont::StyleItalic);
 
187
 
 
188
    m_fonts[StatusBar].setFamily("Arial");
 
189
    m_fonts[StatusBar].setPixelSize(16);
 
190
    m_fonts[StatusBar].setStyle(QFont::StyleItalic);
 
191
 
 
192
    m_fonts[MenuItem].setFamily("Arial");
 
193
    m_fonts[MenuItem].setPixelSize(14);
 
194
    m_fonts[MenuItem].setStyle(QFont::StyleItalic);
 
195
 
 
196
    m_pixmapPath = ":/themes/lime/";
 
197
 
 
198
    m_listItemBackgroundBrushEven = QBrush(QPixmap(":/avatars/avatar_014.png"));
 
199
    m_listItemBackgroundOpacityEven = 0.05;
 
200
 
 
201
    m_listItemBackgroundBrushOdd = QBrush(QPixmap(":/avatars/avatar_012.png"));
 
202
    m_listItemBackgroundOpacityOdd = 0.15;
 
203
 
 
204
    m_listItemBorderPen = QPen(QColor(0,0,0,55), 3, Qt::SolidLine);
 
205
    m_listItemRounding = QSize(12.0, 12.0);
 
206
 
 
207
    m_iconOpacityEffectEnabled[ListItem::LeftIcon] = true;
 
208
    m_iconOpacityEffectEnabled[ListItem::RightIcon] = false;
 
209
 
 
210
    m_iconRotation[ListItem::LeftIcon] = -4.0;
 
211
    m_iconRotation[ListItem::RightIcon] = 0.0;
 
212
 
 
213
    m_iconSmoothTransformation[ListItem::LeftIcon] = true;
 
214
    m_iconSmoothTransformation[ListItem::RightIcon] = false;
 
215
}
 
216
 
 
217
QPixmap Theme::pixmap(const QString filename, QSize size)
 
218
{
 
219
    if (filename.endsWith(".svg", Qt::CaseInsensitive))
 
220
    {
 
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);
 
229
        return pix;
 
230
    }
 
231
    else
 
232
    {
 
233
        QPixmap pix(m_pixmapPath+filename);
 
234
        return pix.scaled(size);
 
235
    }
 
236
}