Screen keep lit when playing
authorArto Hyvättinen <arto.hyvattinen@gmail.com>
Fri, 17 Sep 2010 19:14:08 +0000 (22:14 +0300)
committerArto Hyvättinen <arto.hyvattinen@gmail.com>
Fri, 17 Sep 2010 19:14:08 +0000 (22:14 +0300)
chessclockwindow.cpp
classes/clockswidget.cpp
classes/clockswidget.h

index 5d42baa..43b64cd 100644 (file)
@@ -41,7 +41,6 @@
 #include <QStackedWidget>
 #include <QProcess>
 #include <QAction>
-#include "classes/screenlitkeeper.h"
 
 ChessClockWindow::ChessClockWindow(QWidget *parent)
     : QMainWindow(parent)
@@ -63,13 +62,9 @@ ChessClockWindow::ChessClockWindow(QWidget *parent)
 
     connect( start_, SIGNAL(selected(TimeControl*)), this, SLOT(startGame(TimeControl*)));
 
-    ScreenLitKeeper* keeper = new ScreenLitKeeper(this);
-    QAction* keepAction = new QAction( tr("Keep screen lit"), this);
-    keepAction->setCheckable(true);
-    connect( keepAction, SIGNAL(triggered(bool)), keeper, SLOT(keepScreenLit(bool)));
 
     // Set up menu
-    menuBar()->addAction( tr("Pause"), this, SLOT(pause()));
+//    menuBar()->addAction( tr("Pause"), this, SLOT(pause()));   // UNUSED - Pause button
     menuBar()->addAction( tr("New game"), this, SLOT(newGame()));
     menuBar()->addAction( keepAction );
     menuBar()->addAction( tr("Visit web page"), this, SLOT(visitWeb()));
index f1cc66c..82efa89 100644 (file)
@@ -22,6 +22,8 @@
 #include "clockswidget.h"
 #include "chessclock.h"
 
+#include "screenlitkeeper.h"
+
 #include <QLabel>
 #include <QPixmap>
 #include <QApplication>
@@ -92,6 +94,9 @@ ClocksWidget::ClocksWidget(ChessClock *white, ChessClock *black, QWidget *parent
     delayTimer_.start(); // Initial start
 
     recentX = recentY = -1;
+
+    // ScreenLitKeeper to keep screen lit when playing
+    keeper_ = new ScreenLitKeeper(this);
 }
 
 ClocksWidget::~ClocksWidget()
@@ -108,6 +113,8 @@ void ClocksWidget::pause()
         white_->pauseTurn();
         pauseLabel_->setVisible(true);
         pauseButton_->setVisible(false);
+        keeper_->keepScreenLit(false);
+
     }
     else if( status_ == BlackTurn)
     {
@@ -115,6 +122,7 @@ void ClocksWidget::pause()
         black_->pauseTurn();
         pauseLabel_->setVisible(true);
         pauseButton_->setVisible(false);
+        keeper_->keepScreenLit(false);
     }
 }
 
@@ -146,6 +154,7 @@ void ClocksWidget::mouseReleaseEvent(QMouseEvent *event)
             // Start game!
             welcomeLabel_->setVisible(false);
             pauseButton_->setVisible(true);
+            keeper_->keepScreenLit(true);
             white_->startTurn();
             status_ = WhiteTurn;
             break;
@@ -163,6 +172,7 @@ void ClocksWidget::mouseReleaseEvent(QMouseEvent *event)
             break;
         case WhitePause:
             // Continue play
+            keeper_->keepScreenLit(true);
             pauseLabel_->setVisible(false);
             pauseButton_->setVisible(true);
             white_->continueTurn();
@@ -170,6 +180,7 @@ void ClocksWidget::mouseReleaseEvent(QMouseEvent *event)
             break;
         case BlackPause:
             // Continue play
+            keeper_->keepScreenLit();
             pauseLabel_->setVisible(false);
             pauseButton_->setVisible(true);
             black_->continueTurn();
index 8df5a06..e629ab3 100644 (file)
@@ -30,6 +30,7 @@ class QVBoxLayout;
 class QLabel;
 class TurnInformation;
 class QToolButton;
+class ScreenLitKeeper;
 
 class ChessClock;
 
@@ -72,6 +73,7 @@ protected:
     QLabel* pauseLabel_;
     QLabel* welcomeLabel_;
     QToolButton* pauseButton_;
+    ScreenLitKeeper* keeper_;
 
     enum GameStatus {
         Stopped  /*! Not running */,