|  | Home · All Namespaces · All Classes · Main Classes · Grouped Classes · Modules · Functions |

# splashitem.cpp Example File
graphicsview/padnavigator/splashitem.cpp

     /****************************************************************************
     **
     ** Copyright (C) 1992-$THISYEAR$ $TROLLTECH$. All rights reserved.
     **
     ** This file is part of the $MODULE$ of the Qt Toolkit.
     **
     ** $TROLLTECH_DUAL_LICENSE$
     **
     ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
     ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
     **
     ****************************************************************************/

     #include "splashitem.h"

     #include <QtGui/QtGui>

     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"
                   " to activate an item. Please press any key to continue.");
         resize(400, 175);
     }

     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());
         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 */)
     {
         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();
     }