summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2010-05-11 14:02:16 (GMT)
committerAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2010-05-12 14:36:10 (GMT)
commite4902b4f25ca9c1ecff99609dbe376b407d9c6c5 (patch)
treef66db8d2cc152da3208fe1f3729692b9dfe00996 /examples
parent953411c6eecc4175752ade1834bf8db3398961c5 (diff)
downloadQt-e4902b4f25ca9c1ecff99609dbe376b407d9c6c5.zip
Qt-e4902b4f25ca9c1ecff99609dbe376b407d9c6c5.tar.gz
Qt-e4902b4f25ca9c1ecff99609dbe376b407d9c6c5.tar.bz2
New Pad Nagivator example implementation.
The old implementation was demo-quality and didn't really belong in the examples section. This new code cleans up the implementation, and also makes use of brand new features such as the state machine and animated transitions system. The new code is more suitable for documentation, and full docs are coming up in the next commit.
Diffstat (limited to 'examples')
-rw-r--r--examples/graphicsview/padnavigator/backside.ui208
-rw-r--r--examples/graphicsview/padnavigator/flippablepad.cpp90
-rw-r--r--examples/graphicsview/padnavigator/flippablepad.h63
-rw-r--r--examples/graphicsview/padnavigator/main.cpp12
-rw-r--r--examples/graphicsview/padnavigator/padnavigator.cpp265
-rw-r--r--examples/graphicsview/padnavigator/padnavigator.h (renamed from examples/graphicsview/padnavigator/panel.h)51
-rw-r--r--examples/graphicsview/padnavigator/padnavigator.pro23
-rw-r--r--examples/graphicsview/padnavigator/panel.cpp238
-rw-r--r--examples/graphicsview/padnavigator/roundrectitem.cpp129
-rw-r--r--examples/graphicsview/padnavigator/roundrectitem.h48
-rw-r--r--examples/graphicsview/padnavigator/splashitem.cpp44
-rw-r--r--examples/graphicsview/padnavigator/splashitem.h23
12 files changed, 524 insertions, 670 deletions
diff --git a/examples/graphicsview/padnavigator/backside.ui b/examples/graphicsview/padnavigator/backside.ui
deleted file mode 100644
index afa488c..0000000
--- a/examples/graphicsview/padnavigator/backside.ui
+++ /dev/null
@@ -1,208 +0,0 @@
-<ui version="4.0" >
- <class>BackSide</class>
- <widget class="QWidget" name="BackSide" >
- <property name="geometry" >
- <rect>
- <x>0</x>
- <y>0</y>
- <width>378</width>
- <height>385</height>
- </rect>
- </property>
- <property name="windowTitle" >
- <string>BackSide</string>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout_2" >
- <item>
- <widget class="QGroupBox" name="groupBox" >
- <property name="title" >
- <string>Settings</string>
- </property>
- <property name="flat" >
- <bool>true</bool>
- </property>
- <property name="checkable" >
- <bool>true</bool>
- </property>
- <layout class="QGridLayout" name="gridLayout" >
- <item row="0" column="0" >
- <widget class="QLabel" name="label" >
- <property name="text" >
- <string>Title:</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1" >
- <widget class="QLineEdit" name="hostName" >
- <property name="text" >
- <string>Pad Navigator Example</string>
- </property>
- </widget>
- </item>
- <item row="1" column="0" >
- <widget class="QLabel" name="label_2" >
- <property name="text" >
- <string>Modified:</string>
- </property>
- </widget>
- </item>
- <item row="2" column="0" >
- <widget class="QLabel" name="label_3" >
- <property name="text" >
- <string>Extent</string>
- </property>
- </widget>
- </item>
- <item row="2" column="1" >
- <layout class="QHBoxLayout" name="horizontalLayout" >
- <item>
- <widget class="QSlider" name="horizontalSlider" >
- <property name="value" >
- <number>42</number>
- </property>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QSpinBox" name="spinBox" >
- <property name="value" >
- <number>42</number>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item row="1" column="1" >
- <widget class="QDateTimeEdit" name="dateTimeEdit" />
- </item>
- </layout>
- </widget>
- </item>
- <item>
- <widget class="QGroupBox" name="groupBox_2" >
- <property name="title" >
- <string>Other input</string>
- </property>
- <property name="flat" >
- <bool>true</bool>
- </property>
- <property name="checkable" >
- <bool>true</bool>
- </property>
- <layout class="QHBoxLayout" name="horizontalLayout_2" >
- <item>
- <widget class="QTreeWidget" name="treeWidget" >
- <column>
- <property name="text" >
- <string>Widgets On Graphics View</string>
- </property>
- </column>
- <item>
- <property name="text" >
- <string>QGraphicsProxyWidget</string>
- </property>
- <item>
- <property name="text" >
- <string>QGraphicsWidget</string>
- </property>
- <item>
- <property name="text" >
- <string>QObject</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>QGraphicsItem</string>
- </property>
- </item>
- <item>
- <property name="text" >
- <string>QGraphicsLayoutItem</string>
- </property>
- </item>
- </item>
- </item>
- <item>
- <property name="text" >
- <string>QGraphicsGridLayout</string>
- </property>
- <item>
- <property name="text" >
- <string>QGraphicsLayout</string>
- </property>
- <item>
- <property name="text" >
- <string>QGraphicsLayoutItem</string>
- </property>
- </item>
- </item>
- </item>
- <item>
- <property name="text" >
- <string>QGraphicsLinearLayout</string>
- </property>
- <item>
- <property name="text" >
- <string>QGraphicsLayout</string>
- </property>
- <item>
- <property name="text" >
- <string>QGraphicsLayoutItem</string>
- </property>
- </item>
- </item>
- </item>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- </layout>
- </widget>
- <tabstops>
- <tabstop>groupBox</tabstop>
- <tabstop>hostName</tabstop>
- <tabstop>dateTimeEdit</tabstop>
- <tabstop>horizontalSlider</tabstop>
- <tabstop>spinBox</tabstop>
- <tabstop>groupBox_2</tabstop>
- <tabstop>treeWidget</tabstop>
- </tabstops>
- <resources/>
- <connections>
- <connection>
- <sender>horizontalSlider</sender>
- <signal>valueChanged(int)</signal>
- <receiver>spinBox</receiver>
- <slot>setValue(int)</slot>
- <hints>
- <hint type="sourcelabel" >
- <x>184</x>
- <y>125</y>
- </hint>
- <hint type="destinationlabel" >
- <x>275</x>
- <y>127</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>spinBox</sender>
- <signal>valueChanged(int)</signal>
- <receiver>horizontalSlider</receiver>
- <slot>setValue(int)</slot>
- <hints>
- <hint type="sourcelabel" >
- <x>272</x>
- <y>114</y>
- </hint>
- <hint type="destinationlabel" >
- <x>190</x>
- <y>126</y>
- </hint>
- </hints>
- </connection>
- </connections>
-</ui>
diff --git a/examples/graphicsview/padnavigator/flippablepad.cpp b/examples/graphicsview/padnavigator/flippablepad.cpp
new file mode 100644
index 0000000..61f421f
--- /dev/null
+++ b/examples/graphicsview/padnavigator/flippablepad.cpp
@@ -0,0 +1,90 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 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 "flippablepad.h"
+
+#include <QtGui/QtGui>
+
+static QRectF boundsFromSize(const QSize &size)
+{
+ return QRectF((-size.width() / 2.0) * 150, (-size.height() / 2.0) * 150,
+ size.width() * 150, size.height() * 150);
+}
+
+static QPointF posForLocation(int x, int y, const QSize &size)
+{
+ return QPointF(x * 150, y * 150)
+ - QPointF((size.width() - 1) * 75, (size.height() - 1) * 75);
+}
+
+FlippablePad::FlippablePad(const QSize &size, QGraphicsItem *parent)
+ : RoundRectItem(boundsFromSize(size), QColor(226, 255, 92, 64), parent)
+{
+ columns = size.width();
+
+ int numIcons = size.width() * size.height();
+ QList<QPixmap> pixmaps;
+ QDirIterator it(":/images", QStringList() << "*.png");
+ while (it.hasNext() && pixmaps.size() < numIcons)
+ pixmaps << it.next();
+
+ const QRectF iconRect(-54, -54, 108, 108);
+ const QColor iconColor(214, 240, 110, 128);
+
+ iconGrid.resize(size.height());
+
+ int n = 0;
+ for (int y = 0; y < size.height(); ++y) {
+ iconGrid[y].resize(columns);
+ for (int x = 0; x < size.width(); ++x) {
+ RoundRectItem *rect = new RoundRectItem(iconRect, iconColor, this);
+ rect->setZValue(1);
+ rect->setPos(posForLocation(x, y, size));
+ rect->setPixmap(pixmaps.at(n++ % pixmaps.size()));
+ iconGrid[y][x] = rect;
+ }
+ }
+}
+
+RoundRectItem *FlippablePad::iconAt(int x, int y) const
+{
+ return iconGrid[y][x];
+}
diff --git a/examples/graphicsview/padnavigator/flippablepad.h b/examples/graphicsview/padnavigator/flippablepad.h
new file mode 100644
index 0000000..9adb18b
--- /dev/null
+++ b/examples/graphicsview/padnavigator/flippablepad.h
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 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 FLIPPABLEPAD_H
+#define FLIPPABLEPAD_H
+
+#include "roundrectitem.h"
+
+#include <QGraphicsObject>
+#include <QLinearGradient>
+#include <QVector>
+
+class FlippablePad : public RoundRectItem
+{
+public:
+ FlippablePad(const QSize &size, QGraphicsItem *parent = 0);
+
+ RoundRectItem *iconAt(int x, int y) const;
+
+private:
+ int columns;
+ QVector<QVector<RoundRectItem *> > iconGrid;
+};
+
+#endif // FLIPPABLEPAD_H
diff --git a/examples/graphicsview/padnavigator/main.cpp b/examples/graphicsview/padnavigator/main.cpp
index fb6c120..6d148bb 100644
--- a/examples/graphicsview/padnavigator/main.cpp
+++ b/examples/graphicsview/padnavigator/main.cpp
@@ -39,21 +39,17 @@
**
****************************************************************************/
-#include <QtGui>
-#ifndef QT_NO_OPENGL
-# include <QtOpenGL>
-#endif
+#include "padnavigator.h"
-#include "panel.h"
+#include <QtGui/QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Q_INIT_RESOURCE(padnavigator);
- Panel panel(3, 3);
- panel.setFocus();
- panel.show();
+ PadNavigator navigator(QSize(3, 3));
+ navigator.show();
return app.exec();
}
diff --git a/examples/graphicsview/padnavigator/padnavigator.cpp b/examples/graphicsview/padnavigator/padnavigator.cpp
new file mode 100644
index 0000000..456b3f4
--- /dev/null
+++ b/examples/graphicsview/padnavigator/padnavigator.cpp
@@ -0,0 +1,265 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 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 "flippablepad.h"
+#include "padnavigator.h"
+#include "splashitem.h"
+#include "ui_form.h"
+
+#include <QtGui/QtGui>
+#ifndef QT_NO_OPENGL
+#include <QtOpenGL/QtOpenGL>
+#endif
+
+PadNavigator::PadNavigator(const QSize &size, QWidget *parent)
+ : QGraphicsView(parent)
+{
+ // Prepare splash item
+ SplashItem *splash = new SplashItem;
+ splash->setZValue(1);
+
+ // Prepare pad item
+ FlippablePad *pad = new FlippablePad(size);
+ QGraphicsRotation *flipRotation = new QGraphicsRotation(pad);
+ flipRotation->setAxis(Qt::YAxis);
+ QGraphicsRotation *xRotation = new QGraphicsRotation(pad);
+ xRotation->setAxis(Qt::YAxis);
+ QGraphicsRotation *yRotation = new QGraphicsRotation(pad);
+ yRotation->setAxis(Qt::XAxis);
+ pad->setTransformations(QList<QGraphicsTransform *>()
+ << flipRotation
+ << xRotation << yRotation);
+
+ // Prepare backitem
+ form = new Ui_Form;
+ QWidget *widget = new QWidget;
+ form->setupUi(widget);
+ form->hostName->setFocus();
+ QGraphicsProxyWidget *backItem = new QGraphicsProxyWidget(pad);
+ backItem->setCacheMode(QGraphicsItem::ItemCoordinateCache);
+ backItem->setWidget(widget);
+ backItem->setTransform(QTransform()
+ .rotate(180, Qt::YAxis)
+ .translate(-backItem->rect().width()/2, -backItem->rect().height()/2));
+ backItem->setFocus();
+ backItem->setVisible(false);
+
+ // Prepare selection item
+ RoundRectItem *selectionItem = new RoundRectItem(QRectF(-60, -60, 120, 120),
+ Qt::gray, pad);
+ selectionItem->setZValue(0.5);
+
+ // Selection animation setup
+ QPropertyAnimation *smoothXSelection = new QPropertyAnimation(selectionItem, "x");
+ smoothXSelection->setDuration(125);
+ smoothXSelection->setEasingCurve(QEasingCurve::InOutQuad);
+ QPropertyAnimation *smoothYSelection = new QPropertyAnimation(selectionItem, "y");
+ smoothYSelection->setDuration(125);
+ smoothYSelection->setEasingCurve(QEasingCurve::InOutQuad);
+ QPropertyAnimation *smoothXRotation = new QPropertyAnimation(xRotation, "angle");
+ smoothXRotation->setDuration(125);
+ smoothXRotation->setEasingCurve(QEasingCurve::InOutQuad);
+ QPropertyAnimation *smoothYRotation = new QPropertyAnimation(yRotation, "angle");
+ smoothYRotation->setDuration(125);
+ smoothYRotation->setEasingCurve(QEasingCurve::InOutQuad);
+ QPropertyAnimation *smoothScale = new QPropertyAnimation(pad, "scale");
+ smoothScale->setDuration(500);
+ smoothScale->setKeyValueAt(0, qVariantValue<qreal>(1.0));
+ smoothScale->setKeyValueAt(0.5, qVariantValue<qreal>(0.7));
+ smoothScale->setKeyValueAt(1, qVariantValue<qreal>(1.0));
+ smoothScale->setEasingCurve(QEasingCurve::InOutQuad);
+
+ // Flip animation setup
+ QPropertyAnimation *smoothFlipRotation = new QPropertyAnimation(flipRotation, "angle");
+ smoothFlipRotation->setDuration(500);
+ smoothFlipRotation->setEasingCurve(QEasingCurve::InOutQuad);
+ QPropertyAnimation *flipSmoothXRotation = new QPropertyAnimation(xRotation, "angle");
+ flipSmoothXRotation->setDuration(500);
+ flipSmoothXRotation->setEasingCurve(QEasingCurve::InOutQuad);
+ QPropertyAnimation *flipSmoothYRotation = new QPropertyAnimation(yRotation, "angle");
+ flipSmoothYRotation->setDuration(500);
+ flipSmoothYRotation->setEasingCurve(QEasingCurve::InOutQuad);
+ QPropertyAnimation *setBackItemVisibleAnim = new QPropertyAnimation(backItem, "visible");
+ setBackItemVisibleAnim->setDuration(0);
+ QPropertyAnimation *setSelectionItemVisibleAnim = new QPropertyAnimation(selectionItem, "visible");
+ setSelectionItemVisibleAnim->setDuration(0);
+ QPropertyAnimation *setFillAnim = new QPropertyAnimation(pad, "fill");
+ setFillAnim->setDuration(0);
+ QSequentialAnimationGroup *setVisibleAnimation = new QSequentialAnimationGroup;
+ setVisibleAnimation->addPause(250);
+ setVisibleAnimation->addAnimation(setBackItemVisibleAnim);
+ setVisibleAnimation->addAnimation(setSelectionItemVisibleAnim);
+ setVisibleAnimation->addAnimation(setFillAnim);
+ QParallelAnimationGroup *flipAnimation = new QParallelAnimationGroup(this);
+ flipAnimation->addAnimation(smoothFlipRotation);
+ flipAnimation->addAnimation(smoothScale);
+ flipAnimation->addAnimation(flipSmoothXRotation);
+ flipAnimation->addAnimation(flipSmoothYRotation);
+ flipAnimation->addAnimation(setVisibleAnimation);
+
+ QPropertyAnimation *smoothSplashMove = new QPropertyAnimation(splash, "y");
+ smoothSplashMove->setEasingCurve(QEasingCurve::InQuad);
+ smoothSplashMove->setDuration(250);
+ QPropertyAnimation *smoothSplashOpacity = new QPropertyAnimation(splash, "opacity");
+ smoothSplashOpacity->setDuration(250);
+
+ // Build the state machine
+ QStateMachine *stateMachine = new QStateMachine(this);
+ QState *splashState = new QState(stateMachine);
+ QState *frontState = new QState(stateMachine);
+ QHistoryState *historyState = new QHistoryState(frontState);
+ QState *backState = new QState(stateMachine);
+ frontState->assignProperty(splash, "opacity", 0.0);
+ frontState->assignProperty(flipRotation, "angle", qVariantValue<qreal>(0.0));
+ frontState->assignProperty(backItem, "visible", false);
+ frontState->assignProperty(selectionItem, "visible", true);
+ frontState->assignProperty(pad, "fill", false);
+ backState->assignProperty(flipRotation, "angle", qVariantValue<qreal>(180.0));
+ backState->assignProperty(xRotation, "angle", qVariantValue<qreal>(0.0));
+ backState->assignProperty(yRotation, "angle", qVariantValue<qreal>(0.0));
+ backState->assignProperty(selectionItem, "visible", false);
+ backState->assignProperty(backItem, "visible", true);
+ backState->assignProperty(pad, "fill", true);
+ stateMachine->addDefaultAnimation(smoothXRotation);
+ stateMachine->addDefaultAnimation(smoothYRotation);
+ stateMachine->addDefaultAnimation(smoothXSelection);
+ stateMachine->addDefaultAnimation(smoothYSelection);
+ stateMachine->setInitialState(splashState);
+
+ // Transitions
+ QEventTransition *anyKeyTransition = new QEventTransition(this, QEvent::KeyPress, splashState);
+ anyKeyTransition->setTargetState(frontState);
+ anyKeyTransition->addAnimation(smoothSplashMove);
+ anyKeyTransition->addAnimation(smoothSplashOpacity);
+
+ QKeyEventTransition *enterTransition = new QKeyEventTransition(this, QEvent::KeyPress, Qt::Key_Enter, backState);
+ enterTransition->setTargetState(historyState);
+ QKeyEventTransition *returnTransition = new QKeyEventTransition(this, QEvent::KeyPress, Qt::Key_Return, backState);
+ returnTransition->setTargetState(historyState);
+ QKeyEventTransition *backEnterTransition = new QKeyEventTransition(this, QEvent::KeyPress, Qt::Key_Enter, frontState);
+ backEnterTransition->setTargetState(backState);
+ QKeyEventTransition *backReturnTransition = new QKeyEventTransition(this, QEvent::KeyPress, Qt::Key_Return, frontState);
+ backReturnTransition->setTargetState(backState);
+ enterTransition->addAnimation(flipAnimation);
+ returnTransition->addAnimation(flipAnimation);
+ backEnterTransition->addAnimation(flipAnimation);
+ backReturnTransition->addAnimation(flipAnimation);
+
+ // Substates, one for each icon
+ int columns = size.width();
+ int rows = size.height();
+ QVector< QVector< QState * > > stateGrid;
+ stateGrid.resize(rows);
+ for (int y = 0; y < rows; ++y) {
+ stateGrid[y].resize(columns);
+ for (int x = 0; x < columns; ++x) {
+ QState *state = new QState(frontState);
+ stateGrid[y][x] = state;
+ }
+ }
+ frontState->setInitialState(stateGrid[0][0]);
+ selectionItem->setPos(pad->iconAt(0, 0)->pos());
+
+ // Enable key navigation using state transitions
+ for (int y = 0; y < rows; ++y) {
+ for (int x = 0; x < columns; ++x) {
+ QState *state = stateGrid[y][x];
+ QKeyEventTransition *rightTransition = new QKeyEventTransition(this, QEvent::KeyPress, Qt::Key_Right, state);
+ rightTransition->setTargetState(stateGrid[y][(x + 1) % columns]);
+ QKeyEventTransition *leftTransition = new QKeyEventTransition(this, QEvent::KeyPress, Qt::Key_Left, state);
+ leftTransition->setTargetState(stateGrid[y][((x - 1) + columns) % columns]);
+ QKeyEventTransition *downTransition = new QKeyEventTransition(this, QEvent::KeyPress, Qt::Key_Down, state);
+ downTransition->setTargetState(stateGrid[(y + 1) % rows][x]);
+ QKeyEventTransition *upTransition = new QKeyEventTransition(this, QEvent::KeyPress, Qt::Key_Up, state);
+ upTransition->setTargetState(stateGrid[((y - 1) + rows) % rows][x]);
+
+ RoundRectItem *icon = pad->iconAt(x, y);
+ state->assignProperty(xRotation, "angle", -icon->x() / 6.0);
+ state->assignProperty(yRotation, "angle", icon->y() / 6.0);
+ state->assignProperty(selectionItem, "x", icon->x());
+ state->assignProperty(selectionItem, "y", icon->y());
+ frontState->assignProperty(icon, "visible", true);
+ backState->assignProperty(icon, "visible", false);
+
+ QPropertyAnimation *setVisibleAnim = new QPropertyAnimation(icon, "visible");
+ setVisibleAnim->setDuration(0);
+ setVisibleAnimation->addAnimation(setVisibleAnim);
+ }
+ }
+
+ // Setup scene
+ QGraphicsScene *scene = new QGraphicsScene(this);
+ scene->setBackgroundBrush(QPixmap(":/images/blue_angle_swirl.jpg"));
+ scene->setItemIndexMethod(QGraphicsScene::NoIndex);
+ scene->addItem(pad);
+ scene->setSceneRect(scene->itemsBoundingRect());
+ setScene(scene);
+
+ // Adjust splash item
+ splash->setPos(-splash->boundingRect().width() / 2, scene->sceneRect().top());
+ frontState->assignProperty(splash, "y", splash->y() - 100.0);
+ scene->addItem(splash);
+
+ // Setup view
+ setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ setMinimumSize(50, 50);
+ setViewportUpdateMode(FullViewportUpdate);
+ setCacheMode(CacheBackground);
+ setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform
+ | QPainter::TextAntialiasing);
+#ifndef QT_NO_OPENGL
+ setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
+#endif
+
+ stateMachine->start();
+}
+
+PadNavigator::~PadNavigator()
+{
+ delete form;
+}
+
+void PadNavigator::resizeEvent(QResizeEvent *event)
+{
+ QGraphicsView::resizeEvent(event);
+ fitInView(scene()->sceneRect(), Qt::KeepAspectRatio);
+}
diff --git a/examples/graphicsview/padnavigator/panel.h b/examples/graphicsview/padnavigator/padnavigator.h
index 908092b..c79a13c 100644
--- a/examples/graphicsview/padnavigator/panel.h
+++ b/examples/graphicsview/padnavigator/padnavigator.h
@@ -39,54 +39,27 @@
**
****************************************************************************/
-#include <QtGui/qgraphicsview.h>
+#ifndef PADNAVIGATOR_H
+#define PADNAVIGATOR_H
-QT_BEGIN_NAMESPACE
-class QTimeLine;
-class Ui_BackSide;
-QT_END_NAMESPACE
+#include <QGraphicsView>
-class RoundRectItem;
+class QState;
+class QStateMachine;
+class Ui_Form;
-class Panel : public QGraphicsView
+class PadNavigator : public QGraphicsView
{
Q_OBJECT
public:
- Panel(int width, int height);
- ~Panel();
+ explicit PadNavigator(const QSize &size, QWidget *parent = 0);
+ ~PadNavigator();
protected:
- void keyPressEvent(QKeyEvent *event);
void resizeEvent(QResizeEvent *event);
-private Q_SLOTS:
- void updateSelectionStep(qreal val);
- void updateFlipStep(qreal val);
- void flip();
-
private:
- QPointF posForLocation(int x, int y) const;
-
- QGraphicsScene *scene;
- RoundRectItem *selectionItem;
- RoundRectItem *baseItem;
- RoundRectItem *backItem;
- QGraphicsWidget *splash;
- QTimeLine *selectionTimeLine;
- QTimeLine *flipTimeLine;
- int selectedX, selectedY;
-
- QGraphicsItem ***grid;
-
- QPointF startPos;
- QPointF endPos;
- qreal xrot, yrot;
- qreal xrot2, yrot2;
-
- int width;
- int height;
- bool flipped;
- bool flipLeft;
-
- Ui_BackSide *ui;
+ Ui_Form *form;
};
+
+#endif // PADNAVIGATOR_H
diff --git a/examples/graphicsview/padnavigator/padnavigator.pro b/examples/graphicsview/padnavigator/padnavigator.pro
index d6f536c..93ea293 100644
--- a/examples/graphicsview/padnavigator/padnavigator.pro
+++ b/examples/graphicsview/padnavigator/padnavigator.pro
@@ -1,19 +1,20 @@
-HEADERS += \
- panel.h \
- roundrectitem.h \
- splashitem.h
+SOURCES += main.cpp \
+ roundrectitem.cpp \
+ flippablepad.cpp \
+ padnavigator.cpp \
+ splashitem.cpp
-SOURCES += \
- panel.cpp \
- roundrectitem.cpp \
- splashitem.cpp \
- main.cpp
+HEADERS += \
+ roundrectitem.h \
+ flippablepad.h \
+ padnavigator.h \
+ splashitem.h
RESOURCES += \
- padnavigator.qrc
+ padnavigator.qrc
FORMS += \
- backside.ui
+ form.ui
contains(QT_CONFIG, opengl):QT += opengl
diff --git a/examples/graphicsview/padnavigator/panel.cpp b/examples/graphicsview/padnavigator/panel.cpp
deleted file mode 100644
index c4a5cd9..0000000
--- a/examples/graphicsview/padnavigator/panel.cpp
+++ /dev/null
@@ -1,238 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2010 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 "panel.h"
-#include "roundrectitem.h"
-#include "splashitem.h"
-#include "ui_backside.h"
-
-#ifndef QT_NO_OPENGL
-#include <QtOpenGL/QtOpenGL>
-#else
-#endif
-#include <QtGui/QtGui>
-
-#include <math.h>
-
-Panel::Panel(int width, int height)
- : selectedX(0),
- selectedY(0),
- width(width),
- height(height),
- flipped(false),
- flipLeft(true)
-{
- setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- setCacheMode(CacheBackground);
- setViewportUpdateMode(FullViewportUpdate);
- setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform
- | QPainter::TextAntialiasing);
- setBackgroundBrush(QPixmap(":/images/blue_angle_swirl.jpg"));
-#ifndef QT_NO_OPENGL
- setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
-#endif
- setMinimumSize(50, 50);
-
- selectionTimeLine = new QTimeLine(150, this);
- flipTimeLine = new QTimeLine(500, this);
-
- QRectF bounds((-width / 2.0) * 150, (-height / 2.0) * 150, width * 150, height * 150);
-
- scene = new QGraphicsScene(bounds, this);
- scene->setItemIndexMethod(QGraphicsScene::NoIndex);
- setScene(scene);
-
- baseItem = new RoundRectItem(bounds, QColor(226, 255, 92, 64));
- scene->addItem(baseItem);
-
- QWidget *embed = new QWidget;
- ui = new Ui_BackSide;
- ui->setupUi(embed);
- ui->hostName->setFocus();
-
- backItem = new RoundRectItem(bounds, embed->palette().window(), embed);
- backItem->setTransform(QTransform().rotate(180, Qt::YAxis));
- backItem->setParentItem(baseItem);
-
- selectionItem = new RoundRectItem(QRectF(-60, -60, 120, 120), Qt::gray);
- selectionItem->setParentItem(baseItem);
- selectionItem->setZValue(-1);
- selectionItem->setPos(posForLocation(0, 0));
- startPos = selectionItem->pos();
-
- grid = new QGraphicsItem **[height];
-
- for (int y = 0; y < height; ++y) {
- grid[y] = new QGraphicsItem *[width];
-
- for (int x = 0; x < width; ++x) {
- RoundRectItem *item = new RoundRectItem(QRectF(-54, -54, 108, 108),
- QColor(214, 240, 110, 128));
- item->setPos(posForLocation(x, y));
-
- item->setParentItem(baseItem);
- item->setFlag(QGraphicsItem::ItemIsFocusable);
- grid[y][x] = item;
-
- switch (qrand() % 9) {
- case 0: item->setPixmap(QPixmap(":/images/kontact_contacts.png")); break;
- case 1: item->setPixmap(QPixmap(":/images/kontact_journal.png")); break;
- case 2: item->setPixmap(QPixmap(":/images/kontact_notes.png")); break;
- case 3: item->setPixmap(QPixmap(":/images/kopeteavailable.png")); break;
- case 4: item->setPixmap(QPixmap(":/images/metacontact_online.png")); break;
- case 5: item->setPixmap(QPixmap(":/images/minitools.png")); break;
- case 6: item->setPixmap(QPixmap(":/images/kontact_journal.png")); break;
- case 7: item->setPixmap(QPixmap(":/images/kontact_contacts.png")); break;
- case 8: item->setPixmap(QPixmap(":/images/kopeteavailable.png")); break;
- default:
- break;
- }
-
- connect(item, SIGNAL(activated()), this, SLOT(flip()));
- }
- }
-
- grid[0][0]->setFocus();
-
- connect(backItem, SIGNAL(activated()),
- this, SLOT(flip()));
- connect(selectionTimeLine, SIGNAL(valueChanged(qreal)),
- this, SLOT(updateSelectionStep(qreal)));
- connect(flipTimeLine, SIGNAL(valueChanged(qreal)),
- this, SLOT(updateFlipStep(qreal)));
-
- splash = new SplashItem;
- splash->setZValue(5);
- splash->setPos(-splash->rect().width() / 2, scene->sceneRect().top());
- scene->addItem(splash);
-
- splash->grabKeyboard();
-
- updateSelectionStep(0);
-
- setWindowTitle(tr("Pad Navigator Example"));
-}
-
-Panel::~Panel()
-{
- for (int y = 0; y < height; ++y)
- delete [] grid[y];
- delete [] grid;
-}
-
-void Panel::keyPressEvent(QKeyEvent *event)
-{
- if (splash->isVisible() || event->key() == Qt::Key_Return || flipped) {
- QGraphicsView::keyPressEvent(event);
- return;
- }
-
- selectedX = (selectedX + width + (event->key() == Qt::Key_Right) - (event->key() == Qt::Key_Left)) % width;
- selectedY = (selectedY + height + (event->key() == Qt::Key_Down) - (event->key() == Qt::Key_Up)) % height;
- grid[selectedY][selectedX]->setFocus();
-
- selectionTimeLine->stop();
- startPos = selectionItem->pos();
- endPos = posForLocation(selectedX, selectedY);
- selectionTimeLine->start();
-}
-
-void Panel::resizeEvent(QResizeEvent *event)
-{
- QGraphicsView::resizeEvent(event);
- fitInView(scene->sceneRect(), Qt::KeepAspectRatio);
-}
-
-void Panel::updateSelectionStep(qreal val)
-{
- QPointF newPos(startPos.x() + (endPos - startPos).x() * val,
- startPos.y() + (endPos - startPos).y() * val);
- selectionItem->setPos(newPos);
-
- QTransform transform;
- yrot = newPos.x() / 6.0;
- xrot = newPos.y() / 6.0;
- transform.rotate(newPos.x() / 6.0, Qt::YAxis);
- transform.rotate(newPos.y() / 6.0, Qt::XAxis);
- baseItem->setTransform(transform);
-}
-
-void Panel::updateFlipStep(qreal val)
-{
- qreal finalxrot = xrot - xrot * val;
- qreal finalyrot;
- if (flipLeft)
- finalyrot = yrot - yrot * val - 180 * val;
- else
- finalyrot = yrot - yrot * val + 180 * val;
- QTransform transform;
- transform.rotate(finalyrot, Qt::YAxis);
- transform.rotate(finalxrot, Qt::XAxis);
- qreal scale = 1 - sin(3.14 * val) * 0.3;
- transform.scale(scale, scale);
- baseItem->setTransform(transform);
- if (val == 0)
- grid[selectedY][selectedX]->setFocus();
-}
-
-void Panel::flip()
-{
- if (flipTimeLine->state() == QTimeLine::Running)
- return;
-
- if (flipTimeLine->currentValue() == 0) {
- flipTimeLine->setDirection(QTimeLine::Forward);
- flipTimeLine->start();
- flipped = true;
- flipLeft = selectionItem->pos().x() < 0;
- } else {
- flipTimeLine->setDirection(QTimeLine::Backward);
- flipTimeLine->start();
- flipped = false;
- }
-}
-
-QPointF Panel::posForLocation(int x, int y) const
-{
- return QPointF(x * 150, y * 150)
- - QPointF((width - 1) * 75, (height - 1) * 75);
-}
diff --git a/examples/graphicsview/padnavigator/roundrectitem.cpp b/examples/graphicsview/padnavigator/roundrectitem.cpp
index d53eea4..2141e9a 100644
--- a/examples/graphicsview/padnavigator/roundrectitem.cpp
+++ b/examples/graphicsview/padnavigator/roundrectitem.cpp
@@ -43,122 +43,61 @@
#include <QtGui/QtGui>
-RoundRectItem::RoundRectItem(const QRectF &rect, const QBrush &brush, QWidget *embeddedWidget)
- : QGraphicsRectItem(rect),
- brush(brush),
- timeLine(75),
- lastVal(0),
- opa(1),
- proxyWidget(0)
+RoundRectItem::RoundRectItem(const QRectF &bounds, const QColor &color,
+ QGraphicsItem *parent)
+ : QGraphicsObject(parent), fillRect(false), color(color), bounds(bounds)
{
- connect(&timeLine, SIGNAL(valueChanged(qreal)),
- this, SLOT(updateValue(qreal)));
-
- if (embeddedWidget) {
- proxyWidget = new QGraphicsProxyWidget(this);
- proxyWidget->setFocusPolicy(Qt::StrongFocus);
- proxyWidget->setWidget(embeddedWidget);
- proxyWidget->setGeometry(boundingRect().adjusted(25, 25, -25, -25));
- }
-}
+ gradient.setStart(bounds.topLeft());
+ gradient.setFinalStop(bounds.bottomRight());
+ gradient.setColorAt(0, color);
+ gradient.setColorAt(1, color.dark(200));
-void RoundRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
-{
- QTransform x = painter->worldTransform();
-
- QLineF unit = x.map(QLineF(0, 0, 1, 1));
- if (unit.p1().x() > unit.p2().x() || unit.p1().y() > unit.p2().y()) {
- if (proxyWidget && proxyWidget->isVisible()) {
- proxyWidget->hide();
- proxyWidget->setGeometry(rect());
- }
- return;
- }
-
- if (proxyWidget && !proxyWidget->isVisible()) {
- proxyWidget->show();
- proxyWidget->setFocus();
- }
- if (proxyWidget && proxyWidget->pos() != QPoint())
- proxyWidget->setGeometry(boundingRect().adjusted(25, 25, -25, -25));
-
- painter->setOpacity(opacity());
- painter->setPen(Qt::NoPen);
- painter->setBrush(QColor(0, 0, 0, 64));
- painter->drawRoundRect(rect().translated(2, 2));
-
- if (!proxyWidget) {
- QLinearGradient gradient(rect().topLeft(), rect().bottomRight());
- const QColor col = brush.color();
- gradient.setColorAt(0, col);
- gradient.setColorAt(1, col.dark(int(200 + lastVal * 50)));
- painter->setBrush(gradient);
- } else {
- painter->setBrush(brush);
- }
-
- painter->setPen(QPen(Qt::black, 1));
- painter->drawRoundRect(rect());
- if (!pix.isNull()) {
- painter->scale(1.95, 1.95);
- painter->drawPixmap(-pix.width() / 2, -pix.height() / 2, pix);;
- }
+ setCacheMode(ItemCoordinateCache);
}
-QRectF RoundRectItem::boundingRect() const
+QPixmap RoundRectItem::pixmap() const
{
- qreal penW = 0.5;
- qreal shadowW = 2.0;
- return rect().adjusted(-penW, -penW, penW + shadowW, penW + shadowW);
+ return pix;
}
void RoundRectItem::setPixmap(const QPixmap &pixmap)
{
pix = pixmap;
- if (scene() && isVisible())
- update();
-}
-
-qreal RoundRectItem::opacity() const
-{
- RoundRectItem *parent = parentItem() ? (RoundRectItem *)parentItem() : 0;
- return opa + (parent ? parent->opacity() : 0);
+ update();
}
-void RoundRectItem::setOpacity(qreal opacity)
+QRectF RoundRectItem::boundingRect() const
{
- opa = opacity;
- update();
+ return bounds.adjusted(0, 0, 2, 2);
}
-void RoundRectItem::keyPressEvent(QKeyEvent *event)
+void RoundRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget)
{
- if (event->isAutoRepeat() || event->key() != Qt::Key_Return
- || (timeLine.state() == QTimeLine::Running && timeLine.direction() == QTimeLine::Forward)) {
- QGraphicsRectItem::keyPressEvent(event);
- return;
+ Q_UNUSED(option);
+ Q_UNUSED(widget);
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(QColor(0, 0, 0, 64));
+ painter->drawRoundRect(bounds.translated(2, 2));
+ if (fillRect)
+ painter->setBrush(QApplication::palette().brush(QPalette::Window));
+ else
+ painter->setBrush(gradient);
+ painter->setPen(QPen(Qt::black, 1));
+ painter->drawRoundRect(bounds);
+ if (!pix.isNull()) {
+ painter->scale(1.95, 1.95);
+ painter->drawPixmap(-pix.width() / 2, -pix.height() / 2, pix);
}
-
- timeLine.stop();
- timeLine.setDirection(QTimeLine::Forward);
- timeLine.start();
- emit activated();
}
-void RoundRectItem::keyReleaseEvent(QKeyEvent *event)
+bool RoundRectItem::fill() const
{
- if (event->key() != Qt::Key_Return) {
- QGraphicsRectItem::keyReleaseEvent(event);
- return;
- }
- timeLine.stop();
- timeLine.setDirection(QTimeLine::Backward);
- timeLine.start();
+ return fillRect;
}
-void RoundRectItem::updateValue(qreal value)
+void RoundRectItem::setFill(bool fill)
{
- lastVal = value;
- if (!proxyWidget)
- setTransform(QTransform().scale(1 - value / 10.0, 1 - value / 10.0));
+ fillRect = fill;
+ update();
}
diff --git a/examples/graphicsview/padnavigator/roundrectitem.h b/examples/graphicsview/padnavigator/roundrectitem.h
index 683c09f..ae5fb4c 100644
--- a/examples/graphicsview/padnavigator/roundrectitem.h
+++ b/examples/graphicsview/padnavigator/roundrectitem.h
@@ -39,45 +39,35 @@
**
****************************************************************************/
-#include <QtCore/qobject.h>
-#include <QtCore/qtimeline.h>
-#include <QtGui/qgraphicsitem.h>
-#include <QtGui/qbrush.h>
+#ifndef ROUNDRECTITEM_H
+#define ROUNDRECTITEM_H
-QT_BEGIN_NAMESPACE
-class QGraphicsProxyWidget;
-QT_END_NAMESPACE
+#include <QGraphicsObject>
+#include <QLinearGradient>
-class RoundRectItem : public QObject, public QGraphicsRectItem
+class RoundRectItem : public QGraphicsObject
{
Q_OBJECT
+ Q_PROPERTY(bool fill READ fill WRITE setFill)
public:
- RoundRectItem(const QRectF &rect, const QBrush &brush, QWidget *embeddedWidget = 0);
-
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *);
- QRectF boundingRect() const;
+ RoundRectItem(const QRectF &bounds, const QColor &color,
+ QGraphicsItem *parent = 0);
+ QPixmap pixmap() const;
void setPixmap(const QPixmap &pixmap);
- qreal opacity() const;
- void setOpacity(qreal opacity);
-
-Q_SIGNALS:
- void activated();
-
-protected:
- void keyPressEvent(QKeyEvent *event);
- void keyReleaseEvent(QKeyEvent *event);
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
-private slots:
- void updateValue(qreal value);
+ bool fill() const;
+ void setFill(bool fill);
private:
- QBrush brush;
QPixmap pix;
- QTimeLine timeLine;
- qreal lastVal;
- qreal opa;
-
- QGraphicsProxyWidget *proxyWidget;
+ bool fillRect;
+ QColor color;
+ QRectF bounds;
+ QLinearGradient gradient;
};
+
+#endif // ROUNDRECTITEM_H
diff --git a/examples/graphicsview/padnavigator/splashitem.cpp b/examples/graphicsview/padnavigator/splashitem.cpp
index b5b03d4..e609656 100644
--- a/examples/graphicsview/padnavigator/splashitem.cpp
+++ b/examples/graphicsview/padnavigator/splashitem.cpp
@@ -43,31 +43,31 @@
#include <QtGui/QtGui>
-SplashItem::SplashItem(QGraphicsItem *parent)
- : QGraphicsWidget(parent)
+SplashItem::SplashItem(QGraphicsItem *parent) :
+ QGraphicsObject(parent)
{
- opacity = 1.0;
-
-
- timeLine = new QTimeLine(350);
- timeLine->setCurveShape(QTimeLine::EaseInCurve);
- connect(timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(setValue(qreal)));
-
text = tr("Welcome to the Pad Navigator Example. You can use the"
" keyboard arrows to navigate the icons, and press enter"
- " to activate an item. Please press any key to continue.");
- resize(400, 175);
+ " to activate an item. Press any key to begin.");
+ setCacheMode(DeviceCoordinateCache);
+}
+
+QRectF SplashItem::boundingRect() const
+{
+ return QRectF(0, 0, 400, 175);
}
-void SplashItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
+void SplashItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget)
{
- painter->setOpacity(opacity);
+ Q_UNUSED(option);
+ Q_UNUSED(widget);
painter->setPen(QPen(Qt::black, 2));
painter->setBrush(QColor(245, 245, 255, 220));
- painter->setClipRect(rect());
+ painter->setClipRect(boundingRect());
painter->drawRoundRect(3, -100 + 3, 400 - 6, 250 - 6);
- QRectF textRect = rect().adjusted(10, 10, -10, -10);
+ QRectF textRect = boundingRect().adjusted(10, 10, -10, -10);
int flags = Qt::AlignTop | Qt::AlignLeft | Qt::TextWordWrap;
QFont font;
@@ -76,17 +76,3 @@ void SplashItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWid
painter->setFont(font);
painter->drawText(textRect, flags, text);
}
-
-void SplashItem::keyPressEvent(QKeyEvent * /* event */)
-{
- if (timeLine->state() == QTimeLine::NotRunning)
- timeLine->start();
-}
-
-void SplashItem::setValue(qreal value)
-{
- opacity = 1 - value;
- setPos(x(), scene()->sceneRect().top() - rect().height() * value);
- if (value == 1)
- hide();
-}
diff --git a/examples/graphicsview/padnavigator/splashitem.h b/examples/graphicsview/padnavigator/splashitem.h
index 7a33bee..9d57653 100644
--- a/examples/graphicsview/padnavigator/splashitem.h
+++ b/examples/graphicsview/padnavigator/splashitem.h
@@ -39,25 +39,22 @@
**
****************************************************************************/
-#include <QtCore/qobject.h>
-#include <QtCore/qtimeline.h>
-#include <QtGui/qgraphicswidget.h>
+#ifndef SPLASHITEM_H
+#define SPLASHITEM_H
-class SplashItem : public QGraphicsWidget
+#include <QGraphicsObject>
+
+class SplashItem : public QGraphicsObject
{
Q_OBJECT
public:
- SplashItem(QGraphicsItem *parent = 0);
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
-
-protected:
- void keyPressEvent(QKeyEvent *event);
+ explicit SplashItem(QGraphicsItem *parent = 0);
-private Q_SLOTS:
- void setValue(qreal value);
+ QRectF boundingRect() const;
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
private:
- QTimeLine *timeLine;
QString text;
- qreal opacity;
};
+
+#endif // SPLASHITEM_H