1 #include "mainwindow.h"
2 #include "timercontrolledtursas.h"
11 MainWindow::MainWindow(QWidget *parent)
16 pScene_ = new QGraphicsScene ();
17 pView_ = new QGraphicsView ();
19 QPixmap waves (":/pix/meri.png");
20 pScene_->setBackgroundBrush(QBrush(waves));
22 pTursas_ = new OrientationControlledGraphicsPixmapObject(QPixmap(":/pix/tursas.png"));
23 pScene_->addItem(pTursas_);
25 pView_->setScene(pScene_);
26 setCentralWidget(pView_);
29 //the boundaries of the scene are set to match the size of the view window, which is not
30 //available in the constructor --> timer needed
31 QTimer::singleShot(100,this,SLOT(initializeBoundaries()));
34 QAction * pPauseAction = new QAction(tr("Pause"),this);
35 pPauseAction->setCheckable(true);
36 addAction(pPauseAction);
37 connect(pPauseAction,SIGNAL(triggered(bool)),this,SLOT(pause(bool)));
38 menuBar()->addAction(pPauseAction);
40 QGraphicsPixmapItem * pGhost = pScene_->addPixmap(QPixmap(":/pix/aave.png"));
41 pGhost->setData(0,"ghost");
42 QGraphicsPixmapItem * pRock = pScene_->addPixmap(QPixmap(":/pix/kari.png"));
43 QGraphicsPixmapItem * pRock2 = pScene_->addPixmap(QPixmap(":/pix/kari.png"));
45 pRock->setData(0,"rock");
46 pRock2->moveBy(80,80);
47 pRock2->setData(0,"rock");
49 TimerControlledTursas * pMustekala = new TimerControlledTursas (QPixmap(":/pix/tursas.png"),100);
50 pScene_->addItem(pMustekala);
51 pMustekala->moveBy(100,100);
52 pMustekala->startMoving();
59 MainWindow::~MainWindow()
64 void MainWindow::initializeBoundaries()
66 //the boundaries of the scene are set to match the size of the view window, and
67 //the view is set to show exactly the whole scene area
70 QSize windowsize = pView_->size();
71 QRectF rectangle (topleft,windowsize);
74 pScene_->setSceneRect(rectangle);
75 pView_->setSceneRect(rectangle);
76 pTursas_->setBoundaries(rectangle);
77 pTursas_->startMoving();
79 qDebug() << "Initialized boundaries" << rectangle.left() << rectangle.right() << pView_->width();
82 void MainWindow::pause(bool paused)
84 // qDebug() << "pause pressed " << paused;
85 if (paused_ == paused)
92 // qDebug() << "starting to move again";
93 pTursas_->startMoving();
98 qDebug("about to stop movement");
99 pTursas_->stopMoving();