timercontrolledtursas.cpp \
seascene.cpp \
seaview.cpp \
- ship.cpp
+ ship.cpp \
+ screenlitkeeper.cpp
HEADERS += mainwindow.h \
orientationcontrolledgraphicspixmapobject.h \
timercontrolledtursas.h \
seascene.h \
seaview.h \
- ship.h
+ ship.h \
+ screenlitkeeper.h
CONFIG += mobility
MOBILITY = sensors
+MOBILITY += systeminfo
symbian {
TARGET.UID3 = 0xe3f4bbc2
pView_->setScene(pScene_);
setCentralWidget(pView_);
- QAction * pPauseAction = new QAction(tr("Pause"),this);
- pPauseAction->setCheckable(true);
- addAction(pPauseAction);
- connect(pPauseAction,SIGNAL(triggered(bool)),pScene_,SLOT(pause(bool)));
- menuBar()->addAction(pPauseAction);
+ pPauseAction_ = new QAction(tr("Pause"),this);
+ pPauseAction_->setCheckable(true);
+ addAction(pPauseAction_);
+ connect(pPauseAction_,SIGNAL(triggered(bool)),pScene_,SLOT(pause(bool)));
+ menuBar()->addAction(pPauseAction_);
QAction * pRestartLevelAction = new QAction(tr("Restart level"),this);
addAction(pRestartLevelAction);
restartLevel();
}
+
+bool MainWindow::event(QEvent *event)
+{
+
+ switch (event->type())
+ {
+ //pause if app goes to background
+ case QEvent::WindowDeactivate:
+
+ if (pScene_)
+ pScene_->pause(true);
+ break;
+
+ //un-pause if app gomes back to foreground unless it was paused before going to background
+ case QEvent::WindowActivate:
+
+
+ if (pPauseAction_ && !pPauseAction_->isChecked())
+ {
+ if (pScene_)
+ pScene_->pause(false);
+ }
+ break;
+
+ //Just to keep the compiler from complaining...
+ default:
+ break;
+
+ }
+
+
+
+ //pass the event to the ancestor for handling
+ return QMainWindow::event(event);
+
+ }
#include "orientationcontrolledgraphicspixmapobject.h"
#include "seascene.h"
+
class MainWindow : public QMainWindow
{
Q_OBJECT
MainWindow(QWidget *parent = 0);
~MainWindow();
+ bool event(QEvent *event);
+
public slots:
void initializeBoundaries();
void restartLevel();
SeaScene * pScene_;
QGraphicsView * pView_;
-
-
-
+QAction* pPauseAction_;
};
--- /dev/null
+/**************************************************************************
+ ScreenLitKeeper
+
+ Copyright (C) 2010 Heli Hyvättinen
+
+ This file is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+**************************************************************************/
+
+
+
+
+
+#include "screenlitkeeper.h"
+
+ScreenLitKeeper::ScreenLitKeeper(QObject *parent) :
+ QObject(parent)
+{
+ p_screensaver_ = NULL;
+ isKeptLit_ = false;
+}
+
+void ScreenLitKeeper::keepScreenLit(bool keepLit)
+{
+
+ //If the requested state is the same as the current state do nothing.
+ if (keepLit == isKeptLit_)
+ return;
+
+
+
+ if (keepLit == true )
+ {
+ //a new screensaver is created, parent is given so that it is automatically destroyed when this object is destroyed
+ p_screensaver_ = new QSystemScreenSaver(this);
+ //screensaver is disabled, which keeps the screen lit on N900
+ p_screensaver_->setScreenSaverInhibit();
+ isKeptLit_ = true;
+
+ }
+
+ else if (p_screensaver_ != NULL) //just to be on the safe side, it should never be NULL if this line is reached
+ {
+ delete p_screensaver_; //The object must be deleted to reverse the effect of setScreenSaverInhibit()
+ p_screensaver_ = NULL;
+ isKeptLit_ = false;
+
+ }
+
+ return;
+
+}
--- /dev/null
+/**************************************************************************
+ ScreenLitKeeper
+
+ Copyright (C) 2010 Heli Hyvättinen
+
+ This file is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+**************************************************************************/
+
+
+
+
+
+#ifndef SCREENLITKEEPER_H
+#define SCREENLITKEEPER_H
+
+#include <QObject>
+#include <QSystemScreenSaver>
+using namespace QtMobility;
+
+
+/*! Allows keeping the sreen lit by disabling the screensaver
+
+Works at least on N900.
+The sreen can be set to be kept lit or not.
+To use this class, you must have the following lines in your .pro file:
+CONFIG += mobility
+MOBILITY += systeminfo
+
+@author Heli Hyvättinen
+@date 2010-09-07
+@version 1
+
+ */
+
+class ScreenLitKeeper : public QObject
+{
+ Q_OBJECT
+public:
+ explicit ScreenLitKeeper(QObject *parent = 0);
+
+signals:
+
+public slots:
+ /*!
+Sets whether the screen is to be kept lit
+@param keepLit true for keeping lit, false for allowing blanking
+*/
+
+ void keepScreenLit(bool keepLit);
+
+private:
+ QSystemScreenSaver * p_screensaver_;
+ bool isKeptLit_;
+
+};
+
+#endif // SCREENLITKEEPER_H
QGraphicsScene(parent)
{
paused_ = false;
+ screenLitKeeper_.keepScreenLit(true);
//set background
qsrand(QTime::currentTime().msec()+2); //+2 to avoid setting it to 1
+
+
}
void SeaScene::setupMap(int ghosts, int rocks, int octopuses)
{
// qDebug() << "starting to move again";
emit pauseOff();
+ screenLitKeeper_.keepScreenLit(true);
}
else
{
// qDebug("about to stop movement");
emit pauseOn();
+ screenLitKeeper_.keepScreenLit(false);
}
}
#define SEASCENE_H
#include <QGraphicsScene>
+#include "screenlitkeeper.h"
class SeaScene : public QGraphicsScene
{
bool paused_;
+ ScreenLitKeeper screenLitKeeper_;
+