| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2010 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 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 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 | ** 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 have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at qt-info@nokia.com.
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "fademessage.h"
|
|---|
| 43 |
|
|---|
| 44 | #include <QtGui>
|
|---|
| 45 |
|
|---|
| 46 | FadeMessage::FadeMessage(QWidget *parent): QGraphicsView(parent)
|
|---|
| 47 | {
|
|---|
| 48 | setScene(&m_scene);
|
|---|
| 49 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|---|
| 50 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|---|
| 51 |
|
|---|
| 52 | setupScene();
|
|---|
| 53 |
|
|---|
| 54 | m_animation = new QPropertyAnimation(m_effect, "strength", this);
|
|---|
| 55 | m_animation->setDuration(500);
|
|---|
| 56 | m_animation->setEasingCurve(QEasingCurve::InOutSine);
|
|---|
| 57 | m_animation->setStartValue(0);
|
|---|
| 58 | m_animation->setEndValue(1);
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 | setRenderHint(QPainter::Antialiasing, true);
|
|---|
| 62 | setFrameStyle(QFrame::NoFrame);
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | void FadeMessage::togglePopup()
|
|---|
| 66 | {
|
|---|
| 67 | if (m_message->isVisible()) {
|
|---|
| 68 | m_message->setVisible(false);
|
|---|
| 69 | m_animation->setDirection(QAbstractAnimation::Backward);
|
|---|
| 70 | } else {
|
|---|
| 71 | m_message->setVisible(true);
|
|---|
| 72 | m_animation->setDirection(QAbstractAnimation::Forward);
|
|---|
| 73 | }
|
|---|
| 74 | m_animation->start();
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | void FadeMessage::setupScene()
|
|---|
| 78 | {
|
|---|
| 79 | QGraphicsRectItem *parent = m_scene.addRect(0, 0, 400, 600);
|
|---|
| 80 | parent->setPen(Qt::NoPen);
|
|---|
| 81 | parent->setZValue(0);
|
|---|
| 82 |
|
|---|
| 83 | QGraphicsPixmapItem *bg = m_scene.addPixmap(QPixmap(":/background.jpg"));
|
|---|
| 84 | bg->setParentItem(parent);
|
|---|
| 85 | bg->setZValue(-1);
|
|---|
| 86 |
|
|---|
| 87 | for (int i = 1; i < 5; ++i)
|
|---|
| 88 | for (int j = 2; j < 5; ++j) {
|
|---|
| 89 | QGraphicsRectItem *item = m_scene.addRect(i * 50, j * 50, 38, 38);
|
|---|
| 90 | item->setParentItem(parent);
|
|---|
| 91 | item->setZValue(1);
|
|---|
| 92 | int hue = 12 * (i * 5 + j);
|
|---|
| 93 | item->setBrush(QColor::fromHsv(hue, 128, 128));
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | QFont font;
|
|---|
| 97 | font.setPointSize(font.pointSize() * 2);
|
|---|
| 98 | font.setBold(true);
|
|---|
| 99 | QFontMetrics fontMetrics(font);
|
|---|
| 100 | int fh = fontMetrics.height();
|
|---|
| 101 |
|
|---|
| 102 | QString sceneText = "Qt Everywhere!";
|
|---|
| 103 | int sceneTextWidth = fontMetrics.width(sceneText);
|
|---|
| 104 |
|
|---|
| 105 | QGraphicsRectItem *block = m_scene.addRect(50, 300, sceneTextWidth, fh + 3);
|
|---|
| 106 | block->setPen(Qt::NoPen);
|
|---|
| 107 | block->setBrush(QColor(102, 153, 51));
|
|---|
| 108 |
|
|---|
| 109 | QGraphicsTextItem *text = m_scene.addText(sceneText, font);
|
|---|
| 110 | text->setDefaultTextColor(Qt::white);
|
|---|
| 111 | text->setPos(50, 300);
|
|---|
| 112 | block->setZValue(2);
|
|---|
| 113 | block->hide();
|
|---|
| 114 |
|
|---|
| 115 | text->setParentItem(block);
|
|---|
| 116 | m_message = block;
|
|---|
| 117 |
|
|---|
| 118 | m_effect = new QGraphicsColorizeEffect;
|
|---|
| 119 | m_effect->setColor(QColor(122, 193, 66));
|
|---|
| 120 | m_effect->setStrength(0);
|
|---|
| 121 | m_effect->setEnabled(true);
|
|---|
| 122 | parent->setGraphicsEffect(m_effect);
|
|---|
| 123 |
|
|---|
| 124 | QPushButton *press = new QPushButton;
|
|---|
| 125 | press->setText(tr("Press me"));
|
|---|
| 126 | connect(press, SIGNAL(clicked()), SLOT(togglePopup()));
|
|---|
| 127 | m_scene.addWidget(press);
|
|---|
| 128 | press->move(300, 500);
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|