Changeset 846 for trunk/examples/graphicsview/padnavigator
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 3 deleted
- 8 edited
- 5 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/examples/graphicsview/padnavigator/main.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 7 7 ** This file is part of the examples of the Qt Toolkit. 8 8 ** 9 ** $QT_BEGIN_LICENSE:LGPL$ 10 ** Commercial Usage 11 ** Licensees holding valid Qt Commercial licenses may use this file in 12 ** accordance with the Qt Commercial License Agreement provided with the 13 ** Software or, alternatively, in accordance with the terms contained in 14 ** a written agreement between you and Nokia. 9 ** $QT_BEGIN_LICENSE:BSD$ 10 ** You may use this file under the terms of the BSD license as follows: 15 11 ** 16 ** GNU Lesser General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU Lesser 18 ** General Public License version 2.1 as published by the Free Software 19 ** Foundation and appearing in the file LICENSE.LGPL included in the 20 ** packaging of this file. Please review the following information to 21 ** ensure the GNU Lesser General Public License version 2.1 requirements 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 12 ** "Redistribution and use in source and binary forms, with or without 13 ** modification, are permitted provided that the following conditions are 14 ** met: 15 ** * Redistributions of source code must retain the above copyright 16 ** notice, this list of conditions and the following disclaimer. 17 ** * Redistributions in binary form must reproduce the above copyright 18 ** notice, this list of conditions and the following disclaimer in 19 ** the documentation and/or other materials provided with the 20 ** distribution. 21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor 22 ** the names of its contributors may be used to endorse or promote 23 ** products derived from this software without specific prior written 24 ** permission. 23 25 ** 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 ** 28 ** GNU General Public License Usage 29 ** Alternatively, this file may be used under the terms of the GNU 30 ** General Public License version 3.0 as published by the Free Software 31 ** Foundation and appearing in the file LICENSE.GPL included in the 32 ** packaging of this file. Please review the following information to 33 ** ensure the GNU General Public License version 3.0 requirements will be 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 ** 36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 38 37 ** $QT_END_LICENSE$ 39 38 ** 40 39 ****************************************************************************/ 41 40 42 #include <QtGui> 43 #ifndef QT_NO_OPENGL 44 # include <QtOpenGL> 45 #endif 41 #include "padnavigator.h" 46 42 47 #include "panel.h"43 #include <QtGui/QtGui> 48 44 45 //! [0] 49 46 int main(int argc, char *argv[]) 50 47 { … … 52 49 Q_INIT_RESOURCE(padnavigator); 53 50 54 Panel panel(3, 3); 55 panel.setFocus(); 56 panel.show(); 51 PadNavigator navigator(QSize(3, 3)); 52 navigator.show(); 57 53 58 54 return app.exec(); 59 55 } 56 //! [0] -
trunk/examples/graphicsview/padnavigator/padnavigator.pro
r561 r846 1 SOURCES += main.cpp \ 2 roundrectitem.cpp \ 3 flippablepad.cpp \ 4 padnavigator.cpp \ 5 splashitem.cpp 6 1 7 HEADERS += \ 2 panel.h \ 3 roundrectitem.h \ 4 splashitem.h 5 6 SOURCES += \ 7 panel.cpp \ 8 roundrectitem.cpp \ 9 splashitem.cpp \ 10 main.cpp 8 roundrectitem.h \ 9 flippablepad.h \ 10 padnavigator.h \ 11 splashitem.h 11 12 12 13 RESOURCES += \ 13 14 padnavigator.qrc 14 15 15 16 FORMS += \ 16 backside.ui17 form.ui 17 18 18 19 contains(QT_CONFIG, opengl):QT += opengl -
trunk/examples/graphicsview/padnavigator/padnavigator.qrc
r2 r846 10 10 <file>images/metacontact_online.png</file> 11 11 <file>images/minitools.png</file> 12 <file>images/blue_angle_swirl.jpg</file>13 12 </qresource> 14 13 </RCC> -
trunk/examples/graphicsview/padnavigator/roundrectitem.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 7 7 ** This file is part of the examples of the Qt Toolkit. 8 8 ** 9 ** $QT_BEGIN_LICENSE:LGPL$ 10 ** Commercial Usage 11 ** Licensees holding valid Qt Commercial licenses may use this file in 12 ** accordance with the Qt Commercial License Agreement provided with the 13 ** Software or, alternatively, in accordance with the terms contained in 14 ** a written agreement between you and Nokia. 9 ** $QT_BEGIN_LICENSE:BSD$ 10 ** You may use this file under the terms of the BSD license as follows: 15 11 ** 16 ** GNU Lesser General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU Lesser 18 ** General Public License version 2.1 as published by the Free Software 19 ** Foundation and appearing in the file LICENSE.LGPL included in the 20 ** packaging of this file. Please review the following information to 21 ** ensure the GNU Lesser General Public License version 2.1 requirements 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 12 ** "Redistribution and use in source and binary forms, with or without 13 ** modification, are permitted provided that the following conditions are 14 ** met: 15 ** * Redistributions of source code must retain the above copyright 16 ** notice, this list of conditions and the following disclaimer. 17 ** * Redistributions in binary form must reproduce the above copyright 18 ** notice, this list of conditions and the following disclaimer in 19 ** the documentation and/or other materials provided with the 20 ** distribution. 21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor 22 ** the names of its contributors may be used to endorse or promote 23 ** products derived from this software without specific prior written 24 ** permission. 23 25 ** 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 ** 28 ** GNU General Public License Usage 29 ** Alternatively, this file may be used under the terms of the GNU 30 ** General Public License version 3.0 as published by the Free Software 31 ** Foundation and appearing in the file LICENSE.GPL included in the 32 ** packaging of this file. Please review the following information to 33 ** ensure the GNU General Public License version 3.0 requirements will be 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 ** 36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 38 37 ** $QT_END_LICENSE$ 39 38 ** … … 44 43 #include <QtGui/QtGui> 45 44 46 RoundRectItem::RoundRectItem(const QRectF &rect, const QBrush &brush, QWidget *embeddedWidget) 47 : QGraphicsRectItem(rect), 48 brush(brush), 49 timeLine(75), 50 lastVal(0), 51 opa(1), 52 proxyWidget(0) 45 //! [0] 46 RoundRectItem::RoundRectItem(const QRectF &bounds, const QColor &color, 47 QGraphicsItem *parent) 48 : QGraphicsObject(parent), fillRect(false), bounds(bounds) 53 49 { 54 connect(&timeLine, SIGNAL(valueChanged(qreal)), 55 this, SLOT(updateValue(qreal))); 56 57 if (embeddedWidget) { 58 proxyWidget = new QGraphicsProxyWidget(this); 59 proxyWidget->setFocusPolicy(Qt::StrongFocus); 60 proxyWidget->setWidget(embeddedWidget); 61 proxyWidget->setGeometry(boundingRect().adjusted(25, 25, -25, -25)); 62 } 50 gradient.setStart(bounds.topLeft()); 51 gradient.setFinalStop(bounds.bottomRight()); 52 gradient.setColorAt(0, color); 53 gradient.setColorAt(1, color.dark(200)); 54 setCacheMode(ItemCoordinateCache); 63 55 } 56 //! [0] 64 57 65 void RoundRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) 58 //! [1] 59 QPixmap RoundRectItem::pixmap() const 66 60 { 67 QTransform x = painter->worldTransform(); 68 69 QLineF unit = x.map(QLineF(0, 0, 1, 1)); 70 if (unit.p1().x() > unit.p2().x() || unit.p1().y() > unit.p2().y()) { 71 if (proxyWidget && proxyWidget->isVisible()) { 72 proxyWidget->hide(); 73 proxyWidget->setGeometry(rect()); 74 } 75 return; 76 } 77 78 if (proxyWidget && !proxyWidget->isVisible()) { 79 proxyWidget->show(); 80 proxyWidget->setFocus(); 81 } 82 if (proxyWidget && proxyWidget->pos() != QPoint()) 83 proxyWidget->setGeometry(boundingRect().adjusted(25, 25, -25, -25)); 84 85 painter->setOpacity(opacity()); 86 painter->setPen(Qt::NoPen); 87 painter->setBrush(QColor(0, 0, 0, 64)); 88 painter->drawRoundRect(rect().translated(2, 2)); 89 90 if (!proxyWidget) { 91 QLinearGradient gradient(rect().topLeft(), rect().bottomRight()); 92 const QColor col = brush.color(); 93 gradient.setColorAt(0, col); 94 gradient.setColorAt(1, col.dark(int(200 + lastVal * 50))); 95 painter->setBrush(gradient); 96 } else { 97 painter->setBrush(brush); 98 } 99 100 painter->setPen(QPen(Qt::black, 1)); 101 painter->drawRoundRect(rect()); 102 if (!pix.isNull()) { 103 painter->scale(1.95, 1.95); 104 painter->drawPixmap(-pix.width() / 2, -pix.height() / 2, pix);; 105 } 61 return pix; 106 62 } 107 108 QRectF RoundRectItem::boundingRect() const109 {110 qreal penW = 0.5;111 qreal shadowW = 2.0;112 return rect().adjusted(-penW, -penW, penW + shadowW, penW + shadowW);113 }114 115 63 void RoundRectItem::setPixmap(const QPixmap &pixmap) 116 64 { 117 65 pix = pixmap; 118 if (scene() && isVisible())119 update();120 }121 122 qreal RoundRectItem::opacity() const123 {124 RoundRectItem *parent = parentItem() ? (RoundRectItem *)parentItem() : 0;125 return opa + (parent ? parent->opacity() : 0);126 }127 128 void RoundRectItem::setOpacity(qreal opacity)129 {130 opa = opacity;131 66 update(); 132 67 } 68 //! [1] 133 69 134 void RoundRectItem::keyPressEvent(QKeyEvent *event) 70 //! [2] 71 QRectF RoundRectItem::boundingRect() const 135 72 { 136 if (event->isAutoRepeat() || event->key() != Qt::Key_Return 137 || (timeLine.state() == QTimeLine::Running && timeLine.direction() == QTimeLine::Forward)) { 138 QGraphicsRectItem::keyPressEvent(event); 139 return; 73 return bounds.adjusted(0, 0, 2, 2); 74 } 75 //! [2] 76 77 //! [3] 78 void RoundRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, 79 QWidget *widget) 80 { 81 Q_UNUSED(option); 82 Q_UNUSED(widget); 83 painter->setPen(Qt::NoPen); 84 painter->setBrush(QColor(0, 0, 0, 64)); 85 painter->drawRoundRect(bounds.translated(2, 2)); 86 //! [3] 87 //! [4] 88 if (fillRect) 89 painter->setBrush(QApplication::palette().brush(QPalette::Window)); 90 else 91 painter->setBrush(gradient); 92 painter->setPen(QPen(Qt::black, 1)); 93 painter->drawRoundRect(bounds); 94 //! [4] 95 //! [5] 96 if (!pix.isNull()) { 97 painter->scale(1.95, 1.95); 98 painter->drawPixmap(-pix.width() / 2, -pix.height() / 2, pix); 140 99 } 100 } 101 //! [5] 141 102 142 timeLine.stop(); 143 timeLine.setDirection(QTimeLine::Forward); 144 timeLine.start(); 145 emit activated();103 //! [6] 104 bool RoundRectItem::fill() const 105 { 106 return fillRect; 146 107 } 147 148 void RoundRectItem::keyReleaseEvent(QKeyEvent *event) 108 void RoundRectItem::setFill(bool fill) 149 109 { 150 if (event->key() != Qt::Key_Return) { 151 QGraphicsRectItem::keyReleaseEvent(event); 152 return; 153 } 154 timeLine.stop(); 155 timeLine.setDirection(QTimeLine::Backward); 156 timeLine.start(); 110 fillRect = fill; 111 update(); 157 112 } 158 159 void RoundRectItem::updateValue(qreal value) 160 { 161 lastVal = value; 162 if (!proxyWidget) 163 setTransform(QTransform().scale(1 - value / 10.0, 1 - value / 10.0)); 164 } 113 //! [6] -
trunk/examples/graphicsview/padnavigator/roundrectitem.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 7 7 ** This file is part of the examples of the Qt Toolkit. 8 8 ** 9 ** $QT_BEGIN_LICENSE:LGPL$ 10 ** Commercial Usage 11 ** Licensees holding valid Qt Commercial licenses may use this file in 12 ** accordance with the Qt Commercial License Agreement provided with the 13 ** Software or, alternatively, in accordance with the terms contained in 14 ** a written agreement between you and Nokia. 9 ** $QT_BEGIN_LICENSE:BSD$ 10 ** You may use this file under the terms of the BSD license as follows: 15 11 ** 16 ** GNU Lesser General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU Lesser 18 ** General Public License version 2.1 as published by the Free Software 19 ** Foundation and appearing in the file LICENSE.LGPL included in the 20 ** packaging of this file. Please review the following information to 21 ** ensure the GNU Lesser General Public License version 2.1 requirements 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 12 ** "Redistribution and use in source and binary forms, with or without 13 ** modification, are permitted provided that the following conditions are 14 ** met: 15 ** * Redistributions of source code must retain the above copyright 16 ** notice, this list of conditions and the following disclaimer. 17 ** * Redistributions in binary form must reproduce the above copyright 18 ** notice, this list of conditions and the following disclaimer in 19 ** the documentation and/or other materials provided with the 20 ** distribution. 21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor 22 ** the names of its contributors may be used to endorse or promote 23 ** products derived from this software without specific prior written 24 ** permission. 23 25 ** 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 ** 28 ** GNU General Public License Usage 29 ** Alternatively, this file may be used under the terms of the GNU 30 ** General Public License version 3.0 as published by the Free Software 31 ** Foundation and appearing in the file LICENSE.GPL included in the 32 ** packaging of this file. Please review the following information to 33 ** ensure the GNU General Public License version 3.0 requirements will be 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 ** 36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 38 37 ** $QT_END_LICENSE$ 39 38 ** 40 39 ****************************************************************************/ 41 40 42 #include <QtCore/qobject.h> 43 #include <QtCore/qtimeline.h> 44 #include <QtGui/qgraphicsitem.h> 45 #include <QtGui/qbrush.h> 41 #ifndef ROUNDRECTITEM_H 42 #define ROUNDRECTITEM_H 46 43 47 QT_BEGIN_NAMESPACE 48 class QGraphicsProxyWidget; 49 QT_END_NAMESPACE 44 #include <QGraphicsObject> 45 #include <QLinearGradient> 50 46 51 class RoundRectItem : public QObject, public QGraphicsRectItem 47 //! [0] 48 class RoundRectItem : public QGraphicsObject 52 49 { 53 50 Q_OBJECT 51 Q_PROPERTY(bool fill READ fill WRITE setFill) 54 52 public: 55 RoundRectItem(const QRectF &rect, const QBrush &brush, QWidget *embeddedWidget = 0); 53 RoundRectItem(const QRectF &bounds, const QColor &color, 54 QGraphicsItem *parent = 0); 56 55 57 void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *); 58 QRectF boundingRect() const; 59 56 QPixmap pixmap() const; 60 57 void setPixmap(const QPixmap &pixmap); 61 58 62 qreal opacity() const;63 void setOpacity(qreal opacity);59 QRectF boundingRect() const; 60 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); 64 61 65 Q_SIGNALS: 66 void activated(); 62 bool fill() const; 63 void setFill(bool fill); 64 //! [0] 67 65 68 protected: 69 void keyPressEvent(QKeyEvent *event); 70 void keyReleaseEvent(QKeyEvent *event); 66 //! [1] 67 private: 68 QPixmap pix; 69 bool fillRect; 70 QRectF bounds; 71 QLinearGradient gradient; 72 }; 73 //! [1] 71 74 72 private slots: 73 void updateValue(qreal value); 74 75 private: 76 QBrush brush; 77 QPixmap pix; 78 QTimeLine timeLine; 79 qreal lastVal; 80 qreal opa; 81 82 QGraphicsProxyWidget *proxyWidget; 83 }; 75 #endif // ROUNDRECTITEM_H -
trunk/examples/graphicsview/padnavigator/splashitem.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 7 7 ** This file is part of the examples of the Qt Toolkit. 8 8 ** 9 ** $QT_BEGIN_LICENSE:LGPL$ 10 ** Commercial Usage 11 ** Licensees holding valid Qt Commercial licenses may use this file in 12 ** accordance with the Qt Commercial License Agreement provided with the 13 ** Software or, alternatively, in accordance with the terms contained in 14 ** a written agreement between you and Nokia. 9 ** $QT_BEGIN_LICENSE:BSD$ 10 ** You may use this file under the terms of the BSD license as follows: 15 11 ** 16 ** GNU Lesser General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU Lesser 18 ** General Public License version 2.1 as published by the Free Software 19 ** Foundation and appearing in the file LICENSE.LGPL included in the 20 ** packaging of this file. Please review the following information to 21 ** ensure the GNU Lesser General Public License version 2.1 requirements 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 12 ** "Redistribution and use in source and binary forms, with or without 13 ** modification, are permitted provided that the following conditions are 14 ** met: 15 ** * Redistributions of source code must retain the above copyright 16 ** notice, this list of conditions and the following disclaimer. 17 ** * Redistributions in binary form must reproduce the above copyright 18 ** notice, this list of conditions and the following disclaimer in 19 ** the documentation and/or other materials provided with the 20 ** distribution. 21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor 22 ** the names of its contributors may be used to endorse or promote 23 ** products derived from this software without specific prior written 24 ** permission. 23 25 ** 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 ** 28 ** GNU General Public License Usage 29 ** Alternatively, this file may be used under the terms of the GNU 30 ** General Public License version 3.0 as published by the Free Software 31 ** Foundation and appearing in the file LICENSE.GPL included in the 32 ** packaging of this file. Please review the following information to 33 ** ensure the GNU General Public License version 3.0 requirements will be 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 ** 36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 38 37 ** $QT_END_LICENSE$ 39 38 ** … … 44 43 #include <QtGui/QtGui> 45 44 45 //! [0] 46 46 SplashItem::SplashItem(QGraphicsItem *parent) 47 : QGraphics Widget(parent)47 : QGraphicsObject(parent) 48 48 { 49 opacity = 1.0;50 51 52 timeLine = new QTimeLine(350);53 timeLine->setCurveShape(QTimeLine::EaseInCurve);54 connect(timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(setValue(qreal)));55 56 49 text = tr("Welcome to the Pad Navigator Example. You can use the" 57 50 " keyboard arrows to navigate the icons, and press enter" 58 " to activate an item. P lease press any key to continue.");59 resize(400, 175);51 " to activate an item. Press any key to begin."); 52 setCacheMode(DeviceCoordinateCache); 60 53 } 54 //! [0] 61 55 62 void SplashItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) 56 //! [1] 57 QRectF SplashItem::boundingRect() const 63 58 { 64 painter->setOpacity(opacity); 59 return QRectF(0, 0, 400, 175); 60 } 61 //! [1] 62 63 //! [2] 64 void SplashItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, 65 QWidget *widget) 66 { 67 Q_UNUSED(option); 68 Q_UNUSED(widget); 65 69 painter->setPen(QPen(Qt::black, 2)); 66 70 painter->setBrush(QColor(245, 245, 255, 220)); 67 painter->setClipRect( rect());71 painter->setClipRect(boundingRect()); 68 72 painter->drawRoundRect(3, -100 + 3, 400 - 6, 250 - 6); 69 73 70 QRectF textRect = rect().adjusted(10, 10, -10, -10);74 QRectF textRect = boundingRect().adjusted(10, 10, -10, -10); 71 75 int flags = Qt::AlignTop | Qt::AlignLeft | Qt::TextWordWrap; 72 76 … … 77 81 painter->drawText(textRect, flags, text); 78 82 } 79 80 void SplashItem::keyPressEvent(QKeyEvent * /* event */) 81 { 82 if (timeLine->state() == QTimeLine::NotRunning) 83 timeLine->start(); 84 } 85 86 void SplashItem::setValue(qreal value) 87 { 88 opacity = 1 - value; 89 setPos(x(), scene()->sceneRect().top() - rect().height() * value); 90 if (value == 1) 91 hide(); 92 } 83 //! [2] -
trunk/examples/graphicsview/padnavigator/splashitem.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 7 7 ** This file is part of the examples of the Qt Toolkit. 8 8 ** 9 ** $QT_BEGIN_LICENSE:LGPL$ 10 ** Commercial Usage 11 ** Licensees holding valid Qt Commercial licenses may use this file in 12 ** accordance with the Qt Commercial License Agreement provided with the 13 ** Software or, alternatively, in accordance with the terms contained in 14 ** a written agreement between you and Nokia. 9 ** $QT_BEGIN_LICENSE:BSD$ 10 ** You may use this file under the terms of the BSD license as follows: 15 11 ** 16 ** GNU Lesser General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU Lesser 18 ** General Public License version 2.1 as published by the Free Software 19 ** Foundation and appearing in the file LICENSE.LGPL included in the 20 ** packaging of this file. Please review the following information to 21 ** ensure the GNU Lesser General Public License version 2.1 requirements 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 12 ** "Redistribution and use in source and binary forms, with or without 13 ** modification, are permitted provided that the following conditions are 14 ** met: 15 ** * Redistributions of source code must retain the above copyright 16 ** notice, this list of conditions and the following disclaimer. 17 ** * Redistributions in binary form must reproduce the above copyright 18 ** notice, this list of conditions and the following disclaimer in 19 ** the documentation and/or other materials provided with the 20 ** distribution. 21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor 22 ** the names of its contributors may be used to endorse or promote 23 ** products derived from this software without specific prior written 24 ** permission. 23 25 ** 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 ** 28 ** GNU General Public License Usage 29 ** Alternatively, this file may be used under the terms of the GNU 30 ** General Public License version 3.0 as published by the Free Software 31 ** Foundation and appearing in the file LICENSE.GPL included in the 32 ** packaging of this file. Please review the following information to 33 ** ensure the GNU General Public License version 3.0 requirements will be 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 ** 36 ** If you have questions regarding the use of this file, please contact 37 ** Nokia at qt-info@nokia.com. 26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 38 37 ** $QT_END_LICENSE$ 39 38 ** 40 39 ****************************************************************************/ 41 40 42 #include <QtCore/qobject.h> 43 #include <QtCore/qtimeline.h> 44 #include <QtGui/qgraphicswidget.h> 41 #ifndef SPLASHITEM_H 42 #define SPLASHITEM_H 45 43 46 class SplashItem : public QGraphicsWidget 44 #include <QGraphicsObject> 45 46 //! [0] 47 class SplashItem : public QGraphicsObject 47 48 { 48 49 Q_OBJECT 49 50 public: 50 SplashItem(QGraphicsItem *parent = 0); 51 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); 51 explicit SplashItem(QGraphicsItem *parent = 0); 52 52 53 protected: 54 void keyPressEvent(QKeyEvent *event); 55 56 private Q_SLOTS: 57 void setValue(qreal value); 53 QRectF boundingRect() const; 54 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); 58 55 59 56 private: 60 QTimeLine *timeLine;61 57 QString text; 62 qreal opacity;63 58 }; 59 //! [0] 60 61 #endif // SPLASHITEM_H
Note:
See TracChangeset
for help on using the changeset viewer.