1 #include "mainwindow.h"
10 MainWindow::MainWindow(QWidget *parent)
15 pScene_ = new QGraphicsScene ();
16 pView_ = new QGraphicsView ();
18 QPixmap waves (":/pix/meri.png");
19 pScene_->setBackgroundBrush(QBrush(waves));
21 pTursas_ = new OrientationControlledGraphicsPixmapObject(QPixmap(":/pix/tursas.png"));
22 pScene_->addItem(pTursas_);
24 pView_->setScene(pScene_);
25 setCentralWidget(pView_);
28 //the boundaries of the scene are set to match the size of the view window, which is not
29 //available in the constructor --> timer needed
30 QTimer::singleShot(100,this,SLOT(initializeBoundaries()));
33 QAction * pPauseAction = new QAction(tr("Pause"),this);
34 pPauseAction->setCheckable(true);
35 addAction(pPauseAction);
36 connect(pPauseAction,SIGNAL(triggered(bool)),this,SLOT(pause(bool)));
37 menuBar()->addAction(pPauseAction);
39 QGraphicsPixmapItem * pGhost = pScene_->addPixmap(QPixmap(":/pix/aave.png"));
40 pGhost->setData(0,"ghost");
41 QGraphicsPixmapItem * pRock = pScene_->addPixmap(QPixmap(":/pix/kari.png"));
42 QGraphicsPixmapItem * pRock2 = pScene_->addPixmap(QPixmap(":/pix/kari.png"));
44 pRock->setData(0,"rock");
45 pRock2->moveBy(80,80);
46 pRock2->setData(0,"rock");
51 MainWindow::~MainWindow()
56 void MainWindow::initializeBoundaries()
58 //the boundaries of the scene are set to match the size of the view window, and
59 //the view is set to show exactly the whole scene area
62 QSize windowsize = pView_->size();
63 QRectF rectangle (topleft,windowsize);
66 pScene_->setSceneRect(rectangle);
67 pView_->setSceneRect(rectangle);
68 pTursas_->setBoundaries(rectangle);
69 pTursas_->startMoving();
71 qDebug() << "Initialized boundaries" << rectangle.left() << rectangle.right() << pView_->width();
74 void MainWindow::pause(bool paused)
76 // qDebug() << "pause pressed " << paused;
77 if (paused_ == paused)
84 // qDebug() << "starting to move again";
85 pTursas_->startMoving();
90 qDebug("about to stop movement");
91 pTursas_->stopMoving();