Distance double clicks control
authorArto Hyvättinen <arto.hyvattinen@gmail.com>
Thu, 19 Aug 2010 20:10:07 +0000 (23:10 +0300)
committerArto Hyvättinen <arto.hyvattinen@gmail.com>
Thu, 19 Aug 2010 20:10:07 +0000 (23:10 +0300)
delete old clocks only onece in starting new game.

chessclockwindow.cpp
classes/clockswidget.cpp
classes/clockswidget.h
plan/ChessClock.zargo [new file with mode: 0644]

index 7e49c0e..b30b5f3 100644 (file)
@@ -113,11 +113,7 @@ void ChessClockWindow::startGame(TimeControl *timecontrol)
     ClocksWidget* newWidget = timecontrol->initGame(false);
     if( newWidget )
     {
-        if( clocks_ )
-        {
-            stack_->removeWidget(clocks_);
-            delete clocks_;
-        }
+
         clocks_ = newWidget;
         stack_->addWidget(clocks_);
         stack_->setCurrentWidget(clocks_);
index 82cf7c3..859925f 100644 (file)
@@ -28,7 +28,8 @@
 #include <QHBoxLayout>
 #include <QVBoxLayout>
 #include <QFont>
-
+#include <cstdio>
+#include <QMouseEvent>
 
 ClocksWidget::ClocksWidget(ChessClock *white, ChessClock *black, QWidget *parent):
     QWidget(parent)
@@ -74,6 +75,8 @@ ClocksWidget::ClocksWidget(ChessClock *white, ChessClock *black, QWidget *parent
     black_->setAnother(white_);
 
     delayTimer_.start(); // Initial start
+
+    recentX = recentY = -1;
 }
 
 ClocksWidget::~ClocksWidget()
@@ -110,8 +113,16 @@ void ClocksWidget::stopPlay()
 
 void ClocksWidget::mouseReleaseEvent(QMouseEvent *event)
 {
-    if( delayTimer_.elapsed() > CLICKDELAY )  // To avoid double clicks
+
+    // To avoid double clicks
+    // a) delay (default 1,2 secs) OR
+    // b) distance more than 90 pixels in axis.
+    if( delayTimer_.elapsed() > CLICKDELAY ||
+        std::abs( event->x() - recentX ) > 90 ||
+        std::abs( event->y() - recentY ) > 90
+        )
     {
+        delayTimer_.start();    // to reset delay timer!
         switch( status_)
         {
         case Welcome :
@@ -150,6 +161,8 @@ void ClocksWidget::mouseReleaseEvent(QMouseEvent *event)
 
         }
     }
+    recentX = event->x();
+    recentY = event->y();
 }
 
 int const ClocksWidget::CLICKDELAY;
index 4f87423..d7e2ba7 100644 (file)
@@ -83,7 +83,10 @@ protected:
     GameStatus status_;
     QTime delayTimer_; /*! To avoid double clicks */
 
-    static int const CLICKDELAY = 500 ; /*! Click delay in msecs */
+    int recentX;
+    int recentY;
+
+    static int const CLICKDELAY = 1500 ; /*! Click delay in msecs */
 
 
 
diff --git a/plan/ChessClock.zargo b/plan/ChessClock.zargo
new file mode 100644 (file)
index 0000000..f68c944
Binary files /dev/null and b/plan/ChessClock.zargo differ