Debian Codegraph @

src/board/boardwindow.cpp

raw symbols SCIP
1 /***************************************************************************
2 * Copyright (C) 2009 by The qGo Project *
3 * *
4 * This file is part of qGo. *
5 * *
6 * qGo is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, see <http://www.gnu.org/licenses/> *
18 * or write to the Free Software Foundation, Inc., *
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 ***************************************************************************/
21
22 #include "boardwindow.h"
23 #include "board.h"
24 #include "clockdisplay.h"
25 #include "qgoboard.h"
26 #include "qgoboard_net.h"
27 #include "qgoboardlocalinterface.h"
28 #include "move.h"
29 #include "tree.h"
30 #include "boarddispatch.h"
31 #include "gameinfo.h"
32 #include "matrix.h"
33 #include "ui_boardwindow.h"
34 #include <QtWidgets>
35
36 class BoardHandler;
37
38 BoardWindow::BoardWindow(GameData *gd, bool iAmBlack , bool iAmWhite, class BoardDispatch * _dispatch)
39 : QMainWindow(0, 0), ui(new Ui::BoardWindow), addtime_menu(0), boardSize(gd->board_size)
40 {
41 ui->setupUi(this);
42
43 if(gd != NULL)
44 {
45 gameData = gd;
46 } else {
47 gameData = new GameData();
48 gameData->gameMode = modeEdit;
49 }
50
51 dispatch = _dispatch;
52
53 if(gameData->nigiriToBeSettled)
54 {
55 myColorIsBlack = false;
56 myColorIsWhite = false;
57 }
58 else
59 {
60 myColorIsBlack = iAmBlack;
61 myColorIsWhite = iAmWhite;
62 }
63
64 gamePhase = phaseInit;
65
66 //Creates the game tree
67 tree = new Tree(boardSize, gameData->komi);
68
69 //Loads the sgf file if any
70 if (! gameData->fileName.isEmpty())
71 tree->importSGFFile(gameData->fileName);
72
73 QSettings settings;
74 ui->actionWhatsThis = QWhatsThis::createAction ();
75
76 moveNumLabel = new QLabel(ui->statusbar);
77 komiLabel = new QLabel(ui->statusbar);
78 buyoyomiLabel = new QLabel(ui->statusbar);
79 handicapLabel = new QLabel(ui->statusbar);
80 freeratedLabel = new QLabel(ui->statusbar);
81 ui->statusbar->addPermanentWidget(moveNumLabel);
82 ui->statusbar->addPermanentWidget(handicapLabel);
83 ui->statusbar->addPermanentWidget(komiLabel);
84 ui->statusbar->addPermanentWidget(buyoyomiLabel);
85 ui->statusbar->addPermanentWidget(freeratedLabel);
86
87 // Initialises the buttons and else
88 editButtons = new QButtonGroup(this);
89 editButtons->addButton(ui->stoneButton, 0);
90 editButtons->addButton(ui->squareButton, 1);
91 editButtons->addButton(ui->circleButton, 2);
92 editButtons->addButton(ui->triangleButton, 3);
93 editButtons->addButton(ui->crossButton, 4);
94 editButtons->addButton(ui->labelLetterButton, 5);
95 editButtons->addButton(ui->labelNumberButton, 6);
96 editButtons->addButton(ui->colorButton, 7);
97 editButtons->setExclusive(false);
98
99
100 QMenu *menu = new QMenu();
101 // menu->insertAction(0,ui->fileExportASCII);
102 menu->insertAction(0,ui->actionExportSgfClipB);
103 menu->insertAction(0,ui->actionExportPic);
104 menu->insertAction(0,ui->actionExportPicClipB);
105
106 ui->actionExport->setMenu(menu);
107
108 QToolButton *exportButton = new QToolButton();
109 exportButton->setDefaultAction(ui->actionExport);
110
111 exportButton->setPopupMode( QToolButton::InstantPopup);
112 ui->toolBar->insertWidget ( ui->actionImport, exportButton );
113
114 clockDisplay = new ClockDisplay(this, gameData->timeSystem, gameData->maintime, gameData->stones_periods, gameData->periodtime);
115
116 if(dispatch && dispatch->flipCoords())
117 ui->board->setCoordType(numberbottomi);
118 else
119 ui->board->setCoordType(numbertopnoi);
120 ui->board->init(boardSize);
121
122 setMode(gameData->gameMode);
123 updateCaption();
124
125 int window_x, window_y;
126 QVariant board_window_size_x = settings.value("BOARD_WINDOW_SIZE_X");
127 if(board_window_size_x != QVariant())
128 {
129 window_x = board_window_size_x.toInt();
130 window_y = settings.value("BOARD_WINDOW_SIZE_Y").toInt();
131 resize(window_x, window_y);
132 }
133
134 // Connects the nav buttons to the slots
135 connect(ui->actionNext_move,&QAction::triggered,tree,&Tree::slotNavForward);
136 connect(ui->actionPrevious_move,&QAction::triggered,tree,&Tree::slotNavBackward);
137 connect(ui->actionFirst_move,&QAction::triggered,tree,&Tree::slotNavFirst);
138 connect(ui->actionLast_move,&QAction::triggered,tree,&Tree::slotNavLast);
139 connect(ui->actionPrevious_variation,&QAction::triggered,tree,&Tree::slotNavPrevVar);
140 connect(ui->actionNext_variation,&QAction::triggered,tree,&Tree::slotNavNextVar);
141 connect(ui->actionFind_move,&QAction::triggered,this,&BoardWindow::slotNavIntersection);
142 connect(ui->actionMain_branch,&QAction::triggered,tree,&Tree::slotNavMainBranch);
143 connect(ui->actionPrevious_comment,&QAction::triggered,tree,&Tree::slotNavPrevComment);
144 connect(ui->actionNext_comment,&QAction::triggered,tree,&Tree::slotNavNextComment);
145 connect(ui->slider, &QSlider::sliderMoved, tree , &Tree::slotNthMove);
146
147 wheelTime = QTime::currentTime();
148 connect(ui->board, &Board::signalWheelEvent, this, &BoardWindow::slotWheelEvent);
149
150
151 //Connects the 'edit' buttons to the slots
152 connect(editButtons, QOverload<int>::of(&QButtonGroup::buttonPressed), this, &BoardWindow::slotEditButtonPressed);
153 connect(ui->deleteButton, &QPushButton::pressed, this, &BoardWindow::slotEditDelete);
154 connect(ui->actionCoordinates, &QAction::toggled, ui->board, &Board::setShowCoords);
155 connect(ui->actionFileSave, &QAction::triggered, this, &BoardWindow::slotFileSave);
156 connect(ui->actionFileSaveAs, &QAction::triggered, this, &BoardWindow::slotFileSaveAs);
157 connect(ui->actionExportSgfClipB, &QAction::triggered, this, &BoardWindow::slotExportSGFtoClipB);
158 connect(ui->actionExportPicClipB, &QAction::triggered, this, &BoardWindow::slotExportPicClipB);
159 connect(ui->actionExportPic, &QAction::triggered, this, &BoardWindow::slotExportPic);
160 connect(ui->actionDuplicate, &QAction::triggered, this, &BoardWindow::slotDuplicate);
161 connect(ui->actionGameInfo, &QAction::triggered, this, &BoardWindow::slotGameInfo);
162
163 connect(tree, &Tree::currentMoveChanged, this, &BoardWindow::updateMove);
164 connect(tree, &Tree::scoreChanged, this, &BoardWindow::slotGetScore);
165
166 connect(ui->buttonModeEdit, &QPushButton::clicked, this, &BoardWindow::switchToEditMode);
167 connect(ui->buttonModeLocal, &QPushButton::clicked, this, &BoardWindow::switchToLocalMode);
168
169 ui->insertMoveButton->setChecked(false);
170 ui->insertMoveButton->setEnabled(gameData->gameMode == modeEdit);
171 if(gameData->gameMode == modeMatch /* or teaching? */ && dispatch && dispatch->supportsAddTime())
172 {
173 addtime_menu = new QMenu();
174 QAction * act = addtime_menu->addAction(tr("Add 1 min"));
175 act->setData(1);
176 act = addtime_menu->addAction(tr("Add 5 min"));
177 act->setData(5);
178 act = addtime_menu->addAction(tr("Add 10 min"));
179 act->setData(10);
180 act = addtime_menu->addAction(tr("Add 60 min"));
181 act->setData(60);
182 act = addtime_menu->addAction(tr("Cancel"));
183 act->setData(-1);
184
185 /* Right now, IGS is the only server with addtime, but if nigiri is done in another order
186 * this will have to be moved elsewhere: */
187 if(!gameData->nigiriToBeSettled)
188 {
189 if(myColorIsBlack)
190 {
191 ui->pb_timeWhite->setMenu(addtime_menu);
192 }
193 else if(myColorIsWhite)
194 {
195 ui->pb_timeBlack->setMenu(addtime_menu);
196 }
197 else
198 qDebug("Warning: Nigiri settled in match mode but player has no color");
199 connect(addtime_menu, &QMenu::triggered, this, &BoardWindow::slot_addtime_menu);
200 }
201 }
202
203 //connects the comments and edit line to the slots
204 connect(ui->commentEdit, &QTextEdit::textChanged, this, &BoardWindow::slotUpdateComment);
205 connect(ui->commentEdit2, &QLineEdit::returnPressed, this, &BoardWindow::slotSendComment);
206
207 connect(ui->computerBlack, &QCheckBox::toggled,this,&BoardWindow::setComputerBlack);
208 connect(ui->computerWhite, &QCheckBox::toggled, this, &BoardWindow::setComputerWhite);
209 connect(ui->computerMakeMove, &QPushButton::clicked, this, &BoardWindow::requestComputerMove);
210 ui->computerControlsWidget->setVisible(gameData->gameMode == modeLocal);
211
212 if ((gameData->gameMode == modeLocal) || (gameData->gameMode == modeEdit))
213 {
214 connect(ui->blackName, &QLineEdit::textChanged, this, &BoardWindow::setBlackName);
215 connect(ui->whiteName, &QLineEdit::textChanged, this, &BoardWindow::setWhiteName);
216 ui->blackName->setReadOnly(false);
217 ui->whiteName->setReadOnly(false);
218 }
219
220 //creates the board interface (or proxy) that will handle the moves an command requests
221 switch (gameData->gameMode)
222 {
223 case modeEdit :
224 case modeLocal :
225 qgoboard = new qGoBoardLocalInterface(this, tree,gameData);
226 ui->computerBlack->setChecked(!iAmBlack);
227 ui->computerWhite->setChecked(!iAmWhite);
228 break;
229 case modeObserve :
230 qgoboard = new qGoBoardObserveInterface(this, tree,gameData);
231 break;
232 case modeMatch :
233 try
234 {
235 qgoboard = new qGoBoardMatchInterface(this, tree,gameData);
236 }
237 catch(QString err)
238 {
239 QMessageBox::warning(this,QObject::tr("Error"), err);
240 return;
241 }
242 break;
243
244 case modeReview :
245 qgoboard = new qGoBoardReviewInterface(this, tree,gameData);
246 break;
247
248 default:
249 break;
250 }
251 if (gameData->gameMode == modeLocal)
252 connect(ui->insertMoveButton, &QPushButton::toggled, static_cast<qGoBoardLocalInterface*>(qgoboard), &qGoBoardLocalInterface::slotToggleInsertStones);
253 //make sure to set the sound button to the proper state before anything
254 ui->actionSound->setChecked(qgoboard->getPlaySound());
255 connect(ui->actionSound, &QAction::toggled, qgoboard, &qGoBoard::setPlaySound);
256
257 //Connects the board to the interface and boardhandler
258 connect(ui->board, &Board::signalClicked, qgoboard, &qGoBoard::slotBoardClicked);
259
260 //Connects the game buttons to the slots
261 connect(ui->passButton, &QPushButton::pressed, qgoboard, &qGoBoard::passRequest);
262 connect(ui->passButton_2, &QPushButton::pressed, qgoboard, &qGoBoard::passRequest);
263 connect(ui->scoreButton, &QPushButton::toggled, qgoboard, &qGoBoard::slotScoreToggled);
264
265
266 connect(ui->doneButton, &QPushButton::pressed, qgoboard, &qGoBoard::slotDonePressed);
267 connect(ui->reviewButton, &QPushButton::pressed, qgoboard, &qGoBoard::slotReviewPressed);
268 connect(ui->undoButton, &QPushButton::pressed, qgoboard, &qGoBoard::slotUndoPressed);
269
270 // Why is this conditional? FIXME
271 if (gameData->gameMode == modeMatch || gameData->gameMode == modeLocal || gameData->gameMode == modeEdit)
272 connect(ui->resignButton, &QPushButton::pressed, qgoboard, &qGoBoard::slotResignPressed);
273
274 if(gameData->gameMode == modeMatch)
275 {
276 connect(ui->adjournButton, &QPushButton::pressed, static_cast<qGoBoardNetworkInterface*>(qgoboard), &qGoBoardNetworkInterface::slotAdjournPressed);
277 connect(ui->countButton, &QPushButton::pressed, qgoboard, &qGoBoard::slotCountPressed);
278 connect(ui->drawButton, &QPushButton::pressed, qgoboard, &qGoBoard::slotDrawPressed);
279 } else {
280 ui->adjournButton->hide();
281 ui->countButton->hide();
282 ui->drawButton->hide();
283 }
284 if(dispatch && !dispatch->supportsRequestAdjourn())
285 ui->adjournButton->hide();
286 if(dispatch && !dispatch->supportsRequestCount())
287 ui->countButton->hide();
288 if(dispatch && !dispatch->supportsRequestDraw())
289 ui->drawButton->hide();
290
291 setGamePhase(phaseOngoing);
292 show();
293 checkHideToolbar(height());
294 setFocus();
295
296 //update();
297 //gridLayout->update();
298
299 if(gameData->record_sgf != QString())
300 tree->importSGFString(gameData->record_sgf);
301 }
302
303 BoardWindow::~BoardWindow()
304 {
305 qDebug("Deleting BoardWindow\n");
306 QSettings settings;
307
308 settings.setValue("BOARD_WINDOW_SIZE_X", width());
309 settings.setValue("BOARD_WINDOW_SIZE_Y", height());
310 // settings.setValue("BOARD_SIZES", ui->boardSplitter->saveState());
311
312 delete tree; //okay?
313
314 delete gameData;
315 delete addtime_menu;
316 }
317
318 bool BoardWindow::okayToQuit(void)
319 {
320 if (!qgoboard->getModified())
321 return true;
322
323 switch (QMessageBox::warning(this, PACKAGE,
324 tr("You modified the game.\nDo you want to save your changes?"),
325 QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel , QMessageBox::Cancel))
326 {
327 case QMessageBox::Save:
328 return slotFileSave() && !qgoboard->getModified();
329 case QMessageBox::Discard:
330 return true;
331 case QMessageBox::Cancel:
332 return false;
333 default:
334 return true;
335 }
336 }
337
338 /* FIXME make sure closeEvent doesn't get called on delete */
339 void BoardWindow::closeEvent(QCloseEvent *e)
340 {
341 if(dispatch && !dispatch->canClose())
342 {
343 e->ignore();
344 }
345 else if (okayToQuit())
346 {
347 e->accept();
348 if(dispatch)
349 {
350 dispatch->closeBoard();
351 }
352 //FIXME delete, make sure there's no canvas destruction
353 //crashes
354 deleteLater();
355 }
356 else
357 e->ignore();
358 }
359
360 void BoardWindow::resizeEvent(QResizeEvent * e)
361 {
362 checkHideToolbar(e->size().height());
363 }
364
365 void BoardWindow::checkHideToolbar(int h)
366 {
367 ui->varLabel->setVisible(h > 700);
368 }
369
370 void BoardWindow::gameDataChanged(void)
371 {
372 updateCaption();
373 clockDisplay->setTimeSettings(gameData->timeSystem, gameData->maintime, gameData->periodtime, gameData->stones_periods);
374 }
375
376 void BoardWindow::swapColors(bool noswap)
377 {
378 if(!noswap)
379 {
380 QString rank, name;
381
382 name = gameData->black_name;
383 rank = gameData->black_rank;
384 gameData->black_name = gameData->white_name;
385 gameData->black_rank = gameData->white_rank;
386 gameData->white_name = name;
387 gameData->white_rank = rank;
388 }
389 gameData->nigiriToBeSettled = false;
390
391 myColorIsBlack = (gameData->black_name == dispatch->getUsername());
392 myColorIsWhite = !myColorIsBlack;
393
394 updateCaption();
395 updateCursor();
396 //also need to start any timers if necessary
397 //also network timers in addition to game timers
398 }
399
400 void BoardWindow::saveRecordToGameData(void)
401 {
402 gameData->record_sgf = tree->exportSGFString(gameData);
403 }
404
405 /*
406 * One of the buttons in the 'Edit Tools' frame has been pressed
407 */
408 void BoardWindow::slotEditButtonPressed( int m )
409 {
410 Move *current = tree->getCurrent();
411
412 //we have to emulate exclusive buttons, while raise the button if it was down
413 if (m >= 0 && m < 7 )
414 {
415 if ( m== editButtons->checkedId())
416 {
417 // editButtons->button (m)->setChecked( false);
418 gamePhase = phaseOngoing;
419 updateCursor();
420 editButtons->button (7)->setDisabled( false);
421 }
422 else
423 {
424 gamePhase = phaseEdit;
425 updateCursor( ); //this still has turn change FIXME
426 editButtons->button (7)->setDisabled( true);
427
428 for (int i= 0;i<7;i++)
429 if (i!=m)
430 editButtons->button (i)->setChecked( false);
431
432 }
433 }
434 switch(m)
435 {
436 case 0:
437 editMark = markNone;
438 if(gamePhase == phaseEdit)
439 current->setGamePhase(phaseEdit); //permanent on this move, right?
440 break;
441
442 case 1:
443 editMark = markSquare;
444 break;
445
446 case 2:
447 editMark = markCircle;
448 break;
449
450 case 3:
451 editMark = markTriangle;
452 break;
453
454 case 4:
455 editMark = markCross;
456 break;
457
458 case 5:
459 editMark = markText;
460 break;
461
462 case 6:
463 editMark = markNumber;
464 break;
465
466 case 7:
467 {
468 // set next move's color
469 if (qgoboard->getBlackTurn())
470 {
471 current->setPLinfo(stoneWhite);
472 //#ifndef USE_XPM
473 // mainWidget->colorButton->setPixmap(QPixmap(ICON_NODE_WHITE));
474 //#else
475 ui->colorButton->setIcon(QIcon(":/boardicons/resources/pics/stone_white.png"));
476 updateCursor(stoneBlack);
477 //#endif
478 }
479 else
480 {
481 current->setPLinfo(stoneBlack);
482 //#ifndef USE_XPM
483 // mainWidget->colorButton->setPixmap(QPixmap(ICON_NODE_BLACK));
484 //#else
485 ui->colorButton->setIcon(QIcon(":/boardicons/resources/pics/stone_black.png"));
486 updateCursor(stoneWhite);
487 //#endif
488 }
489 // check if set color is natural color:
490 if ((current->getMoveNumber() == 0 && current->getPLnextMove() == stoneBlack) ||
491 (current->getMoveNumber() > 0 && current->getColor() != current->getPLnextMove()))
492 current->clearPLinfo();
493 // board->setCurStoneColor();
494 return;
495 }
496
497 default:
498 return;
499 }
500
501 // statusMark->setText(getStatusMarkText(t));
502 // board->setMarkType(t);
503 }
504
505 /*
506 * button menu 'export to clipboard' activated
507 */
508 void BoardWindow::slotExportSGFtoClipB()
509 {
510 QString str = tree->exportSGFString(gameData);
511 QApplication::clipboard()->setText(str);
512 }
513
514 /*
515 * button menu 'export picture' activated
516 */
517 void BoardWindow::slotExportPic()
518 {
519 QString *filter = new QString();
520 QString fileName = QFileDialog::getSaveFileName(this,
521 tr("Export image as"),
522 QString(""),
523 QString("JPEG (*.jpeg);;PNG (*.png);;BMP (*.bmp);;XPM (*.xpm);;XBM (*.xbm);;PNM (*.pnm);;GIF (*.gif);;MNG (*.mng)"),
524 filter, QFileDialog::DontUseNativeDialog);
525
526
527 if (fileName.isEmpty())
528 return;
529
530
531 // Confirm overwriting file.
532 // if ( QFile::exists( fileName ) )
533 // if (QMessageBox::information(this, PACKAGE,
534 // tr("This file already exists. Do you want to overwrite it?"),
535 // tr("Yes"), tr("No"), 0, 0, 1) == 1)
536 // return;
537
538 QString ext = "." + filter->section(" ",0,0).toLower();
539 if (!fileName.endsWith(ext))
540 fileName.append(ext);
541
542 ui->board->exportPicture(fileName, new QString(filter->section(" ",0,0)), false);//->left(3));
543 }
544
545 /*
546 * button menu 'export picture to clipboard' activated
547 */
548 void BoardWindow::slotExportPicClipB()
549 {
550 QString null = "";
551 ui->board->exportPicture(0, 0 , true);
552 }
553
554 /*
555 * button 'duplicate board' activated
556 */
557 void BoardWindow::slotDuplicate()
558 {
559 saveRecordToGameData();
560 GameData * gd = new GameData(gameData);
561 gd->gameMode = modeEdit;
562 gd->fileName = "";
563 new BoardWindow(gd, true, true);
564 }
565
566 void BoardWindow::slotGameInfo(bool /*toggle*/)
567 {
568 new GameInfo(this);
569 }
570
571 /*
572 * Saves the game tree under file 'filename'
573 * Note that qt handles overwrite check. */
574 bool BoardWindow::doSave(QString fileName, bool force)
575 {
576 if (!force)
577 {
578 if (fileName == NULL ||
579 fileName.isNull() ||
580 fileName.isEmpty() ||
581 QDir(fileName).exists())
582 {
583 QString base = getCandidateFileName();
584 if (fileName == NULL || fileName.isNull() || fileName.isEmpty())
585 fileName = base;
586 else
587 fileName.append(base);
588 }
589 fileName = QFileDialog::getSaveFileName(this,tr("Save File"), fileName, tr("SGF Files (*.sgf);;All Files (*)"), new QString(""), QFileDialog::DontUseNativeDialog );
590 }
591
592 if (fileName.isEmpty())
593 return false;
594
595 // if (getFileExtension(fileName, false).isEmpty())
596
597 if (fileName.right(4).toLower() != ".sgf")
598 fileName.append(".sgf");
599
600 gameData->fileName = fileName;
601
602 // if (setting->readBoolEntry("REM_DIR"))
603 // rememberLastDir(fileName);
604
605 QString SGF = tree->exportSGFString(gameData);
606
607 QFile file(fileName);
608 if (!file.open(QIODevice::WriteOnly))
609 {
610 QMessageBox::warning(this, PACKAGE, QObject::tr("Could not open file:") + " " + fileName);
611 return false;
612 }
613 file.write(SGF.toLatin1());
614 file.flush();
615 file.close();
616
617 qgoboard->setModified(false);
618 return true;
619 }
620
621 void BoardWindow::setGamePhase(GamePhase gp)
622 {
623 gamePhase = gp;
624 /* FIXME We should set and clear ALL buttons and the like here */
625 switch(gp)
626 {
627 case phaseInit:
628 //more defaults FIXME, and doublecheck
629 //also consider vanishing buttons instead of making
630 //them disabled, especially with like computer go, etc.
631 ui->adjournButton->setEnabled(false);
632 ui->drawButton->setEnabled(false);
633 break;
634 case phaseEnded:
635 if(ui->undoButton)
636 ui->undoButton->setDisabled(true);
637 if(ui->resignButton)
638 ui->resignButton->setDisabled(true);
639 if(ui->adjournButton)
640 ui->adjournButton->setDisabled(true);
641 if(ui->passButton)
642 ui->passButton->setDisabled(true);
643 if(ui->countButton)
644 ui->countButton->setDisabled(true);
645 if(ui->drawButton)
646 ui->drawButton->setDisabled(true);
647 /* Done button only for scoring, otherwise close
648 * window */
649 if(ui->doneButton)
650 ui->doneButton->setDisabled(true);
651 break;
652 case phaseOngoing:
653 /* among many other things: FIXME, adding as we go, for now,
654 * sloppy */
655 ui->tabDisplay->setCurrentIndex(0);
656 if(ui->passButton)
657 ui->passButton->setEnabled(true);
658 if(gameData->undoAllowed || gameData->gameMode == modeLocal)
659 ui->undoButton->setEnabled(true);
660 else
661 ui->undoButton->setEnabled(false);
662 if(gameData->gameMode == modeMatch)
663 {
664 if(gamePhase == phaseScore) //was phaseScore
665 ui->undoButton->setText(tr("Undo"));
666 if(dispatch)
667 {
668 ui->countButton->setEnabled(dispatch->supportsRequestCount());
669 ui->drawButton->setEnabled(dispatch->supportsRequestDraw());
670 ui->adjournButton->setEnabled(dispatch->supportsRequestAdjourn());
671 }
672 }
673 break;
674 case phaseScore:
675 /* Maybe we should take everything out of
676 * qgoboard enterScoreMode and put it here */
677 /* We might also disable the pass button... except
678 * really maybe its already disabled from being not
679 * our turn.. also, should the button's being
680 * disabled prevent sending the message instead
681 * of the button checking state? Probably. FIXME */
682 if(ui->countButton)
683 ui->countButton->setDisabled(true);
684 if(ui->undoButton && gameData->gameMode == modeMatch && dispatch)
685 {
686 if(dispatch->supportsRequestMatchMode())
687 {
688 ui->undoButton->setText(tr("Match Mode"));
689 ui->undoButton->setEnabled(true); //even in rated
690 }
691 else if(dispatch->undoResetsScore())
692 {
693 ui->undoButton->setEnabled(true); //even in rated
694 }
695 }
696 if(ui->passButton)
697 ui->passButton->setDisabled(true);
698 //Disable the draw button?
699 /* FIXME doublecheck, what is doneButton connected to
700 * in observing a game ?? */
701 if(dispatch && dispatch->canMarkStonesDeadinScore()) //FIXME or maybe as for tygem, it accepts the score as is
702 ui->doneButton->setEnabled(true);
703 ui->tabDisplay->setCurrentIndex(1);
704
705 break;
706 default:
707 break;
708 }
709 updateCursor();
710 }
711
712 /*
713 * Generate a candidate for the filename for this game
714 */
715 QString BoardWindow::getCandidateFileName()
716 {
717
718 QString base = QDate::currentDate().toString("yyyy-MM-dd") + "-" + gameData->white_name + "-" + gameData->black_name ;
719 QString result = base ;
720 QString dir= "" ;
721
722 // if (setting->readBoolEntry("REM_DIR"))
723 // dir = setting->readEntry("LAST_DIR");
724 int i = 1;
725 while (QFile(dir + result+".sgf").exists())
726 {
727 //number = Q.number(i++);
728 result = base + "-"+ QString::number(i++);
729 //fileName = fileName + ".sgf";
730 }
731 return dir + result + ".sgf";
732 }
733
734 /*
735 * The 'save' icon has been pressed
736 */
737 bool BoardWindow::slotFileSave()
738 {
739 QString fileName= gameData->fileName;
740 if (fileName.isEmpty())
741 {
742 // if (setting->readBoolEntry("REM_DIR"))
743 // fileName = setting->readEntry("LAST_DIR");
744 // else
745 // fileName = QString::null;
746 return doSave(fileName, false);
747 }
748 else
749 return doSave(fileName, true);
750 }
751
752 /*
753 * The 'save as' icon has been pressed
754 */
755 bool BoardWindow::slotFileSaveAs()
756 {
757 return doSave(0, false);
758 }
759
760 /*
761 * The 'delete node' button has been pressed
762 */
763 void BoardWindow::slotEditDelete()
764 {
765 tree->deleteNode();
766 }
767
768 void BoardWindow::setBoardDispatch(BoardDispatch * d)
769 {
770 dispatch = d;
771 }
772
773 //this seems like its more appropriately a qgoboard slot but...
774 void BoardWindow::slot_addtime_menu(QAction * a)
775 {
776 switch(a->data().toInt())
777 {
778 case -1:
779 break;
780 case 1:
781 dispatch->sendAddTime(1);
782 break;
783 case 5:
784 dispatch->sendAddTime(5);
785 break;
786 case 10:
787 dispatch->sendAddTime(10);
788 break;
789 case 60:
790 dispatch->sendAddTime(60);
791 break;
792 }
793 }
794
795 void BoardWindow::setComputerBlack(bool val)
796 {
797 myColorIsBlack = !val;
798
799 // dynamic_cast downcasts the pointer and returns null if this is not safe
800 // This requires Run-Time Type Information to be enabled at compile time
801 qGoBoardLocalInterface* qgoboard_temp = dynamic_cast<qGoBoardLocalInterface*>(qgoboard);
802 if (qgoboard_temp != NULL)
803 {
804 qgoboard_temp->checkComputersTurn();
805 }
806 }
807
808 void BoardWindow::setComputerWhite(bool val)
809 {
810 myColorIsWhite = !val;
811
812 // dynamic_cast downcasts the pointer and returns null if this is not safe
813 // This requires Run-Time Type Information to be enabled at compile time
814 qGoBoardLocalInterface* qgoboard_temp = dynamic_cast<qGoBoardLocalInterface*>(qgoboard);
815 if (qgoboard_temp != NULL)
816 {
817 qgoboard_temp->checkComputersTurn();
818 }
819 }
820
821 void BoardWindow::requestComputerMove()
822 {
823 // dynamic_cast downcasts the pointer and returns null if this is not safe
824 // This requires Run-Time Type Information to be enabled at compile time
825 qGoBoardLocalInterface* qgoboard_temp = dynamic_cast<qGoBoardLocalInterface*>(qgoboard);
826 if (qgoboard_temp != NULL)
827 {
828 qgoboard_temp->checkComputersTurn(true);
829 }
830 }
831
832 void BoardWindow::setBlackName(QString name)
833 {
834 gameData->black_name = name;
835 ui->blackName->blockSignals(true);
836 ui->blackName->setText(name);
837 updateCaption();
838 ui->blackName->blockSignals(false);
839 }
840
841 void BoardWindow::setWhiteName(QString name)
842 {
843 gameData->white_name = name;
844 ui->whiteName->blockSignals(true);
845 ui->whiteName->setText(name);
846 updateCaption();
847 ui->whiteName->blockSignals(false);
848 }
849
850 void BoardWindow::switchToEditMode()
851 {
852 gameData->gameMode = modeEdit;
853 setMode(modeEdit);
854 ui->computerControlsWidget->setVisible(gameData->gameMode == modeLocal);
855 myColorIsBlack = true;
856 myColorIsWhite = true;
857 }
858
859 void BoardWindow::switchToLocalMode()
860 {
861 gameData->gameMode = modeLocal;
862 setMode(modeLocal);
863 ui->computerControlsWidget->setVisible(gameData->gameMode == modeLocal);
864 myColorIsBlack = !(ui->computerBlack->isChecked());
865 myColorIsWhite = !(ui->computerWhite->isChecked());
866
867 // dynamic_cast downcasts the pointer and returns null if this is not safe
868 // This requires Run-Time Type Information to be enabled at compile time
869 qGoBoardLocalInterface* qgoboard_temp = dynamic_cast<qGoBoardLocalInterface*>(qgoboard);
870 if (qgoboard_temp != NULL)
871 {
872 tree->setCurrent(tree->findLastMoveInCurrentBranch());
873 qgoboard_temp->feedPositionThroughGtp();
874 }
875 }
876
877 /*
878 * The text in the comment zone has been changed
879 */
880 void BoardWindow::slotUpdateComment()
881 {
882 tree->getCurrent()->setComment(ui->commentEdit->toPlainText());
883 }
884
885 void BoardWindow::updateButtons(StoneColor lastMoveColor)
886 {
887 switch (getGameMode())
888 {
889 case modeMatch:
890 case modeLocal:
891 if(getGamePhase() == phaseOngoing)
892 {
893 bool onMove = (lastMoveColor == stoneBlack && getMyColorIsWhite()) ||
894 (lastMoveColor == stoneWhite && getMyColorIsBlack());
895 ui->passButton->setEnabled(onMove);
896 ui->resignButton->setEnabled(onMove);
897 }
898 break;
899 default:
900 break;
901 }
902 }
903
904 void BoardWindow::updateCursor(StoneColor currentMoveColor)
905 {
906 CursorType cur = cursorIdle;
907
908 switch (getGameMode())
909 {
910 case modeEdit :
911 case modeTeach :
912 case modeUndefined:
913 if (getGamePhase() == phaseScore || getGamePhase() == phaseEdit )
914 cur = cursorIdle;
915 else
916 cur = (currentMoveColor == stoneBlack ? cursorGhostWhite : cursorGhostBlack);
917 break;
918 case modeReview:
919 break;
920 case modeObserve :
921 break;
922 case modeMatch :
923 case modeLocal :
924 if(getGamePhase() == phaseOngoing)
925 {
926 if (currentMoveColor == stoneNone )
927 currentMoveColor = qgoboard->getBlackTurn() ? stoneWhite : stoneBlack;
928 if (currentMoveColor == stoneBlack )
929 cur = ( getMyColorIsWhite() ? cursorGhostWhite : cursorIdle );
930 else
931 cur = ( getMyColorIsBlack() ? cursorGhostBlack : cursorIdle );
932 if (getGameMode() == modeLocal && cur == cursorIdle)
933 cur = cursorWait;
934 }
935 break;
936 }
937
938 ui->board->setCursorType(cur);
939 }
940
941 /*
942 * This deals with updating the 'board' and the 'interface handler' with the data
943 * stored in the tree at the move place.
944 * This involves calling and update for the board stones, and
945 * an update of the interface
946 */
947 void BoardWindow::updateMove(Move *m)
948 {
949 if (m == NULL)
950 {
951 m = tree->getCurrent();
952 }
953
954 // Update slider branch length
955 setSliderMax(m->getLastMove(true)->getMoveNumber());
956 setMoveData(
957 m->getMoveNumber(),
958 (m->getColor() != stoneBlack),
959 m->getNumBrothers(),
960 m->getNumSons(),
961 m->hasParent(),
962 m->hasPrevBrother(),
963 m->hasNextBrother(),
964 m->getX(),
965 m->getY());
966
967 // Update comment if normal game (if observe or match, the comment zone is kept as is)
968 if (getGameMode() == modeEdit)
969 ui->commentEdit->setPlainText(m->getComment());
970
971 // Isn't updateAll() sufficient? FIXME
972 ui->board->removeGhosts();
973 ui->board->updateAll(m);
974 ui->board->updateLastMove(m);
975
976 updateButtons(m->getColor());
977 updateCursor(m->getColor());
978
979 // Update the ghosts indicating variations
980 if (m->getNumBrothers())// && setting->readIntEntry("VAR_GHOSTS")) TODO
981 ui->board->updateVariationGhosts(m);
982
983 // Oops, something serious went wrong
984 if (m->getMatrix() == NULL)
985 qFatal(" *** Move returns NULL pointer for matrix! ***");
986
987 ui->capturesBlack->setText(QString::number(m->getCapturesBlack()));
988 ui->capturesWhite->setText(QString::number(m->getCapturesWhite()));
989
990 // Display times
991 if(getGameMode() == modeEdit)
992 {
993 if(m->getMoveNumber() == 0)
994 {
995 if (gameData->timelimit == 0)
996 getClockDisplay()->setTimeInfo(0, -1, 0, -1);
997 else
998 getClockDisplay()->setTimeInfo(gameData->timelimit, -1, gameData->timelimit, -1);
999 }
1000 else if(m->getTimeinfo())
1001 {
1002 int other_time, other_stones_periods;
1003 if(m->parent && m->parent->getMoveNumber() != 0 && m->parent->getTimeinfo())
1004 {
1005 other_time = (int)m->parent->getTimeLeft();
1006 other_stones_periods = (m->parent->getOpenMoves() == 0 ? -1 : m->parent->getOpenMoves());
1007 }
1008 else
1009 {
1010 other_time = 0;
1011 other_stones_periods = -1;
1012 }
1013 if(!qgoboard->getBlackTurn())
1014 getClockDisplay()->setTimeInfo((int)m->getTimeLeft(), m->getOpenMoves() == 0 ? -1 : m->getOpenMoves(), other_time, other_stones_periods);
1015 else
1016 getClockDisplay()->setTimeInfo(other_time, other_stones_periods, (int)m->getTimeLeft(), m->getOpenMoves() == 0 ? -1 : m->getOpenMoves());
1017 }
1018 }
1019 }
1020
1021 void BoardWindow::slotSendComment()
1022 {
1023 QString ourcomment = ui->commentEdit2->text();
1024 ui->commentEdit2->clear();
1025
1026 if (dispatch)
1027 {
1028 dispatch->sendKibitz(ourcomment);
1029 // User name only prepended for local display
1030 ourcomment.prepend(dispatch->getUsername() + "[" + dispatch->getOurRank() + "]: ");
1031 }
1032 ourcomment.prepend( "(" + QString::number(tree->getCurrent()->getMoveNumber()) + ") ");
1033
1034 displayComment(ourcomment);
1035 }
1036
1037 /*
1038 * Called when the 'nav to' button is pressed
1039 */
1040 void BoardWindow::slotNavIntersection()
1041 {
1042 //should not happen
1043 if (getGameMode() != modeEdit &&
1044 getGameMode() != modeObserve)
1045 return;
1046 /* Double check the above, seems like we should be able to use
1047 * the nav button in any mode except maybe the scorephase of
1048 * a game.. but I mean why can't we look back over moves whenever?
1049 * FIXME */
1050
1051 setGamePhase ( phaseNavTo );
1052 ui->board->setCursorType(cursorNavTo);
1053 }
1054
1055 void BoardWindow::slotWheelEvent(QWheelEvent *e)
1056 {
1057 // leave if not editing
1058 if (getGameMode() != modeEdit &&
1059 getGameMode() != modeObserve) //or observing
1060 return;
1061
1062 if (getGamePhase() != phaseOngoing)
1063 return;
1064
1065 // Check delay
1066 if (QTime::currentTime() < wheelTime)
1067 return;
1068
1069 // Needs an extra check on variable mouseState as state() does not work on Windows.
1070 if (e->delta() > 0)
1071 {
1072 if (e->buttons() == Qt::RightButton || e-> modifiers() == Qt::ShiftModifier)
1073 tree->slotNavNextVar();
1074 else
1075 tree->slotNavForward();
1076 }
1077 else
1078 {
1079 if (e->buttons() == Qt::RightButton || e-> modifiers() == Qt::ShiftModifier)//|| mouseState == RightButton)
1080 tree->slotNavPrevVar();
1081 else
1082 tree->slotNavBackward();
1083 }
1084
1085 // Delay of 100 msecs to avoid too fast scrolling
1086 wheelTime = QTime::currentTime();
1087 wheelTime = wheelTime.addMSecs(50);
1088
1089 e->accept();
1090 }
1091
1092 void BoardWindow::slotGetScore(int terrBlack, int captBlack, int deadWhite, int terrWhite, int captWhite, int deadBlack)
1093 {
1094 ui->komiScore->setText(QString::number(gameData->komi));
1095 ui->terrWhite->setText(QString::number(terrWhite));
1096 ui->capturesWhiteScore->setText(QString::number(captWhite+deadBlack));
1097 ui->totalWhite->setText(QString::number((float)(terrWhite+captWhite+deadBlack) + gameData->komi));
1098 ui->terrBlack->setText(QString::number(terrBlack));
1099 ui->capturesBlackScore->setText(QString::number(captBlack+deadWhite));
1100 ui->totalBlack->setText(QString::number(terrBlack+captBlack+deadWhite));
1101
1102 gameData->black_prisoners = captBlack;
1103 gameData->white_prisoners = captWhite;
1104 }
1105
1106 /*
1107 * displays the informations relative to a game on the board window
1108 */
1109 void BoardWindow::updateCaption()
1110 {
1111 // Print caption
1112 // example: qGo 0.0.5 - Zotan 8k vs. tgmouse 10k
1113 // or if game name is given: qGo 0.0.5 - Kogo's Joseki Dictionary
1114 setWindowTitle( /* QString(isModified ? "* " : "") + */
1115 ( (gameData->number != 0 && gameData->number < 10000) ?
1116 "(" + QString::number(gameData->number) + ") " :
1117 QString()) + (gameData->gameName.isEmpty() ?
1118 gameData->white_name
1119 + (!gameData->white_rank.isEmpty() ?
1120 " " + gameData->white_rank :
1121 QString())
1122 + " " + QObject::tr("vs.") + " " + gameData->black_name
1123 + (!gameData->black_rank.isEmpty() ?
1124 " " + gameData->black_rank :
1125 QString()) :
1126 gameData->gameName) + " - " + QString(PACKAGE));
1127
1128
1129 bool simple = gameData->white_rank.length() == 0 && gameData->black_rank.length() == 0;
1130 /* This name stuff is super redundant with below FIXME */
1131 QString player = gameData->white_name;
1132 if (simple && player == QObject::tr("White"))
1133 {
1134 ui->whiteName->setText(QObject::tr("White"));
1135 ui->whiteFrame_score_label->setText(QObject::tr("White"));
1136 }
1137 else if(!gameData->nigiriToBeSettled)
1138 {
1139 // truncate to 13 characters max
1140 player.truncate(13);
1141
1142 if (gameData->white_rank.length() != 0)
1143 player = player + " " + gameData->white_rank;
1144
1145 ui->whiteName->setText(player);
1146 ui->whiteFrame_score_label->setText(QObject::tr("W") + ": " + player);
1147 }
1148
1149 player = gameData->black_name;
1150 if (simple && player == QObject::tr("Black"))
1151 {
1152 ui->blackName->setText(QObject::tr("Black"));
1153 ui->blackFrame_score_label->setText(QObject::tr("Black"));
1154 }
1155 else if(!gameData->nigiriToBeSettled)
1156 {
1157 // truncate to 13 characters max
1158 player.truncate(13);
1159
1160 if (gameData->black_rank.length() != 0)
1161 player = player + " " + gameData->black_rank;
1162
1163 ui->blackName->setText(player);
1164 ui->blackFrame_score_label->setText(QObject::tr("B") + ": " + player);
1165 }
1166
1167 //TODO set clock
1168
1169 if(gameData->free_rated == RATED)
1170 freeratedLabel->setText("Rated");
1171 else if(gameData->free_rated == FREE)
1172 freeratedLabel->setText("Free");
1173 else if(gameData->free_rated == TEACHING)
1174 freeratedLabel->setText("Teaching");
1175
1176 komiLabel->setText(QString("Komi: ").append(QString().setNum(gameData->komi)));
1177 handicapLabel->setText(QString("H: ").append(QString().setNum(gameData->handicap)));
1178 }
1179
1180 /*
1181 * This updates the UI with the correct layout depending on the game mode
1182 */
1183 void BoardWindow::setMode(GameMode mode)
1184 {
1185 if ((mode == modeEdit) || (mode == modeLocal))
1186 {
1187 ui->commentEdit2->setDisabled(true);
1188 } else {
1189 ui->buttonModeEdit->hide();
1190 ui->buttonModeLocal->hide();
1191 }
1192
1193
1194 switch (mode)
1195 {
1196
1197 case modeEdit:
1198 ui->actionPlay->setEnabled(true);
1199 ui->tabTools->setCurrentIndex(0) ;//setVisible(false);
1200 ui->scoreButton->setEnabled(true);
1201 ui->passButton_2->setEnabled(true);
1202 ui->commentEdit->setReadOnly(false);
1203 ui->commentEdit2->setDisabled(true);
1204 return;
1205
1206 case modeObserve:
1207 ui->actionPlay->setDisabled(true);
1208 ui->tabTools->setVisible(false) ;
1209 ui->passButton_2->setDisabled(true);
1210 ui->commentEdit->setReadOnly(true);
1211 ui->commentEdit2->setReadOnly(false);
1212 ui->commentEdit2->setEnabled(true);
1213 return ;
1214
1215 case modeMatch :
1216 ui->actionPlay->setDisabled(true);
1217 ui->tabTools->setCurrentIndex(1) ;
1218 ui->scoreButton->setDisabled(true);
1219 ui->passButton->setEnabled(true);
1220 ui->undoButton->setEnabled(true);
1221 ui->resignButton->setEnabled(true);
1222 ui->reviewButton->setDisabled(true);
1223 ui->reviewButton->setVisible(true);
1224 ui->adjournButton->setEnabled(true);
1225 /* FIXME we could have the refreshButton refresh the observers on
1226 * IGS. This requires a "supports" protocol function, etc., to
1227 * send the refresh. Or we could just periodically refresh the
1228 * observers.
1229 * But note that its currently not "connect"ed to anything. */
1230 //ui->refreshButton->setEnabled(true);
1231 ui->refreshButton->setEnabled(false);
1232
1233 ui->doneButton->setEnabled(false);
1234 ui->commentEdit->setReadOnly(true);
1235 ui->commentEdit2->setEnabled(true);
1236 ui->commentEdit2->setReadOnly(false);
1237 return ;
1238
1239 case modeLocal :
1240 ui->actionPlay->setDisabled(true);
1241 ui->tabTools->setCurrentIndex(1) ;
1242 ui->scoreButton->setDisabled(true);
1243 ui->passButton->setEnabled(true);
1244 ui->undoButton->setEnabled(true);
1245 ui->resignButton->setEnabled(true);
1246 ui->adjournButton->setEnabled(false);
1247 ui->doneButton->setEnabled(false);
1248 ui->commentEdit->setReadOnly(true);
1249 ui->commentEdit2->setDisabled(true);
1250 ui->reviewButton->setDisabled(true);
1251 return ;
1252
1253 case modeTeach:
1254 ui->actionPlay->setDisabled(true);
1255 ui->tabTools->setCurrentIndex(1) ;
1256 ui->scoreButton->setDisabled(true);
1257 ui->passButton->setEnabled(true);
1258 ui->undoButton->setEnabled(true);
1259 ui->resignButton->setEnabled(true);
1260 ui->adjournButton->setEnabled(true);
1261 ui->doneButton->setEnabled(false);
1262 ui->commentEdit->setReadOnly(true);
1263 ui->commentEdit2->setReadOnly(false);
1264 ui->commentEdit2->setEnabled(true);
1265 return ;
1266
1267 case modeReview :
1268 ui->actionPlay->setDisabled(true);
1269 ui->tabTools->setCurrentIndex(1) ;
1270 ui->scoreButton->setDisabled(true);
1271 ui->passButton->setEnabled(true);
1272 ui->undoButton->setEnabled(true);
1273 ui->resignButton->setEnabled(true);
1274 ui->adjournButton->setEnabled(true);
1275 ui->doneButton->setEnabled(false);
1276 ui->commentEdit->setReadOnly(true);
1277 ui->commentEdit2->setReadOnly(false);
1278 ui->commentEdit2->setEnabled(true);
1279 return ;
1280 case modeUndefined:
1281 return;
1282 }
1283 }
1284
1285 /*
1286 * Resets all displays on the board window
1287 */
1288 void BoardWindow::clearData()
1289 {
1290 ui->board->clearData();
1291
1292 ui->commentEdit->clear();
1293
1294 ui->capturesBlack->setText("0");
1295 ui->capturesWhite->setText("0");
1296
1297 ui->pb_timeBlack->setText("00:00");
1298 ui->pb_timeWhite->setText("00:00");
1299
1300 ui->scoreButton->setDown(false);
1301
1302 ui->slider->setValue(0);
1303 ui->slider->setMaximum(0);
1304 }
1305
1306 /*
1307 * displays the informations relative to a move on the board window
1308 */
1309 void BoardWindow::setMoveData(int n, bool black, int brothers, int sons, bool hasParent, bool hasPrev, bool hasNext, int lastX, int lastY)
1310 {
1311 // move number
1312 QString s(QObject::tr("Move") + " ");
1313 s.append(QString::number(n));
1314
1315 // color and coordinates
1316 if (lastX >= 1 && lastX <= getBoardSize() && lastY >= 1 && lastY <= getBoardSize())
1317 {
1318 s.append(" (");
1319 s.append(black ? QObject::tr("W")+" " : QObject::tr("B")+" ");
1320 s.append(QString(QChar(static_cast<const char>('A' + (lastX<9?lastX:lastX+1) - 1))) +
1321 QString::number(getBoardSize()-lastY+1) + ")");
1322 }
1323
1324 //pass move
1325 else if (lastX == PASS_XY && lastY == PASS_XY)
1326 {
1327 s.append(" (");
1328 s.append(black ? QObject::tr("W")+" " : QObject::tr("B")+" ");
1329 s.append(" " + QObject::tr("Pass") + ")");
1330 }
1331
1332 moveNumLabel->setText(s);
1333
1334 // set turn information (and color on the edit button)
1335 s = black ? QObject::tr("Black to play") : QObject::tr("White to play");
1336 ui->turnLabel->setText(s);
1337
1338 ui->colorButton->setIcon(black ? QIcon(":/boardicons/resources/pics/stone_black.png") : QIcon(":/boardicons/resources/pics/stone_white.png") );
1339
1340 // sons and variatons display
1341 s = "";
1342 s.append(QString::number(brothers));
1343 if (brothers == 1)
1344 s.append(" " + QObject::tr("brother") + "\n");
1345 else
1346 s.append(" " + QObject::tr("brothers") + "\n");
1347
1348 s.append(QString::number(sons));
1349 if (sons == 1)
1350 s.append(" " + QObject::tr("son"));
1351 else
1352 s.append(" " + QObject::tr("sons"));
1353 ui->varLabel->setText(s);
1354
1355 if(getGameMode() == modeReview)
1356 {
1357 /* For now, just disable navigation if its in the review mode, they can always duplicate
1358 * the board and a lot more is necessary for qgo to do reviews. */
1359 ui->toolBar_Navigation->setEnabled(false);
1360 ui->slider->setEnabled(false);
1361 }
1362 else if (getGameMode() == modeEdit || getGameMode() == modeObserve )//|| board->getGameMode() == modeEdit)
1363 {
1364 // Update the toolbar buttons
1365 ui->toolBar_Navigation->setEnabled(true);
1366 ui->slider->setEnabled(true);
1367 }
1368
1369 // Update slider
1370 ui->slider->blockSignals(true);
1371 if (ui->slider->maximum() < n)
1372 setSliderMax(n);
1373 ui->slider->setValue(n);
1374 ui->slider->blockSignals(false);
1375 }
1376
1377 void BoardWindow::setUndoEnabled(bool state)
1378 {
1379 ui->undoButton->setEnabled(state);
1380 }
1381
1382 void BoardWindow::setDrawEnabled(bool state)
1383 {
1384 ui->drawButton->setEnabled(state);
1385 }
1386
1387 void BoardWindow::setCountEnabled(bool state)
1388 {
1389 ui->countButton->setEnabled(state);
1390 }
1391
1392 void BoardWindow::setDoneEnabled(bool state)
1393 {
1394 ui->doneButton->setEnabled(state);
1395 }
1396
1397 void BoardWindow::setAdjournEnabled(bool state)
1398 {
1399 ui->adjournButton->setEnabled(state);
1400 }
1401
1402 void BoardWindow::setResignEnabled(bool state)
1403 {
1404 ui->resignButton->setEnabled(state);
1405 }
1406
1407 void BoardWindow::setObserverModel(QAbstractItemModel *model)
1408 {
1409 ui->observerView->setModel(model);
1410 }
1411
1412 void BoardWindow::setTimeBlack(QString time)
1413 {
1414 ui->pb_timeBlack->setText(time);
1415 }
1416
1417 void BoardWindow::setTimeWhite(QString time)
1418 {
1419 ui->pb_timeWhite->setText(time);
1420 }
1421
1422 void BoardWindow::warnTimeBlack(TimeWarnState state)
1423 {
1424 switch (state)
1425 {
1426 case TimeOK:
1427 if(ui->pb_timeBlack->palette().color(QPalette::Background) != Qt::black)
1428 {
1429 ui->pb_timeBlack->setPalette(QPalette(Qt::black));
1430 #if defined(Q_OS_WIN) || defined(Q_OS_MAC)
1431 /* Otherwise windows XP/Mac style makes time buttons ugly white on white.
1432 * This could interfere with blinking warning. */
1433 ui->pb_timeBlack->setStyleSheet("background-color: black; color: white");
1434 #endif //Q_OS_WIN
1435 }
1436 return;
1437 case TimeLow:
1438 if(ui->pb_timeBlack->palette().color(QPalette::Background) == Qt::black)
1439 ui->pb_timeBlack->setPalette(QPalette(Qt::yellow));
1440 else
1441 ui->pb_timeBlack->setPalette(QPalette(Qt::black));
1442 return;
1443 case TimeExpired:
1444 ui->pb_timeBlack->setPalette(QPalette(Qt::red));
1445 }
1446 }
1447
1448 void BoardWindow::warnTimeWhite(TimeWarnState state)
1449 {
1450 switch (state)
1451 {
1452 case TimeOK:
1453 if(ui->pb_timeWhite->palette().color(QPalette::Background) != Qt::black)
1454 {
1455 ui->pb_timeWhite->setPalette(QPalette(Qt::black));
1456 #if defined(Q_OS_WIN) || defined(Q_OS_MAC)
1457 /* Otherwise windows XP/Mac style makes time buttons ugly white on white.
1458 * This could interfere with blinking warning. */
1459 ui->pb_timeWhite->setStyleSheet("background-color: black; color: white");
1460 #endif //Q_OS_WIN
1461 }
1462 return;
1463 case TimeLow:
1464 if(ui->pb_timeWhite->palette().color(QPalette::Background) == Qt::black)
1465 ui->pb_timeWhite->setPalette(QPalette(Qt::yellow));
1466 else
1467 ui->pb_timeWhite->setPalette(QPalette(Qt::black));
1468 return;
1469 case TimeExpired:
1470 ui->pb_timeWhite->setPalette(QPalette(Qt::red));
1471 }
1472 }
1473
1474 void BoardWindow::displayComment(QString comment)
1475 {
1476 // add comments to SGF/tree FIXME
1477 QString txt = tree->getCurrent()->getComment();
1478 if(getGamePhase() != phaseEnded)
1479 txt.append(comment);
1480 tree->getCurrent()->setComment(txt);
1481
1482 ui->commentEdit->append(comment);
1483 /* Should probably update the history in a central location
1484 * and update display automatically,
1485 * but this is not implemented yet */
1486 }
1487
1488 /*
1489 * modifies the maximum value of the slider (used when a move is added)
1490 */
1491 void BoardWindow::setSliderMax(int n)
1492 {
1493 if (n < 0)
1494 n = 0;
1495
1496 if (n == ui->slider->maximum())
1497 return;
1498
1499 ui->slider->blockSignals (true);
1500 ui->slider->setMaximum(n);
1501 ui->slider->blockSignals (false);
1502 ui->sliderRightLabel->setText(QString::number(n));
1503 }