247
257
// Paint table and board on the pixmap
248
258
QPainter painter;
250
board.setPixmap(*(ImageHandler::getBoardPixmap(static_cast<skinType>(setting->readIntEntry("SKIN")))));
260
// board.setPixmap(*(ImageHandler::getBoardPixmap(static_cast<skinType>(setting->readIntEntry("SKIN")))));
261
//board.setPixmap(*(ImageHandler::getBoardPixmap(setting->readEntry("SKIN"))));
252
263
// table.setPixmap(*(imageHandler->getTablePixmap()));
253
table.setPixmap(*(ImageHandler::getTablePixmap()));
264
//table.setPixmap(*(ImageHandler::getTablePixmap()));
254
266
painter.begin(&all);
255
267
painter.setPen(NoPen);
256
painter.fillRect(0, 0, w, h, table);
257
painter.fillRect(offsetX - offset,
268
//painter.fillRect(0, 0, w, h, table);
269
painter.drawTiledPixmap (0, 0, w, h,*(ImageHandler::getTablePixmap(setting->readEntry("SKIN_TABLE"))));
271
painter.drawTiledPixmap (
258
273
offsetY - offset,
259
274
board_pixel_size + offset*2,
260
275
board_pixel_size + offset*2,
265
QColor c = QColor("darkGrey") ;
267
painter.setRasterOp(Qt::AndROP);
269
painter.setPen(c.dark(145));
270
painter.drawLine( offsetX - offset,
273
offsetY + board_pixel_size + offset);
276
painter.drawLine(offsetX - offset +1,
279
offsetY + board_pixel_size + offset);
282
painter.setPen(c.dark(145));
283
painter.drawLine( offsetX - offset,
284
offsetY + board_pixel_size + offset -1 ,
285
offsetX + board_pixel_size + offset,
286
offsetY + board_pixel_size + offset -1);
289
painter.drawLine( offsetX - offset,
290
offsetY + board_pixel_size + offset -2,
291
offsetX + board_pixel_size + offset,
292
offsetY + board_pixel_size + offset -2 );
294
painter.setRasterOp(Qt::OrROP);
296
painter.setPen(c.light(100));
297
painter.drawLine( offsetX + board_pixel_size + offset-1,
299
offsetX + board_pixel_size + offset-1,
300
offsetY + board_pixel_size + offset -1);
303
painter.drawLine(offsetX + board_pixel_size + offset-2,
305
offsetX + board_pixel_size + offset-2,
306
offsetY + board_pixel_size + offset -1);
309
painter.setPen(c.light(100));
310
painter.drawLine(offsetX - offset,
312
offsetX + board_pixel_size + offset -1,
316
painter.drawLine( offsetX - offset,
318
offsetX + board_pixel_size + offset -1,
319
offsetY - offset +1);
326
// Set pixmap as canvas background
327
canvas->setBackgroundPixmap(all);
276
*(ImageHandler::getBoardPixmap(setting->readEntry("SKIN"))));
280
QImage image = all.convertToImage();
287
for (y= offsetY - offset +x ; y<offsetY + board_pixel_size + offset-x ;y++)
292
QColor(image.pixel(offsetX - offset+x,y)).dark(int(100 + darker*(width-x)*(width-x)/width/width)).rgb());
295
offsetX + board_pixel_size + offset-x -1,
297
QColor(image.pixel(offsetX + board_pixel_size + offset-x-1,y)).light(100+ int(lighter*(width-x)*(width-x)/width/width)).rgb());
301
for (x= offsetX - offset +y ; x<offsetX + board_pixel_size + offset-y ;x++)
306
QColor(image.pixel(x,offsetY - offset+y)).light(int(100 + lighter*(width-y)*(width-y)/width/width)).rgb());
310
offsetY + board_pixel_size + offset-y -1,
311
QColor(image.pixel(x,offsetY + board_pixel_size + offset-y-1)).dark(100+ int(darker*(width-y)*(width-y)/width/width)).rgb());
318
for(x=0;(x<=width)&&(offsetX - offset-x >0) ;x++)
319
for (y= offsetY - offset+x ; (y<offsetY + board_pixel_size + offset+x)&&(y<h) ;y++)
322
offsetX - offset-1-x ,
324
QColor(image.pixel(offsetX - offset-1-x,y)).dark(int(100 + darker*(width-x)/width)).rgb());
327
for(y=0;(y<=width)&&(offsetY + board_pixel_size + offset+y+1<h);y++)
328
for (x= (offsetX - offset - y > 0 ? offsetX - offset - y:0) ; x<offsetX + board_pixel_size + offset-y ;x++)
332
offsetY + board_pixel_size + offset+y +1,
333
QColor(image.pixel(x,offsetY + board_pixel_size + offset+y+1)).dark(100+ int(darker*(width-y)/width)).rgb());
337
all.convertFromImage(image);
338
// Set pixmap as canvas background
339
canvas->setBackgroundPixmap(all);
330
342
void Board::drawGatter()
344
/* QCanvasLine *line;
347
static QCanvasLine *VGatter[361];
348
static QCanvasLine *HGatter[361];
335
350
// Draw vertical lines
336
351
for (i=0; i<board_size; i++)
397
414
QCanvasText *coord;
400
coord_centre = (offset - square_size/2 )/2; // centres the coordinates text within the remaining space at table edge
417
const int coord_centre = (offset - square_size/2 )/2; // centres the coordinates text within the remaining space at table edge
403
420
// Draw vertical coordinates. Numbers
404
421
for (i=0; i<board_size; i++)
407
coord = new QCanvasText(QString::number(board_size-i), canvas);
425
txt = QString(QChar(static_cast<const char>('a' + i)));
427
txt = QString::number(board_size - i);
428
coord = new QCanvasText(txt, canvas);
408
429
coord->setX(offsetX - offset + coord_centre - coord->boundingRect().width()/2 );
409
430
coord->setY(offsetY + square_size * i - coord->boundingRect().height()/2);
412
coord = new QCanvasText(QString::number(board_size-i), canvas);
413
coord->setX(offsetX + board_pixel_size + offset - coord_centre - coord->boundingRect().width()/2 );
433
coord = new QCanvasText(txt, canvas);
434
coord->setX(offsetX + board_pixel_size + offset - coord_centre - coord->boundingRect().width()/2 );
414
435
coord->setY(offsetY + square_size * i - coord->boundingRect().height()/2);
445
469
case 1: // Stone exists and is visible
446
470
// qDebug("*** Already a stone at %d, %d.", x, y);
447
471
if (boardHandler->display_incoming_move)
449
473
else // we are observig a game, and we are just observing a sone that is
450
474
// taken later. A new incoming stone is played there.
451
475
// Ok, this is BAD.
453
Stone *s = boardHandler->getStoneHandler()->getStoneAt(x, y);
477
Stone *s = boardHandler->getStoneHandler()->getStoneAt(x, y);
460
484
case 0: // No stone existing. Create a new one
462
486
// qDebug("*** Did not find any stone at %d, %d.", x, y);
464
Stone *s = new Stone(imageHandler->getStonePixmaps(), canvas, c, x, y);
465
if (boardHandler->getGameData()->oneColorGo)
466
s->toggleOneColorGo(true);
488
Stone *s = new Stone(imageHandler->getStonePixmaps(), canvas, c, x, y,WHITE_STONES_NB,true);
490
if (boardHandler->getGameData()->oneColorGo)
491
s->toggleOneColorGo(true);
470
495
s->setX(offsetX + square_size * (x-1));
471
496
s->setY(offsetY + square_size * (y-1));
473
499
// Change color of a mark on this spot to white, if we have a black stone
474
500
if (c == stoneBlack)
586
612
curStone->setX(offsetX + square_size * (x-1));
587
613
curStone->setY(offsetY + square_size * (y-1));
588
614
curStone->setPos(x, y);
616
bool notMyTurn = (curStone->getColor() == stoneBlack && !myColorIsBlack ||
617
curStone->getColor() == stoneWhite && myColorIsBlack);
619
if (navIntersectionStatus ||
620
boardHandler->getGameMode() == modeObserve ||
621
( boardHandler->getGameMode() == modeMatch && notMyTurn) ||
622
( boardHandler->getGameMode() == modeComputer && notMyTurn))
590
if (navIntersectionStatus || //SL added eb 11
591
boardHandler->getGameMode() == modeObserve ||
592
boardHandler->getGameMode() == modeMatch ||
593
boardHandler->getGameMode() == modeComputer &&
594
(curStone->getColor() == stoneBlack && !myColorIsBlack ||
595
curStone->getColor() == stoneWhite && myColorIsBlack))
596
624
curStone->hide();
600
628
canvas->update();
638
void Board::contentsMouseReleaseEvent(QMouseEvent*)
666
void Board::contentsMouseReleaseEvent(QMouseEvent* e)
640
mouseState = NoButton;
668
mouseState = NoButton;
670
int x = convertCoordsToPoint(e->x(), offsetX),
671
y = convertCoordsToPoint(e->y(), offsetY);
673
//qDebug("Mouse should be released after %d,%03d", wheelTime.second(),wheelTime.msec());
674
//qDebug("Mouse released at time %d,%03d", QTime::currentTime().second(),QTime::currentTime().msec());
676
if ( (boardHandler->getGameMode()==modeMatch) &&
677
(QTime::currentTime() > wheelTime))
680
if (boardHandler->getBlackTurn())
684
boardHandler->addStone(stoneBlack, x, y);
685
emit signal_addStone(stoneBlack, x, y);
692
boardHandler->addStone(stoneWhite, x, y);
693
emit signal_addStone(stoneWhite, x, y);
643
703
void Board::contentsMousePressEvent(QMouseEvent *e)
1563
1650
QString Board::getCandidateFileName()
1565
GameData data = getGameData();
1566
QString result = data.playerBlack + "-" + data.playerWhite;
b'\\ No newline at end of file'
1652
GameData data = getGameData();
1653
QString base = QDate::currentDate().toString("yyyy-MM-dd") + "-" + data.playerWhite + "-" + data.playerBlack ;
1654
QString result = base ;
1657
if (setting->readBoolEntry("REM_DIR"))
1658
dir = setting->readEntry("LAST_DIR");
1660
while (QFile(dir + result+".sgf").exists())
1662
//number = Q.number(i++);
1663
result = base + "-"+ QString::number(i++);
1664
//fileName = fileName + ".sgf";
1666
return dir + result + ".sgf";
1670
� * Initialises the gatter intersections and hoshis points
1672
Gatter::Gatter(QCanvas *Canvas, int size)
1679
VGatter.reserve(board_size);
1680
HGatter.reserve(board_size);
1681
for (i=0; i<board_size; i++)
1683
std::vector<QCanvasLine *> row,col;
1684
row.reserve(board_size);
1685
col.reserve(board_size);
1686
VGatter.push_back(row);
1687
HGatter.push_back(col);
1689
for (j=0; j<board_size; j++)
1691
VGatter[i].push_back(new QCanvasLine(canvas));
1692
HGatter[i].push_back(new QCanvasLine(canvas));
1693
CHECK_PTR(VGatter[i][j]);
1694
CHECK_PTR(HGatter[i][j]);
1698
int edge_dist = (board_size > 12 ? 4 : 3);
1699
int low = edge_dist;
1700
int middle = (board_size + 1) / 2;
1701
int high = board_size + 1 - edge_dist;
1702
if (board_size % 2 && board_size > 9)
1704
hoshisList.insert(middle*board_size + low , new QCanvasEllipse(canvas));
1705
hoshisList.insert(middle*board_size + middle , new QCanvasEllipse(canvas));
1706
hoshisList.insert(middle*board_size + high , new QCanvasEllipse(canvas));
1707
hoshisList.insert(low*board_size + middle , new QCanvasEllipse(canvas));
1708
hoshisList.insert(high*board_size + middle , new QCanvasEllipse(canvas));
1710
hoshisList.insert(low*board_size + low ,new QCanvasEllipse(canvas));
1711
hoshisList.insert(high*board_size + low , new QCanvasEllipse(canvas));
1712
hoshisList.insert(high*board_size + high , new QCanvasEllipse(canvas));
1713
hoshisList.insert(low*board_size + high ,new QCanvasEllipse(canvas));
1715
QIntDictIterator<QCanvasEllipse> it( hoshisList );
1716
for ( ; it.current(); ++it )
1717
it.current()->setBrush(Qt::black);
1723
� * Calculates the gatter intersections and hoshis position
1725
void Gatter::resize(int offsetX, int offsetY, int square_size)
1730
int size = square_size / 5;
1731
// Round size top be even
1738
for (i=0; i<board_size; i++)
1739
for (j=0; j<board_size; j++)
1741
HGatter[i][j]->setPoints(int(offsetX + square_size * ( i - 0.5*(i!=0))),
1742
offsetY + square_size * j,
1743
int(offsetX + square_size * ( i + 0.5 * (i+1 != board_size))),
1744
offsetY + square_size * j );
1746
VGatter[i][j]->setPoints(offsetX + square_size * i,
1747
int(offsetY + square_size * ( j - 0.5*(j!=0))),
1748
offsetX + square_size * i,
1749
int(offsetY + square_size * ( j + 0.5 * (j+1 != board_size))));
1751
e=hoshisList.find(board_size*(i+1)+j+1);
1754
e->setSize(size, size);
1755
e->setX(offsetX + square_size * i);
1756
e->setY(offsetY + square_size * j);
1763
� * Resets all interctions and hoshis to be shown
1765
void Gatter::showAll()
1770
for (i=0; i<board_size; i++)
1771
for (j=0; j<board_size; j++)
1773
VGatter[i][j]->show();
1774
HGatter[i][j]->show();
1777
QIntDictIterator<QCanvasEllipse> it( hoshisList );
1778
for ( ; it.current(); ++it )
1779
it.current()->show();
1783
� * Hides an intersection (when placing a letter mark)
1785
void Gatter::hide(int i, int j)
1789
if (( i<1) || (i > board_size) || ( j<1) || (j > board_size))
1792
VGatter[i-1][j-1]->hide();
1793
HGatter[i-1][j-1]->hide();
1795
e=hoshisList.find(board_size*i+j);
1802
� * shows an intersection (when removing a letter mark)
1804
void Gatter::show(int i, int j)
1808
if (( i<1) || (i > board_size) || ( j<1) || (j > board_size))
1811
VGatter[i-1][j-1]->show();
1812
HGatter[i-1][j-1]->show();
1814
e=hoshisList.find(board_size*i+j);