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
64 QSize windowsize = pView_->size();
65 QRectF rectangle (topleft,windowsize);
68 pScene_->setSceneRect(rectangle);
69 pView_->setSceneRect(rectangle);
71 qDebug() << "Initialized boundaries" << rectangle.right() << rectangle.bottom() << pView_->width() << pView_->height();
77 void MainWindow::restartLevel()
79 pScene_->setupMap(5,10,0);
82 void MainWindow::about()
84 QMessageBox::about(this, tr("About %1").arg(QApplication::applicationName()),
86 "<p>Copyright 2011 Heli Hyvättinen"
87 "<p>License: General Public License v2"
88 "<p>Bug Reports: https://bugs.maemo.org/enter_bug.cgi?product=Ghosts%20Overboard"
89 ).arg(QApplication::applicationVersion()));
95 void MainWindow::nextLevel()
98 //for now, just the handling of last level is implemented, and there is just one level
102 QDialog* pVictoryDialog = new QDialog(this);
103 pVictoryDialog->setWindowTitle(tr("You won!"));
106 QPushButton* pPlayAgainButton = new QPushButton(tr("Play again"));
107 // QPushButton* pQuitButton = new QPushButton(tr("Quit game"));
109 QPixmap victoryIcon (":/pix/aavesaari.png");
110 QLabel* pVictoryLabel = new QLabel();
111 pVictoryLabel->setPixmap(victoryIcon);
113 QLabel* pTextLabel = new QLabel(tr("Congratulations! <p>You have saved all the ghosts."));
116 QVBoxLayout* pMainLayout = new QVBoxLayout;
118 QHBoxLayout* pTopLayout = new QHBoxLayout;
119 pMainLayout->addLayout(pTopLayout);
121 pTopLayout->addWidget(pVictoryLabel);
122 pTopLayout->addWidget(pTextLabel);
126 QHBoxLayout* pButtonLayout = new QHBoxLayout();
127 pMainLayout->addLayout(pButtonLayout);
129 // pButtonLayout->addWidget(pQuitButton);
130 pButtonLayout->addWidget(pPlayAgainButton);
134 pVictoryDialog->setLayout(pMainLayout);
136 connect(pPlayAgainButton, SIGNAL(clicked()),pVictoryDialog,SLOT(accept()));
138 pVictoryDialog->exec();
140 //Never mind if the user cancels the dialog: restart the game anyway