|
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 "fademessage.h" |
|
43 |
|
44 #include <QtGui> |
|
45 |
|
46 FadeMessage::FadeMessage(QWidget *parent): QGraphicsView(parent), m_index(0.0) |
|
47 { |
|
48 setScene(&m_scene); |
|
49 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
50 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
51 |
|
52 setupScene(); |
|
53 |
|
54 m_timeLine = new QTimeLine(500, this); |
|
55 m_timeLine->setCurveShape(QTimeLine::EaseInOutCurve); |
|
56 connect(m_timeLine, SIGNAL(valueChanged(qreal)), m_effect, SLOT(setStrength(qreal))); |
|
57 |
|
58 setRenderHint(QPainter::Antialiasing, true); |
|
59 setFrameStyle(QFrame::NoFrame); |
|
60 } |
|
61 |
|
62 void FadeMessage::togglePopup() |
|
63 { |
|
64 if (m_message->isVisible()) { |
|
65 m_message->setVisible(false); |
|
66 m_timeLine->setDirection(QTimeLine::Backward); |
|
67 m_timeLine->start(); |
|
68 } else { |
|
69 m_message->setVisible(true); |
|
70 m_timeLine->setDirection(QTimeLine::Forward); |
|
71 m_timeLine->start(); |
|
72 } |
|
73 } |
|
74 |
|
75 void FadeMessage::setupScene() |
|
76 { |
|
77 QGraphicsRectItem *parent = m_scene.addRect(0, 0, 400, 600); |
|
78 parent->setPen(Qt::NoPen); |
|
79 parent->setZValue(0); |
|
80 |
|
81 QGraphicsPixmapItem *bg = m_scene.addPixmap(QPixmap(":/background.jpg")); |
|
82 bg->setParentItem(parent); |
|
83 bg->setZValue(-1); |
|
84 |
|
85 for (int i = 1; i < 5; ++i) |
|
86 for (int j = 2; j < 5; ++j) { |
|
87 QGraphicsRectItem *item = m_scene.addRect(i * 50, j * 50, 38, 38); |
|
88 item->setParentItem(parent); |
|
89 item->setZValue(1); |
|
90 int hue = 12 * (i * 5 + j); |
|
91 item->setBrush(QColor::fromHsv(hue, 128, 128)); |
|
92 } |
|
93 |
|
94 QFont font; |
|
95 font.setPointSize(font.pointSize() * 2); |
|
96 font.setBold(true); |
|
97 int fh = QFontMetrics(font).height(); |
|
98 |
|
99 QGraphicsRectItem *block = m_scene.addRect(50, 300, 300, fh + 3); |
|
100 block->setPen(Qt::NoPen); |
|
101 block->setBrush(QColor(102, 153, 51)); |
|
102 |
|
103 QGraphicsTextItem *text = m_scene.addText("Qt Everywhere!", font); |
|
104 text->setDefaultTextColor(Qt::white); |
|
105 text->setPos(50, 300); |
|
106 block->setZValue(2); |
|
107 block->hide(); |
|
108 |
|
109 text->setParentItem(block); |
|
110 m_message = block; |
|
111 |
|
112 m_effect = new QGraphicsColorizeEffect; |
|
113 m_effect->setColor(QColor(122, 193, 66)); |
|
114 m_effect->setStrength(0); |
|
115 m_effect->setEnabled(true); |
|
116 parent->setGraphicsEffect(m_effect); |
|
117 |
|
118 QPushButton *press = new QPushButton; |
|
119 press->setText(tr("Press me")); |
|
120 connect(press, SIGNAL(clicked()), SLOT(togglePopup())); |
|
121 m_scene.addWidget(press); |
|
122 press->move(300, 500); |
|
123 } |
|
124 |