X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=www%2Fhtml%2Fchessclockwidget_8cpp_source.html;fp=www%2Fhtml%2Fchessclockwidget_8cpp_source.html;h=26ecad24455b354ecda0f5bc1b68cf19a182aab1;hb=ebe5873e30a11983068a087332c5046720637fd1;hp=0000000000000000000000000000000000000000;hpb=e73c22c391bf535f610f3ad49c730d7d2d46d978;p=chessclock diff --git a/www/html/chessclockwidget_8cpp_source.html b/www/html/chessclockwidget_8cpp_source.html new file mode 100644 index 0000000..26ecad2 --- /dev/null +++ b/www/html/chessclockwidget_8cpp_source.html @@ -0,0 +1,221 @@ + + + +
+ +00001 /************************************************************************** +00002 +00003 Chess Clock +00004 +00005 Copyright (c) Arto Hyvättinen 2010 +00006 +00007 This file is part of Chess Clock software. +00008 +00009 Chess Clock is free software: you can redistribute it and/or modify +00010 it under the terms of the GNU General Public License as published by +00011 the Free Software Foundation, either version 3 of the License, or +00012 (at your option) any later version. +00013 +00014 Chess Clock is distributed in the hope that it will be useful, +00015 but WITHOUT ANY WARRANTY; without even the implied warranty of +00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +00017 GNU General Public License for more details. +00018 +00019 +00020 **************************************************************************/ +00021 +00022 #include "chessclockwidget.h" +00023 +00024 #include <QLabel> +00025 #include <QFont> +00026 #include <QVBoxLayout> +00027 #include <QHBoxLayout> +00028 +00029 ChessClockWidget::ChessClockWidget(bool white, QWidget *parent) : +00030 ChessClock(white, parent) +00031 { +00032 mainLayout = new QVBoxLayout; +00033 +00034 initPictures(); +00035 initLabels(); +00036 initTop(); +00037 initBottom(); +00038 +00039 setLayout( mainLayout ); +00040 } +00041 +00042 +00043 void ChessClockWidget::initPictures() +00044 { +00045 // Load pictures from resources. +00046 if( isWhite() ) +00047 { +00048 picActive_.load(":/rc/pic/white_blue.png"); +00049 picPassive_.load(":/rc/pic/white_gray.png"); +00050 } +00051 else +00052 { +00053 picActive_.load(":/rc/pic/black_blue.png"); +00054 picPassive_.load(":/rc/pic/black_gray.png"); +00055 } +00056 picLoser_.load(":/rc/pic/loser.png"); +00057 } +00058 +00059 void ChessClockWidget::initLabels() +00060 { +00061 QFont normalFont("Helvetica",24); +00062 +00063 pictureLabel_ = new QLabel; +00064 pictureLabel_->setPixmap( picPassive_ ); +00065 +00066 timeUsedLabel_ = new QLabel; +00067 timeAverageLabel_ = new QLabel; +00068 turnLabel_=new QLabel; +00069 +00070 timeUsedLabel_->setFont(normalFont); +00071 timeAverageLabel_->setFont(normalFont); +00072 turnLabel_->setFont(normalFont); +00073 +00074 loserLabel_ = new QLabel; +00075 loserLabel_->setPixmap(picLoser_); +00076 loserLabel_->setVisible(false); +00077 +00078 } +00079 +00080 void ChessClockWidget::initTop() +00081 { +00082 QVBoxLayout* details = new QVBoxLayout(); +00083 details->addWidget(timeUsedLabel_); +00084 details->addWidget(timeAverageLabel_); +00085 details->addWidget(turnLabel_); +00086 +00087 QHBoxLayout* topLayout = new QHBoxLayout(); +00088 if( isWhite() ) +00089 { +00090 // White player +00091 // Picture | Details | .. | LOSER +00092 topLayout->addWidget( pictureLabel_ ); +00093 topLayout->addLayout( details ); +00094 topLayout->addStretch(); +00095 topLayout->addWidget(loserLabel_); +00096 } +00097 else +00098 { +00099 // Black player +00100 // LOSER | ... | Details | Picture +00101 topLayout->addWidget(loserLabel_); +00102 topLayout->addStretch(); +00103 topLayout->addLayout( details ); +00104 topLayout->addWidget( pictureLabel_ ); +00105 } +00106 mainLayout->addLayout(topLayout); +00107 } +00108 +00109 void ChessClockWidget::initBottom() +00110 { +00111 // At bottom, time left in BIG font! +00112 QFont bigfont("Helvetica",65,QFont::Bold); +00113 leftLabel_ = new QLabel("0.00.00"); +00114 leftLabel_->setFont(bigfont); +00115 // Black player: right alignment +00116 if( isWhite() ) +00117 leftLabel_->setAlignment(Qt::AlignRight | Qt::AlignVCenter); +00118 mainLayout->addWidget(leftLabel_); +00119 } +00120 +00121 void ChessClockWidget::repaintClock() +00122 { +00123 // Set picture +00124 if( getStatus() == Running ) +00125 pictureLabel_->setPixmap( picActive_); +00126 else +00127 pictureLabel_->setPixmap(picPassive_); +00128 +00129 timeUsedLabel_->setText( timeString( getTimePlayed() )); +00130 +00131 // Time average per turn +00132 int timeAverage; +00133 if( getTurn() == 0) +00134 timeAverage = 0; +00135 else +00136 timeAverage = getTimePlayed() / getTurn(); +00137 timeAverageLabel_->setText( tr("Average %1 per turn").arg( timeString( timeAverage ) ) ); +00138 +00139 turnLabel_->setText( tr("Turn %1").arg(getTurn())); +00140 +00141 // Loser flag +00142 loserLabel_->setVisible( isLoser()); +00143 +00144 leftLabel_->setText( timeString(getTimeAvailable())); +00145 +00146 } +00147 +00148 QString ChessClockWidget::timeString(int msecs) +00149 { +00150 int secs = msecs / 1000 % 60; +00151 int mins = msecs / ( 60 * 1000) % 60; +00152 int hours = msecs / ( 60 * 60 * 1000 ); +00153 if( msecs < 0) +00154 return QString(tr("<font color=red> %1:%2:%3 <font>").arg(0-hours).arg(0-mins,2,10,QChar('0')).arg(0-secs,2,10,QChar('0'))); +00155 else +00156 return QString(tr("%1:%2:%3").arg(hours).arg(mins,2,10,QChar('0')).arg(secs,2,10,QChar('0'))); +00157 +00158 } +