From 68065f13ba6822e925601a0614e4c2c1c286ae91 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Heli=20Hyv=C3=A4ttinen?= Date: Fri, 26 Aug 2011 22:13:36 +0300 Subject: [PATCH] Work towards pause on swipeout C++ detects swipeout, but QML does not get it --- chessclock.pro | 6 ++++-- chessclockview.cpp | 34 ++++++++++++++++++++++++++++++++++ chessclockview.h | 20 ++++++++++++++++++++ main.cpp | 3 ++- qml/ClocksPage.qml | 11 +++++++++++ 5 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 chessclockview.cpp create mode 100644 chessclockview.h diff --git a/chessclock.pro b/chessclock.pro index 97deea2..c887210 100644 --- a/chessclock.pro +++ b/chessclock.pro @@ -43,7 +43,8 @@ SOURCES += main.cpp \ classes/timecontrol/hourglassclock.cpp \ classes/timecontrol/hourglasstimecontrol.cpp \ classes/screenlitkeeper.cpp \ - classes/wrappedclockswidget.cpp + classes/wrappedclockswidget.cpp \ + chessclockview.cpp HEADERS += chessclockwindow.h \ classes/turninformation.h \ @@ -66,7 +67,8 @@ HEADERS += chessclockwindow.h \ classes/timecontrol/hourglasstimecontrol.h \ classes/timecontrol/hourglassclock.h \ classes/screenlitkeeper.h \ - classes/wrappedclockswidget.h + classes/wrappedclockswidget.h \ + chessclockview.h OTHER_FILES += \ diff --git a/chessclockview.cpp b/chessclockview.cpp new file mode 100644 index 0000000..7e07520 --- /dev/null +++ b/chessclockview.cpp @@ -0,0 +1,34 @@ +#include "chessclockview.h" +#include +#include + +ChessClockView::ChessClockView(QWidget *parent) : + QDeclarativeView(parent) +{ +} + +bool ChessClockView::event(QEvent *event) +{ + + if (event->type() == QEvent::WindowDeactivate) + { + QDeclarativeContext * pContext = rootContext(); + if (pContext) + { + pContext->setContextProperty("clocksPage.applicationActive", false); + qDebug() << "Window deactivated"; + } + } + + else if (event->type() == QEvent::WindowActivate) + { + QDeclarativeContext * pContext = rootContext(); + if (pContext) + { + pContext->setContextProperty("clocksPage.applicationActive", true); + } + } + + + return QDeclarativeView::event(event); +} diff --git a/chessclockview.h b/chessclockview.h new file mode 100644 index 0000000..b35cb0d --- /dev/null +++ b/chessclockview.h @@ -0,0 +1,20 @@ +#ifndef CHESSCLOCKVIEW_H +#define CHESSCLOCKVIEW_H + +#include + +class ChessClockView : public QDeclarativeView +{ + Q_OBJECT +public: + explicit ChessClockView(QWidget *parent = 0); + + bool event (QEvent *event); + +signals: + +public slots: + +}; + +#endif // CHESSCLOCKVIEW_H diff --git a/main.cpp b/main.cpp index c58099f..353cc34 100644 --- a/main.cpp +++ b/main.cpp @@ -22,6 +22,7 @@ #include #include #include "classes/wrappedclockswidget.h" +#include "chessclockview.h" Q_DECL_EXPORT int main(int argc, char *argv[]) @@ -31,7 +32,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) qmlRegisterType("ChessClocks", 1, 0, "WrappedClocksWidget"); - QDeclarativeView view; + ChessClockView view; view.setSource(QUrl("qrc:/qml/main.qml")); view.showFullScreen(); return app.exec(); diff --git a/qml/ClocksPage.qml b/qml/ClocksPage.qml index ed046ee..52a3a87 100644 --- a/qml/ClocksPage.qml +++ b/qml/ClocksPage.qml @@ -30,6 +30,8 @@ Page { id: clocksPage + property bool applicationActive: true //This is supposed to be set from C++ + property int timeControl //properties cannot be declared as enumerations in QML //...must be a valid enum from WrappedClocksWidget property int whiteInitialTime @@ -47,6 +49,13 @@ Page wrappedClocksWidget.startGame(timeControl,whiteInitialTime,whiteAdditionalTime,whiteTurnsPerAddition,blackInitialTime,blackAdditionalTime,blackTurnsPerAddition) } + onApplicationActiveChanged: + { + if (applicationActive == false) + wrappedClocksWidget.pause() + + + } tools: ToolBarLayout @@ -71,6 +80,8 @@ Page } Item{} //placeholder needed to put pause button in the middle + + } -- 1.7.9.5