The menu items trigger expected behaviour
[ghostsoverboard] / mainwindow.cpp
1 /**************************************************************************
2         Ghosts Overboard - a game for Maemo 5
3
4         Copyright (C) 2011  Heli Hyvättinen
5
6         This file is part of Ghosts Overboard
7
8         Ghosts Overboard is free software: you can redistribute it and/or modify
9         it under the terms of the GNU General Public License as published by
10         the Free Software Foundation, either version 2 of the License, or
11         (at your option) any later version.
12
13         This program is distributed in the hope that it will be useful,
14         but WITHOUT ANY WARRANTY; without even the implied warranty of
15         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16         GNU General Public License for more details.
17
18         You should have received a copy of the GNU General Public License
19         along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 **************************************************************************/
22
23 #include "mainwindow.h"
24 #include <QPixmap>
25 #include <QTimer>
26 #include <QDebug>
27 #include <QAction>
28 #include <QMenuBar>
29 #include <QMessageBox>
30 #include <QApplication>
31 #include <QLabel>
32 #include <QPushButton>
33 #include <QVBoxLayout>
34
35
36
37 MainWindow::MainWindow(QWidget *parent)
38     : QMainWindow(parent)
39 {
40     setWindowIcon(QIcon(":/pix/laiva_3aave.png"));
41     setWindowTitle("Ghosts Overboard");
42
43     pScene_ = new SeaScene ();
44     connect(pScene_,SIGNAL(allGhostsPicked()),pScene_,SLOT(nextLevel()));
45
46     pView_  = new SeaView ();
47
48
49     pView_->setScene(pScene_);
50     setCentralWidget(pView_);
51
52     connect(pView_,SIGNAL(screenTapped()),pScene_,SLOT(handleScreenTapped()));
53     connect(pView_,SIGNAL(goingBackgroung()),pScene_,SLOT(forcePause()));
54     connect(pView_,SIGNAL(goingForeground()),pScene_,SLOT(softContinue()));
55
56
57
58     //the boundaries of the scene are set to match the size of the view window, which is not
59     //available in the constructor --> timer needed
60     QTimer::singleShot(100,this,SLOT(initializeBoundaries()));
61
62
63 }
64
65 MainWindow::~MainWindow()
66 {
67
68 }
69
70 void MainWindow::initializeBoundaries()
71 {
72         //the boundaries of the scene are set to match the size of the view window, and
73         //the view is set to show exactly the whole scene area
74
75     //this occasionally gives a tiny scene, so using a fixed size fit for N900/Maemo5 until a fix is found
76
77 //    QPoint topleft (0,0);
78 //    QSize windowsize = pView_->size();
79 //    QRectF rectangle (topleft,windowsize);
80
81     QRectF rectangle(0,0,800,424);
82
83     pScene_->setSceneRect(rectangle);
84     pView_->setSceneRect(rectangle);
85
86     // qDebug() << "Initialized boundaries" << rectangle.right() << rectangle.bottom() << pView_->width() << pView_->height();
87
88     pScene_->restartLevel();
89 }
90