splashitem.cpp Example File
graphicsview/padnavigator/splashitem.cpp
#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 * )
{
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();
}
| Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies) |
Trademarks |
Qt 4.6.0-tp1 |