diff options
author | Ariya Hidayat <ariya.hidayat@nokia.com> | 2009-09-13 16:28:45 (GMT) |
---|---|---|
committer | Ariya Hidayat <ariya.hidayat@nokia.com> | 2009-09-14 16:22:41 (GMT) |
commit | 037e5066f8ef5279fae8fd9636a1b710cf187d1f (patch) | |
tree | 515bdf200b9de91523767b7f9e5497c01e3e0477 /examples | |
parent | ab35f0f8b0d872bc2e963c6ef869fade71b83e3f (diff) | |
download | Qt-037e5066f8ef5279fae8fd9636a1b710cf187d1f.zip Qt-037e5066f8ef5279fae8fd9636a1b710cf187d1f.tar.gz Qt-037e5066f8ef5279fae8fd9636a1b710cf187d1f.tar.bz2 |
Add an example that shows strength animation QGraphicsColorizeEffect.
When a button is pressed, a popup message is shown and the background
(everything, every items, behind the popup message) is faded to light
green.
Reviewed-by: Bjørn Erik Nilsen
Diffstat (limited to 'examples')
-rw-r--r-- | examples/effects/effects.pro | 3 | ||||
-rw-r--r-- | examples/effects/fademessage/README.txt | 2 | ||||
-rw-r--r-- | examples/effects/fademessage/background.jpg | bin | 0 -> 159108 bytes | |||
-rw-r--r-- | examples/effects/fademessage/fademessage.cpp | 124 | ||||
-rw-r--r-- | examples/effects/fademessage/fademessage.h | 72 | ||||
-rw-r--r-- | examples/effects/fademessage/fademessage.pro | 13 | ||||
-rw-r--r-- | examples/effects/fademessage/fademessage.qrc | 5 | ||||
-rw-r--r-- | examples/effects/fademessage/main.cpp | 56 |
8 files changed, 274 insertions, 1 deletions
diff --git a/examples/effects/effects.pro b/examples/effects/effects.pro index 60b5baf..01fa293 100644 --- a/examples/effects/effects.pro +++ b/examples/effects/effects.pro @@ -2,7 +2,8 @@ TEMPLATE = \ subdirs SUBDIRS = \ blurpicker \ - lighting + lighting \ + fademessage contains(QT_CONFIG, opengl)|contains(QT_CONFIG, opengles2):SUBDIRS += customshader diff --git a/examples/effects/fademessage/README.txt b/examples/effects/fademessage/README.txt new file mode 100644 index 0000000..f639e76 --- /dev/null +++ b/examples/effects/fademessage/README.txt @@ -0,0 +1,2 @@ +The background is taken from a public domain photo at: +http://www.photos8.com/view/windows_problem_blue-800x600.html diff --git a/examples/effects/fademessage/background.jpg b/examples/effects/fademessage/background.jpg Binary files differnew file mode 100644 index 0000000..9884233 --- /dev/null +++ b/examples/effects/fademessage/background.jpg diff --git a/examples/effects/fademessage/fademessage.cpp b/examples/effects/fademessage/fademessage.cpp new file mode 100644 index 0000000..818d00f --- /dev/null +++ b/examples/effects/fademessage/fademessage.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "fademessage.h" + +#include <QtGui> + +FadeMessage::FadeMessage(QWidget *parent): QGraphicsView(parent), m_index(0.0) +{ + setScene(&m_scene); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + + setupScene(); + + m_timeLine = new QTimeLine(500, this); + m_timeLine->setCurveShape(QTimeLine::EaseInOutCurve); + connect(m_timeLine, SIGNAL(valueChanged(qreal)), m_effect, SLOT(setStrength(qreal))); + + setRenderHint(QPainter::Antialiasing, true); + setFrameStyle(QFrame::NoFrame); +} + +void FadeMessage::togglePopup() +{ + if (m_message->isVisible()) { + m_message->setVisible(false); + m_timeLine->setDirection(QTimeLine::Backward); + m_timeLine->start(); + } else { + m_message->setVisible(true); + m_timeLine->setDirection(QTimeLine::Forward); + m_timeLine->start(); + } +} + +void FadeMessage::setupScene() +{ + QGraphicsRectItem *parent = m_scene.addRect(0, 0, 400, 600); + parent->setPen(Qt::NoPen); + parent->setZValue(0); + + QGraphicsPixmapItem *bg = m_scene.addPixmap(QPixmap(":/background.jpg")); + bg->setParentItem(parent); + bg->setZValue(-1); + + for (int i = 1; i < 5; ++i) + for (int j = 2; j < 5; ++j) { + QGraphicsRectItem *item = m_scene.addRect(i * 50, j * 50, 38, 38); + item->setParentItem(parent); + item->setZValue(1); + int hue = 12 * (i * 5 + j); + item->setBrush(QColor::fromHsv(hue, 128, 128)); + } + + QFont font; + font.setPointSize(font.pointSize() * 2); + font.setBold(true); + int fh = QFontMetrics(font).height(); + + QGraphicsRectItem *block = m_scene.addRect(50, 300, 300, fh + 3); + block->setPen(Qt::NoPen); + block->setBrush(QColor(102, 153, 51)); + + QGraphicsTextItem *text = m_scene.addText("Qt Everywhere!", font); + text->setDefaultTextColor(Qt::white); + text->setPos(50, 300); + block->setZValue(2); + block->hide(); + + text->setParentItem(block); + m_message = block; + + m_effect = new QGraphicsColorizeEffect; + m_effect->setColor(QColor(122, 193, 66)); + m_effect->setStrength(0); + m_effect->setEnabled(true); + parent->setGraphicsEffect(m_effect); + + QPushButton *press = new QPushButton; + press->setText(tr("Press me")); + connect(press, SIGNAL(clicked()), SLOT(togglePopup())); + m_scene.addWidget(press); + press->move(300, 500); +} + diff --git a/examples/effects/fademessage/fademessage.h b/examples/effects/fademessage/fademessage.h new file mode 100644 index 0000000..34e2fb8 --- /dev/null +++ b/examples/effects/fademessage/fademessage.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef FADEMESSAGE_H +#define FADEMESSAGE_H + +#include <QGraphicsEffect> +#include <QGraphicsView> +#include <QTimeLine> + +#include "fademessage.h" + +class FadeMessage: public QGraphicsView +{ + Q_OBJECT + +public: + FadeMessage(QWidget *parent = 0); + +private: + void setupScene(); + +private slots: + void togglePopup(); + +private: + qreal m_index; + QGraphicsScene m_scene; + QGraphicsColorizeEffect *m_effect; + QGraphicsItem *m_message; + QTimeLine *m_timeLine; +}; + +#endif // FADEMESSAGE_H diff --git a/examples/effects/fademessage/fademessage.pro b/examples/effects/fademessage/fademessage.pro new file mode 100644 index 0000000..ed9e53d --- /dev/null +++ b/examples/effects/fademessage/fademessage.pro @@ -0,0 +1,13 @@ +SOURCES += main.cpp fademessage.cpp +HEADERS += fademessage.h +RESOURCES += fademessage.qrc +INSTALLS += target sources + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/effects/fademessage +sources.files = $$SOURCES \ + $$HEADERS \ + $$RESOURCES \ + $$FORMS \ + fademessage.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/effects/fademessage diff --git a/examples/effects/fademessage/fademessage.qrc b/examples/effects/fademessage/fademessage.qrc new file mode 100644 index 0000000..9efea6a --- /dev/null +++ b/examples/effects/fademessage/fademessage.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/" > + <file>background.jpg</file> + </qresource> +</RCC> diff --git a/examples/effects/fademessage/main.cpp b/examples/effects/fademessage/main.cpp new file mode 100644 index 0000000..65a4291 --- /dev/null +++ b/examples/effects/fademessage/main.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include "fademessage.h" + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + FadeMessage widget; + widget.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Popup Message with Effect")); + widget.setFixedSize(400, 600); + widget.show(); + + return app.exec(); +} |