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(60,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);
41 MainWindow::~MainWindow()
46 void MainWindow::initializeBoundaries()
48 //the boundaries of the scene are set to match the size of the view window, and
49 //the view is set to show exactly the whole scene area
52 QSize windowsize = pView_->size();
53 QRectF rectangle (topleft,windowsize);
56 pScene_->setSceneRect(rectangle);
57 pView_->setSceneRect(rectangle);
58 pTursas_->setBoundaries(rectangle);
59 pTursas_->startMoving();
61 qDebug() << "Initialized boundaries" << rectangle.left() << rectangle.right() << pView_->width();
64 void MainWindow::pause(bool paused)
66 // qDebug() << "pause pressed " << paused;
67 if (paused_ == paused)
74 // qDebug() << "starting to move again";
75 pTursas_->startMoving();
80 qDebug("about to stop movement");
81 pTursas_->stopMoving();