X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=www%2Fhtml%2Fclockswidget_8cpp_source.html;fp=www%2Fhtml%2Fclockswidget_8cpp_source.html;h=705cc8989e499078c8d6d35ed41b85f6b447b14f;hb=152fa893f072373a21c125340ce9072a73503a54;hp=0a7e68487916186f5c296ea1303cd2309db66d20;hpb=8e60d556e00dbb7e86f2425605cf1b0a688a69e9;p=chessclock diff --git a/www/html/clockswidget_8cpp_source.html b/www/html/clockswidget_8cpp_source.html index 0a7e684..705cc89 100644 --- a/www/html/clockswidget_8cpp_source.html +++ b/www/html/clockswidget_8cpp_source.html @@ -66,137 +66,207 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); 00022 #include "clockswidget.h" 00023 #include "chessclock.h" 00024 -00025 #include <QLabel> -00026 #include <QPixmap> -00027 #include <QApplication> -00028 #include <QHBoxLayout> -00029 #include <QVBoxLayout> -00030 #include <QFont> -00031 -00032 -00033 ClocksWidget::ClocksWidget(ChessClock *white, ChessClock *black, QWidget *parent): -00034 QWidget(parent) -00035 { -00036 // Set up clocks -00037 white_ = white; -00038 black_ = black; -00039 -00040 // SET UP UI -00041 // Make layout for clocks -00042 QHBoxLayout* clockLayout = new QHBoxLayout; -00043 clockLayout->addWidget(white_ ); -00044 clockLayout->addWidget( black_ ); +00025 #include "screenlitkeeper.h" +00026 +00027 #include <QLabel> +00028 #include <QPixmap> +00029 #include <QApplication> +00030 #include <QHBoxLayout> +00031 #include <QVBoxLayout> +00032 #include <QFont> +00033 #include <cstdlib> +00034 #include <QMouseEvent> +00035 #include <QToolButton> +00036 #include <QSize> +00037 #include <QWidget> +00038 +00039 ClocksWidget::ClocksWidget(ChessClock *white, ChessClock *black, QWidget *parent): +00040 QWidget(parent) +00041 { +00042 // Set up clocks +00043 white_ = white; +00044 black_ = black; 00045 -00046 // Pause information label -00047 pauseLabel_ = new QLabel( tr("<font color=yellow>Paused. Touch to continue.</font>")); -00048 pauseLabel_->setFont( QFont("Helvetica",25)); -00049 pauseLabel_->setAlignment( Qt::AlignCenter); -00050 pauseLabel_->setVisible( false ); +00046 // SET UP UI +00047 // Make layout for clocks +00048 QHBoxLayout* clockLayout = new QHBoxLayout; +00049 clockLayout->addWidget(white_ ); +00050 clockLayout->addWidget( black_ ); 00051 -00052 // Welcome label for first touch -00053 welcomeLabel_ = new QLabel( tr("<font color=green>Welcome! Please touch to start game.<br>" -00054 "Then touch to end turn.</font>")); -00055 welcomeLabel_->setFont( QFont("Helvetica",25)); -00056 welcomeLabel_->setAlignment( Qt::AlignCenter); -00057 welcomeLabel_->setVisible( true ); // Show welcome message -00058 -00059 // Put all in layout -00060 QVBoxLayout* mainLayout = new QVBoxLayout; -00061 mainLayout->addLayout(clockLayout); -00062 mainLayout->addWidget(pauseLabel_); -00063 mainLayout->addWidget(welcomeLabel_); +00052 // Pause information label +00053 pauseLabel_ = new QLabel( tr("<font color=yellow>Paused. Touch to continue.</font>"),this); +00054 pauseLabel_->setFont( QFont("Helvetica",25)); +00055 pauseLabel_->setAlignment( Qt::AlignCenter); +00056 pauseLabel_->setVisible( false ); +00057 +00058 // Welcome label for first touch +00059 welcomeLabel_ = new QLabel( tr("<font color=green>Welcome! Please touch to start game.<br>" +00060 "Then touch to end turn.</font>"),this); +00061 welcomeLabel_->setFont( QFont("Helvetica",25)); +00062 welcomeLabel_->setAlignment( Qt::AlignCenter); +00063 welcomeLabel_->setVisible( true ); // Show welcome message 00064 -00065 setLayout( mainLayout); -00066 status_ = Welcome; -00067 -00068 // First paint -00069 white_->repaintClock(); -00070 black_->repaintClock(); +00065 // Pause button +00066 pauseButton_ = new QToolButton; +00067 pauseButton_->setIcon( QIcon(":/rc/pic/pausebutton.png")); +00068 pauseButton_->setIconSize(QSize(75,75)); +00069 connect(pauseButton_, SIGNAL(clicked()), this, SLOT(pause())); +00070 pauseButton_->setVisible(false); 00071 -00072 // Set up others -00073 white_->setAnother(black_); -00074 black_->setAnother(white_); +00072 // Put all in layout +00073 QVBoxLayout* mainLayout = new QVBoxLayout; +00074 mainLayout->addLayout(clockLayout); 00075 -00076 delayTimer_.start(); // Initial start -00077 } -00078 -00079 ClocksWidget::~ClocksWidget() -00080 { -00081 delete white_; -00082 delete black_; -00083 } -00084 -00085 void ClocksWidget::pause() -00086 { -00087 if(status_ == WhiteTurn) -00088 { -00089 status_= WhitePause; -00090 white_->pauseTurn(); -00091 pauseLabel_->setVisible(true); -00092 } -00093 else if( status_ == BlackTurn) -00094 { -00095 status_ = BlackPause; -00096 black_->pauseTurn(); -00097 pauseLabel_->setVisible(true); -00098 } -00099 } -00100 -00101 void ClocksWidget::stopPlay() -00102 { -00103 if( status_ == BlackTurn || status_ == BlackPause ) -00104 emit TurnFinished( black_->endTurn()); -00105 else if( status_ == WhiteTurn || status_ == WhitePause ) -00106 emit TurnFinished( white_->endTurn()); -00107 status_ = Stopped; -00108 } +00076 // Extra layout and widget for information +00077 QVBoxLayout* extraLayout = new QVBoxLayout; +00078 extraLayout->addWidget(pauseLabel_); +00079 extraLayout->addWidget(welcomeLabel_); +00080 +00081 QHBoxLayout* pbLayout = new QHBoxLayout; +00082 pbLayout->addStretch(); +00083 pbLayout->addWidget(pauseButton_); +00084 pbLayout->addStretch(); +00085 extraLayout->addLayout(pbLayout); +00086 +00087 QWidget* extraWidget = new QWidget(this); +00088 extraWidget->setLayout(extraLayout); +00089 // Some fun event filtering to grap clicking welcome and pause labels... +00090 extraWidget->installEventFilter(this); +00091 pauseLabel_->installEventFilter(this); +00092 welcomeLabel_->installEventFilter(this); +00093 +00094 mainLayout->addWidget(extraWidget); +00095 setLayout( mainLayout); +00096 status_ = Welcome; +00097 +00098 // First paint +00099 white_->repaintClock(); +00100 black_->repaintClock(); +00101 +00102 // Set up others +00103 white_->setAnother(black_); +00104 black_->setAnother(white_); +00105 +00106 delayTimer_.start(); // Initial start +00107 +00108 recentX = recentY = -1; 00109 -00110 -00111 void ClocksWidget::mouseReleaseEvent(QMouseEvent *event) -00112 { -00113 if( delayTimer_.elapsed() > CLICKDELAY ) // To avoid double clicks -00114 { -00115 switch( status_) -00116 { -00117 case Welcome : -00118 // Start game! -00119 welcomeLabel_->setVisible(false); -00120 white_->startTurn(); -00121 status_ = WhiteTurn; -00122 break; -00123 case WhiteTurn: -00124 // White turn finished, then black -00125 emit TurnFinished( white_->endTurn()); -00126 black_->startTurn(); -00127 status_=BlackTurn; -00128 break; -00129 case BlackTurn: -00130 // Black finished, then white -00131 emit TurnFinished( black_->endTurn()); -00132 white_->startTurn(); -00133 status_=WhiteTurn; -00134 break; -00135 case WhitePause: -00136 // Continue play -00137 pauseLabel_->setVisible(false); -00138 white_->continueTurn(); -00139 status_=WhiteTurn; -00140 break; -00141 case BlackPause: -00142 // Continue play -00143 pauseLabel_->setVisible(false); -00144 black_->continueTurn(); -00145 status_=BlackTurn; -00146 break; -00147 case Stopped: -00148 emit ClickedWhenStopped(); +00110 // ScreenLitKeeper to keep screen lit when playing +00111 keeper_ = new ScreenLitKeeper(this); +00112 } +00113 +00114 ClocksWidget::~ClocksWidget() +00115 { +00116 delete white_; +00117 delete black_; +00118 } +00119 +00120 void ClocksWidget::pause() +00121 { +00122 if(status_ == WhiteTurn) +00123 { +00124 status_= WhitePause; +00125 white_->pauseTurn(); +00126 pauseLabel_->setVisible(true); +00127 pauseButton_->setVisible(false); +00128 keeper_->keepScreenLit(false); +00129 +00130 } +00131 else if( status_ == BlackTurn) +00132 { +00133 status_ = BlackPause; +00134 black_->pauseTurn(); +00135 pauseLabel_->setVisible(true); +00136 pauseButton_->setVisible(false); +00137 keeper_->keepScreenLit(false); +00138 } +00139 } +00140 +00141 void ClocksWidget::stopPlay() +00142 { +00143 if( status_ == BlackTurn || status_ == BlackPause ) +00144 emit TurnFinished( black_->endTurn()); +00145 else if( status_ == WhiteTurn || status_ == WhitePause ) +00146 emit TurnFinished( white_->endTurn()); +00147 status_ = Stopped; +00148 } 00149 00150 -00151 } -00152 } -00153 } -00154 -00155 int const ClocksWidget::CLICKDELAY; +00151 void ClocksWidget::mouseReleaseEvent(QMouseEvent *event) +00152 { +00153 +00154 // To avoid double clicks +00155 // a) delay (default 1,2 secs) OR +00156 // b) distance more than 90 pixels in axis. +00157 if( delayTimer_.elapsed() > CLICKDELAY || +00158 std::abs( event->x() - recentX ) > 90 || +00159 std::abs( event->y() - recentY ) > 90 +00160 ) +00161 { +00162 delayTimer_.start(); // to reset delay timer! +00163 switch( status_) +00164 { +00165 case Welcome : +00166 // Start game! +00167 welcomeLabel_->setVisible(false); +00168 pauseButton_->setVisible(true); +00169 keeper_->keepScreenLit(true); +00170 white_->startTurn(); +00171 status_ = WhiteTurn; +00172 break; +00173 case WhiteTurn: +00174 // White turn finished, then black +00175 emit TurnFinished( white_->endTurn()); +00176 black_->startTurn(); +00177 status_=BlackTurn; +00178 break; +00179 case BlackTurn: +00180 // Black finished, then white +00181 emit TurnFinished( black_->endTurn()); +00182 white_->startTurn(); +00183 status_=WhiteTurn; +00184 break; +00185 case WhitePause: +00186 // Continue play +00187 keeper_->keepScreenLit(true); +00188 pauseLabel_->setVisible(false); +00189 pauseButton_->setVisible(true); +00190 white_->continueTurn(); +00191 status_=WhiteTurn; +00192 break; +00193 case BlackPause: +00194 // Continue play +00195 keeper_->keepScreenLit(false); +00196 pauseLabel_->setVisible(false); +00197 pauseButton_->setVisible(true); +00198 black_->continueTurn(); +00199 status_=BlackTurn; +00200 break; +00201 case Stopped: +00202 emit ClickedWhenStopped(); +00203 +00204 +00205 } +00206 } +00207 recentX = event->x(); +00208 recentY = event->y(); +00209 } +00210 +00211 // to grap clicking pause or welcome label +00212 bool ClocksWidget::eventFilter(QObject *obj, QEvent *event) +00213 { +00214 if (event->type() == QEvent::MouseButtonRelease) { +00215 QMouseEvent *mEvent = static_cast<QMouseEvent *>(event); +00216 mouseReleaseEvent( mEvent ); +00217 return true; +00218 } else { +00219 // standard event processing +00220 return QObject::eventFilter(obj, event); +00221 } +00222 } +00223 +00224 +00225 int const ClocksWidget::CLICKDELAY;
-
Generated on Thu Aug 19 21:04:20 2010 for Chess Clock by  +
Generated on Mon Sep 27 18:30:33 2010 for Chess Clock by  doxygen 1.6.3