1 #include "mainwindow.h"
2 #include "timercontrolledtursas.h"
9 #include <QApplication>
11 #include <QPushButton>
12 #include <QVBoxLayout>
16 MainWindow::MainWindow(QWidget *parent)
19 setWindowIcon(QIcon(":/pix/laiva_10aave.png"));
20 setWindowTitle("Ghosts Overboard");
22 pScene_ = new SeaScene ();
23 connect(pScene_,SIGNAL(allGhostsPicked()),this,SLOT(nextLevel()));
25 pView_ = new QGraphicsView ();
27 pView_->setScene(pScene_);
28 setCentralWidget(pView_);
30 QAction * pPauseAction = new QAction(tr("Pause"),this);
31 pPauseAction->setCheckable(true);
32 addAction(pPauseAction);
33 connect(pPauseAction,SIGNAL(triggered(bool)),pScene_,SLOT(pause(bool)));
34 menuBar()->addAction(pPauseAction);
36 QAction * pRestartLevelAction = new QAction(tr("Restart level"),this);
37 addAction(pRestartLevelAction);
38 connect(pRestartLevelAction,SIGNAL(triggered()),this,SLOT(restartLevel()));
39 menuBar()->addAction(pRestartLevelAction);
42 QAction * pAboutAction = new QAction(tr("About"),this);
43 addAction(pAboutAction);
44 connect(pAboutAction,SIGNAL(triggered()),this,SLOT(about()));
45 menuBar()->addAction(pAboutAction);
48 //the boundaries of the scene are set to match the size of the view window, which is not
49 //available in the constructor --> timer needed
50 QTimer::singleShot(100,this,SLOT(initializeBoundaries()));
53 MainWindow::~MainWindow()
58 void MainWindow::initializeBoundaries()
60 //the boundaries of the scene are set to match the size of the view window, and
61 //the view is set to show exactly the whole scene area
63 //this occasionally gives a tiny scene, so using a fixed size fit for N900/Maemo5 until a fix is found
65 // QPoint topleft (0,0);
66 // QSize windowsize = pView_->size();
67 // QRectF rectangle (topleft,windowsize);
69 QRectF rectangle(0,0,800,424);
71 pScene_->setSceneRect(rectangle);
72 pView_->setSceneRect(rectangle);
74 // qDebug() << "Initialized boundaries" << rectangle.right() << rectangle.bottom() << pView_->width() << pView_->height();
80 void MainWindow::restartLevel()
82 pScene_->setupMap(5,10,0);
85 void MainWindow::about()
87 QMessageBox::about(this, tr("About %1").arg(QApplication::applicationName()),
89 "<p>Copyright 2011 Heli Hyvättinen"
90 "<p>License: General Public License v2"
91 "<p>Bug Reports: https://bugs.maemo.org/ "
92 "enter_bug.cgi?product=Ghosts%20Overboard"
93 ).arg(QApplication::applicationVersion()));
99 void MainWindow::nextLevel()
102 //for now, just the handling of last level is implemented, and there is just one level
106 QDialog* pVictoryDialog = new QDialog(this);
107 pVictoryDialog->setWindowTitle(tr("You won!"));
110 QPushButton* pPlayAgainButton = new QPushButton(tr("Play again"));
111 // QPushButton* pQuitButton = new QPushButton(tr("Quit game"));
113 QPixmap victoryIcon (":/pix/aavesaari.png");
114 QLabel* pVictoryLabel = new QLabel();
115 pVictoryLabel->setPixmap(victoryIcon);
117 QLabel* pTextLabel = new QLabel(tr("Congratulations! <p>You have saved all the ghosts."));
120 QVBoxLayout* pMainLayout = new QVBoxLayout;
122 QHBoxLayout* pTopLayout = new QHBoxLayout;
123 pMainLayout->addLayout(pTopLayout);
125 pTopLayout->addWidget(pVictoryLabel);
126 pTopLayout->addWidget(pTextLabel);
130 QHBoxLayout* pButtonLayout = new QHBoxLayout();
131 pMainLayout->addLayout(pButtonLayout);
133 // pButtonLayout->addWidget(pQuitButton);
134 pButtonLayout->addWidget(pPlayAgainButton);
138 pVictoryDialog->setLayout(pMainLayout);
140 connect(pPlayAgainButton, SIGNAL(clicked()),pVictoryDialog,SLOT(accept()));
142 pVictoryDialog->exec();
144 //Never mind if the user cancels the dialog: restart the game anyway