|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the examples 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 "blurpicker.h" |
|
43 |
|
44 #include <QtGui> |
|
45 |
|
46 #include "blureffect.h" |
|
47 #include "customshadereffect.h" |
|
48 |
|
49 #ifndef M_PI |
|
50 #define M_PI 3.14159265358979323846 |
|
51 #endif |
|
52 |
|
53 BlurPicker::BlurPicker(QWidget *parent): QGraphicsView(parent), m_index(0.0) |
|
54 { |
|
55 setBackgroundBrush(QPixmap(":/images/background.jpg")); |
|
56 setScene(&m_scene); |
|
57 |
|
58 setupScene(); |
|
59 updateIconPositions(); |
|
60 |
|
61 connect(&m_timeLine, SIGNAL(valueChanged(qreal)), SLOT(updateIconPositions())); |
|
62 m_timeLine.setDuration(400); |
|
63 |
|
64 setRenderHint(QPainter::Antialiasing, true); |
|
65 setFrameStyle(QFrame::NoFrame); |
|
66 } |
|
67 |
|
68 void BlurPicker::updateIconPositions() |
|
69 { |
|
70 m_index = m_timeLine.currentFrame() / 1000.0; |
|
71 |
|
72 qreal baseline = 0; |
|
73 for (int i = 0; i < m_icons.count(); ++i) { |
|
74 QGraphicsItem *icon = m_icons[i]; |
|
75 qreal a = ((i + m_index) * 2 * M_PI) / m_icons.count(); |
|
76 qreal xs = 170 * sin(a); |
|
77 qreal ys = 100 * cos(a); |
|
78 QPointF pos(xs, ys); |
|
79 pos = QTransform().rotate(-20).map(pos); |
|
80 pos -= QPointF(40, 40); |
|
81 icon->setPos(pos); |
|
82 baseline = qMax(baseline, ys); |
|
83 if (i != 3) |
|
84 static_cast<BlurEffect *>(icon->graphicsEffect())->setBaseLine(baseline); |
|
85 } |
|
86 |
|
87 m_scene.update(); |
|
88 } |
|
89 |
|
90 void BlurPicker::setupScene() |
|
91 { |
|
92 m_scene.setSceneRect(-200, -120, 400, 240); |
|
93 |
|
94 QStringList names; |
|
95 names << ":/images/accessories-calculator.png"; |
|
96 names << ":/images/accessories-text-editor.png"; |
|
97 names << ":/images/help-browser.png"; |
|
98 names << ":/images/internet-group-chat.png"; |
|
99 names << ":/images/internet-mail.png"; |
|
100 names << ":/images/internet-web-browser.png"; |
|
101 names << ":/images/office-calendar.png"; |
|
102 names << ":/images/system-users.png"; |
|
103 |
|
104 for (int i = 0; i < names.count(); i++) { |
|
105 QPixmap pixmap(names[i]); |
|
106 QGraphicsPixmapItem *icon = m_scene.addPixmap(pixmap); |
|
107 icon->setZValue(1); |
|
108 if (i == 3) |
|
109 icon->setGraphicsEffect(new CustomShaderEffect()); |
|
110 else |
|
111 icon->setGraphicsEffect(new BlurEffect(icon)); |
|
112 m_icons << icon; |
|
113 } |
|
114 |
|
115 QGraphicsPixmapItem *bg = m_scene.addPixmap(QPixmap(":/images/background.jpg")); |
|
116 bg->setZValue(0); |
|
117 bg->setPos(-200, -150); |
|
118 } |
|
119 |
|
120 void BlurPicker::keyPressEvent(QKeyEvent *event) |
|
121 { |
|
122 if (event->key() == Qt::Key_Left) { |
|
123 if (m_timeLine.state() == QTimeLine::NotRunning) { |
|
124 m_timeLine.setFrameRange(m_index * 1000, m_index * 1000 - 1000); |
|
125 m_timeLine.start(); |
|
126 event->accept(); |
|
127 } |
|
128 } |
|
129 |
|
130 if (event->key() == Qt::Key_Right) { |
|
131 if (m_timeLine.state() == QTimeLine::NotRunning) { |
|
132 m_timeLine.setFrameRange(m_index * 1000, m_index * 1000 + 1000); |
|
133 m_timeLine.start(); |
|
134 event->accept(); |
|
135 } |
|
136 } |
|
137 } |