From ebe5873e30a11983068a087332c5046720637fd1 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Arto=20Hyv=C3=A4ttinen?=
Date: Sat, 14 Aug 2010 01:48:56 +0300
Subject: [PATCH] Added ChessClockWizard class Added simple web page
---
chessclock.pro | 9 +-
chessclock.qrc | 9 +
chessclockwindow.cpp | 6 +
classes/chessclock.cpp | 40 +-
classes/chessclock.h | 20 +-
classes/chessclockwidget.cpp | 158 ++++++++
classes/chessclockwidget.h | 82 ++++
main.cpp | 27 ++
www/html/annotated.html | 7 +-
www/html/chessclock_8cpp.html | 73 ++++
www/html/chessclock_8cpp_source.html | 198 ++++++++++
www/html/chessclock_8h.html | 75 ++++
www/html/chessclock_8h_source.html | 154 ++++++++
www/html/chessclockwidget_8cpp.html | 74 ++++
www/html/chessclockwidget_8cpp_source.html | 221 +++++++++++
www/html/chessclockwidget_8h.html | 75 ++++
www/html/chessclockwidget_8h_source.html | 132 +++++++
www/html/chessclockwindow_8cpp.html | 7 +-
www/html/chessclockwindow_8cpp_source.html | 28 +-
www/html/chessclockwindow_8h.html | 4 +-
www/html/chessclockwindow_8h_source.html | 4 +-
www/html/class_chess_clock-members.html | 86 +++++
www/html/class_chess_clock.html | 483 ++++++++++++++++++++++++
www/html/class_chess_clock.png | Bin 0 -> 452 bytes
www/html/class_chess_clock_widget-members.html | 102 +++++
www/html/class_chess_clock_widget.html | 434 +++++++++++++++++++++
www/html/class_chess_clock_widget.png | Bin 0 -> 451 bytes
www/html/class_chess_clock_window-members.html | 5 +-
www/html/class_chess_clock_window.html | 9 +-
www/html/class_turn_information-members.html | 15 +-
www/html/class_turn_information.html | 45 +--
www/html/classes.html | 9 +-
www/html/files.html | 8 +-
www/html/functions.html | 207 +++++++++-
www/html/functions_enum.html | 80 ++++
www/html/functions_eval.html | 86 +++++
www/html/functions_func.html | 140 ++++++-
www/html/functions_vars.html | 37 +-
www/html/globals.html | 4 +-
www/html/globals_func.html | 4 +-
www/html/hierarchy.html | 74 ++++
www/html/index.html | 15 +-
www/html/main_8cpp.html | 6 +-
www/html/main_8cpp_source.html | 34 +-
www/html/search/all_63.html | 54 ++-
www/html/search/all_65.html | 26 ++
www/html/search/all_67.html | 32 +-
www/html/search/all_69.html | 38 +-
www/html/search/all_6c.html | 32 ++
www/html/search/all_6d.html | 6 +
www/html/search/all_6e.html | 26 ++
www/html/search/all_70.html | 38 +-
www/html/search/all_72.html | 41 ++
www/html/search/all_73.html | 32 ++
www/html/search/all_74.html | 46 ++-
www/html/search/all_75.html | 26 ++
www/html/search/classes_63.html | 12 +-
www/html/search/enums_72.html | 26 ++
www/html/search/enumvalues_6e.html | 26 ++
www/html/search/enumvalues_70.html | 26 ++
www/html/search/enumvalues_72.html | 26 ++
www/html/search/files_63.html | 24 +-
www/html/search/functions_63.html | 20 +-
www/html/search/functions_65.html | 26 ++
www/html/search/functions_67.html | 32 +-
www/html/search/functions_69.html | 38 +-
www/html/search/functions_70.html | 26 ++
www/html/search/functions_72.html | 29 ++
www/html/search/functions_73.html | 32 ++
www/html/search/functions_74.html | 16 +-
www/html/search/functions_75.html | 26 ++
www/html/search/search.js | 12 +-
www/html/search/variables_6c.html | 32 ++
www/html/search/variables_6d.html | 26 ++
www/html/search/variables_70.html | 24 ++
www/html/search/variables_74.html | 22 +-
www/html/turninformation_8cpp.html | 6 +-
www/html/turninformation_8cpp_source.html | 37 +-
www/html/turninformation_8h.html | 4 +-
www/html/turninformation_8h_source.html | 14 +-
www/index.html | 49 +++
www/logo.png | Bin 0 -> 62826 bytes
82 files changed, 4111 insertions(+), 183 deletions(-)
create mode 100644 chessclock.qrc
create mode 100644 classes/chessclockwidget.cpp
create mode 100644 classes/chessclockwidget.h
create mode 100644 www/html/chessclock_8cpp.html
create mode 100644 www/html/chessclock_8cpp_source.html
create mode 100644 www/html/chessclock_8h.html
create mode 100644 www/html/chessclock_8h_source.html
create mode 100644 www/html/chessclockwidget_8cpp.html
create mode 100644 www/html/chessclockwidget_8cpp_source.html
create mode 100644 www/html/chessclockwidget_8h.html
create mode 100644 www/html/chessclockwidget_8h_source.html
create mode 100644 www/html/class_chess_clock-members.html
create mode 100644 www/html/class_chess_clock.html
create mode 100644 www/html/class_chess_clock.png
create mode 100644 www/html/class_chess_clock_widget-members.html
create mode 100644 www/html/class_chess_clock_widget.html
create mode 100644 www/html/class_chess_clock_widget.png
create mode 100644 www/html/functions_enum.html
create mode 100644 www/html/functions_eval.html
create mode 100644 www/html/hierarchy.html
create mode 100644 www/html/search/all_65.html
create mode 100644 www/html/search/all_6c.html
create mode 100644 www/html/search/all_6e.html
create mode 100644 www/html/search/all_72.html
create mode 100644 www/html/search/all_73.html
create mode 100644 www/html/search/all_75.html
create mode 100644 www/html/search/enums_72.html
create mode 100644 www/html/search/enumvalues_6e.html
create mode 100644 www/html/search/enumvalues_70.html
create mode 100644 www/html/search/enumvalues_72.html
create mode 100644 www/html/search/functions_65.html
create mode 100644 www/html/search/functions_70.html
create mode 100644 www/html/search/functions_72.html
create mode 100644 www/html/search/functions_73.html
create mode 100644 www/html/search/functions_75.html
create mode 100644 www/html/search/variables_6c.html
create mode 100644 www/html/search/variables_6d.html
create mode 100644 www/index.html
create mode 100644 www/logo.png
diff --git a/chessclock.pro b/chessclock.pro
index 4248040..c173879 100644
--- a/chessclock.pro
+++ b/chessclock.pro
@@ -13,11 +13,13 @@ TEMPLATE = app
SOURCES += main.cpp\
chessclockwindow.cpp \
classes/turninformation.cpp \
- classes/chessclock.cpp
+ classes/chessclock.cpp \
+ classes/chessclockwidget.cpp
HEADERS += chessclockwindow.h \
classes/turninformation.h \
- classes/chessclock.h
+ classes/chessclock.h \
+ classes/chessclockwidget.h
CONFIG += mobility
MOBILITY =
@@ -28,3 +30,6 @@ symbian {
TARGET.EPOCSTACKSIZE = 0x14000
TARGET.EPOCHEAPSIZE = 0x020000 0x800000
}
+
+RESOURCES += \
+ chessclock.qrc
diff --git a/chessclock.qrc b/chessclock.qrc
new file mode 100644
index 0000000..aefab1b
--- /dev/null
+++ b/chessclock.qrc
@@ -0,0 +1,9 @@
+
+
+ pic/black_blue.png
+ pic/black_gray.png
+ pic/loser.png
+ pic/white_blue.png
+ pic/white_gray.png
+
+
diff --git a/chessclockwindow.cpp b/chessclockwindow.cpp
index b41a893..a75cccf 100644
--- a/chessclockwindow.cpp
+++ b/chessclockwindow.cpp
@@ -21,9 +21,15 @@
#include "chessclockwindow.h"
+#include "classes/chessclockwidget.h"
+
ChessClockWindow::ChessClockWindow(QWidget *parent)
: QMainWindow(parent)
{
+
+ ChessClockWidget* widget = new ChessClockWidget(true, this);
+ setCentralWidget(widget);
+
}
ChessClockWindow::~ChessClockWindow()
diff --git a/classes/chessclock.cpp b/classes/chessclock.cpp
index d7df9d3..896f654 100644
--- a/classes/chessclock.cpp
+++ b/classes/chessclock.cpp
@@ -31,8 +31,9 @@ ChessClock::ChessClock(bool white, QWidget *parent) :
isWhite_ = white;
loser_ = false;
turn_ = 0;
- timePlayed_ = 0;
+ timePlayedBeforeTurn_ = 0;
status_ = NotRunning;
+ another_ = 0;
// Set clock timer calculating played time
clockTime_.start();
@@ -52,7 +53,7 @@ void ChessClock::startTurn()
status_=Running;
// Repaint clock
- repaintClock();
+ updateClock();
}
void ChessClock::pauseTurn()
@@ -60,7 +61,7 @@ void ChessClock::pauseTurn()
// Update turn time
currentTurn_->addTime( clockTime_.restart() );
status_ = Paused;
- repaintClock();
+ updateClock();
}
void ChessClock::continueTurn()
@@ -69,7 +70,7 @@ void ChessClock::continueTurn()
// Add pause duration to information object
currentTurn_->addPause( clockTime_.restart() );
status_ = Running;
- repaintClock();
+ updateClock();
}
@@ -78,9 +79,11 @@ TurnInformation* ChessClock::endTurn()
status_ = NotRunning;
// Update turn time
currentTurn_->addTime( clockTime_.restart());
+ // Count time played
+ timePlayedBeforeTurn_ = getTimePlayed();
// Count time available
timeAvailableBeforeTurn_ = getTimeAvailable();
- repaintClock();
+ updateClock();
// Close and return turn information
currentTurn_->turnReady(timeAvailableBeforeTurn_ );
@@ -103,3 +106,30 @@ int ChessClock::getTimeAvailable()
else
return timeAvailableBeforeTurn_;
}
+
+
+int ChessClock::getTimePlayed() const
+{
+ // Count time played time
+ if( currentTurn_ )
+ return timePlayedBeforeTurn_ + currentTurn_->getDuration();
+ else
+ return timePlayedBeforeTurn_;
+}
+
+void ChessClock::updateClock()
+{
+ // Check loser
+ if( another_ && !another_->isLoser())
+ {
+ if( getTimeAvailable() < 0 && !loser_)
+ {
+ loser_ = true;
+ emit timeOutLoser();
+ }
+
+ }
+ repaintClock();
+
+}
+
diff --git a/classes/chessclock.h b/classes/chessclock.h
index 528b58b..4504061 100644
--- a/classes/chessclock.h
+++ b/classes/chessclock.h
@@ -36,6 +36,9 @@ class TurnInformation;
Base class of chess clock.
+ ChessClock has not GUI itself, but it is subclass of QWidget
+ avoiding polymorphism.
+
*/
class ChessClock : public QWidget
{
@@ -52,6 +55,8 @@ public:
bool isLoser() const { return loser_; }
int getTurn() const { return turn_; }
+ bool isWhite() const { return isWhite_; }
+ RunningStatus getStatus() const { return status_ ; }
/*! Start new turn */
@@ -80,16 +85,23 @@ public:
@return Time available in msecs */
virtual int getTimeAvailable();
+ /*! Get total time played
+ @return Time played in msecs */
+ virtual int getTimePlayed() const;
+
+
signals:
- void timeOut();
+ void timeOutLoser();
public slots:
/*! Refresh clock information */
virtual void repaintClock() = 0;
+ /*! Update clock information, check looser state and refresh */
+ virtual void updateClock();
-protected:
+private:
ChessClock* another_; /*! Another player's clock */
bool loser_; /*! Is player losed because of timeout */
@@ -97,8 +109,8 @@ protected:
RunningStatus status_;
TurnInformation* currentTurn_;
- int timePlayed_; /*! Time played in this game */
- int timeAvailableBeforeTurn_; /*! Time available for play BEFORE this turn!*/
+ int timePlayedBeforeTurn_; /*! Time played in this game BEFORE this turn msecs */
+ int timeAvailableBeforeTurn_; /*! Time available for play BEFORE this turn msecs !*/
bool isWhite_; /*! True if white player */
diff --git a/classes/chessclockwidget.cpp b/classes/chessclockwidget.cpp
new file mode 100644
index 0000000..6dbcc8a
--- /dev/null
+++ b/classes/chessclockwidget.cpp
@@ -0,0 +1,158 @@
+ /**************************************************************************
+
+ Chess Clock
+
+ Copyright (c) Arto Hyvättinen 2010
+
+ This file is part of Chess Clock software.
+
+ Chess Clock 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.
+
+ Chess Clock 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.
+
+
+**************************************************************************/
+
+#include "chessclockwidget.h"
+
+#include
+#include
+#include
+#include
+
+ChessClockWidget::ChessClockWidget(bool white, QWidget *parent) :
+ ChessClock(white, parent)
+{
+ mainLayout = new QVBoxLayout;
+
+ initPictures();
+ initLabels();
+ initTop();
+ initBottom();
+
+ setLayout( mainLayout );
+}
+
+
+void ChessClockWidget::initPictures()
+{
+ // Load pictures from resources.
+ if( isWhite() )
+ {
+ picActive_.load(":/rc/pic/white_blue.png");
+ picPassive_.load(":/rc/pic/white_gray.png");
+ }
+ else
+ {
+ picActive_.load(":/rc/pic/black_blue.png");
+ picPassive_.load(":/rc/pic/black_gray.png");
+ }
+ picLoser_.load(":/rc/pic/loser.png");
+}
+
+void ChessClockWidget::initLabels()
+{
+ QFont normalFont("Helvetica",24);
+
+ pictureLabel_ = new QLabel;
+ pictureLabel_->setPixmap( picPassive_ );
+
+ timeUsedLabel_ = new QLabel;
+ timeAverageLabel_ = new QLabel;
+ turnLabel_=new QLabel;
+
+ timeUsedLabel_->setFont(normalFont);
+ timeAverageLabel_->setFont(normalFont);
+ turnLabel_->setFont(normalFont);
+
+ loserLabel_ = new QLabel;
+ loserLabel_->setPixmap(picLoser_);
+ loserLabel_->setVisible(false);
+
+}
+
+void ChessClockWidget::initTop()
+{
+ QVBoxLayout* details = new QVBoxLayout();
+ details->addWidget(timeUsedLabel_);
+ details->addWidget(timeAverageLabel_);
+ details->addWidget(turnLabel_);
+
+ QHBoxLayout* topLayout = new QHBoxLayout();
+ if( isWhite() )
+ {
+ // White player
+ // Picture | Details | .. | LOSER
+ topLayout->addWidget( pictureLabel_ );
+ topLayout->addLayout( details );
+ topLayout->addStretch();
+ topLayout->addWidget(loserLabel_);
+ }
+ else
+ {
+ // Black player
+ // LOSER | ... | Details | Picture
+ topLayout->addWidget(loserLabel_);
+ topLayout->addStretch();
+ topLayout->addLayout( details );
+ topLayout->addWidget( pictureLabel_ );
+ }
+ mainLayout->addLayout(topLayout);
+}
+
+void ChessClockWidget::initBottom()
+{
+ // At bottom, time left in BIG font!
+ QFont bigfont("Helvetica",65,QFont::Bold);
+ leftLabel_ = new QLabel("0.00.00");
+ leftLabel_->setFont(bigfont);
+ // Black player: right alignment
+ if( isWhite() )
+ leftLabel_->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
+ mainLayout->addWidget(leftLabel_);
+}
+
+void ChessClockWidget::repaintClock()
+{
+ // Set picture
+ if( getStatus() == Running )
+ pictureLabel_->setPixmap( picActive_);
+ else
+ pictureLabel_->setPixmap(picPassive_);
+
+ timeUsedLabel_->setText( timeString( getTimePlayed() ));
+
+ // Time average per turn
+ int timeAverage;
+ if( getTurn() == 0)
+ timeAverage = 0;
+ else
+ timeAverage = getTimePlayed() / getTurn();
+ timeAverageLabel_->setText( tr("Average %1 per turn").arg( timeString( timeAverage ) ) );
+
+ turnLabel_->setText( tr("Turn %1").arg(getTurn()));
+
+ // Loser flag
+ loserLabel_->setVisible( isLoser());
+
+ leftLabel_->setText( timeString(getTimeAvailable()));
+
+}
+
+QString ChessClockWidget::timeString(int msecs)
+{
+ int secs = msecs / 1000 % 60;
+ int mins = msecs / ( 60 * 1000) % 60;
+ int hours = msecs / ( 60 * 60 * 1000 );
+ if( msecs < 0)
+ return QString(tr(" %1:%2:%3 ").arg(0-hours).arg(0-mins,2,10,QChar('0')).arg(0-secs,2,10,QChar('0')));
+ else
+ return QString(tr("%1:%2:%3").arg(hours).arg(mins,2,10,QChar('0')).arg(secs,2,10,QChar('0')));
+
+}
diff --git a/classes/chessclockwidget.h b/classes/chessclockwidget.h
new file mode 100644
index 0000000..8de2136
--- /dev/null
+++ b/classes/chessclockwidget.h
@@ -0,0 +1,82 @@
+ /**************************************************************************
+
+ Chess Clock
+
+ Copyright (c) Arto Hyvättinen 2010
+
+ This file is part of Chess Clock software.
+
+ Chess Clock 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.
+
+ Chess Clock 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.
+
+
+**************************************************************************/
+
+#ifndef CHESSCLOCKWIDGET_H
+#define CHESSCLOCKWIDGET_H
+
+#include "chessclock.h"
+#include
+#include
+
+class QVBoxLayout;
+class QLabel;
+
+/*! Simple chess clock widget
+
+ @author Arto Hyvättinen
+ @date 2010-08-14
+
+
+ */
+class ChessClockWidget : public ChessClock
+{
+ Q_OBJECT
+public:
+ ChessClockWidget(bool white, QWidget *parent = 0);
+
+signals:
+
+public slots:
+ virtual void repaintClock();
+
+protected:
+ /*! Init pictures from resources */
+ virtual void initPictures();
+ /*! Init QLabels */
+ virtual void initLabels();
+ /*! Init top: picture, details, loser mark */
+ virtual void initTop();
+ /*! Init time left in bottom.
+ Override to make different bottom area */
+ virtual void initBottom();
+
+ /*! Convert msecs to h:mm:ss QString */
+ QString timeString(int msecs);
+
+protected:
+
+ QPixmap picActive_;
+ QPixmap picPassive_;
+ QPixmap picLoser_;
+
+ QLabel* pictureLabel_;
+ QLabel* timeUsedLabel_;
+ QLabel* timeAverageLabel_;
+ QLabel* turnLabel_;
+ QLabel* loserLabel_;
+ QLabel* leftLabel_;
+
+ QVBoxLayout* mainLayout;
+
+
+};
+
+#endif // CHESSCLOCKWIDGET_H
diff --git a/main.cpp b/main.cpp
index 213ff2b..e369fe1 100644
--- a/main.cpp
+++ b/main.cpp
@@ -20,6 +20,33 @@
**************************************************************************/
+/*! @mainpage Chess Clock
+
+ @author Arto Hyvättinen
+ @version 0.1.0
+
+
+ Chess Clock
+
+ Game clock for chess players with N900. Support many game controls.
+
+ Copyright © Arto Hyvättinen 2010
+
+ Chess Clock 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.
+
+ Chess Clock 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.
+
+
+
+ */
+
+
#include
#include "chessclockwindow.h"
diff --git a/www/html/annotated.html b/www/html/annotated.html
index 5817ec8..a9a8e61 100644
--- a/www/html/annotated.html
+++ b/www/html/annotated.html
@@ -38,12 +38,15 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
Class List
Here are the classes, structs, unions and interfaces with brief descriptions:
@@ -53,7 +56,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
-
All Classes Files Functions Variables
+ All Classes Files Functions Variables Enumerations Enumerator
@@ -62,7 +65,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
-Generated on Fri Aug 13 22:27:27 2010 for Chess Clock by
+Generated on Sat Aug 14 01:28:48 2010 for Chess Clock by
1.6.3
+
+
+
+
+
/holvi/arto/ohjelmointi/ChessClock/chessclock/classes/chessclock.cpp File Reference
#include "chessclock.h"
+
#include <QWidget>
+
#include <QTime>
+
#include <QTimer>
+
+
Go to the source code of this file.
+
+
+
+
+
+
+
+
+
+
+Generated on Sat Aug 14 01:28:48 2010 for Chess Clock by
+
+ 1.6.3
+
diff --git a/www/html/chessclock_8cpp.html b/www/html/chessclock_8cpp.html
new file mode 100644
index 0000000..e0802cd
--- /dev/null
+++ b/www/html/chessclock_8cpp.html
@@ -0,0 +1,73 @@
+
+
+
+