diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2009-05-20 15:16:48 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-05-20 15:17:27 (GMT) |
commit | 1cad8c56002a61a6240e6580cdbd784209821fa6 (patch) | |
tree | fce7cb89eca27a6acf5ebd948f63a85d34af55cc | |
parent | 8769a71f56886ea4925fc460a553f53500dd0b4e (diff) | |
download | Qt-1cad8c56002a61a6240e6580cdbd784209821fa6.zip Qt-1cad8c56002a61a6240e6580cdbd784209821fa6.tar.gz Qt-1cad8c56002a61a6240e6580cdbd784209821fa6.tar.bz2 |
update the padnavigator example and suppress the padnavigator-ng
27 files changed, 154 insertions, 1190 deletions
diff --git a/examples/animation/padnavigator-ng/backside.ui b/examples/animation/padnavigator-ng/backside.ui deleted file mode 100644 index afa488c..0000000 --- a/examples/animation/padnavigator-ng/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/animation/padnavigator-ng/images/artsfftscope.png b/examples/animation/padnavigator-ng/images/artsfftscope.png Binary files differdeleted file mode 100644 index b4b8775..0000000 --- a/examples/animation/padnavigator-ng/images/artsfftscope.png +++ /dev/null diff --git a/examples/animation/padnavigator-ng/images/blue_angle_swirl.jpg b/examples/animation/padnavigator-ng/images/blue_angle_swirl.jpg Binary files differdeleted file mode 100644 index 5bf0deb..0000000 --- a/examples/animation/padnavigator-ng/images/blue_angle_swirl.jpg +++ /dev/null diff --git a/examples/animation/padnavigator-ng/images/kontact_contacts.png b/examples/animation/padnavigator-ng/images/kontact_contacts.png Binary files differdeleted file mode 100644 index 6fb4cc8..0000000 --- a/examples/animation/padnavigator-ng/images/kontact_contacts.png +++ /dev/null diff --git a/examples/animation/padnavigator-ng/images/kontact_journal.png b/examples/animation/padnavigator-ng/images/kontact_journal.png Binary files differdeleted file mode 100644 index b1fedb6..0000000 --- a/examples/animation/padnavigator-ng/images/kontact_journal.png +++ /dev/null diff --git a/examples/animation/padnavigator-ng/images/kontact_mail.png b/examples/animation/padnavigator-ng/images/kontact_mail.png Binary files differdeleted file mode 100644 index 672f8fa..0000000 --- a/examples/animation/padnavigator-ng/images/kontact_mail.png +++ /dev/null diff --git a/examples/animation/padnavigator-ng/images/kontact_notes.png b/examples/animation/padnavigator-ng/images/kontact_notes.png Binary files differdeleted file mode 100644 index 229bf73..0000000 --- a/examples/animation/padnavigator-ng/images/kontact_notes.png +++ /dev/null diff --git a/examples/animation/padnavigator-ng/images/kopeteavailable.png b/examples/animation/padnavigator-ng/images/kopeteavailable.png Binary files differdeleted file mode 100644 index 2eaf41a..0000000 --- a/examples/animation/padnavigator-ng/images/kopeteavailable.png +++ /dev/null diff --git a/examples/animation/padnavigator-ng/images/metacontact_online.png b/examples/animation/padnavigator-ng/images/metacontact_online.png Binary files differdeleted file mode 100644 index 6a398dd..0000000 --- a/examples/animation/padnavigator-ng/images/metacontact_online.png +++ /dev/null diff --git a/examples/animation/padnavigator-ng/images/minitools.png b/examples/animation/padnavigator-ng/images/minitools.png Binary files differdeleted file mode 100644 index 0248c9d..0000000 --- a/examples/animation/padnavigator-ng/images/minitools.png +++ /dev/null diff --git a/examples/animation/padnavigator-ng/main.cpp b/examples/animation/padnavigator-ng/main.cpp deleted file mode 100644 index f8b167f..0000000 --- a/examples/animation/padnavigator-ng/main.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtCore module 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui> -#include "panel.h" - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - Q_INIT_RESOURCE(padnavigator); - - Panel panel(3, 3); - panel.show(); - - return app.exec(); -} diff --git a/examples/animation/padnavigator-ng/padnavigator.pro b/examples/animation/padnavigator-ng/padnavigator.pro deleted file mode 100644 index 8e53a6d..0000000 --- a/examples/animation/padnavigator-ng/padnavigator.pro +++ /dev/null @@ -1,24 +0,0 @@ -HEADERS = \ - panel.h \ - roundrectitem.h \ - splashitem.h - -SOURCES = \ - panel.cpp \ - roundrectitem.cpp \ - splashitem.cpp \ - main.cpp - -RESOURCES = \ - padnavigator.qrc - -FORMS = \ - backside.ui - -contains(QT_CONFIG, opengl):QT += opengl - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/animation/padnavigator-ng -sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS padnavigator.pro images -sources.path = $$[QT_INSTALL_EXAMPLES]/animation/padnavigator-ng -INSTALLS += target sources diff --git a/examples/animation/padnavigator-ng/padnavigator.qrc b/examples/animation/padnavigator-ng/padnavigator.qrc deleted file mode 100644 index 30ee8e1..0000000 --- a/examples/animation/padnavigator-ng/padnavigator.qrc +++ /dev/null @@ -1,14 +0,0 @@ -<RCC> - <qresource> - <file>images/blue_angle_swirl.jpg</file> - <file>images/artsfftscope.png</file> - <file>images/kontact_contacts.png</file> - <file>images/kontact_journal.png</file> - <file>images/kontact_mail.png</file> - <file>images/kontact_notes.png</file> - <file>images/kopeteavailable.png</file> - <file>images/metacontact_online.png</file> - <file>images/minitools.png</file> - <file>images/blue_angle_swirl.jpg</file> - </qresource> -</RCC> diff --git a/examples/animation/padnavigator-ng/panel.cpp b/examples/animation/padnavigator-ng/panel.cpp deleted file mode 100644 index e61be0e..0000000 --- a/examples/animation/padnavigator-ng/panel.cpp +++ /dev/null @@ -1,246 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtCore module 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@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> - -Panel::Panel(int width, int height) - : selectedIndex(0), - grid(width*height), - width(width), - height(height), - flipped(false), - flippingGroup(0), - rotationXanim(0), - rotationYanim(0) -{ - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setCacheMode(CacheBackground); - setViewportUpdateMode(FullViewportUpdate); - setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); - setBackgroundBrush(QPixmap(":/images/blue_angle_swirl.jpg")); -#ifndef QT_NO_OPENGL - setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); -#endif - - QRectF bounds((-width / 2.0) * 150, (-height / 2.0) * 150, width * 150, height * 150); - - setScene(new QGraphicsScene(bounds, this)); - - 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->setYRotation(180); - backItem->setParentItem(baseItem); - - selectionItem = new RoundRectItem(QRectF(-60, -60, 120, 120), Qt::gray); - selectionItem->setParentItem(baseItem); - selectionItem->setZValue(-1); - selectionItem->setPos(posForLocation(0)); - - int currentIndex = 0; - for (int y = 0; y < height; ++y) { - for (int x = 0; x < width; ++x) { - RoundRectItem *item = new RoundRectItem(QRectF(-54, -54, 108, 108), - QColor(214, 240, 110, 128)); - item->setPos(posForLocation(currentIndex)); - - item->setParentItem(baseItem); - item->setFlag(QGraphicsItem::ItemIsFocusable); - grid[currentIndex++] = 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.first()->setFocus(); - - connect(backItem, SIGNAL(activated()), - this, SLOT(flip())); - - splash = new SplashItem; - splash->setZValue(5); - splash->setPos(-splash->rect().width() / 2, scene()->sceneRect().top()); - scene()->addItem(splash); - - splash->grabKeyboard(); - - //initialize the position - baseItem->setYRotation(selectionItem->x()/6.); - baseItem->setXRotation(selectionItem->y()/6.); - - setWindowTitle(tr("Pad Navigator Example")); -} - -Panel::~Panel() -{ -} - -void Panel::keyPressEvent(QKeyEvent *event) -{ - if (splash->isVisible() || event->key() == Qt::Key_Return || flipped) { - QGraphicsView::keyPressEvent(event); - return; - } - - selectedIndex = (selectedIndex + grid.count() + (event->key() == Qt::Key_Right) - (event->key() == Qt::Key_Left) - + width * ((event->key() == Qt::Key_Down) - (event->key() == Qt::Key_Up))) % grid.count(); - grid[selectedIndex]->setFocus(); - - const QPointF pos = posForLocation(selectedIndex); - - const double angleY = pos.x() / 6., - angleX = pos.y() / 6.; - - QAnimationGroup *group = new QParallelAnimationGroup(); - - QVariantAnimation *anim = new QPropertyAnimation(baseItem, "xRotation"); - anim->setEndValue(angleX); - anim->setDuration(150); - anim->setEasingCurve(QEasingCurve::OutInSine); - group->addAnimation(anim); - - anim = new QPropertyAnimation(baseItem, "yRotation"); - anim->setEndValue(angleY); - anim->setDuration(150); - anim->setEasingCurve(QEasingCurve::OutInSine); - group->addAnimation(anim); - - anim = new QPropertyAnimation(selectionItem, "pos"); - anim->setEndValue(pos); - anim->setDuration(150); - anim->setEasingCurve(QEasingCurve::Linear); - group->addAnimation(anim); - - group->start(QAbstractAnimation::DeleteWhenStopped); -} - -void Panel::resizeEvent(QResizeEvent *event) -{ - QGraphicsView::resizeEvent(event); - fitInView(scene()->sceneRect(), Qt::KeepAspectRatio); -} - -void Panel::flip() -{ - grid[selectedIndex]->setFocus(); - - if (flippingGroup == 0) { - flippingGroup = new QParallelAnimationGroup(this); - - const qreal zoomOut = qreal(.75); - - //slight scaling down while flipping - QVariantAnimation *anim = new QPropertyAnimation(baseItem, "yScale"); - anim->setKeyValueAt(qreal(.5), zoomOut); - anim->setEndValue(1); - anim->setEasingCurve(QEasingCurve::OutInSine); - anim->setDuration(500); - flippingGroup->addAnimation(anim); - - anim = new QPropertyAnimation(baseItem, "xScale"); - anim->setKeyValueAt(qreal(.5), zoomOut); - anim->setEndValue(1); - anim->setEasingCurve(QEasingCurve::OutInSine); - anim->setDuration(500); - flippingGroup->addAnimation(anim); - - rotationXanim = new QPropertyAnimation(baseItem, "xRotation"); - rotationXanim->setEndValue(0); - rotationXanim->setDuration(500); - flippingGroup->addAnimation(rotationXanim); - - rotationYanim = new QPropertyAnimation(baseItem, "yRotation"); - rotationYanim->setEndValue(180); - rotationYanim->setDuration(500); - flippingGroup->addAnimation(rotationYanim); - } - - if (flippingGroup->currentTime() != 0 && flippingGroup->direction() == QAbstractAnimation::Forward) { - flippingGroup->setDirection(QAbstractAnimation::Backward); - } else { - flippingGroup->setDirection(QAbstractAnimation::Forward); - if (flippingGroup->currentTime() == 0) { - //we always make sure when it is at the beginning - rotationXanim->setStartValue(baseItem->xRotation()); - rotationYanim->setStartValue(baseItem->yRotation()); - } - } - flippingGroup->start(); - flipped = !flipped; -} - -QPointF Panel::posForLocation(int index) const -{ - const int x = index % width, - y = index / width; - return QPointF(x * 150, y * 150) - - QPointF((width - 1) * 75, (height - 1) * 75); -} diff --git a/examples/animation/padnavigator-ng/panel.h b/examples/animation/padnavigator-ng/panel.h deleted file mode 100644 index 9aca29d..0000000 --- a/examples/animation/padnavigator-ng/panel.h +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtCore module 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui/qgraphicsview.h> -#include <QtGui/qgraphicswidget.h> - -QT_BEGIN_NAMESPACE -class Ui_BackSide; -class QAnimationGroup; -class QPropertyAnimation; -QT_END_NAMESPACE; - -class RoundRectItem; - -class Panel : public QGraphicsView -{ - Q_OBJECT -public: - Panel(int width, int height); - ~Panel(); - -protected: - void keyPressEvent(QKeyEvent *event); - void resizeEvent(QResizeEvent *event); - -private Q_SLOTS: - void flip(); - -private: - QPointF posForLocation(int index) const; - - QGraphicsWidget *selectionItem; - QGraphicsWidget *baseItem; - RoundRectItem *backItem; - QGraphicsWidget *splash; - int selectedIndex; - - QVector<QGraphicsItem*> grid; - - int width; - int height; - bool flipped; - Ui_BackSide *ui; - - QAnimationGroup *flippingGroup; - QPropertyAnimation *rotationXanim, *rotationYanim; -}; diff --git a/examples/animation/padnavigator-ng/roundrectitem.cpp b/examples/animation/padnavigator-ng/roundrectitem.cpp deleted file mode 100644 index 2ff216c..0000000 --- a/examples/animation/padnavigator-ng/roundrectitem.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtCore module 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "roundrectitem.h" - -#include <QtGui/QtGui> - -RoundRectItem::RoundRectItem(const QRectF &rect, const QBrush &brush, QWidget *embeddedWidget) - : QGraphicsWidget(), - m_rect(rect), - brush(brush), - proxyWidget(0) -{ - if (embeddedWidget) { - proxyWidget = new QGraphicsProxyWidget(this); - proxyWidget->setFocusPolicy(Qt::StrongFocus); - proxyWidget->setWidget(embeddedWidget); - } -} - -void RoundRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) -{ - const bool widgetHidden = parentItem() == 0 || qAbs(static_cast<QGraphicsWidget*>(parentItem())->yRotation()) < 90; - - if (proxyWidget) { - if (widgetHidden) { - proxyWidget->hide(); - } else { - if (!proxyWidget->isVisible()) { - proxyWidget->setGeometry(boundingRect().adjusted(25, 25, -25, -25)); - proxyWidget->show(); - proxyWidget->setFocus(); - } - painter->setBrush(brush); - painter->setPen(QPen(Qt::black, 1)); - painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); - painter->drawRoundRect(m_rect); - } - } else if (widgetHidden) { - painter->setPen(Qt::NoPen); - painter->setBrush(QColor(0, 0, 0, 64)); - painter->drawRoundRect(m_rect.translated(2, 2)); - - QLinearGradient gradient(m_rect.topLeft(), m_rect.bottomRight()); - const QColor col = brush.color(); - gradient.setColorAt(0, col); - gradient.setColorAt(1, col.dark(200)); - painter->setBrush(gradient); - painter->setPen(QPen(Qt::black, 1)); - painter->drawRoundRect(m_rect); - if (!pix.isNull()) { - painter->scale(qreal(1.95), qreal(1.95)); - painter->drawPixmap(-pix.width() / 2, -pix.height() / 2, pix); - } - } - -} - -QRectF RoundRectItem::boundingRect() const -{ - qreal penW = qreal(.5); - qreal shadowW = 2; - return m_rect.adjusted(-penW, -penW, penW + shadowW, penW + shadowW); -} - -void RoundRectItem::setPixmap(const QPixmap &pixmap) -{ - pix = pixmap; - if (scene() && isVisible()) - update(); -} - -void RoundRectItem::keyPressEvent(QKeyEvent *event) -{ - if (event->isAutoRepeat() || event->key() != Qt::Key_Return) { - QGraphicsWidget::keyPressEvent(event); - return; - } - - if (!proxyWidget) { - setXScale(qreal(.9)); - setYScale(qreal(.9)); - } - emit activated(); -} - -void RoundRectItem::keyReleaseEvent(QKeyEvent *event) -{ - if (event->isAutoRepeat() || event->key() != Qt::Key_Return) { - QGraphicsWidget::keyReleaseEvent(event); - return; - } - - if (!proxyWidget) { - setXScale(1); - setYScale(1); - } -} diff --git a/examples/animation/padnavigator-ng/roundrectitem.h b/examples/animation/padnavigator-ng/roundrectitem.h deleted file mode 100644 index 6a7bf4b..0000000 --- a/examples/animation/padnavigator-ng/roundrectitem.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtCore module 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qobject.h> -#include <QtGui/qbrush.h> -#include <QtGui/qgraphicswidget.h> - -QT_BEGIN_NAMESPACE -class QGraphicsProxyWidget; -QT_END_NAMESPACE; - -class RoundRectItem : public QGraphicsWidget -{ - Q_OBJECT -public: - RoundRectItem(const QRectF &rect, const QBrush &brush, QWidget *embeddedWidget = 0); - - void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *); - QRectF boundingRect() const; - - void setPixmap(const QPixmap &pixmap); - -Q_SIGNALS: - void activated(); - -protected: - void keyPressEvent(QKeyEvent *event); - void keyReleaseEvent(QKeyEvent *event); - -private: - QRectF m_rect; - QBrush brush; - QPixmap pix; - QGraphicsProxyWidget *proxyWidget; -}; diff --git a/examples/animation/padnavigator-ng/splashitem.cpp b/examples/animation/padnavigator-ng/splashitem.cpp deleted file mode 100644 index 1264987..0000000 --- a/examples/animation/padnavigator-ng/splashitem.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtCore module 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "splashitem.h" - -#include <QtGui/QtGui> - -SplashItem::SplashItem(QGraphicsItem *parent) - : QGraphicsWidget(parent) -{ - - 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); -} - -void SplashItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) -{ - painter->setPen(QPen(Qt::black, 2)); - painter->setBrush(QColor(245, 245, 255, 220)); - painter->setClipRect(rect()); - painter->drawRoundRect(3, -100 + 3, 400 - 6, 250 - 6); - - QRectF textRect = rect().adjusted(10, 10, -10, -10); - int flags = Qt::AlignTop | Qt::AlignLeft | Qt::TextWordWrap; - - QFont font; - font.setPixelSize(18); - painter->setPen(Qt::black); - painter->setFont(font); - painter->drawText(textRect, flags, text); -} - -void SplashItem::keyPressEvent(QKeyEvent * /* event */) -{ - QVariantAnimation *anim = new QPropertyAnimation(this, "pos"); - anim->setEndValue(QPointF(x(), scene()->sceneRect().top() - rect().height())); - anim->setDuration(350); - anim->start(QAbstractAnimation::DeleteWhenStopped); - - anim = new QPropertyAnimation(this, "opacity"); - anim->setEndValue(0); - anim->start(QAbstractAnimation::DeleteWhenStopped); - - connect(anim, SIGNAL(finished()), SLOT(close())); -} diff --git a/examples/animation/padnavigator-ng/splashitem.h b/examples/animation/padnavigator-ng/splashitem.h deleted file mode 100644 index 7b4b8a9..0000000 --- a/examples/animation/padnavigator-ng/splashitem.h +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) -** -** This file is part of the QtCore module 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. -** -** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/qobject.h> -#include <QtGui/qgraphicswidget.h> - -class SplashItem : public QGraphicsWidget -{ - Q_OBJECT -public: - SplashItem(QGraphicsItem *parent = 0); - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - -protected: - void keyPressEvent(QKeyEvent *event); - -private: - QString text; -}; diff --git a/examples/graphicsview/padnavigator/images/artsfftscope.png b/examples/graphicsview/padnavigator/images/artsfftscope.png Binary files differindex 4db003f..756a1cf 100644 --- a/examples/graphicsview/padnavigator/images/artsfftscope.png +++ b/examples/graphicsview/padnavigator/images/artsfftscope.png diff --git a/examples/graphicsview/padnavigator/main.cpp b/examples/graphicsview/padnavigator/main.cpp index dc5ff0c..f7d6f90 100644 --- a/examples/graphicsview/padnavigator/main.cpp +++ b/examples/graphicsview/padnavigator/main.cpp @@ -40,10 +40,6 @@ ****************************************************************************/ #include <QtGui> -#ifndef QT_NO_OPENGL -# include <QtOpenGL> -#endif - #include "panel.h" int main(int argc, char *argv[]) diff --git a/examples/graphicsview/padnavigator/panel.cpp b/examples/graphicsview/padnavigator/panel.cpp index 28a3cb4..c088fbc 100644 --- a/examples/graphicsview/padnavigator/panel.cpp +++ b/examples/graphicsview/padnavigator/panel.cpp @@ -50,15 +50,15 @@ #endif #include <QtGui/QtGui> -#include <math.h> - Panel::Panel(int width, int height) - : selectedX(0), - selectedY(0), + : selectedIndex(0), + grid(width*height), width(width), height(height), flipped(false), - flipLeft(true) + flippingGroup(0), + rotationXanim(0), + rotationYanim(0) { setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); @@ -72,12 +72,9 @@ Panel::Panel(int width, int height) #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); + QGraphicsScene *scene = new QGraphicsScene(bounds, this); scene->setItemIndexMethod(QGraphicsScene::NoIndex); setScene(scene); @@ -90,28 +87,24 @@ Panel::Panel(int width, int height) ui->hostName->setFocus(); backItem = new RoundRectItem(bounds, embed->palette().window(), embed); - backItem->setTransform(QTransform().rotate(180, Qt::YAxis)); + backItem->setYRotation(180); 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(); + selectionItem->setPos(posForLocation(0)); - grid = new QGraphicsItem **[height]; - + int currentIndex = 0; 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->setPos(posForLocation(currentIndex)); item->setParentItem(baseItem); item->setFlag(QGraphicsItem::ItemIsFocusable); - grid[y][x] = item; + grid[currentIndex++] = item; switch (qrand() % 9) { case 0: item->setPixmap(QPixmap(":/images/kontact_contacts.png")); break; @@ -131,14 +124,10 @@ Panel::Panel(int width, int height) } } - grid[0][0]->setFocus(); + grid.first()->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); @@ -147,16 +136,15 @@ Panel::Panel(int width, int height) splash->grabKeyboard(); - updateSelectionStep(0); + //initialize the position + baseItem->setYRotation(selectionItem->x()/6.); + baseItem->setXRotation(selectionItem->y()/6.); setWindowTitle(tr("Pad Navigator Example")); } Panel::~Panel() { - for (int y = 0; y < height; ++y) - delete [] grid[y]; - delete [] grid; } void Panel::keyPressEvent(QKeyEvent *event) @@ -166,73 +154,93 @@ void Panel::keyPressEvent(QKeyEvent *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(); + selectedIndex = (selectedIndex + grid.count() + (event->key() == Qt::Key_Right) - (event->key() == Qt::Key_Left) + + width * ((event->key() == Qt::Key_Down) - (event->key() == Qt::Key_Up))) % grid.count(); + grid[selectedIndex]->setFocus(); + + const QPointF pos = posForLocation(selectedIndex); + + const double angleY = pos.x() / 6., + angleX = pos.y() / 6.; + + QAnimationGroup *group = new QParallelAnimationGroup(); + + QVariantAnimation *anim = new QPropertyAnimation(baseItem, "xRotation"); + anim->setEndValue(angleX); + anim->setDuration(150); + anim->setEasingCurve(QEasingCurve::OutInSine); + group->addAnimation(anim); + + anim = new QPropertyAnimation(baseItem, "yRotation"); + anim->setEndValue(angleY); + anim->setDuration(150); + anim->setEasingCurve(QEasingCurve::OutInSine); + group->addAnimation(anim); + + anim = new QPropertyAnimation(selectionItem, "pos"); + anim->setEndValue(pos); + anim->setDuration(150); + anim->setEasingCurve(QEasingCurve::Linear); + group->addAnimation(anim); + + group->start(QAbstractAnimation::DeleteWhenStopped); } void Panel::resizeEvent(QResizeEvent *event) { QGraphicsView::resizeEvent(event); - fitInView(scene->sceneRect(), Qt::KeepAspectRatio); + fitInView(scene()->sceneRect(), Qt::KeepAspectRatio); } -void Panel::updateSelectionStep(qreal val) +void Panel::flip() { - 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); -} + grid[selectedIndex]->setFocus(); + + if (flippingGroup == 0) { + flippingGroup = new QParallelAnimationGroup(this); + + const qreal zoomOut = qreal(.75); + + //slight scaling down while flipping + QVariantAnimation *anim = new QPropertyAnimation(baseItem, "yScale"); + anim->setKeyValueAt(qreal(.5), zoomOut); + anim->setEndValue(1); + anim->setEasingCurve(QEasingCurve::OutInSine); + anim->setDuration(500); + flippingGroup->addAnimation(anim); + + anim = new QPropertyAnimation(baseItem, "xScale"); + anim->setKeyValueAt(qreal(.5), zoomOut); + anim->setEndValue(1); + anim->setEasingCurve(QEasingCurve::OutInSine); + anim->setDuration(500); + flippingGroup->addAnimation(anim); + + rotationXanim = new QPropertyAnimation(baseItem, "xRotation"); + rotationXanim->setEndValue(0); + rotationXanim->setDuration(500); + flippingGroup->addAnimation(rotationXanim); + + rotationYanim = new QPropertyAnimation(baseItem, "yRotation"); + rotationYanim->setStartValue(0); + rotationYanim->setEndValue(180); + rotationYanim->setDuration(500); + flippingGroup->addAnimation(rotationYanim); + } -void Panel::updateFlipStep(qreal val) -{ - qreal finalxrot = xrot - xrot * val; - qreal finalyrot; - if (flipLeft) - finalyrot = yrot - yrot * val - 180 * val; + if (flippingGroup->currentTime() != 0 && flippingGroup->direction() == QAbstractAnimation::Forward) + flippingGroup->setDirection(QAbstractAnimation::Backward); 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(); -} + flippingGroup->setDirection(QAbstractAnimation::Forward); -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; - } + flippingGroup->start(); + flipped = !flipped; } -QPointF Panel::posForLocation(int x, int y) const +QPointF Panel::posForLocation(int index) const { + const int x = index % width, + y = index / width; return QPointF(x * 150, y * 150) - QPointF((width - 1) * 75, (height - 1) * 75); } diff --git a/examples/graphicsview/padnavigator/panel.h b/examples/graphicsview/padnavigator/panel.h index 03876b7..cc03530 100644 --- a/examples/graphicsview/padnavigator/panel.h +++ b/examples/graphicsview/padnavigator/panel.h @@ -40,10 +40,12 @@ ****************************************************************************/ #include <QtGui/qgraphicsview.h> +#include <QtGui/qgraphicswidget.h> QT_BEGIN_NAMESPACE -class QTimeLine; class Ui_BackSide; +class QAnimationGroup; +class QPropertyAnimation; QT_END_NAMESPACE; class RoundRectItem; @@ -60,33 +62,24 @@ protected: 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; + QPointF posForLocation(int index) const; - QGraphicsScene *scene; - RoundRectItem *selectionItem; - RoundRectItem *baseItem; + QGraphicsWidget *selectionItem; + QGraphicsWidget *baseItem; RoundRectItem *backItem; QGraphicsWidget *splash; - QTimeLine *selectionTimeLine; - QTimeLine *flipTimeLine; - int selectedX, selectedY; + int selectedIndex; - QGraphicsItem ***grid; + QVector<QGraphicsItem*> grid; - QPointF startPos; - QPointF endPos; - qreal xrot, yrot; - qreal xrot2, yrot2; - int width; int height; bool flipped; - bool flipLeft; - Ui_BackSide *ui; + + QAnimationGroup *flippingGroup; + QPropertyAnimation *rotationXanim, *rotationYanim; }; diff --git a/examples/graphicsview/padnavigator/roundrectitem.cpp b/examples/graphicsview/padnavigator/roundrectitem.cpp index c5dc35d..ec91966 100644 --- a/examples/graphicsview/padnavigator/roundrectitem.cpp +++ b/examples/graphicsview/padnavigator/roundrectitem.cpp @@ -44,72 +44,61 @@ #include <QtGui/QtGui> RoundRectItem::RoundRectItem(const QRectF &rect, const QBrush &brush, QWidget *embeddedWidget) - : QGraphicsRectItem(rect), + : QGraphicsWidget(), + m_rect(rect), brush(brush), - timeLine(75), - lastVal(0), - opa(1), proxyWidget(0) { - 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)); } } 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()) { + const bool widgetHidden = parentItem() == 0 || qAbs(static_cast<QGraphicsWidget*>(parentItem())->yRotation()) < 90; + + if (proxyWidget) { + if (widgetHidden) { proxyWidget->hide(); - proxyWidget->setGeometry(rect()); + } else { + if (!proxyWidget->isVisible()) { + proxyWidget->setGeometry(boundingRect().adjusted(25, 25, -25, -25)); + proxyWidget->show(); + proxyWidget->setFocus(); + } + painter->setBrush(brush); + painter->setPen(QPen(Qt::black, 1)); + painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); + painter->drawRoundRect(m_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)); + } else if (widgetHidden) { + painter->setPen(Qt::NoPen); + painter->setBrush(QColor(0, 0, 0, 64)); + painter->drawRoundRect(m_rect.translated(2, 2)); - if (!proxyWidget) { - QLinearGradient gradient(rect().topLeft(), rect().bottomRight()); + QLinearGradient gradient(m_rect.topLeft(), m_rect.bottomRight()); const QColor col = brush.color(); gradient.setColorAt(0, col); - gradient.setColorAt(1, col.dark(int(200 + lastVal * 50))); + gradient.setColorAt(1, col.dark(200)); painter->setBrush(gradient); - } else { - painter->setBrush(brush); + painter->setPen(QPen(Qt::black, 1)); + painter->drawRoundRect(m_rect); + if (!pix.isNull()) { + painter->scale(qreal(1.95), qreal(1.95)); + painter->drawPixmap(-pix.width() / 2, -pix.height() / 2, pix); + } } - 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);; - } } QRectF RoundRectItem::boundingRect() const { - qreal penW = 0.5; - qreal shadowW = 2.0; - return rect().adjusted(-penW, -penW, penW + shadowW, penW + shadowW); + qreal penW = qreal(.5); + qreal shadowW = 2; + return m_rect.adjusted(-penW, -penW, penW + shadowW, penW + shadowW); } void RoundRectItem::setPixmap(const QPixmap &pixmap) @@ -119,46 +108,29 @@ void RoundRectItem::setPixmap(const QPixmap &pixmap) update(); } -qreal RoundRectItem::opacity() const -{ - RoundRectItem *parent = parentItem() ? (RoundRectItem *)parentItem() : 0; - return opa + (parent ? parent->opacity() : 0); -} - -void RoundRectItem::setOpacity(qreal opacity) -{ - opa = opacity; - update(); -} - void RoundRectItem::keyPressEvent(QKeyEvent *event) { - if (event->isAutoRepeat() || event->key() != Qt::Key_Return - || (timeLine.state() == QTimeLine::Running && timeLine.direction() == QTimeLine::Forward)) { - QGraphicsRectItem::keyPressEvent(event); + if (event->isAutoRepeat() || event->key() != Qt::Key_Return) { + QGraphicsWidget::keyPressEvent(event); return; } - timeLine.stop(); - timeLine.setDirection(QTimeLine::Forward); - timeLine.start(); + if (!proxyWidget) { + setXScale(qreal(.9)); + setYScale(qreal(.9)); + } emit activated(); } void RoundRectItem::keyReleaseEvent(QKeyEvent *event) { - if (event->key() != Qt::Key_Return) { - QGraphicsRectItem::keyReleaseEvent(event); + if (event->isAutoRepeat() || event->key() != Qt::Key_Return) { + QGraphicsWidget::keyReleaseEvent(event); return; } - timeLine.stop(); - timeLine.setDirection(QTimeLine::Backward); - timeLine.start(); -} -void RoundRectItem::updateValue(qreal value) -{ - lastVal = value; - if (!proxyWidget) - setTransform(QTransform().scale(1 - value / 10.0, 1 - value / 10.0)); + if (!proxyWidget) { + setXScale(1); + setYScale(1); + } } diff --git a/examples/graphicsview/padnavigator/roundrectitem.h b/examples/graphicsview/padnavigator/roundrectitem.h index 33e33d7..b0d44dd 100644 --- a/examples/graphicsview/padnavigator/roundrectitem.h +++ b/examples/graphicsview/padnavigator/roundrectitem.h @@ -40,15 +40,14 @@ ****************************************************************************/ #include <QtCore/qobject.h> -#include <QtCore/qtimeline.h> -#include <QtGui/qgraphicsitem.h> #include <QtGui/qbrush.h> +#include <QtGui/qgraphicswidget.h> QT_BEGIN_NAMESPACE class QGraphicsProxyWidget; QT_END_NAMESPACE; -class RoundRectItem : public QObject, public QGraphicsRectItem +class RoundRectItem : public QGraphicsWidget { Q_OBJECT public: @@ -59,9 +58,6 @@ public: void setPixmap(const QPixmap &pixmap); - qreal opacity() const; - void setOpacity(qreal opacity); - Q_SIGNALS: void activated(); @@ -69,15 +65,9 @@ protected: void keyPressEvent(QKeyEvent *event); void keyReleaseEvent(QKeyEvent *event); -private slots: - void updateValue(qreal value); - private: + QRectF m_rect; QBrush brush; QPixmap pix; - QTimeLine timeLine; - qreal lastVal; - qreal opa; - QGraphicsProxyWidget *proxyWidget; }; diff --git a/examples/graphicsview/padnavigator/splashitem.cpp b/examples/graphicsview/padnavigator/splashitem.cpp index 2a374bf..a83d4d5 100644 --- a/examples/graphicsview/padnavigator/splashitem.cpp +++ b/examples/graphicsview/padnavigator/splashitem.cpp @@ -46,12 +46,6 @@ SplashItem::SplashItem(QGraphicsItem *parent) : QGraphicsWidget(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" @@ -61,7 +55,6 @@ SplashItem::SplashItem(QGraphicsItem *parent) void SplashItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { - painter->setOpacity(opacity); painter->setPen(QPen(Qt::black, 2)); painter->setBrush(QColor(245, 245, 255, 220)); painter->setClipRect(rect()); @@ -79,14 +72,14 @@ void SplashItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWid void SplashItem::keyPressEvent(QKeyEvent * /* event */) { - if (timeLine->state() == QTimeLine::NotRunning) - timeLine->start(); -} + QVariantAnimation *anim = new QPropertyAnimation(this, "pos"); + anim->setEndValue(QPointF(x(), scene()->sceneRect().top() - rect().height())); + anim->setDuration(350); + anim->start(QAbstractAnimation::DeleteWhenStopped); -void SplashItem::setValue(qreal value) -{ - opacity = 1 - value; - setPos(x(), scene()->sceneRect().top() - rect().height() * value); - if (value == 1) - hide(); + anim = new QPropertyAnimation(this, "opacity"); + anim->setEndValue(0); + anim->start(QAbstractAnimation::DeleteWhenStopped); + + connect(anim, SIGNAL(finished()), SLOT(close())); } diff --git a/examples/graphicsview/padnavigator/splashitem.h b/examples/graphicsview/padnavigator/splashitem.h index 982bbe2..e2655ec 100644 --- a/examples/graphicsview/padnavigator/splashitem.h +++ b/examples/graphicsview/padnavigator/splashitem.h @@ -40,7 +40,6 @@ ****************************************************************************/ #include <QtCore/qobject.h> -#include <QtCore/qtimeline.h> #include <QtGui/qgraphicswidget.h> class SplashItem : public QGraphicsWidget @@ -53,11 +52,6 @@ public: protected: void keyPressEvent(QKeyEvent *event); -private Q_SLOTS: - void setValue(qreal value); - private: - QTimeLine *timeLine; QString text; - qreal opacity; }; |