Added bugtracker info
[ghostsoverboard] / mainwindow.cpp
1 #include "mainwindow.h"
2 #include "timercontrolledtursas.h"
3 #include <QPixmap>
4 #include <QTimer>
5 #include <QDebug>
6 #include <QAction>
7 #include <QMenuBar>
8 #include <QMessageBox>
9 #include <QApplication>
10 #include <QLabel>
11 #include <QPushButton>
12 #include <QVBoxLayout>
13
14
15
16 MainWindow::MainWindow(QWidget *parent)
17     : QMainWindow(parent)
18 {
19     setWindowIcon(QIcon(":/pix/laiva_10aave.png"));
20     setWindowTitle("Ghosts Overboard");
21
22     pScene_ = new SeaScene ();
23     connect(pScene_,SIGNAL(allGhostsPicked()),this,SLOT(nextLevel()));
24
25     pView_  = new QGraphicsView ();
26
27     pView_->setScene(pScene_);
28     setCentralWidget(pView_);
29
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);
35
36     QAction * pRestartLevelAction = new QAction(tr("Restart level"),this);
37     addAction(pRestartLevelAction);
38     connect(pRestartLevelAction,SIGNAL(triggered()),this,SLOT(restartLevel()));
39     menuBar()->addAction(pRestartLevelAction);
40
41
42     QAction * pAboutAction = new QAction(tr("About"),this);
43     addAction(pAboutAction);
44     connect(pAboutAction,SIGNAL(triggered()),this,SLOT(about()));
45     menuBar()->addAction(pAboutAction);
46
47
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()));
51 }
52
53 MainWindow::~MainWindow()
54 {
55
56 }
57
58 void MainWindow::initializeBoundaries()
59 {
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
62
63     QPoint topleft (0,0);
64     QSize windowsize = pView_->size();
65     QRectF rectangle (topleft,windowsize);
66
67
68     pScene_->setSceneRect(rectangle);
69     pView_->setSceneRect(rectangle);
70
71     qDebug() << "Initialized boundaries" << rectangle.right() << rectangle.bottom() << pView_->width() << pView_->height();
72
73     restartLevel();
74 }
75
76
77 void MainWindow::restartLevel()
78 {
79     pScene_->setupMap(5,10,0);
80 }
81
82 void MainWindow::about()
83 {
84     QMessageBox::about(this, tr("About %1").arg(QApplication::applicationName()),
85                        tr("Version %1"
86                           "<p>Copyright 2011 Heli Hyv&auml;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()));
90
91
92
93 }
94
95 void MainWindow::nextLevel()
96 {
97
98     //for now, just the handling of last level is implemented, and there is just one level
99
100
101
102        QDialog* pVictoryDialog = new QDialog(this);
103        pVictoryDialog->setWindowTitle(tr("You won!"));
104
105
106        QPushButton* pPlayAgainButton = new QPushButton(tr("Play again"));
107 //       QPushButton* pQuitButton = new QPushButton(tr("Quit game"));
108
109        QPixmap victoryIcon (":/pix/aavesaari.png");
110        QLabel* pVictoryLabel = new QLabel();
111        pVictoryLabel->setPixmap(victoryIcon);
112
113        QLabel* pTextLabel = new QLabel(tr("Congratulations! <p>You have saved all the ghosts."));
114
115
116        QVBoxLayout* pMainLayout = new QVBoxLayout;
117
118        QHBoxLayout* pTopLayout = new QHBoxLayout;
119        pMainLayout->addLayout(pTopLayout);
120
121        pTopLayout->addWidget(pVictoryLabel);
122        pTopLayout->addWidget(pTextLabel);
123
124
125
126        QHBoxLayout* pButtonLayout = new QHBoxLayout();
127        pMainLayout->addLayout(pButtonLayout);
128
129  //      pButtonLayout->addWidget(pQuitButton);
130        pButtonLayout->addWidget(pPlayAgainButton);
131
132
133
134        pVictoryDialog->setLayout(pMainLayout);
135
136        connect(pPlayAgainButton, SIGNAL(clicked()),pVictoryDialog,SLOT(accept()));
137
138        pVictoryDialog->exec();
139
140         //Never mind if the user cancels the dialog: restart the game anyway
141
142        restartLevel();
143
144 }