diff options
Diffstat (limited to 'examples/graphicsview')
39 files changed, 595 insertions, 375 deletions
diff --git a/examples/graphicsview/anchorlayout/anchorlayout.pro b/examples/graphicsview/anchorlayout/anchorlayout.pro index fd085cc..f56a4f9 100644 --- a/examples/graphicsview/anchorlayout/anchorlayout.pro +++ b/examples/graphicsview/anchorlayout/anchorlayout.pro @@ -7,3 +7,8 @@ sources.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/anchorlayout INSTALLS += target sources TARGET = anchorlayout + +symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) +maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri) + +simulator: warning(This example might not fully work on Simulator platform) diff --git a/examples/graphicsview/anchorlayout/main.cpp b/examples/graphicsview/anchorlayout/main.cpp index c31afd2..dbe9f19 100644 --- a/examples/graphicsview/anchorlayout/main.cpp +++ b/examples/graphicsview/anchorlayout/main.cpp @@ -122,7 +122,12 @@ int main(int argc, char **argv) scene.addItem(w); scene.setBackgroundBrush(Qt::darkGreen); QGraphicsView view(&scene); + +#if defined(Q_WS_S60) + view.showMaximized(); +#else view.show(); +#endif return app.exec(); } diff --git a/examples/graphicsview/basicgraphicslayouts/basicgraphicslayouts.pro b/examples/graphicsview/basicgraphicslayouts/basicgraphicslayouts.pro index 9549174..796d9de 100644 --- a/examples/graphicsview/basicgraphicslayouts/basicgraphicslayouts.pro +++ b/examples/graphicsview/basicgraphicslayouts/basicgraphicslayouts.pro @@ -15,3 +15,5 @@ symbian { TARGET.UID3 = 0xA000A645 include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) } +maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri) +simulator: warning(This example might not fully work on Simulator platform) diff --git a/examples/graphicsview/basicgraphicslayouts/main.cpp b/examples/graphicsview/basicgraphicslayouts/main.cpp index 57448a5..11da183 100644 --- a/examples/graphicsview/basicgraphicslayouts/main.cpp +++ b/examples/graphicsview/basicgraphicslayouts/main.cpp @@ -51,8 +51,12 @@ int main(int argc, char **argv) Window *window = new Window; scene.addItem(window); QGraphicsView view(&scene); +#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR) + view.showMaximized(); +#else view.resize(600, 600); view.show(); +#endif return app.exec(); } diff --git a/examples/graphicsview/collidingmice/collidingmice.pro b/examples/graphicsview/collidingmice/collidingmice.pro index 207c645..6205414 100644 --- a/examples/graphicsview/collidingmice/collidingmice.pro +++ b/examples/graphicsview/collidingmice/collidingmice.pro @@ -17,3 +17,5 @@ symbian { TARGET.UID3 = 0xA000A643 include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) } +maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri) +simulator: warning(This example might not fully work on Simulator platform) diff --git a/examples/graphicsview/collidingmice/main.cpp b/examples/graphicsview/collidingmice/main.cpp index 2970a00..4359402 100644 --- a/examples/graphicsview/collidingmice/main.cpp +++ b/examples/graphicsview/collidingmice/main.cpp @@ -79,8 +79,12 @@ int main(int argc, char **argv) view.setDragMode(QGraphicsView::ScrollHandDrag); //! [5] //! [6] view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Colliding Mice")); +#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR) + view.showMaximized(); +#else view.resize(400, 300); view.show(); +#endif QTimer timer; QObject::connect(&timer, SIGNAL(timeout()), &scene, SLOT(advance())); diff --git a/examples/graphicsview/diagramscene/diagramscene.pro b/examples/graphicsview/diagramscene/diagramscene.pro index 2021e24..1782dac 100644 --- a/examples/graphicsview/diagramscene/diagramscene.pro +++ b/examples/graphicsview/diagramscene/diagramscene.pro @@ -19,4 +19,8 @@ sources.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/diagramscene INSTALLS += target sources symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) +maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri) +symbian: warning(This example might not fully work on Symbian platform) +maemo5: warning(This example might not fully work on Maemo platform) +simulator: warning(This example might not fully work on Simulator platform) diff --git a/examples/graphicsview/dragdroprobot/dragdroprobot.pro b/examples/graphicsview/dragdroprobot/dragdroprobot.pro index 3d100c0..25b03a5 100644 --- a/examples/graphicsview/dragdroprobot/dragdroprobot.pro +++ b/examples/graphicsview/dragdroprobot/dragdroprobot.pro @@ -18,3 +18,6 @@ sources.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/dragdroprobot INSTALLS += target sources symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) +maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri) + +simulator: warning(This example might not fully work on Simulator platform) diff --git a/examples/graphicsview/dragdroprobot/main.cpp b/examples/graphicsview/dragdroprobot/main.cpp index 315d2b6..c8b84ec 100644 --- a/examples/graphicsview/dragdroprobot/main.cpp +++ b/examples/graphicsview/dragdroprobot/main.cpp @@ -45,6 +45,22 @@ #include <math.h> +class GraphicsView : public QGraphicsView +{ +public: + GraphicsView(QGraphicsScene *scene) : QGraphicsView(scene) + { + } + +protected: + virtual void resizeEvent(QResizeEvent *event) + { +#if defined(Q_OS_SYMBIAN) + fitInView(sceneRect(), Qt::KeepAspectRatio); +#endif + } +}; + //! [0] int main(int argc, char **argv) { @@ -69,12 +85,16 @@ int main(int argc, char **argv) scene.addItem(robot); //! [1] //! [2] - QGraphicsView view(&scene); + GraphicsView view(&scene); view.setRenderHint(QPainter::Antialiasing); view.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); view.setBackgroundBrush(QColor(230, 200, 167)); view.setWindowTitle("Drag and Drop Robot"); - view.show(); +#if defined(Q_OS_SYMBIAN) + view.showMaximized(); +#else + view.show(); +#endif return app.exec(); } diff --git a/examples/graphicsview/elasticnodes/edge.cpp b/examples/graphicsview/elasticnodes/edge.cpp index 2b5cae5..652ab73 100644 --- a/examples/graphicsview/elasticnodes/edge.cpp +++ b/examples/graphicsview/elasticnodes/edge.cpp @@ -144,6 +144,6 @@ void Edge::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) painter->setBrush(Qt::black); painter->drawPolygon(QPolygonF() << line.p1() << sourceArrowP1 << sourceArrowP2); - painter->drawPolygon(QPolygonF() << line.p2() << destArrowP1 << destArrowP2); + painter->drawPolygon(QPolygonF() << line.p2() << destArrowP1 << destArrowP2); } //! [6] diff --git a/examples/graphicsview/elasticnodes/elasticnodes.pro b/examples/graphicsview/elasticnodes/elasticnodes.pro index c086461..69b5bb2 100644 --- a/examples/graphicsview/elasticnodes/elasticnodes.pro +++ b/examples/graphicsview/elasticnodes/elasticnodes.pro @@ -21,3 +21,6 @@ symbian { TARGET.UID3 = 0xA000A642 include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) } +maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri) + +simulator: warning(This example might not fully work on Simulator platform) diff --git a/examples/graphicsview/elasticnodes/graphwidget.cpp b/examples/graphicsview/elasticnodes/graphwidget.cpp index c875b65..f6bf05d 100644 --- a/examples/graphicsview/elasticnodes/graphwidget.cpp +++ b/examples/graphicsview/elasticnodes/graphwidget.cpp @@ -132,17 +132,14 @@ void GraphWidget::keyPressEvent(QKeyEvent *event) centerNode->moveBy(20, 0); break; case Qt::Key_Plus: - scaleView(qreal(1.2)); + zoomIn(); break; case Qt::Key_Minus: - scaleView(1 / qreal(1.2)); + zoomOut(); break; case Qt::Key_Space: case Qt::Key_Enter: - foreach (QGraphicsItem *item, scene()->items()) { - if (qgraphicsitem_cast<Node *>(item)) - item->setPos(-150 + qrand() % 300, -150 + qrand() % 300); - } + shuffle(); break; default: QGraphicsView::keyPressEvent(event); @@ -206,6 +203,7 @@ void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect) painter->setBrush(Qt::NoBrush); painter->drawRect(sceneRect); +#if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_MAEMO_5) // Text QRectF textRect(sceneRect.left() + 4, sceneRect.top() + 4, sceneRect.width() - 4, sceneRect.height() - 4); @@ -220,6 +218,7 @@ void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect) painter->drawText(textRect.translated(2, 2), message); painter->setPen(Qt::black); painter->drawText(textRect, message); +#endif } //! [6] @@ -233,3 +232,21 @@ void GraphWidget::scaleView(qreal scaleFactor) scale(scaleFactor, scaleFactor); } //! [7] + +void GraphWidget::shuffle() +{ + foreach (QGraphicsItem *item, scene()->items()) { + if (qgraphicsitem_cast<Node *>(item)) + item->setPos(-150 + qrand() % 300, -150 + qrand() % 300); + } +} + +void GraphWidget::zoomIn() +{ + scaleView(qreal(1.2)); +} + +void GraphWidget::zoomOut() +{ + scaleView(1 / qreal(1.2)); +} diff --git a/examples/graphicsview/elasticnodes/graphwidget.h b/examples/graphicsview/elasticnodes/graphwidget.h index 764bb3f..524ef67 100644 --- a/examples/graphicsview/elasticnodes/graphwidget.h +++ b/examples/graphicsview/elasticnodes/graphwidget.h @@ -55,6 +55,11 @@ public: void itemMoved(); +public slots: + void shuffle(); + void zoomIn(); + void zoomOut(); + protected: void keyPressEvent(QKeyEvent *event); void timerEvent(QTimerEvent *event); diff --git a/examples/graphicsview/elasticnodes/main.cpp b/examples/graphicsview/elasticnodes/main.cpp index ab7e7cf..d653da5 100644 --- a/examples/graphicsview/elasticnodes/main.cpp +++ b/examples/graphicsview/elasticnodes/main.cpp @@ -47,7 +47,18 @@ int main(int argc, char **argv) QApplication app(argc, argv); qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); - GraphWidget widget; - widget.show(); + GraphWidget *widget = new GraphWidget; + + QMainWindow mainWindow; + mainWindow.setCentralWidget(widget); + +#if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) + mainWindow.menuBar()->addAction("Shuffle", widget, SLOT(shuffle())); + mainWindow.menuBar()->addAction("Zoom In", widget, SLOT(zoomIn())); + mainWindow.menuBar()->addAction("Zoom Out", widget, SLOT(zoomOut())); + mainWindow.showMaximized(); +#else + mainWindow.show(); +#endif return app.exec(); } diff --git a/examples/graphicsview/elasticnodes/node.cpp b/examples/graphicsview/elasticnodes/node.cpp index 8d1dadd..b345f83 100644 --- a/examples/graphicsview/elasticnodes/node.cpp +++ b/examples/graphicsview/elasticnodes/node.cpp @@ -141,9 +141,16 @@ bool Node::advance() //! [8] QRectF Node::boundingRect() const { +#if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) + // Add some extra space around the circle for easier touching with finger + qreal adjust = 30; + return QRectF( -10 - adjust, -10 - adjust, + 20 + adjust * 2, 20 + adjust * 2); +#else qreal adjust = 2; - return QRectF(-10 - adjust, -10 - adjust, + return QRectF( -10 - adjust, -10 - adjust, 23 + adjust, 23 + adjust); +#endif } //! [8] @@ -151,7 +158,12 @@ QRectF Node::boundingRect() const QPainterPath Node::shape() const { QPainterPath path; +#if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) + // Add some extra space around the circle for easier touching with finger + path.addEllipse( -40, -40, 80, 80); +#else path.addEllipse(-10, -10, 20, 20); +#endif return path; } //! [9] @@ -174,6 +186,7 @@ void Node::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid gradient.setColorAt(1, Qt::darkYellow); } painter->setBrush(gradient); + painter->setPen(QPen(Qt::black, 0)); painter->drawEllipse(-10, -10, 20, 20); } diff --git a/examples/graphicsview/flowlayout/flowlayout.pro b/examples/graphicsview/flowlayout/flowlayout.pro index ce35367..8a97d2d 100644 --- a/examples/graphicsview/flowlayout/flowlayout.pro +++ b/examples/graphicsview/flowlayout/flowlayout.pro @@ -1,5 +1,4 @@ TEMPLATE = app -TARGET = DEPENDPATH += . INCLUDEPATH += . @@ -8,3 +7,7 @@ QMAKE_PROJECT_NAME = flowlayout_graphicsview # Input HEADERS += flowlayout.h window.h SOURCES += flowlayout.cpp main.cpp window.cpp + +symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) +maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri) +simulator: warning(This example might not fully work on Simulator platform) diff --git a/examples/graphicsview/flowlayout/main.cpp b/examples/graphicsview/flowlayout/main.cpp index cee08d7..cc5eeb6 100644 --- a/examples/graphicsview/flowlayout/main.cpp +++ b/examples/graphicsview/flowlayout/main.cpp @@ -49,7 +49,13 @@ int main(int argc, char **argv) QGraphicsView *view = new QGraphicsView(&scene); Window *w = new Window; scene.addItem(w); + +#if defined(Q_OS_SYMBIAN) + view->showMaximized(); +#else view->resize(400, 300); view->show(); +#endif + return app.exec(); } diff --git a/examples/graphicsview/graphicsview.pro b/examples/graphicsview/graphicsview.pro index 8f65d51..2aa68ec 100644 --- a/examples/graphicsview/graphicsview.pro +++ b/examples/graphicsview/graphicsview.pro @@ -22,4 +22,3 @@ sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS graphicsview.pro README sources.path = $$[QT_INSTALL_EXAMPLES]/graphicsview INSTALLS += target sources -symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) diff --git a/examples/graphicsview/padnavigator/main.cpp b/examples/graphicsview/padnavigator/main.cpp index 8f4a681..d7d2f56 100644 --- a/examples/graphicsview/padnavigator/main.cpp +++ b/examples/graphicsview/padnavigator/main.cpp @@ -49,8 +49,11 @@ int main(int argc, char *argv[]) Q_INIT_RESOURCE(padnavigator); PadNavigator navigator(QSize(3, 3)); +#if defined(Q_OS_SYMBIAN) + navigator.showMaximized(); +#else navigator.show(); - +#endif return app.exec(); } //! [0] diff --git a/examples/graphicsview/padnavigator/padnavigator.pro b/examples/graphicsview/padnavigator/padnavigator.pro index 93ea293..cf142bc 100644 --- a/examples/graphicsview/padnavigator/padnavigator.pro +++ b/examples/graphicsview/padnavigator/padnavigator.pro @@ -30,3 +30,6 @@ symbian { TARGET.UID3 = 0xA000A644 include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) } +maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri) + +simulator: warning(This example might not fully work on Simulator platform) diff --git a/examples/graphicsview/portedasteroids/animateditem.cpp b/examples/graphicsview/portedasteroids/animateditem.cpp index 489ef34..c36c141 100644 --- a/examples/graphicsview/portedasteroids/animateditem.cpp +++ b/examples/graphicsview/portedasteroids/animateditem.cpp @@ -40,12 +40,13 @@ #include "animateditem.h" -#include <QtGui/qbitmap.h> -#include <QtGui/qpainter.h> +#include <QtGui/QBitmap> +#include <QtGui/QPainter> +#include <QGraphicsScene> AnimatedPixmapItem::AnimatedPixmapItem(const QList<QPixmap> &animation, QGraphicsScene *scene) - : QGraphicsItem(0, scene), currentFrame(0), vx(0), vy(0) + : QGraphicsItem(0), currentFrame(0), vx(0), vy(0) { for (int i = 0; i < animation.size(); ++i) { QPixmap pixmap = animation.at(i); @@ -55,6 +56,8 @@ AnimatedPixmapItem::AnimatedPixmapItem(const QList<QPixmap> &animation, frame.boundingRect = pixmap.rect(); frames << frame; } + + scene->addItem(this); } void AnimatedPixmapItem::setFrame(int frame) @@ -63,6 +66,8 @@ void AnimatedPixmapItem::setFrame(int frame) prepareGeometryChange(); currentFrame = frame % frames.size(); } + + //scene->addItem(this); } void AnimatedPixmapItem::advance(int phase) diff --git a/examples/graphicsview/portedasteroids/animateditem.h b/examples/graphicsview/portedasteroids/animateditem.h index 712d70d..23117b4 100644 --- a/examples/graphicsview/portedasteroids/animateditem.h +++ b/examples/graphicsview/portedasteroids/animateditem.h @@ -49,18 +49,12 @@ public: AnimatedPixmapItem(const QList<QPixmap> &animation, QGraphicsScene *scene = 0); void setFrame(int frame); - inline int frame() const - { return currentFrame; } - inline int frameCount() const - { return frames.size(); } - inline QPixmap image(int frame) const - { return frames.isEmpty() ? QPixmap() : frames.at(frame % frames.size()).pixmap; } - inline void setVelocity(qreal xvel, qreal yvel) - { vx = xvel; vy = yvel; } - inline qreal xVelocity() const - { return vx; } - inline qreal yVelocity() const - { return vy; } + inline int frame() const { return currentFrame; } + inline int frameCount() const { return frames.size(); } + inline QPixmap image(int frame) const { return frames.isEmpty() ? QPixmap() : frames.at(frame % frames.size()).pixmap; } + inline void setVelocity(qreal xvel, qreal yvel) { vx = xvel; vy = yvel; } + inline qreal xVelocity() const { return vx; } + inline qreal yVelocity() const { return vy; } QRectF boundingRect() const; QPainterPath shape() const; diff --git a/examples/graphicsview/portedasteroids/ledmeter.cpp b/examples/graphicsview/portedasteroids/ledmeter.cpp index 9653fc6..aefe200 100644 --- a/examples/graphicsview/portedasteroids/ledmeter.cpp +++ b/examples/graphicsview/portedasteroids/ledmeter.cpp @@ -44,15 +44,14 @@ * Part of the KDE project */ -#include <qpainter.h> -//Added by qt3to4: +#include <QPainter> #include <QResizeEvent> -#include <Q3Frame> +#include <QFrame> +#include <QColorGroup> #include "ledmeter.h" -KALedMeter::KALedMeter( QWidget *parent ) : Q3Frame( parent ) +KALedMeter::KALedMeter( QWidget *parent ) : QFrame( parent ) { - mCRanges.setAutoDelete( TRUE ); mRange = 100; mCount = 20; mCurrentCount = 0; @@ -60,6 +59,13 @@ KALedMeter::KALedMeter( QWidget *parent ) : Q3Frame( parent ) setMinimumWidth( mCount * 2 + frameWidth() ); } +KALedMeter::~KALedMeter() +{ + qDeleteAll(mCRanges); + mCRanges.clear(); +} + + void KALedMeter::setRange( int r ) { mRange = r; @@ -106,27 +112,30 @@ void KALedMeter::addColorRange( int pc, const QColor &c ) void KALedMeter::resizeEvent( QResizeEvent *e ) { - Q3Frame::resizeEvent( e ); + QFrame::resizeEvent( e ); int w = ( width() - frameWidth() - 2 ) / mCount * mCount; w += frameWidth() + 2; setFrameRect( QRect( 0, 0, w, height() ) ); } -void KALedMeter::drawContents( QPainter *p ) +void KALedMeter::paintEvent(QPaintEvent *event) { + QFrame::paintEvent(event); + QRect b = contentsRect(); + QPainter p(this); unsigned cidx = 0; int ncol = mCount; - QColor col = colorGroup().foreground(); + QColor col = palette().foreground().color(); if ( !mCRanges.isEmpty() ) { col = mCRanges.at( cidx )->mColor; ncol = mCRanges.at( cidx )->mValue; } - p->setBrush( col ); - p->setPen( col ); + p.setBrush( col ); + p.setPen( col ); int lw = b.width() / mCount; int lx = b.left() + 1; @@ -138,21 +147,22 @@ void KALedMeter::drawContents( QPainter *p ) { col = mCRanges.at( cidx )->mColor; ncol = mCRanges.at( cidx )->mValue; - p->setBrush( col ); - p->setPen( col ); + p.setBrush( col ); + p.setPen( col ); } } - p->drawRect( lx, b.top() + 1, lw - 1, b.height() - 2 ); + p.drawRect( lx, b.top() + 1, lw - 1, b.height() - 2 ); } } void KALedMeter::calcColorRanges() { int prev = 0; - ColorRange *cr; - for ( cr = mCRanges.first(); cr; cr = mCRanges.next() ) + + for(QList<ColorRange*>::iterator it = mCRanges.begin(); it != mCRanges.end(); it++) { + ColorRange *cr = *it; cr->mValue = prev + cr->mPc * mCount / 100; prev = cr->mValue; } diff --git a/examples/graphicsview/portedasteroids/ledmeter.h b/examples/graphicsview/portedasteroids/ledmeter.h index 2d4ae23..0e3851f 100644 --- a/examples/graphicsview/portedasteroids/ledmeter.h +++ b/examples/graphicsview/portedasteroids/ledmeter.h @@ -47,17 +47,17 @@ #ifndef __LEDMETER_H__ #define __LEDMETER_H__ -#include <q3frame.h> -#include <q3ptrlist.h> -//Added by qt3to4: +#include <QFrame> +#include <QList> #include <QResizeEvent> -class KALedMeter : public Q3Frame +class KALedMeter : public QFrame { Q_OBJECT public: KALedMeter( QWidget *parent ); + ~KALedMeter(); int range() const { return mRange; } void setRange( int r ); @@ -74,7 +74,7 @@ public slots: protected: virtual void resizeEvent( QResizeEvent * ); - virtual void drawContents( QPainter * ); + virtual void paintEvent(QPaintEvent *event); void calcColorRanges(); protected: @@ -89,7 +89,7 @@ protected: int mCount; int mCurrentCount; int mValue; - Q3PtrList<ColorRange> mCRanges; + QList<ColorRange*> mCRanges; }; #endif diff --git a/examples/graphicsview/portedasteroids/main.cpp b/examples/graphicsview/portedasteroids/main.cpp index 4ed4e9f..e6c7623 100644 --- a/examples/graphicsview/portedasteroids/main.cpp +++ b/examples/graphicsview/portedasteroids/main.cpp @@ -52,7 +52,11 @@ int main(int argc, char **argv) KAstTopLevel topLevel; topLevel.setWindowTitle("Ported Asteroids Game"); +#if defined(Q_OS_SYMBIAN) + topLevel.showFullScreen(); +#else topLevel.show(); +#endif app.setQuitOnLastWindowClosed(true); return app.exec(); diff --git a/examples/graphicsview/portedasteroids/portedasteroids.pro b/examples/graphicsview/portedasteroids/portedasteroids.pro index b28ab54..98ec4fe 100644 --- a/examples/graphicsview/portedasteroids/portedasteroids.pro +++ b/examples/graphicsview/portedasteroids/portedasteroids.pro @@ -2,13 +2,8 @@ TEMPLATE = app INCLUDEPATH += . # Input -HEADERS += ledmeter.h sprites.h toplevel.h view.h -SOURCES += ledmeter.cpp main.cpp toplevel.cpp view.cpp -#The following line was inserted by qt3to4 -QT += qt3support - -HEADERS += animateditem.h -SOURCES += animateditem.cpp +HEADERS += ledmeter.h sprites.h toplevel.h view.h animateditem.h +SOURCES += ledmeter.cpp main.cpp toplevel.cpp view.cpp animateditem.cpp RESOURCES += portedasteroids.qrc @@ -16,6 +11,10 @@ RESOURCES += portedasteroids.qrc target.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/portedasteroids sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS portedasteroids.pro bg.png sounds sprites sources.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/portedasteroids + INSTALLS += target sources symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) +maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri) + +simulator: warning(This example might not fully work on Simulator platform) diff --git a/examples/graphicsview/portedasteroids/sprites.h b/examples/graphicsview/portedasteroids/sprites.h index e5f1dbb..7275cba 100644 --- a/examples/graphicsview/portedasteroids/sprites.h +++ b/examples/graphicsview/portedasteroids/sprites.h @@ -144,7 +144,7 @@ public: { if (cskip-- <= 0) { setFrame( (frame()+step+frameCount())%frameCount() ); - cskip = QABS(skip); + cskip = qAbs(skip); } } diff --git a/examples/graphicsview/portedasteroids/toplevel.cpp b/examples/graphicsview/portedasteroids/toplevel.cpp index 367f8c6..6aa63c3 100644 --- a/examples/graphicsview/portedasteroids/toplevel.cpp +++ b/examples/graphicsview/portedasteroids/toplevel.cpp @@ -44,21 +44,20 @@ * Part of the KDE project */ // --- toplevel.cpp --- -#include <q3accel.h> -#include <qlabel.h> -#include <qlayout.h> -#include <qlcdnumber.h> -#include <qpushbutton.h> - -#include <qapplication.h> -//Added by qt3to4: -#include <Q3HBoxLayout> +#include <QAction> +#include <QLabel> +#include <QLayout> +#include <QLCDNumber> +#include <QPushButton> + +#include <QApplication> +#include <QHBoxLayout> #include <QShowEvent> -#include <Q3Frame> +#include <QFrame> #include <QPixmap> #include <QHideEvent> #include <QKeyEvent> -#include <Q3VBoxLayout> +#include <QVBoxLayout> #include "toplevel.h" #include "ledmeter.h" @@ -110,18 +109,28 @@ const char *soundDefaults[] = }; -KAstTopLevel::KAstTopLevel( QWidget *parent, const char *name ) - : Q3MainWindow( parent, name, 0 ) +KAstTopLevel::KAstTopLevel( QWidget *parent) + : QMainWindow(parent) { QWidget *border = new QWidget( this ); - border->setBackgroundColor( Qt::black ); + + QPalette palette; + palette.setColor(border->backgroundRole(), Qt::black); + border->setPalette(palette); + setCentralWidget( border ); - Q3VBoxLayout *borderLayout = new Q3VBoxLayout( border ); + QVBoxLayout *borderLayout = new QVBoxLayout( border ); borderLayout->addStretch( 1 ); QWidget *mainWin = new QWidget( border ); +#if defined(Q_WS_MAEMO_5) + mainWin->setFixedSize(800, 430); +#elif defined(Q_OS_SYMBIAN) + mainWin->setFixedSize(640, 340); +#else mainWin->setFixedSize(640, 480); +#endif borderLayout->addWidget( mainWin, 0, Qt::AlignHCenter ); borderLayout->addStretch( 1 ); @@ -133,15 +142,18 @@ KAstTopLevel::KAstTopLevel( QWidget *parent, const char *name ) connect( view, SIGNAL(rocksRemoved()), SLOT(slotRocksRemoved()) ); connect( view, SIGNAL(updateVitals()), SLOT(slotUpdateVitals()) ); - Q3VBoxLayout *vb = new Q3VBoxLayout( mainWin ); - Q3HBoxLayout *hb = new Q3HBoxLayout; - Q3HBoxLayout *hbd = new Q3HBoxLayout; + QVBoxLayout *vb = new QVBoxLayout( mainWin ); + QHBoxLayout *hb = new QHBoxLayout; + QHBoxLayout *hbd = new QHBoxLayout; vb->addLayout( hb ); +#if defined(Q_OS_SYMBIAN) + QFont labelFont( "helvetica", 8 ); +#else QFont labelFont( "helvetica", 24 ); - QColorGroup grp( Qt::darkGreen, Qt::black, QColor( 128, 128, 128 ), - QColor( 64, 64, 64 ), Qt::black, Qt::darkGreen, Qt::black ); - QPalette pal( grp, grp, grp ); +#endif + + QPalette pal(Qt::darkGreen, Qt::black, QColor( 128, 128, 128 ), QColor( 64, 64, 64 ), Qt::black, Qt::darkGreen, Qt::black); mainWin->setPalette( pal ); @@ -155,7 +167,7 @@ KAstTopLevel::KAstTopLevel( QWidget *parent, const char *name ) hb->addWidget( label ); scoreLCD = new QLCDNumber( 6, mainWin ); - scoreLCD->setFrameStyle( Q3Frame::NoFrame ); + scoreLCD->setFrameStyle( QFrame::NoFrame ); scoreLCD->setSegmentStyle( QLCDNumber::Flat ); scoreLCD->setFixedWidth( 150 ); scoreLCD->setPalette( pal ); @@ -169,7 +181,7 @@ KAstTopLevel::KAstTopLevel( QWidget *parent, const char *name ) hb->addWidget( label ); levelLCD = new QLCDNumber( 2, mainWin ); - levelLCD->setFrameStyle( Q3Frame::NoFrame ); + levelLCD->setFrameStyle( QFrame::NoFrame ); levelLCD->setSegmentStyle( QLCDNumber::Flat ); levelLCD->setFixedWidth( 70 ); levelLCD->setPalette( pal ); @@ -183,7 +195,7 @@ KAstTopLevel::KAstTopLevel( QWidget *parent, const char *name ) hb->addWidget( label ); shipsLCD = new QLCDNumber( 1, mainWin ); - shipsLCD->setFrameStyle( Q3Frame::NoFrame ); + shipsLCD->setFrameStyle( QFrame::NoFrame ); shipsLCD->setSegmentStyle( QLCDNumber::Flat ); shipsLCD->setFixedWidth( 40 ); shipsLCD->setPalette( pal ); @@ -196,7 +208,11 @@ KAstTopLevel::KAstTopLevel( QWidget *parent, const char *name ) // -- bottom layout: vb->addLayout( hbd ); +#if defined(Q_OS_SYMBIAN) + QFont smallFont( "helvetica", 6 ); +#else QFont smallFont( "helvetica", 14 ); +#endif hbd->addSpacing( 10 ); QString sprites_prefix = ":/trolltech/examples/graphicsview/portedasteroids/sprites/"; @@ -224,7 +240,7 @@ KAstTopLevel::KAstTopLevel( QWidget *parent, const char *name ) hbd->addWidget( label ); brakesLCD = new QLCDNumber( 1, mainWin ); - brakesLCD->setFrameStyle( Q3Frame::NoFrame ); + brakesLCD->setFrameStyle( QFrame::NoFrame ); brakesLCD->setSegmentStyle( QLCDNumber::Flat ); brakesLCD->setPalette( pal ); brakesLCD->setFixedHeight( 20 ); @@ -240,7 +256,7 @@ KAstTopLevel::KAstTopLevel( QWidget *parent, const char *name ) hbd->addWidget( label ); shieldLCD = new QLCDNumber( 1, mainWin ); - shieldLCD->setFrameStyle( Q3Frame::NoFrame ); + shieldLCD->setFrameStyle( QFrame::NoFrame ); shieldLCD->setSegmentStyle( QLCDNumber::Flat ); shieldLCD->setPalette( pal ); shieldLCD->setFixedHeight( 20 ); @@ -256,7 +272,7 @@ KAstTopLevel::KAstTopLevel( QWidget *parent, const char *name ) hbd->addWidget( label ); shootLCD = new QLCDNumber( 1, mainWin ); - shootLCD->setFrameStyle( Q3Frame::NoFrame ); + shootLCD->setFrameStyle( QFrame::NoFrame ); shootLCD->setSegmentStyle( QLCDNumber::Flat ); shootLCD->setPalette( pal ); shootLCD->setFixedHeight( 20 ); @@ -271,7 +287,7 @@ KAstTopLevel::KAstTopLevel( QWidget *parent, const char *name ) hbd->addWidget( label ); powerMeter = new KALedMeter( mainWin ); - powerMeter->setFrameStyle( Q3Frame::Box | Q3Frame::Plain ); + powerMeter->setFrameStyle( QFrame::Box | QFrame::Plain ); powerMeter->setRange( MAX_POWER_LEVEL ); powerMeter->addColorRange( 10, Qt::darkRed ); powerMeter->addColorRange( 20, QColor(160, 96, 0) ); @@ -295,6 +311,15 @@ KAstTopLevel::KAstTopLevel( QWidget *parent, const char *name ) actions.insert( Qt::Key_L, Launch ); actions.insert( Qt::Key_N, NewGame ); +#if defined(Q_OS_SYMBIAN) + actions.insert( 122, Teleport ); + actions.insert( 120, Brake ); + actions.insert( 115, Shield ); + actions.insert( 112, Pause ); + actions.insert( 108, Launch ); + actions.insert( 110, NewGame ); +#endif + view->showText( tr( "Press N to start playing" ), Qt::yellow ); } @@ -431,14 +456,14 @@ void KAstTopLevel::keyReleaseEvent( QKeyEvent *event ) void KAstTopLevel::showEvent( QShowEvent *e ) { - Q3MainWindow::showEvent( e ); + QMainWindow::showEvent( e ); view->pause( FALSE ); view->setFocus(); } void KAstTopLevel::hideEvent( QHideEvent *e ) { - Q3MainWindow::hideEvent( e ); + QMainWindow::hideEvent( e ); view->pause( TRUE ); } diff --git a/examples/graphicsview/portedasteroids/toplevel.h b/examples/graphicsview/portedasteroids/toplevel.h index 767580e..36b3afc 100644 --- a/examples/graphicsview/portedasteroids/toplevel.h +++ b/examples/graphicsview/portedasteroids/toplevel.h @@ -47,10 +47,9 @@ #ifndef __KAST_TOPLEVEL_H__ #define __KAST_TOPLEVEL_H__ -#include <q3mainwindow.h> -#include <q3dict.h> -#include <qmap.h> -//Added by qt3to4: +#include <QMainWindow> +#include <QMultiHash> +#include <QMap> #include <QShowEvent> #include <QHideEvent> #include <QKeyEvent> @@ -63,11 +62,11 @@ QT_BEGIN_NAMESPACE class QLCDNumber; QT_END_NAMESPACE -class KAstTopLevel : public Q3MainWindow +class KAstTopLevel : public QMainWindow { Q_OBJECT public: - KAstTopLevel( QWidget *parent=0, const char *name=0 ); + KAstTopLevel( QWidget *parent = 0); virtual ~KAstTopLevel(); private: @@ -104,7 +103,7 @@ private: KALedMeter *powerMeter; bool sound; - Q3Dict<QString> soundDict; + //Q3Dict<QString> soundDict; // waiting for user to press Enter to launch a ship bool waitShip; @@ -118,7 +117,7 @@ private: enum Action { Launch, Thrust, RotateLeft, RotateRight, Shoot, Teleport, Brake, Shield, Pause, NewGame }; - QMap<int,Action> actions; + QMap<int, Action> actions; }; #endif diff --git a/examples/graphicsview/portedasteroids/view.cpp b/examples/graphicsview/portedasteroids/view.cpp index 9429111..e4f46c8 100644 --- a/examples/graphicsview/portedasteroids/view.cpp +++ b/examples/graphicsview/portedasteroids/view.cpp @@ -48,16 +48,16 @@ #include <math.h> #include <qapplication.h> #include <qnamespace.h> -#include <q3accel.h> -#include <qmessagebox.h> -#include <q3scrollview.h> -#include <qdir.h> +#include <QAction> +#include <QMessageBox> +#include <QScrollArea> +#include <QDir> #include <QGraphicsItem> -//Added by qt3to4: #include <QTimerEvent> #include <QPixmap> #include <QResizeEvent> #include <QShowEvent> +#include <QtDebug> #include "view.h" @@ -110,10 +110,10 @@ kas_animations [] = { 0, 0, 0 } }; -KAsteroidsView::KAsteroidsView( QWidget *parent, const char *name ) - : QWidget( parent, name ), +KAsteroidsView::KAsteroidsView( QWidget *parent) + : QWidget( parent), field(0, 0, 640, 440), - view(&field,this) + view(&field, this) { view.setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); view.setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); @@ -123,11 +123,6 @@ KAsteroidsView::KAsteroidsView( QWidget *parent, const char *name ) | QGraphicsView::DontSavePainterState | QGraphicsView::DontAdjustForAntialiasing); view.viewport()->setFocusProxy( this ); - rocks.setAutoDelete( TRUE ); - missiles.setAutoDelete( TRUE ); - bits.setAutoDelete( TRUE ); - powerups.setAutoDelete( TRUE ); - exhaust.setAutoDelete( TRUE ); QPixmap pm( IMG_BACKGROUND ); field.setBackgroundBrush( pm ); @@ -164,6 +159,11 @@ KAsteroidsView::KAsteroidsView( QWidget *parent, const char *name ) KAsteroidsView::~KAsteroidsView() { + qDeleteAll(rocks); rocks.clear(); + qDeleteAll(missiles); missiles.clear(); + qDeleteAll(bits); bits.clear(); + qDeleteAll(powerups); powerups.clear(); + qDeleteAll(exhaust); exhaust.clear(); } // - - - @@ -172,11 +172,11 @@ void KAsteroidsView::reset() { if ( !initialized ) return; - rocks.clear(); - missiles.clear(); - bits.clear(); - powerups.clear(); - exhaust.clear(); + qDeleteAll(rocks); rocks.clear(); + qDeleteAll(missiles); missiles.clear(); + qDeleteAll(bits); bits.clear(); + qDeleteAll(powerups); powerups.clear(); + qDeleteAll(exhaust); exhaust.clear(); shotsFired = 0; shotsHit = 0; @@ -217,6 +217,11 @@ void KAsteroidsView::newGame() void KAsteroidsView::endGame() { + qDeleteAll(rocks); rocks.clear(); + qDeleteAll(missiles); missiles.clear(); + qDeleteAll(bits); bits.clear(); + qDeleteAll(powerups); powerups.clear(); + qDeleteAll(exhaust); exhaust.clear(); } void KAsteroidsView::pause( bool p ) @@ -266,7 +271,7 @@ void KAsteroidsView::newShip() ship->show(); shield->show(); mShieldCount = 1; // just in case the ship appears on a rock. - shieldTimer->start( 1000, TRUE ); + shieldTimer->start(1000); } void KAsteroidsView::setShield( bool s ) @@ -410,11 +415,9 @@ void KAsteroidsView::timerEvent( QTimerEvent * ) { field.advance(); - AnimatedPixmapItem *rock; - // move rocks forward - for ( rock = rocks.first(); rock; rock = rocks.next() ) { - ((KRock *)rock)->nextFrame(); + foreach(AnimatedPixmapItem *rock, rocks) { + ((KRock *)rock)->nextFrame(); wrapSprite( rock ); } @@ -424,21 +427,24 @@ void KAsteroidsView::timerEvent( QTimerEvent * ) processMissiles(); // these are generated when a ship explodes - for ( KBit *bit = bits.first(); bit; bit = bits.next() ) + for(QList<KBit*>::iterator it = bits.begin(); it != bits.end(); it++) { - if ( bit->expired() ) + KBit *bit = *it; + if( bit->expired() ) { - bits.removeRef( bit ); + delete bit; + it = bits.erase(it); + break; } else { - bit->growOlder(); - bit->setFrame( ( bit->frame()+1 ) % bit->frameCount() ); + bit->growOlder(); + bit->setFrame( ( bit->frame()+1 ) % bit->frameCount() ); } } - for ( KExhaust *e = exhaust.first(); e; e = exhaust.next() ) - exhaust.removeRef( e ); + qDeleteAll(exhaust); + exhaust.clear(); // move / rotate ship. // check for collision with a rock. @@ -570,7 +576,16 @@ void KAsteroidsView::rockHit( AnimatedPixmapItem *hit ) } else if ( hit->type() == ID_ROCK_SMALL ) emit rockHit( 2 ); - rocks.removeRef( hit ); + + for(QList<AnimatedPixmapItem*>::iterator it = rocks.begin(); it != rocks.end(); it++) + { + if((*it) == hit) { + delete *it; + it = rocks.erase(it); + break; + } + } + if ( rocks.count() == 0 ) emit rocksRemoved(); } @@ -605,38 +620,43 @@ void KAsteroidsView::addExhaust( double x, double y, double dx, void KAsteroidsView::processMissiles() { - KMissile *missile; - // if a missile has hit a rock, remove missile and break rock into smaller // rocks or remove completely. - Q3PtrListIterator<KMissile> it(missiles); - - for ( ; it.current(); ++it ) + QList<KMissile*>::iterator itMissile = missiles.begin(); + while(itMissile != missiles.end()) { - missile = it.current(); - missile->growOlder(); + (*itMissile)->growOlder(); - if ( missile->expired() ) + if ( (*itMissile)->expired() ) { - missiles.removeRef( missile ); - continue; + delete (*itMissile); + itMissile = missiles.erase(itMissile); + continue; } - wrapSprite( missile ); + wrapSprite(*itMissile); - QList<QGraphicsItem *> hits = missile->collidingItems(Qt::IntersectsItemBoundingRect); - QList<QGraphicsItem *>::Iterator hit; - for ( hit = hits.begin(); hit != hits.end(); ++hit ) + bool missileErased = false; + QList<QGraphicsItem*> hits = (*itMissile)->collidingItems(Qt::IntersectsItemBoundingRect); + QList<QGraphicsItem*>::iterator itHit = hits.begin(); + + while (itHit != hits.end()) { - if ( (*hit)->type() >= ID_ROCK_LARGE && - (*hit)->type() <= ID_ROCK_SMALL && (*hit)->collidesWithItem(missile) ) + if ( (*itHit)->type() >= ID_ROCK_LARGE && + (*itHit)->type() <= ID_ROCK_SMALL && (*itHit)->collidesWithItem(*itMissile) ) { shotsHit++; - rockHit( static_cast<AnimatedPixmapItem *>(*hit) ); - missiles.removeRef( missile ); + rockHit( static_cast<AnimatedPixmapItem *>(*itHit) ); + delete *itMissile; + itMissile = missiles.erase(itMissile); + missileErased = true; break; } + itHit++; } + + if(!missileErased) + itMissile++; } } @@ -712,7 +732,7 @@ void KAsteroidsView::processShip() bit->setVelocity( 1-randDouble()*2, 1-randDouble()*2 ); bit->setDeath( 60 + randInt(60) ); - bits.append( bit ); + bits.push_back( bit ); } ship->hide(); shield->hide(); @@ -820,15 +840,15 @@ void KAsteroidsView::processShip() if ( shootShip ) { - if ( !shootDelay && (int)missiles.count() < mShootCount + 2 ) + if ( !shootDelay && (int)missiles.size() < mShootCount + 2 ) { - KMissile *missile = new KMissile( animation[ID_MISSILE], &field ); + KMissile *missile = new KMissile( animation[ID_MISSILE], &field ); missile->setPos( 21+ship->x()+cosangle*21, 21+ship->y()+sinangle*21 ); missile->setFrame( 0 ); missile->setVelocity( shipDx + cosangle*MISSILE_SPEED, shipDy + sinangle*MISSILE_SPEED ); - missiles.append( missile ); + missiles.push_back( missile ); shotsFired++; reducePower( 1 ); @@ -857,75 +877,83 @@ void KAsteroidsView::processShip() void KAsteroidsView::processPowerups() { - if ( !powerups.isEmpty() ) - { - // if player gets the powerup remove it from the screen, if option - // "Can destroy powerups" is enabled and a missile hits the powerup - // destroy it - - KPowerup *pup; - Q3PtrListIterator<KPowerup> it( powerups ); - - for( ; it.current(); ++it ) - { - pup = it.current(); - pup->growOlder(); - - if( pup->expired() ) - { - powerups.removeRef( pup ); - continue; - } - - wrapSprite( pup ); - - QList<QGraphicsItem *> hits = pup->collidingItems(); - QList<QGraphicsItem *>::Iterator it; - for ( it = hits.begin(); it != hits.end(); ++it ) - { - if ( (*it) == ship ) - { - switch( pup->type() ) - { - case ID_ENERGY_POWERUP: - shipPower += 150; - if ( shipPower > MAX_POWER_LEVEL ) - shipPower = MAX_POWER_LEVEL; - break; - case ID_TELEPORT_POWERUP: - mTeleportCount++; - break; - case ID_BRAKE_POWERUP: - if ( mBrakeCount < MAX_BRAKES ) - mBrakeCount++; - break; - case ID_SHIELD_POWERUP: - if ( mShieldCount < MAX_SHIELDS ) - mShieldCount++; - break; - case ID_SHOOT_POWERUP: - if ( mShootCount < MAX_FIREPOWER ) - mShootCount++; - break; - } + // if player gets the powerup remove it from the screen, if option + // "Can destroy powerups" is enabled and a missile hits the powerup + // destroy it + QList<KPowerup*>::iterator itPup = powerups.begin(); - powerups.removeRef( pup ); - vitalsChanged = TRUE; - } - else if ( (*it) == shield ) - { - powerups.removeRef( pup ); - } - else if ( (*it)->type() == ID_MISSILE ) - { - if ( can_destroy_powerups ) - { - powerups.removeRef( pup ); - } - } - } - } - } // -- if( powerups.isEmpty() ) + while(itPup != powerups.end()) + { + (*itPup)->growOlder(); + + if((*itPup)->expired()) + { + delete *itPup; + itPup = powerups.erase(itPup); + continue; + } + + wrapSprite(*itPup); + + bool pupErased = false; + + QList<QGraphicsItem *> hits = (*itPup)->collidingItems(); + for(QList<QGraphicsItem *>::Iterator itHits = hits.begin(); itHits != hits.end(); itHits++) + { + if ( (*itHits) == ship ) + { + switch( (*itPup)->type() ) + { + case ID_ENERGY_POWERUP: + shipPower += 150; + if ( shipPower > MAX_POWER_LEVEL ) + shipPower = MAX_POWER_LEVEL; + break; + case ID_TELEPORT_POWERUP: + mTeleportCount++; + break; + case ID_BRAKE_POWERUP: + if ( mBrakeCount < MAX_BRAKES ) + mBrakeCount++; + break; + case ID_SHIELD_POWERUP: + if ( mShieldCount < MAX_SHIELDS ) + mShieldCount++; + break; + case ID_SHOOT_POWERUP: + if ( mShootCount < MAX_FIREPOWER ) + mShootCount++; + break; + } + + delete *itPup; + itPup = powerups.erase(itPup); + pupErased = true; + vitalsChanged = TRUE; + break; + } + else if((*itHits) == shield ) + { + delete *itPup; + itPup = powerups.erase(itPup); + pupErased = true; + break; + } + else if ( (*itHits)->type() == ID_MISSILE ) + { + if ( can_destroy_powerups ) + { + delete *itPup; + itPup = powerups.erase(itPup); + pupErased = true; + break; + } + } + } + + if(!pupErased) + itPup++; + } } // - - - diff --git a/examples/graphicsview/portedasteroids/view.h b/examples/graphicsview/portedasteroids/view.h index eeb7e2b..31ae3a0 100644 --- a/examples/graphicsview/portedasteroids/view.h +++ b/examples/graphicsview/portedasteroids/view.h @@ -47,13 +47,12 @@ #ifndef __AST_VIEW_H__ #define __AST_VIEW_H__ -#include <qwidget.h> -#include <q3ptrlist.h> -#include <q3intdict.h> -#include <qtimer.h> +#include <QWidget> +#include <QList> +#include <QMultiHash> +#include <QTimer> #include <QGraphicsScene> #include <QGraphicsView> -//Added by qt3to4: #include <QTimerEvent> #include <QShowEvent> #include <QResizeEvent> @@ -65,7 +64,7 @@ class KAsteroidsView : public QWidget { Q_OBJECT public: - KAsteroidsView( QWidget *parent = 0, const char *name = 0 ); + KAsteroidsView( QWidget *parent = 0); virtual ~KAsteroidsView(); int refreshRate; @@ -129,11 +128,11 @@ private: QGraphicsScene field; QGraphicsView view; QMap<int, QList<QPixmap> > animation; - Q3PtrList<AnimatedPixmapItem> rocks; - Q3PtrList<KMissile> missiles; - Q3PtrList<KBit> bits; - Q3PtrList<KExhaust> exhaust; - Q3PtrList<KPowerup> powerups; + QList<AnimatedPixmapItem*> rocks; + QList<KMissile*> missiles; + QList<KBit*> bits; + QList<KExhaust*> exhaust; + QList<KPowerup*> powerups; KShield *shield; AnimatedPixmapItem *ship; QGraphicsTextItem *textSprite; diff --git a/examples/graphicsview/portedcanvas/canvas.cpp b/examples/graphicsview/portedcanvas/canvas.cpp index 7937762..efcfcc5 100644 --- a/examples/graphicsview/portedcanvas/canvas.cpp +++ b/examples/graphicsview/portedcanvas/canvas.cpp @@ -38,27 +38,24 @@ ** ****************************************************************************/ -#include <qdatetime.h> -#include <qmainwindow.h> -#include <qstatusbar.h> -#include <qmessagebox.h> -#include <qmenubar.h> -#include <qapplication.h> -#include <qpainter.h> -#include <qprinter.h> -#include <qlabel.h> -#include <qimage.h> -#include <q3progressdialog.h> -#include <Q3PointArray> -#include <Q3PtrList> +#include <QDateTime> +#include <QMainWindow> +#include <QStatusBar> +#include <QMessageBox> +#include <QMenuBar> +#include <QApplication> +#include <QPainter> +#include <QPrinter> +#include <QPrintDialog> +#include <QLabel> +#include <QImage> +#include <QProgressDialog> #include <QPixmap> -#include <Q3PopupMenu> #include <QMouseEvent> -#include <Q3MemArray> -#include "canvas.h" #include <QStyleOptionGraphicsItem> -#include <qdebug.h> -#include <stdlib.h> +#include <QDebug> + +#include "canvas.h" // We use a global variable to save memory - all the brushes and pens in // the mesh are shared. @@ -79,14 +76,11 @@ private: static int c; }; -static const int imageRTTI = 984376; - class ImageItem: public QGraphicsRectItem { public: ImageItem( QImage img ); - int rtti () const { return imageRTTI; } protected: void paint( QPainter *, const QStyleOptionGraphicsItem *option, QWidget *widget ); private: @@ -101,7 +95,7 @@ ImageItem::ImageItem( QImage img ) setRect(0, 0, image.width(), image.height()); setFlag(ItemIsMovable); #if !defined(Q_WS_QWS) - pixmap.convertFromImage(image, Qt::OrderedAlphaDither); + pixmap.fromImage(image, Qt::OrderedAlphaDither); #endif } @@ -131,8 +125,8 @@ protected: // QPoint center() { return boundingRect().center(); } private: - Q3PtrList<EdgeItem> inList; - Q3PtrList<EdgeItem> outList; + QList<EdgeItem*> inList; + QList<EdgeItem*> outList; }; @@ -163,15 +157,12 @@ void EdgeItem::setToPoint( int x, int y ) QVariant NodeItem::itemChange(GraphicsItemChange change, const QVariant &value) { if (change == ItemPositionHasChanged) { - Q3PtrListIterator<EdgeItem> it1( inList ); EdgeItem *edge; - while (( edge = it1.current() )) { - ++it1; + foreach(edge, inList) { edge->setToPoint( int(x()), int(y()) ); } - Q3PtrListIterator<EdgeItem> it2( outList ); - while (( edge = it2.current() )) { - ++it2; + + foreach(edge, outList) { edge->setFromPoint( int(x()), int(y()) ); } } @@ -311,63 +302,65 @@ static uint mainCount = 0; static QImage *butterflyimg; static QImage *logoimg; -Main::Main(QGraphicsScene& c, QWidget* parent, const char* name, Qt::WindowFlags f) : - Q3MainWindow(parent,name,f), +Main::Main(QGraphicsScene& c, QWidget* parent, Qt::WindowFlags f) : + QMainWindow(parent, f), canvas(c) { editor = new FigureEditor(canvas,this); + QMenuBar* menu = menuBar(); - Q3PopupMenu* file = new Q3PopupMenu( menu ); - file->insertItem("&Fill canvas", this, SLOT(init()), Qt::CTRL+Qt::Key_F); - file->insertItem("&Erase canvas", this, SLOT(clear()), Qt::CTRL+Qt::Key_E); - file->insertItem("&New view", this, SLOT(newView()), Qt::CTRL+Qt::Key_N); - file->insertSeparator(); - file->insertItem("&Print...", this, SLOT(print()), Qt::CTRL+Qt::Key_P); - file->insertSeparator(); - file->insertItem("E&xit", qApp, SLOT(quit()), Qt::CTRL+Qt::Key_Q); - menu->insertItem("&File", file); - - Q3PopupMenu* edit = new Q3PopupMenu( menu ); - edit->insertItem("Add &Circle", this, SLOT(addCircle()), Qt::ALT+Qt::Key_C); - edit->insertItem("Add &Hexagon", this, SLOT(addHexagon()), Qt::ALT+Qt::Key_H); - edit->insertItem("Add &Polygon", this, SLOT(addPolygon()), Qt::ALT+Qt::Key_P); - edit->insertItem("Add Spl&ine", this, SLOT(addSpline()), Qt::ALT+Qt::Key_I); - edit->insertItem("Add &Text", this, SLOT(addText()), Qt::ALT+Qt::Key_T); - edit->insertItem("Add &Line", this, SLOT(addLine()), Qt::ALT+Qt::Key_L); - edit->insertItem("Add &Rectangle", this, SLOT(addRectangle()), Qt::ALT+Qt::Key_R); - edit->insertItem("Add &Sprite", this, SLOT(addSprite()), Qt::ALT+Qt::Key_S); - edit->insertItem("Create &Mesh", this, SLOT(addMesh()), Qt::ALT+Qt::Key_M ); - edit->insertItem("Add &Alpha-blended image", this, SLOT(addButterfly()), Qt::ALT+Qt::Key_A); - menu->insertItem("&Edit", edit); - - Q3PopupMenu* view = new Q3PopupMenu( menu ); - view->insertItem("&Enlarge", this, SLOT(enlarge()), Qt::SHIFT+Qt::CTRL+Qt::Key_Plus); - view->insertItem("Shr&ink", this, SLOT(shrink()), Qt::SHIFT+Qt::CTRL+Qt::Key_Minus); - view->insertSeparator(); - view->insertItem("&Rotate clockwise", this, SLOT(rotateClockwise()), Qt::CTRL+Qt::Key_PageDown); - view->insertItem("Rotate &counterclockwise", this, SLOT(rotateCounterClockwise()), Qt::CTRL+Qt::Key_PageUp); - view->insertItem("&Zoom in", this, SLOT(zoomIn()), Qt::CTRL+Qt::Key_Plus); - view->insertItem("Zoom &out", this, SLOT(zoomOut()), Qt::CTRL+Qt::Key_Minus); - view->insertItem("Translate left", this, SLOT(moveL()), Qt::CTRL+Qt::Key_Left); - view->insertItem("Translate right", this, SLOT(moveR()), Qt::CTRL+Qt::Key_Right); - view->insertItem("Translate up", this, SLOT(moveU()), Qt::CTRL+Qt::Key_Up); - view->insertItem("Translate down", this, SLOT(moveD()), Qt::CTRL+Qt::Key_Down); - view->insertItem("&Mirror", this, SLOT(mirror()), Qt::CTRL+Qt::Key_Home); - menu->insertItem("&View", view); - - menu->insertSeparator(); - - Q3PopupMenu* help = new Q3PopupMenu( menu ); - help->insertItem("&About", this, SLOT(help()), Qt::Key_F1); - help->setItemChecked(dbf_id, TRUE); - menu->insertItem("&Help",help); + QMenu* file = new QMenu("&File", menu ); + file->addAction("&Fill canvas", this, SLOT(init()), Qt::CTRL+Qt::Key_F); + file->addAction("&Erase canvas", this, SLOT(clear()), Qt::CTRL+Qt::Key_E); + file->addAction("&New view", this, SLOT(newView()), Qt::CTRL+Qt::Key_N); + file->addSeparator(); + file->addAction("&Print...", this, SLOT(print()), Qt::CTRL+Qt::Key_P); + file->addSeparator(); + file->addAction("E&xit", qApp, SLOT(quit()), Qt::CTRL+Qt::Key_Q); + menu->addMenu(file); + + QMenu* edit = new QMenu("&Edit", menu ); + edit->addAction("Add &Circle", this, SLOT(addCircle()), Qt::ALT+Qt::Key_C); + edit->addAction("Add &Hexagon", this, SLOT(addHexagon()), Qt::ALT+Qt::Key_H); + edit->addAction("Add &Polygon", this, SLOT(addPolygon()), Qt::ALT+Qt::Key_P); + edit->addAction("Add Spl&ine", this, SLOT(addSpline()), Qt::ALT+Qt::Key_I); + edit->addAction("Add &Text", this, SLOT(addText()), Qt::ALT+Qt::Key_T); + edit->addAction("Add &Line", this, SLOT(addLine()), Qt::ALT+Qt::Key_L); + edit->addAction("Add &Rectangle", this, SLOT(addRectangle()), Qt::ALT+Qt::Key_R); + edit->addAction("Add &Sprite", this, SLOT(addSprite()), Qt::ALT+Qt::Key_S); + edit->addAction("Create &Mesh", this, SLOT(addMesh()), Qt::ALT+Qt::Key_M ); + edit->addAction("Add &Alpha-blended image", this, SLOT(addButterfly()), Qt::ALT+Qt::Key_A); + menu->addMenu(edit); + + QMenu* view = new QMenu("&View", menu ); + view->addAction("&Enlarge", this, SLOT(enlarge()), Qt::SHIFT+Qt::CTRL+Qt::Key_Plus); + view->addAction("Shr&ink", this, SLOT(shrink()), Qt::SHIFT+Qt::CTRL+Qt::Key_Minus); + view->addSeparator(); + view->addAction("&Rotate clockwise", this, SLOT(rotateClockwise()), Qt::CTRL+Qt::Key_PageDown); + view->addAction("Rotate &counterclockwise", this, SLOT(rotateCounterClockwise()), Qt::CTRL+Qt::Key_PageUp); + view->addAction("&Zoom in", this, SLOT(zoomIn()), Qt::CTRL+Qt::Key_Plus); + view->addAction("Zoom &out", this, SLOT(zoomOut()), Qt::CTRL+Qt::Key_Minus); + view->addAction("Translate left", this, SLOT(moveL()), Qt::CTRL+Qt::Key_Left); + view->addAction("Translate right", this, SLOT(moveR()), Qt::CTRL+Qt::Key_Right); + view->addAction("Translate up", this, SLOT(moveU()), Qt::CTRL+Qt::Key_Up); + view->addAction("Translate down", this, SLOT(moveD()), Qt::CTRL+Qt::Key_Down); + view->addAction("&Mirror", this, SLOT(mirror()), Qt::CTRL+Qt::Key_Home); + menu->addMenu(view); + + menu->addSeparator(); + + QMenu* help = new QMenu("&Help", menu ); + help->addAction("&About", this, SLOT(help()), Qt::Key_F1); + menu->addMenu(help); statusBar(); setCentralWidget(editor); +#if !defined(Q_OS_SYMBIAN) printer = 0; +#endif init(); } @@ -397,7 +390,9 @@ void Main::init() Main::~Main() { +#if !defined(Q_OS_SYMBIAN) delete printer; +#endif if ( !--mainCount ) { delete[] butterflyimg; butterflyimg = 0; @@ -409,7 +404,7 @@ Main::~Main() void Main::newView() { // Open a new view... have it delete when closed. - Main *m = new Main(canvas, 0, 0, Qt::WDestructiveClose); + Main *m = new Main(canvas, 0); // AKr, Qt::WA_DeleteOnClose); m->show(); } @@ -428,7 +423,7 @@ void Main::help() "<li> Press ALT-L for some lines." "<li> Drag the objects around." "<li> Read the code!" - "</ul>", QMessageBox::Information, 1, 0, 0, this, 0, FALSE ); + "</ul>", QMessageBox::Information, 1, 0, 0, this, 0); about->setButtonText( 1, "Dismiss" ); about->show(); } @@ -495,11 +490,14 @@ void Main::moveD() void Main::print() { +#if !defined(Q_OS_SYMBIAN) if ( !printer ) printer = new QPrinter; - if ( printer->setup(this) ) { - QPainter pp(printer); + QPrintDialog dialog(printer, this); + if(dialog.exec()) { + QPainter pp(printer); canvas.render(&pp); } +#endif } @@ -522,12 +520,12 @@ void Main::addButterfly() if ( !butterflyimg ) { butterflyimg = new QImage[4]; butterflyimg[0].load( butterfly_fn ); - butterflyimg[1] = butterflyimg[0].smoothScale( int(butterflyimg[0].width()*0.75), - int(butterflyimg[0].height()*0.75) ); - butterflyimg[2] = butterflyimg[0].smoothScale( int(butterflyimg[0].width()*0.5), - int(butterflyimg[0].height()*0.5) ); - butterflyimg[3] = butterflyimg[0].smoothScale( int(butterflyimg[0].width()*0.25), - int(butterflyimg[0].height()*0.25) ); + butterflyimg[1] = butterflyimg[0].scaled( int(butterflyimg[0].width()*0.75), + int(butterflyimg[0].height()*0.75), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + butterflyimg[2] = butterflyimg[0].scaled( int(butterflyimg[0].width()*0.5), + int(butterflyimg[0].height()*0.5), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + butterflyimg[3] = butterflyimg[0].scaled( int(butterflyimg[0].width()*0.25), + int(butterflyimg[0].height()*0.25), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); } QAbstractGraphicsShapeItem* i = new ImageItem(butterflyimg[qrand()%4]); canvas.addItem(i); @@ -543,12 +541,12 @@ void Main::addLogo() if ( !logoimg ) { logoimg = new QImage[4]; logoimg[0].load( logo_fn ); - logoimg[1] = logoimg[0].smoothScale( int(logoimg[0].width()*0.75), - int(logoimg[0].height()*0.75) ); - logoimg[2] = logoimg[0].smoothScale( int(logoimg[0].width()*0.5), - int(logoimg[0].height()*0.5) ); - logoimg[3] = logoimg[0].smoothScale( int(logoimg[0].width()*0.25), - int(logoimg[0].height()*0.25) ); + logoimg[1] = logoimg[0].scaled( int(logoimg[0].width()*0.75), + int(logoimg[0].height()*0.75), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + logoimg[2] = logoimg[0].scaled( int(logoimg[0].width()*0.5), + int(logoimg[0].height()*0.5), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + logoimg[3] = logoimg[0].scaled( int(logoimg[0].width()*0.25), + int(logoimg[0].height()*0.25), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); } QAbstractGraphicsShapeItem* i = new ImageItem(logoimg[qrand()%4]); canvas.addItem(i); @@ -572,14 +570,15 @@ void Main::addCircle() void Main::addHexagon() { const int size = int(canvas.width() / 25); - Q3PointArray pa(6); - pa[0] = QPoint(2*size,0); - pa[1] = QPoint(size,-size*173/100); - pa[2] = QPoint(-size,-size*173/100); - pa[3] = QPoint(-2*size,0); - pa[4] = QPoint(-size,size*173/100); - pa[5] = QPoint(size,size*173/100); - QGraphicsPolygonItem* i = canvas.addPolygon(pa); + QPolygon polygon; + polygon << QPoint(2*size,0) + << QPoint(size,-size*173/100) + << QPoint(-size,-size*173/100) + << QPoint(-2*size,0) + << QPoint(-size,size*173/100) + << QPoint(size,size*173/100); + + QGraphicsPolygonItem* i = canvas.addPolygon(polygon); i->setFlag(QGraphicsItem::ItemIsMovable); i->setPen(Qt::NoPen); i->setBrush( QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8) ); @@ -590,14 +589,15 @@ void Main::addHexagon() void Main::addPolygon() { const int size = int(canvas.width()/2); - Q3PointArray pa(6); - pa[0] = QPoint(0,0); - pa[1] = QPoint(size,size/5); - pa[2] = QPoint(size*4/5,size); - pa[3] = QPoint(size/6,size*5/4); - pa[4] = QPoint(size*3/4,size*3/4); - pa[5] = QPoint(size*3/4,size/4); - QGraphicsPolygonItem* i = canvas.addPolygon(pa); + QPolygon polygon; + polygon << QPoint(0,0) + << QPoint(size,size/5) + << QPoint(size*4/5,size) + << QPoint(size/6,size*5/4) + << QPoint(size*3/4,size*3/4) + << QPoint(size*3/4,size/4); + + QGraphicsPolygonItem* i = canvas.addPolygon(polygon); i->setFlag(QGraphicsItem::ItemIsMovable); i->setPen(Qt::NoPen); i->setBrush( QColor(qrand()%32*8,qrand()%32*8,qrand()%32*8) ); @@ -609,24 +609,24 @@ void Main::addSpline() { const int size = int(canvas.width()/6); - Q3PointArray pa(12); - pa[0] = QPoint(0,0); - pa[1] = QPoint(size/2,0); - pa[2] = QPoint(size,size/2); - pa[3] = QPoint(size,size); - pa[4] = QPoint(size,size*3/2); - pa[5] = QPoint(size/2,size*2); - pa[6] = QPoint(0,size*2); - pa[7] = QPoint(-size/2,size*2); - pa[8] = QPoint(size/4,size*3/2); - pa[9] = QPoint(0,size); - pa[10]= QPoint(-size/4,size/2); - pa[11]= QPoint(-size/2,0); + QPolygon polygon; + polygon << QPoint(0,0) + << QPoint(size/2,0) + << QPoint(size,size/2) + << QPoint(size,size) + << QPoint(size,size*3/2) + << QPoint(size/2,size*2) + << QPoint(0,size*2) + << QPoint(-size/2,size*2) + << QPoint(size/4,size*3/2) + << QPoint(0,size) + << QPoint(-size/4,size/2) + << QPoint(-size/2,0); QPainterPath path; - path.moveTo(pa[0]); - for (int i = 1; i < pa.size(); i += 3) - path.cubicTo(pa[i], pa[(i + 1) % pa.size()], pa[(i + 2) % pa.size()]); + path.moveTo(polygon[0]); + for (int i = 1; i < polygon.size(); i += 3) + path.cubicTo(polygon[i], polygon[(i + 1) % polygon.size()], polygon[(i + 2) % polygon.size()]); QGraphicsPathItem* item = canvas.addPath(path); item->setFlag(QGraphicsItem::ItemIsMovable); @@ -671,13 +671,12 @@ void Main::addMesh() int cols = w / dist; #ifndef QT_NO_PROGRESSDIALOG - Q3ProgressDialog progress( "Creating mesh...", "Abort", rows, - this, "progress", TRUE ); + QProgressDialog progress("Creating mesh...", "Abort", 0, rows, this); #endif canvas.update(); - Q3MemArray<NodeItem*> lastRow(cols); + QVector<NodeItem*> lastRow(cols); for ( int j = 0; j < rows; j++ ) { int n = j%2 ? cols-1 : cols; NodeItem *prev = 0; @@ -707,13 +706,13 @@ void Main::addMesh() } lastRow[n-1]=prev; #ifndef QT_NO_PROGRESSDIALOG - progress.setProgress( j ); - if ( progress.wasCancelled() ) + progress.setValue( j ); + if ( progress.wasCanceled() ) break; #endif } #ifndef QT_NO_PROGRESSDIALOG - progress.setProgress( rows ); + progress.setValue( rows ); #endif // qDebug( "%d nodes, %d edges", nodecount, EdgeItem::count() ); } diff --git a/examples/graphicsview/portedcanvas/canvas.h b/examples/graphicsview/portedcanvas/canvas.h index 1ebdf90..609090b 100644 --- a/examples/graphicsview/portedcanvas/canvas.h +++ b/examples/graphicsview/portedcanvas/canvas.h @@ -41,9 +41,8 @@ #ifndef EXAMPLE_H #define EXAMPLE_H -#include <q3popupmenu.h> -#include <q3mainwindow.h> -#include <q3intdict.h> +#include <QMenu> +#include <QMainWindow> #include <QMouseEvent> #include <QGraphicsView> #include <QGraphicsScene> @@ -76,11 +75,11 @@ signals: void status(const QString&); }; -class Main : public Q3MainWindow { +class Main : public QMainWindow { Q_OBJECT public: - Main(QGraphicsScene&, QWidget* parent=0, const char* name=0, Qt::WindowFlags f=0); + Main(QGraphicsScene&, QWidget* parent=0, Qt::WindowFlags f=0); ~Main(); public slots: @@ -122,9 +121,10 @@ private: QGraphicsScene& canvas; FigureEditor *editor; - Q3PopupMenu* options; + QMenu* options; +#if !defined(Q_OS_SYMBIAN) QPrinter* printer; - int dbf_id; +#endif }; #endif diff --git a/examples/graphicsview/portedcanvas/main.cpp b/examples/graphicsview/portedcanvas/main.cpp index 8478d94..4e447ba 100644 --- a/examples/graphicsview/portedcanvas/main.cpp +++ b/examples/graphicsview/portedcanvas/main.cpp @@ -38,13 +38,13 @@ ** ****************************************************************************/ -#include <qstatusbar.h> -#include <qmessagebox.h> -#include <qmenubar.h> -#include <qapplication.h> -#include <qdesktopwidget.h> -#include <qimage.h> -#include <qtimer.h> +#include <QStatusBar> +#include <QMessageBox> +#include <QMenuBar> +#include <QApplication> +#include <QDesktopWidget> +#include <QImage> +#include <QTimer> #include "canvas.h" @@ -73,12 +73,19 @@ int main(int argc, char** argv) canvas.setSceneRect(0, 0, 800, 600); Main m(canvas); m.resize(m.sizeHint()); - m.setCaption("Ported Canvas Example"); + m.setWindowTitle("Ported Canvas Example"); + +#if defined(Q_OS_SYMBIAN) + m.showMaximized(); +#elif defined(Q_WS_MAEMO_5) + m.show(); +#else if ( QApplication::desktop()->width() > m.width() + 10 && QApplication::desktop()->height() > m.height() +30 ) m.show(); else m.showMaximized(); +#endif QTimer timer; QObject::connect(&timer, SIGNAL(timeout()), &canvas, SLOT(advance())); diff --git a/examples/graphicsview/portedcanvas/portedcanvas.pro b/examples/graphicsview/portedcanvas/portedcanvas.pro index 850b440..f2d626d 100644 --- a/examples/graphicsview/portedcanvas/portedcanvas.pro +++ b/examples/graphicsview/portedcanvas/portedcanvas.pro @@ -5,7 +5,6 @@ CONFIG += qt warn_on HEADERS = canvas.h SOURCES = canvas.cpp main.cpp -QT += qt3support RESOURCES += portedcanvas.qrc @@ -16,3 +15,6 @@ sources.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/portedcanvas INSTALLS += target sources symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) +maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri) + +simulator: warning(This example might not fully work on Simulator platform) diff --git a/examples/graphicsview/simpleanchorlayout/main.cpp b/examples/graphicsview/simpleanchorlayout/main.cpp index 4fa837f..cba37d9 100644 --- a/examples/graphicsview/simpleanchorlayout/main.cpp +++ b/examples/graphicsview/simpleanchorlayout/main.cpp @@ -126,8 +126,15 @@ int main(int argc, char *argv[]) QGraphicsView *view = new QGraphicsView(); view->setScene(scene); view->setWindowTitle(QApplication::translate("simpleanchorlayout", "Simple Anchor Layout")); + +#if defined(Q_OS_SYMBIAN) + view->showMaximized(); +#elif defined(Q_WS_MAEMO_5) + view-show(); +#else view->resize(360, 320); view->show(); +#endif return app.exec(); } diff --git a/examples/graphicsview/simpleanchorlayout/simpleanchorlayout.pro b/examples/graphicsview/simpleanchorlayout/simpleanchorlayout.pro index e1c7aeb..2c8c3c3 100644 --- a/examples/graphicsview/simpleanchorlayout/simpleanchorlayout.pro +++ b/examples/graphicsview/simpleanchorlayout/simpleanchorlayout.pro @@ -7,3 +7,7 @@ sources.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/simpleanchorlayout INSTALLS += target sources TARGET = simpleanchorlayout + +symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) +maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri) +simulator: warning(This example might not fully work on Simulator platform) diff --git a/examples/graphicsview/weatheranchorlayout/main.cpp b/examples/graphicsview/weatheranchorlayout/main.cpp index 67596ac..b1f2c72 100644 --- a/examples/graphicsview/weatheranchorlayout/main.cpp +++ b/examples/graphicsview/weatheranchorlayout/main.cpp @@ -51,6 +51,21 @@ #include <QGraphicsSceneResizeEvent> +class GraphicsView : public QGraphicsView +{ +public: + GraphicsView(QGraphicsScene *scene, QGraphicsWidget *widget) : QGraphicsView(scene), w(widget) + { + } + + virtual void resizeEvent(QResizeEvent *event) + { + w->setGeometry(0, 0, event->size().width(), event->size().height()); + } + + QGraphicsWidget *w; +}; + class PixmapWidget : public QGraphicsLayoutItem { @@ -175,7 +190,10 @@ int main(int argc, char **argv) QApplication app(argc, argv); QGraphicsScene scene; +#if defined(Q_OS_SYMBIAN) +#else scene.setSceneRect(0, 0, 800, 480); +#endif // pixmaps widgets PixmapWidget *title = new PixmapWidget(QPixmap(":/images/title.jpg")); @@ -250,8 +268,13 @@ int main(int argc, char **argv) // QGV setup scene.addItem(w); scene.setBackgroundBrush(Qt::white); +#if defined(Q_OS_SYMBIAN) + GraphicsView *view = new GraphicsView(&scene, w); + view->showMaximized(); +#else QGraphicsView *view = new QGraphicsView(&scene); view->show(); +#endif return app.exec(); } diff --git a/examples/graphicsview/weatheranchorlayout/weatheranchorlayout.pro b/examples/graphicsview/weatheranchorlayout/weatheranchorlayout.pro index fa2733c..68a3a31 100644 --- a/examples/graphicsview/weatheranchorlayout/weatheranchorlayout.pro +++ b/examples/graphicsview/weatheranchorlayout/weatheranchorlayout.pro @@ -12,3 +12,6 @@ sources.files = $$SOURCES $$HEADERS $$RESOURCES weatheranchorlayout.pro images sources.path = $$[QT_INSTALL_EXAMPLES]/graphicsview/weatheranchorlayout INSTALLS += target sources +symbian: include($$QT_SOURCE_TREE/examples/symbianpkgrules.pri) +maemo5: include($$QT_SOURCE_TREE/examples/maemo5pkgrules.pri) +simulator: warning(This example might not fully work on Simulator platform) |