1 /**************************************************************************
2 Ghosts Overboard - a game for 'Meego 1.2 Harmattan'
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 **************************************************************************/
29 SeaView::SeaView(QWidget *parent) :
30 QDeclarativeView(parent)
34 setWindowTitle("Ghosts Overboard");
36 pScene_ = new SeaScene ();
42 connect(this,SIGNAL(screenTapped()),pScene_,SLOT(handleScreenTapped()));
43 connect(this,SIGNAL(goingBackgroung()),pScene_,SLOT(forcePause()));
44 connect(this,SIGNAL(goingForeground()),pScene_,SLOT(softContinue()));
50 //the boundaries of the scene are set to match the size of the view window, which is not
51 //available in the constructor --> timer needed
52 QTimer::singleShot(100,this,SLOT(initializeBoundaries()));
56 void SeaView::mousePressEvent(QMouseEvent *event)
59 QDeclarativeView::mousePressEvent(event);
65 bool SeaView::event(QEvent *event)
70 switch (event->type())
72 //pause if app goes to background
73 case QEvent::WindowDeactivate:
75 emit goingBackgroung();
78 //un-pause if app gomes back to foreground unless it was paused before going to background
79 case QEvent::WindowActivate:
81 emit goingForeground();
84 //Just to keep the compiler from complaining...
92 //pass the event to the ancestor for handling
93 return QDeclarativeView::event(event);
98 void SeaView::initializeBoundaries()
100 //the boundaries of the scene are set to match the size of the view window, and
101 //the view is set to show exactly the whole scene area
103 //this occasionally gives a tiny scene, so using a fixed size fit until a fix is found
105 // QPoint topleft (0,0);
106 // QSize windowsize = size();
107 // QRectF rectangle (topleft,windowsize);
109 // This is for fremantle
110 // QRectF rectangle(0,0,800,480);
112 //This is for Harmattan
113 //The automatic code above gives 854 width and 480 height, but that gives both scrollbars
114 //Found by forking: 843 width and 476 height are the largest that don't bring up the scrollbars (when there is the frame)
115 //With the move from QGraphicsView to QDeclarative view the gray frame is gone and full screen can be used
117 QRectF rectangle(0,0,854,480);
119 pScene_->setSceneRect(rectangle);
120 setSceneRect(rectangle);
122 // qDebug() << "Initialized boundaries" << rectangle.right() << rectangle.bottom() << width() << height();
124 pScene_->restartLevel();