Bugtracker adress now fully visible in the about box
[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/ "
89                           "enter_bug.cgi?product=Ghosts%20Overboard"
90                           ).arg(QApplication::applicationVersion()));
91
92
93
94 }
95
96 void MainWindow::nextLevel()
97 {
98
99     //for now, just the handling of last level is implemented, and there is just one level
100
101
102
103        QDialog* pVictoryDialog = new QDialog(this);
104        pVictoryDialog->setWindowTitle(tr("You won!"));
105
106
107        QPushButton* pPlayAgainButton = new QPushButton(tr("Play again"));
108 //       QPushButton* pQuitButton = new QPushButton(tr("Quit game"));
109
110        QPixmap victoryIcon (":/pix/aavesaari.png");
111        QLabel* pVictoryLabel = new QLabel();
112        pVictoryLabel->setPixmap(victoryIcon);
113
114        QLabel* pTextLabel = new QLabel(tr("Congratulations! <p>You have saved all the ghosts."));
115
116
117        QVBoxLayout* pMainLayout = new QVBoxLayout;
118
119        QHBoxLayout* pTopLayout = new QHBoxLayout;
120        pMainLayout->addLayout(pTopLayout);
121
122        pTopLayout->addWidget(pVictoryLabel);
123        pTopLayout->addWidget(pTextLabel);
124
125
126
127        QHBoxLayout* pButtonLayout = new QHBoxLayout();
128        pMainLayout->addLayout(pButtonLayout);
129
130  //      pButtonLayout->addWidget(pQuitButton);
131        pButtonLayout->addWidget(pPlayAgainButton);
132
133
134
135        pVictoryDialog->setLayout(pMainLayout);
136
137        connect(pPlayAgainButton, SIGNAL(clicked()),pVictoryDialog,SLOT(accept()));
138
139        pVictoryDialog->exec();
140
141         //Never mind if the user cancels the dialog: restart the game anyway
142
143        restartLevel();
144
145 }