1 /**************************************************************************
2 Ghosts Overboard - a game for Maemo 5
4 Copyright (C) 2011 Heli Hyvättinen
6 This file is part of Ghosts Overboard
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.
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.
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/>.
21 **************************************************************************/
28 SeaView::SeaView(QWidget *parent) :
33 setWindowTitle("Ghosts Overboard");
35 pScene_ = new SeaScene ();
41 connect(this,SIGNAL(screenTapped()),pScene_,SLOT(handleScreenTapped()));
42 connect(this,SIGNAL(goingBackgroung()),pScene_,SLOT(forcePause()));
43 connect(this,SIGNAL(goingForeground()),pScene_,SLOT(softContinue()));
45 connect(pScene_,SIGNAL(minimizeRequested()),this,SLOT(showNormal()));
46 connect(pScene_,SIGNAL(fullscreenRequested()),this,SLOT(showFullScreen()));
52 //the boundaries of the scene are set to match the size of the view window, which is not
53 //available in the constructor --> timer needed
54 QTimer::singleShot(100,this,SLOT(initializeBoundaries()));
58 void SeaView::mousePressEvent(QMouseEvent *event)
61 QGraphicsView::mousePressEvent(event);
67 bool SeaView::event(QEvent *event)
72 switch (event->type())
74 //pause if app goes to background
75 case QEvent::WindowDeactivate:
77 emit goingBackgroung();
80 //un-pause if app gomes back to foreground unless it was paused before going to background
81 case QEvent::WindowActivate:
83 emit goingForeground();
86 //Just to keep the compiler from complaining...
94 //pass the event to the ancestor for handling
95 return QGraphicsView::event(event);
100 void SeaView::initializeBoundaries()
102 //the boundaries of the scene are set to match the size of the view window, and
103 //the view is set to show exactly the whole scene area
105 //this occasionally gives a tiny scene, so using a fixed size fit for N900/Maemo5 until a fix is found
107 // QPoint topleft (0,0);
108 // QSize windowsize = pView_->size();
109 // QRectF rectangle (topleft,windowsize);
111 QRectF rectangle(0,0,800,480);
113 pScene_->setSceneRect(rectangle);
114 setSceneRect(rectangle);
116 // qDebug() << "Initialized boundaries" << rectangle.right() << rectangle.bottom() << pView_->width() << pView_->height();
118 pScene_->restartLevel();