Should pause at device lock
[ghostsoverboard] / seascene.h
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
24 #ifndef SEASCENE_H
25 #define SEASCENE_H
26
27 #include <QGraphicsScene>
28 #include<QGraphicsItemGroup>
29 #include "screenlitkeeper.h"
30 #include "level.h"
31 #include <QAction>
32 #include <QTimer>
33 #include <QSystemDeviceInfo>
34
35 using namespace QtMobility;
36
37 class SeaScene : public QGraphicsScene
38 {
39     Q_OBJECT
40 public:
41     explicit SeaScene(QObject *parent = 0);
42
43 signals:
44
45     void allGhostsPicked();
46     void pauseOn();
47     void pauseOff();
48     void vibrationActivated(bool on);
49     void minimizeRequested();
50     void fullscreenRequested();
51
52 public slots:
53
54     /*! Places all needed items for a level to (re)start.
55     Relies on the scene size to be explicitly set to a a value that will persist troughout play.
56     @param ghosts the number of ghosts to be placed on the map
57     @param rocks the number of rocks to be placed on the map
58     @param octopuses number of octopuses to be placed on the map
59     */
60     void setupMap(int ghosts, int rocks, int octopuses, int octopusSpeed);
61
62     void setupMap(Level level);
63
64     void spreadGhosts(int ghosts);
65
66     void removeGhost(QGraphicsItem * pGhost);
67
68     void ghostsDropped(int ghosts);
69
70     void pause (bool paused);
71
72     void vibrationActivate(bool);
73
74     void handleScreenTapped();
75
76     void about();
77
78     void restartLevel();
79
80     void nextLevel();
81
82     void restartGame();
83
84     void forcePause();
85
86     void softContinue();
87
88     void createAboutBoxItems();
89
90     void createVictoryItems();
91
92     void setItemPointersNull();
93
94     void turnPauseOn();
95
96     void handleDeviceLocked(bool isLocked);
97
98
99
100 protected:
101
102     /*! Gives a pointer to a random position if a free one is found. Otherwise returns NULL.
103         The position is the upper left corner of a free 40x40 pixels slot.
104     */
105
106     QPointF* findRandomFreeSlot();
107
108     void createMenuItems();
109     void prepareForMenu(QGraphicsItem * pItem);
110
111     const QString ghostImageFilename_;
112     const QString rockImageFilename_;
113     const QString octopusImageFilename_;
114     const QStringList shipImageFilenames_;
115
116     QList<QPointF> freeTiles_;
117
118     int ghostsLeft_;
119
120     QList<QGraphicsItem*> movingItems_;
121
122     bool paused_;
123
124     ScreenLitKeeper screenLitKeeper_;
125
126     int menuItemCount_;
127
128     QGraphicsTextItem * pPausetextItem_;
129
130     QGraphicsTextItem * pRestartLevelItem_;
131     QGraphicsTextItem * pRestartGameItem_;
132     QGraphicsTextItem * pSettingsItem_;
133     QGraphicsTextItem * pAboutItem_;
134     QGraphicsTextItem * pQuitItem_;
135     QGraphicsTextItem * pMinimizeItem_;
136
137     QGraphicsTextItem * pVictoryCongratulationsItem_;
138     QGraphicsTextItem * pAboutBoxItem_;
139
140     QList<Level> levelList_;
141
142     int currentLevel_;
143
144
145     QAction* pVibrateAction_;
146
147     QAction* pPauseAction_;
148
149     QTimer autopauseTimer;
150
151     QSystemDeviceInfo deviceInfo_;
152
153 };
154
155 #endif // SEASCENE_H