summaryrefslogtreecommitdiffstats
path: root/examples/effects/fademessage
diff options
context:
space:
mode:
Diffstat (limited to 'examples/effects/fademessage')
-rw-r--r--examples/effects/fademessage/README.txt2
-rw-r--r--examples/effects/fademessage/background.jpgbin0 -> 159108 bytes
-rw-r--r--examples/effects/fademessage/fademessage.cpp124
-rw-r--r--examples/effects/fademessage/fademessage.h72
-rw-r--r--examples/effects/fademessage/fademessage.pro13
-rw-r--r--examples/effects/fademessage/fademessage.qrc5
-rw-r--r--examples/effects/fademessage/main.cpp56
7 files changed, 272 insertions, 0 deletions
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
new file mode 100644
index 0000000..9884233
--- /dev/null
+++ b/examples/effects/fademessage/background.jpg
Binary files differ
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();
+}