Changed the section to user/hidden as required for Nokia Store
[ghostsoverboard] / seaview.cpp
1 /**************************************************************************
2         Ghosts Overboard - a game for 'Meego 1.2 Harmattan'
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 "seaview.h"
24
25 #include <QEvent>
26 #include <QTimer>
27 #include <QDebug>
28
29 SeaView::SeaView(QWidget *parent) :
30     QDeclarativeView(parent)
31 {
32
33
34     setWindowTitle("Ghosts Overboard");
35
36     pScene_ = new SeaScene ();
37
38
39     setScene(pScene_);
40
41
42     connect(this,SIGNAL(screenTapped()),pScene_,SLOT(handleScreenTapped()));
43     connect(this,SIGNAL(goingBackgroung()),pScene_,SLOT(forcePause()));
44     connect(this,SIGNAL(goingForeground()),pScene_,SLOT(softContinue()));
45
46     showFullScreen();
47
48
49
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()));
53
54 }
55
56 void  SeaView::mousePressEvent(QMouseEvent *event)
57 {
58
59     QDeclarativeView::mousePressEvent(event);
60     emit screenTapped();
61
62
63 }
64
65 bool SeaView::event(QEvent *event)
66 {
67     if (!event)
68         return false;
69
70     switch (event->type())
71     {
72         //pause if app goes to background
73         case QEvent::WindowDeactivate:
74
75             emit goingBackgroung();
76             break;
77
78         //un-pause if app gomes back to foreground unless it was paused before going to background
79         case QEvent::WindowActivate:
80
81             emit goingForeground();
82             break;
83
84         //Just to keep the compiler from complaining...
85         default:
86             break;
87
88      }
89
90
91
92     //pass the event to the ancestor for handling
93     return QDeclarativeView::event(event);
94
95  }
96
97
98 void SeaView::initializeBoundaries()
99 {
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
102
103     //this occasionally gives a tiny scene, so using a fixed size fit until a fix is found
104
105 //    QPoint topleft (0,0);
106 //    QSize windowsize = size();
107 //    QRectF rectangle (topleft,windowsize);
108
109   //    This is for fremantle
110 //    QRectF rectangle(0,0,800,480);
111
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
116
117     QRectF rectangle(0,0,854,480);
118
119     pScene_->setSceneRect(rectangle);
120     setSceneRect(rectangle);
121
122 //    qDebug() << "Initialized boundaries" << rectangle.right() << rectangle.bottom() << width() << height();
123
124     pScene_->restartLevel();
125 }