diff options
author | Andreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com> | 2010-05-12 14:32:12 (GMT) |
---|---|---|
committer | Andreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com> | 2010-05-12 14:36:10 (GMT) |
commit | 812f78e55aa3db4d51ec8617320358d80c4a71d5 (patch) | |
tree | aaceddad76df5b4d91bd2de4d56bb21b73ca94fa /examples | |
parent | e4902b4f25ca9c1ecff99609dbe376b407d9c6c5 (diff) | |
download | Qt-812f78e55aa3db4d51ec8617320358d80c4a71d5.zip Qt-812f78e55aa3db4d51ec8617320358d80c4a71d5.tar.gz Qt-812f78e55aa3db4d51ec8617320358d80c4a71d5.tar.bz2 |
Documentation for the Pad Navigator Example.
This also does a few touch-ups on the source code.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/graphicsview/padnavigator/flippablepad.cpp | 27 | ||||
-rw-r--r-- | examples/graphicsview/padnavigator/flippablepad.h | 5 | ||||
-rw-r--r-- | examples/graphicsview/padnavigator/main.cpp | 2 | ||||
-rw-r--r-- | examples/graphicsview/padnavigator/padnavigator.cpp | 218 | ||||
-rw-r--r-- | examples/graphicsview/padnavigator/padnavigator.h | 6 | ||||
-rw-r--r-- | examples/graphicsview/padnavigator/roundrectitem.cpp | 19 | ||||
-rw-r--r-- | examples/graphicsview/padnavigator/roundrectitem.h | 5 | ||||
-rw-r--r-- | examples/graphicsview/padnavigator/splashitem.cpp | 10 | ||||
-rw-r--r-- | examples/graphicsview/padnavigator/splashitem.h | 2 |
9 files changed, 186 insertions, 108 deletions
diff --git a/examples/graphicsview/padnavigator/flippablepad.cpp b/examples/graphicsview/padnavigator/flippablepad.cpp index 61f421f..58aea00 100644 --- a/examples/graphicsview/padnavigator/flippablepad.cpp +++ b/examples/graphicsview/padnavigator/flippablepad.cpp @@ -43,37 +43,43 @@ #include <QtGui/QtGui> +//! [0] static QRectF boundsFromSize(const QSize &size) { return QRectF((-size.width() / 2.0) * 150, (-size.height() / 2.0) * 150, size.width() * 150, size.height() * 150); } +//! [0] -static QPointF posForLocation(int x, int y, const QSize &size) +//! [1] +static QPointF posForLocation(int column, int row, const QSize &size) { - return QPointF(x * 150, y * 150) + return QPointF(column * 150, row * 150) - QPointF((size.width() - 1) * 75, (size.height() - 1) * 75); } +//! [1] +//! [2] FlippablePad::FlippablePad(const QSize &size, QGraphicsItem *parent) : RoundRectItem(boundsFromSize(size), QColor(226, 255, 92, 64), parent) { - columns = size.width(); - +//! [2] +//! [3] int numIcons = size.width() * size.height(); QList<QPixmap> pixmaps; QDirIterator it(":/images", QStringList() << "*.png"); while (it.hasNext() && pixmaps.size() < numIcons) pixmaps << it.next(); +//! [3] +//! [4] 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); + iconGrid[y].resize(size.width()); for (int x = 0; x < size.width(); ++x) { RoundRectItem *rect = new RoundRectItem(iconRect, iconColor, this); rect->setZValue(1); @@ -83,8 +89,11 @@ FlippablePad::FlippablePad(const QSize &size, QGraphicsItem *parent) } } } +//! [4] -RoundRectItem *FlippablePad::iconAt(int x, int y) const +//! [5] +RoundRectItem *FlippablePad::iconAt(int column, int row) const { - return iconGrid[y][x]; + return iconGrid[row][column]; } +//! [5] diff --git a/examples/graphicsview/padnavigator/flippablepad.h b/examples/graphicsview/padnavigator/flippablepad.h index 9adb18b..7d99536 100644 --- a/examples/graphicsview/padnavigator/flippablepad.h +++ b/examples/graphicsview/padnavigator/flippablepad.h @@ -48,16 +48,17 @@ #include <QLinearGradient> #include <QVector> +//! [0] class FlippablePad : public RoundRectItem { public: FlippablePad(const QSize &size, QGraphicsItem *parent = 0); - RoundRectItem *iconAt(int x, int y) const; + RoundRectItem *iconAt(int column, int row) const; private: - int columns; QVector<QVector<RoundRectItem *> > iconGrid; }; +//! [0] #endif // FLIPPABLEPAD_H diff --git a/examples/graphicsview/padnavigator/main.cpp b/examples/graphicsview/padnavigator/main.cpp index 6d148bb..984b976 100644 --- a/examples/graphicsview/padnavigator/main.cpp +++ b/examples/graphicsview/padnavigator/main.cpp @@ -43,6 +43,7 @@ #include <QtGui/QtGui> +//! [0] int main(int argc, char *argv[]) { QApplication app(argc, argv); @@ -53,3 +54,4 @@ int main(int argc, char *argv[]) return app.exec(); } +//! [0] diff --git a/examples/graphicsview/padnavigator/padnavigator.cpp b/examples/graphicsview/padnavigator/padnavigator.cpp index 456b3f4..b1d19f6 100644 --- a/examples/graphicsview/padnavigator/padnavigator.cpp +++ b/examples/graphicsview/padnavigator/padnavigator.cpp @@ -42,175 +42,213 @@ #include "flippablepad.h" #include "padnavigator.h" #include "splashitem.h" -#include "ui_form.h" #include <QtGui/QtGui> #ifndef QT_NO_OPENGL #include <QtOpenGL/QtOpenGL> #endif +//! [0] PadNavigator::PadNavigator(const QSize &size, QWidget *parent) : QGraphicsView(parent) { - // Prepare splash item +//! [0] +//! [1] + // Splash item SplashItem *splash = new SplashItem; splash->setZValue(1); +//! [1] - // Prepare pad item +//! [2] + // 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); + flipRotation->setAxis(Qt::YAxis); + xRotation->setAxis(Qt::YAxis); yRotation->setAxis(Qt::XAxis); pad->setTransformations(QList<QGraphicsTransform *>() << flipRotation << xRotation << yRotation); +//! [2] - // Prepare backitem - form = new Ui_Form; - QWidget *widget = new QWidget; - form->setupUi(widget); - form->hostName->setFocus(); +//! [3] + // Back (proxy widget) item QGraphicsProxyWidget *backItem = new QGraphicsProxyWidget(pad); - backItem->setCacheMode(QGraphicsItem::ItemCoordinateCache); + QWidget *widget = new QWidget; + form.setupUi(widget); + form.hostName->setFocus(); backItem->setWidget(widget); + backItem->setVisible(false); + backItem->setFocus(); + backItem->setCacheMode(QGraphicsItem::ItemCoordinateCache); + const QRectF r = backItem->rect(); backItem->setTransform(QTransform() .rotate(180, Qt::YAxis) - .translate(-backItem->rect().width()/2, -backItem->rect().height()/2)); - backItem->setFocus(); - backItem->setVisible(false); + .translate(-r.width()/2, -r.height()/2)); +//! [3] - // Prepare selection item +//! [4] + // Selection item RoundRectItem *selectionItem = new RoundRectItem(QRectF(-60, -60, 120, 120), Qt::gray, pad); selectionItem->setZValue(0.5); +//! [4] - // Selection animation setup +//! [5] + // Splash animations + QPropertyAnimation *smoothSplashMove = new QPropertyAnimation(splash, "y"); + QPropertyAnimation *smoothSplashOpacity = new QPropertyAnimation(splash, "opacity"); + smoothSplashMove->setEasingCurve(QEasingCurve::InQuad); + smoothSplashMove->setDuration(250); + smoothSplashOpacity->setDuration(250); +//! [5] + +//! [6] + // Selection animation 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"); + smoothXSelection->setDuration(125); + smoothYSelection->setDuration(125); + smoothXRotation->setDuration(125); smoothYRotation->setDuration(125); + smoothXSelection->setEasingCurve(QEasingCurve::InOutQuad); + smoothYSelection->setEasingCurve(QEasingCurve::InOutQuad); + smoothXRotation->setEasingCurve(QEasingCurve::InOutQuad); 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); +//! [6] +//! [7] // Flip animation setup QPropertyAnimation *smoothFlipRotation = new QPropertyAnimation(flipRotation, "angle"); + QPropertyAnimation *smoothFlipScale = new QPropertyAnimation(pad, "scale"); + QPropertyAnimation *smoothFlipXRotation = new QPropertyAnimation(xRotation, "angle"); + QPropertyAnimation *smoothFlipYRotation = new QPropertyAnimation(yRotation, "angle"); + QParallelAnimationGroup *flipAnimation = new QParallelAnimationGroup(this); + smoothFlipScale->setDuration(500); smoothFlipRotation->setDuration(500); + smoothFlipXRotation->setDuration(500); + smoothFlipYRotation->setDuration(500); + smoothFlipScale->setEasingCurve(QEasingCurve::InOutQuad); 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); + smoothFlipXRotation->setEasingCurve(QEasingCurve::InOutQuad); + smoothFlipYRotation->setEasingCurve(QEasingCurve::InOutQuad); + smoothFlipScale->setKeyValueAt(0, qVariantValue<qreal>(1.0)); + smoothFlipScale->setKeyValueAt(0.5, qVariantValue<qreal>(0.7)); + smoothFlipScale->setKeyValueAt(1, qVariantValue<qreal>(1.0)); flipAnimation->addAnimation(smoothFlipRotation); - flipAnimation->addAnimation(smoothScale); - flipAnimation->addAnimation(flipSmoothXRotation); - flipAnimation->addAnimation(flipSmoothYRotation); - flipAnimation->addAnimation(setVisibleAnimation); + flipAnimation->addAnimation(smoothFlipScale); + flipAnimation->addAnimation(smoothFlipXRotation); + flipAnimation->addAnimation(smoothFlipYRotation); +//! [7] - QPropertyAnimation *smoothSplashMove = new QPropertyAnimation(splash, "y"); - smoothSplashMove->setEasingCurve(QEasingCurve::InQuad); - smoothSplashMove->setDuration(250); - QPropertyAnimation *smoothSplashOpacity = new QPropertyAnimation(splash, "opacity"); - smoothSplashOpacity->setDuration(250); +//! [8] + // Flip animation delayed property assignment + QSequentialAnimationGroup *setVariablesSequence = new QSequentialAnimationGroup; + QPropertyAnimation *setFillAnimation = new QPropertyAnimation(pad, "fill"); + QPropertyAnimation *setBackItemVisibleAnimation = new QPropertyAnimation(backItem, "visible"); + QPropertyAnimation *setSelectionItemVisibleAnimation = new QPropertyAnimation(selectionItem, "visible"); + setFillAnimation->setDuration(0); + setBackItemVisibleAnimation->setDuration(0); + setSelectionItemVisibleAnimation->setDuration(0); + setVariablesSequence->addPause(250); + setVariablesSequence->addAnimation(setBackItemVisibleAnimation); + setVariablesSequence->addAnimation(setSelectionItemVisibleAnimation); + setVariablesSequence->addAnimation(setFillAnimation); + flipAnimation->addAnimation(setVariablesSequence); +//! [8] +//! [9] // 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); +//! [9] +//! [10] + frontState->assignProperty(pad, "fill", false); frontState->assignProperty(splash, "opacity", 0.0); - frontState->assignProperty(flipRotation, "angle", qVariantValue<qreal>(0.0)); frontState->assignProperty(backItem, "visible", false); + frontState->assignProperty(flipRotation, "angle", qVariantValue<qreal>(0.0)); frontState->assignProperty(selectionItem, "visible", true); - frontState->assignProperty(pad, "fill", false); - backState->assignProperty(flipRotation, "angle", qVariantValue<qreal>(180.0)); + backState->assignProperty(pad, "fill", true); + backState->assignProperty(backItem, "visible", true); backState->assignProperty(xRotation, "angle", qVariantValue<qreal>(0.0)); backState->assignProperty(yRotation, "angle", qVariantValue<qreal>(0.0)); + backState->assignProperty(flipRotation, "angle", qVariantValue<qreal>(180.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); +//! [10] +//! [11] // Transitions QEventTransition *anyKeyTransition = new QEventTransition(this, QEvent::KeyPress, splashState); anyKeyTransition->setTargetState(frontState); anyKeyTransition->addAnimation(smoothSplashMove); anyKeyTransition->addAnimation(smoothSplashOpacity); +//! [11] - QKeyEventTransition *enterTransition = new QKeyEventTransition(this, QEvent::KeyPress, Qt::Key_Enter, backState); +//! [12] + QKeyEventTransition *enterTransition = new QKeyEventTransition(this, QEvent::KeyPress, + Qt::Key_Enter, backState); + QKeyEventTransition *returnTransition = new QKeyEventTransition(this, QEvent::KeyPress, + Qt::Key_Return, backState); + QKeyEventTransition *backEnterTransition = new QKeyEventTransition(this, QEvent::KeyPress, + Qt::Key_Enter, frontState); + QKeyEventTransition *backReturnTransition = new QKeyEventTransition(this, QEvent::KeyPress, + Qt::Key_Return, frontState); 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); +//! [12] - // Substates, one for each icon +//! [13] + // Create substates for each icon; store in temporary grid. 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; - } + for (int x = 0; x < columns; ++x) + stateGrid[y][x] = new QState(frontState); } frontState->setInitialState(stateGrid[0][0]); selectionItem->setPos(pad->iconAt(0, 0)->pos()); +//! [13] +//! [14] // 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); + QKeyEventTransition *rightTransition = new QKeyEventTransition(this, QEvent::KeyPress, + Qt::Key_Right, state); + QKeyEventTransition *leftTransition = new QKeyEventTransition(this, QEvent::KeyPress, + Qt::Key_Left, state); + QKeyEventTransition *downTransition = new QKeyEventTransition(this, QEvent::KeyPress, + Qt::Key_Down, state); + QKeyEventTransition *upTransition = new QKeyEventTransition(this, QEvent::KeyPress, + Qt::Key_Up, 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]); - +//! [14] +//! [15] RoundRectItem *icon = pad->iconAt(x, y); state->assignProperty(xRotation, "angle", -icon->x() / 6.0); state->assignProperty(yRotation, "angle", icon->y() / 6.0); @@ -219,47 +257,51 @@ PadNavigator::PadNavigator(const QSize &size, QWidget *parent) frontState->assignProperty(icon, "visible", true); backState->assignProperty(icon, "visible", false); - QPropertyAnimation *setVisibleAnim = new QPropertyAnimation(icon, "visible"); - setVisibleAnim->setDuration(0); - setVisibleAnimation->addAnimation(setVisibleAnim); + QPropertyAnimation *setIconVisibleAnimation = new QPropertyAnimation(icon, "visible"); + setIconVisibleAnimation->setDuration(0); + setVariablesSequence->addAnimation(setIconVisibleAnimation); } } +//! [15] - // Setup scene +//! [16] + // 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); +//! [16] - // Adjust splash item - splash->setPos(-splash->boundingRect().width() / 2, scene->sceneRect().top()); +//! [17] + // Adjust splash item to scene contents + const QRectF sbr = splash->boundingRect(); + splash->setPos(-sbr.width() / 2, scene->sceneRect().top() - 2); frontState->assignProperty(splash, "y", splash->y() - 100.0); scene->addItem(splash); +//! [17] - // Setup view +//! [18] + // View setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setMinimumSize(50, 50); setViewportUpdateMode(FullViewportUpdate); setCacheMode(CacheBackground); - setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform - | QPainter::TextAntialiasing); + setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing); #ifndef QT_NO_OPENGL setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); #endif stateMachine->start(); +//! [18] } -PadNavigator::~PadNavigator() -{ - delete form; -} - +//! [19] void PadNavigator::resizeEvent(QResizeEvent *event) { QGraphicsView::resizeEvent(event); fitInView(scene()->sceneRect(), Qt::KeepAspectRatio); } +//! [19] diff --git a/examples/graphicsview/padnavigator/padnavigator.h b/examples/graphicsview/padnavigator/padnavigator.h index c79a13c..03a1ea2 100644 --- a/examples/graphicsview/padnavigator/padnavigator.h +++ b/examples/graphicsview/padnavigator/padnavigator.h @@ -43,23 +43,25 @@ #define PADNAVIGATOR_H #include <QGraphicsView> +#include "ui_form.h" class QState; class QStateMachine; class Ui_Form; +//! [0] class PadNavigator : public QGraphicsView { Q_OBJECT public: explicit PadNavigator(const QSize &size, QWidget *parent = 0); - ~PadNavigator(); protected: void resizeEvent(QResizeEvent *event); private: - Ui_Form *form; + Ui_Form form; }; +//! [0] #endif // PADNAVIGATOR_H diff --git a/examples/graphicsview/padnavigator/roundrectitem.cpp b/examples/graphicsview/padnavigator/roundrectitem.cpp index 2141e9a..7a0b279 100644 --- a/examples/graphicsview/padnavigator/roundrectitem.cpp +++ b/examples/graphicsview/padnavigator/roundrectitem.cpp @@ -43,34 +43,39 @@ #include <QtGui/QtGui> +//! [0] RoundRectItem::RoundRectItem(const QRectF &bounds, const QColor &color, QGraphicsItem *parent) - : QGraphicsObject(parent), fillRect(false), color(color), bounds(bounds) + : QGraphicsObject(parent), fillRect(false), bounds(bounds) { gradient.setStart(bounds.topLeft()); gradient.setFinalStop(bounds.bottomRight()); gradient.setColorAt(0, color); gradient.setColorAt(1, color.dark(200)); - setCacheMode(ItemCoordinateCache); } +//! [0] +//! [1] QPixmap RoundRectItem::pixmap() const { return pix; } - void RoundRectItem::setPixmap(const QPixmap &pixmap) { pix = pixmap; update(); } +//! [1] +//! [2] QRectF RoundRectItem::boundingRect() const { return bounds.adjusted(0, 0, 2, 2); } +//! [2] +//! [3] void RoundRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { @@ -79,25 +84,31 @@ void RoundRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt painter->setPen(Qt::NoPen); painter->setBrush(QColor(0, 0, 0, 64)); painter->drawRoundRect(bounds.translated(2, 2)); +//! [3] +//! [4] if (fillRect) painter->setBrush(QApplication::palette().brush(QPalette::Window)); else painter->setBrush(gradient); painter->setPen(QPen(Qt::black, 1)); painter->drawRoundRect(bounds); +//! [4] +//! [5] if (!pix.isNull()) { painter->scale(1.95, 1.95); painter->drawPixmap(-pix.width() / 2, -pix.height() / 2, pix); } } +//! [5] +//! [6] bool RoundRectItem::fill() const { return fillRect; } - void RoundRectItem::setFill(bool fill) { fillRect = fill; update(); } +//! [6] diff --git a/examples/graphicsview/padnavigator/roundrectitem.h b/examples/graphicsview/padnavigator/roundrectitem.h index ae5fb4c..bc58cec 100644 --- a/examples/graphicsview/padnavigator/roundrectitem.h +++ b/examples/graphicsview/padnavigator/roundrectitem.h @@ -45,6 +45,7 @@ #include <QGraphicsObject> #include <QLinearGradient> +//! [0] class RoundRectItem : public QGraphicsObject { Q_OBJECT @@ -61,13 +62,15 @@ public: bool fill() const; void setFill(bool fill); +//! [0] +//! [1] private: QPixmap pix; bool fillRect; - QColor color; QRectF bounds; QLinearGradient gradient; }; +//! [1] #endif // ROUNDRECTITEM_H diff --git a/examples/graphicsview/padnavigator/splashitem.cpp b/examples/graphicsview/padnavigator/splashitem.cpp index e609656..cd7074a 100644 --- a/examples/graphicsview/padnavigator/splashitem.cpp +++ b/examples/graphicsview/padnavigator/splashitem.cpp @@ -43,20 +43,25 @@ #include <QtGui/QtGui> -SplashItem::SplashItem(QGraphicsItem *parent) : - QGraphicsObject(parent) +//! [0] +SplashItem::SplashItem(QGraphicsItem *parent) + : QGraphicsObject(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. Press any key to begin."); setCacheMode(DeviceCoordinateCache); } +//! [0] +//! [1] QRectF SplashItem::boundingRect() const { return QRectF(0, 0, 400, 175); } +//! [1] +//! [2] void SplashItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { @@ -76,3 +81,4 @@ void SplashItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option painter->setFont(font); painter->drawText(textRect, flags, text); } +//! [2] diff --git a/examples/graphicsview/padnavigator/splashitem.h b/examples/graphicsview/padnavigator/splashitem.h index 9d57653..98c4a1f 100644 --- a/examples/graphicsview/padnavigator/splashitem.h +++ b/examples/graphicsview/padnavigator/splashitem.h @@ -44,6 +44,7 @@ #include <QGraphicsObject> +//! [0] class SplashItem : public QGraphicsObject { Q_OBJECT @@ -56,5 +57,6 @@ public: private: QString text; }; +//! [0] #endif // SPLASHITEM_H |