[556] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[556] | 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 | **
|
---|
[846] | 9 | ** $QT_BEGIN_LICENSE:BSD$
|
---|
| 10 | ** You may use this file under the terms of the BSD license as follows:
|
---|
[556] | 11 | **
|
---|
[846] | 12 | ** "Redistribution and use in source and binary forms, with or without
|
---|
| 13 | ** modification, are permitted provided that the following conditions are
|
---|
| 14 | ** met:
|
---|
| 15 | ** * Redistributions of source code must retain the above copyright
|
---|
| 16 | ** notice, this list of conditions and the following disclaimer.
|
---|
| 17 | ** * Redistributions in binary form must reproduce the above copyright
|
---|
| 18 | ** notice, this list of conditions and the following disclaimer in
|
---|
| 19 | ** the documentation and/or other materials provided with the
|
---|
| 20 | ** distribution.
|
---|
| 21 | ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
---|
| 22 | ** the names of its contributors may be used to endorse or promote
|
---|
| 23 | ** products derived from this software without specific prior written
|
---|
| 24 | ** permission.
|
---|
[556] | 25 | **
|
---|
[846] | 26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
| 27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
| 28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
---|
| 29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
---|
| 30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
| 31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
| 32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
| 36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
---|
[556] | 37 | ** $QT_END_LICENSE$
|
---|
| 38 | **
|
---|
| 39 | ****************************************************************************/
|
---|
| 40 |
|
---|
| 41 | #include "fademessage.h"
|
---|
| 42 |
|
---|
| 43 | #include <QtGui>
|
---|
| 44 |
|
---|
| 45 | FadeMessage::FadeMessage(QWidget *parent): QGraphicsView(parent)
|
---|
| 46 | {
|
---|
| 47 | setScene(&m_scene);
|
---|
| 48 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
---|
| 49 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
---|
| 50 |
|
---|
| 51 | setupScene();
|
---|
| 52 |
|
---|
| 53 | m_animation = new QPropertyAnimation(m_effect, "strength", this);
|
---|
| 54 | m_animation->setDuration(500);
|
---|
| 55 | m_animation->setEasingCurve(QEasingCurve::InOutSine);
|
---|
| 56 | m_animation->setStartValue(0);
|
---|
| 57 | m_animation->setEndValue(1);
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | setRenderHint(QPainter::Antialiasing, true);
|
---|
| 61 | setFrameStyle(QFrame::NoFrame);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | void FadeMessage::togglePopup()
|
---|
| 65 | {
|
---|
| 66 | if (m_message->isVisible()) {
|
---|
| 67 | m_message->setVisible(false);
|
---|
| 68 | m_animation->setDirection(QAbstractAnimation::Backward);
|
---|
| 69 | } else {
|
---|
| 70 | m_message->setVisible(true);
|
---|
| 71 | m_animation->setDirection(QAbstractAnimation::Forward);
|
---|
| 72 | }
|
---|
| 73 | m_animation->start();
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | void FadeMessage::setupScene()
|
---|
| 77 | {
|
---|
| 78 | QGraphicsRectItem *parent = m_scene.addRect(0, 0, 400, 600);
|
---|
| 79 | parent->setPen(Qt::NoPen);
|
---|
| 80 | parent->setZValue(0);
|
---|
| 81 |
|
---|
| 82 | QGraphicsPixmapItem *bg = m_scene.addPixmap(QPixmap(":/background.jpg"));
|
---|
| 83 | bg->setParentItem(parent);
|
---|
| 84 | bg->setZValue(-1);
|
---|
| 85 |
|
---|
| 86 | for (int i = 1; i < 5; ++i)
|
---|
| 87 | for (int j = 2; j < 5; ++j) {
|
---|
| 88 | QGraphicsRectItem *item = m_scene.addRect(i * 50, j * 50, 38, 38);
|
---|
| 89 | item->setParentItem(parent);
|
---|
| 90 | item->setZValue(1);
|
---|
| 91 | int hue = 12 * (i * 5 + j);
|
---|
| 92 | item->setBrush(QColor::fromHsv(hue, 128, 128));
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | QFont font;
|
---|
| 96 | font.setPointSize(font.pointSize() * 2);
|
---|
| 97 | font.setBold(true);
|
---|
| 98 | QFontMetrics fontMetrics(font);
|
---|
| 99 | int fh = fontMetrics.height();
|
---|
| 100 |
|
---|
| 101 | QString sceneText = "Qt Everywhere!";
|
---|
| 102 | int sceneTextWidth = fontMetrics.width(sceneText);
|
---|
| 103 |
|
---|
| 104 | QGraphicsRectItem *block = m_scene.addRect(50, 300, sceneTextWidth, fh + 3);
|
---|
| 105 | block->setPen(Qt::NoPen);
|
---|
| 106 | block->setBrush(QColor(102, 153, 51));
|
---|
| 107 |
|
---|
| 108 | QGraphicsTextItem *text = m_scene.addText(sceneText, font);
|
---|
| 109 | text->setDefaultTextColor(Qt::white);
|
---|
| 110 | text->setPos(50, 300);
|
---|
| 111 | block->setZValue(2);
|
---|
| 112 | block->hide();
|
---|
| 113 |
|
---|
| 114 | text->setParentItem(block);
|
---|
| 115 | m_message = block;
|
---|
| 116 |
|
---|
| 117 | m_effect = new QGraphicsColorizeEffect;
|
---|
| 118 | m_effect->setColor(QColor(122, 193, 66));
|
---|
| 119 | m_effect->setStrength(0);
|
---|
| 120 | m_effect->setEnabled(true);
|
---|
| 121 | parent->setGraphicsEffect(m_effect);
|
---|
| 122 |
|
---|
| 123 | QPushButton *press = new QPushButton;
|
---|
| 124 | press->setText(tr("Press me"));
|
---|
| 125 | connect(press, SIGNAL(clicked()), SLOT(togglePopup()));
|
---|
| 126 | m_scene.addWidget(press);
|
---|
| 127 | press->move(300, 500);
|
---|
| 128 | }
|
---|
| 129 |
|
---|