~ubuntu-branches/ubuntu/lucid/qgo/lucid

« back to all changes in this revision

Viewing changes to src/board.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Chaboisseau
  • Date: 2006-10-03 23:46:07 UTC
  • mfrom: (1.2.1 upstream) (2.1.9 edgy)
  • Revision ID: james.westby@ubuntu.com-20061003234607-jtuoreigx712b4lw
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
* board.cpp
3
3
*/
 
4
#include <vector>
4
5
 
5
6
#include "config.h"
6
7
#include "setting.h"
32
33
        
33
34
        board_size = DEFAULT_BOARD_SIZE;
34
35
        showCoords = setting->readBoolEntry("BOARD_COORDS");
35
 
  
 
36
        showSGFCoords = setting->readBoolEntry("SGF_BOARD_COORDS");
 
37
        antiClicko = setting->readBoolEntry("ANTICLICKO");
 
38
 
 
39
        
36
40
        // Create a BoardHandler instance.
37
41
        boardHandler = new BoardHandler(this);
38
42
        CHECK_PTR(boardHandler);
48
52
        canvas->resize(BOARD_X, BOARD_Y);
49
53
        setCanvas(canvas);
50
54
        
 
55
        gatter = new Gatter(canvas, board_size);
 
56
 
51
57
        // Init data storage for marks and ghosts
52
58
        marks = new QPtrList<Mark>;
53
59
        marks->setAutoDelete(TRUE);
58
64
        
59
65
        // Init the gatter size and the imagehandler pixmaps
60
66
        calculateSize();
 
67
 
61
68
        imageHandler->init(square_size);
62
69
        
63
70
        // Initialize some class variables
71
78
                        letterPool[i] = false;
72
79
                numberPool[i] = false;
73
80
        }
74
 
        coordsTip = new Tip(this);
 
81
        
 
82
        //coordsTip = new Tip(this);
75
83
#ifdef Q_WS_WIN
76
84
        resizeDelayFlag = false;
77
85
#endif
86
94
        curStone->hide();                       
87
95
 
88
96
        lockResize = false;
89
 
  navIntersectionStatus = false;
 
97
        navIntersectionStatus = false;
90
98
  
91
99
        updateCaption();
 
100
        gatter_created = false;
92
101
}
93
102
 
94
103
Board::~Board()
95
104
{
96
 
    delete coordsTip;
 
105
//    delete coordsTip;
97
106
    delete curStone;
98
107
    delete boardHandler;
99
108
    marks->clear();
155
164
        boardHandler->gotoFirstMove();
156
165
 
157
166
    // Clear background before canvas is resized
158
 
    canvas->setBackgroundPixmap(*(ImageHandler::getTablePixmap()));
 
167
    canvas->setBackgroundPixmap(*(ImageHandler::getTablePixmap(setting->readEntry("SKIN_TABLE"))));
159
168
 
160
169
    // Resize canvas
161
170
    canvas->resize(w, h);
164
173
    calculateSize();
165
174
 
166
175
    // Rescale the pixmaps in the ImageHandler
167
 
    imageHandler->rescale(square_size, setting->readBoolEntry("SMALL_STONES"));
 
176
    imageHandler->rescale(square_size);//, setting->readBoolEntry("SMALL_STONES"));
168
177
 
169
178
    // Delete gatter lines and update stones positions
170
179
    QCanvasItemList list = canvas->allItems();
173
182
    for(it = list.begin(); it != list.end(); ++it)
174
183
    {
175
184
                item = *it;
176
 
                if (item->rtti() == 6 || item->rtti() == 7 || item->rtti() == 3)
 
185
                if (item->rtti() == 3)// || item->rtti() == 6)// || item->rtti() == 7)
177
186
                {
178
187
                        item->hide();
179
188
                        delete item;
212
221
        // Redraw the board
213
222
        drawBackground();
214
223
        drawGatter();
 
224
        
215
225
        if (showCoords)
216
226
                drawCoordinates();
217
227
 
246
256
        
247
257
    // Paint table and board on the pixmap
248
258
    QPainter painter;
249
 
    QBrush board;
250
 
    board.setPixmap(*(ImageHandler::getBoardPixmap(static_cast<skinType>(setting->readIntEntry("SKIN")))));
251
 
    QBrush table;
 
259
    //QBrush board;
 
260
//    board.setPixmap(*(ImageHandler::getBoardPixmap(static_cast<skinType>(setting->readIntEntry("SKIN")))));
 
261
    //board.setPixmap(*(ImageHandler::getBoardPixmap(setting->readEntry("SKIN"))));
 
262
    //QBrush table;
252
263
    // table.setPixmap(*(imageHandler->getTablePixmap()));
253
 
    table.setPixmap(*(ImageHandler::getTablePixmap()));
 
264
    //table.setPixmap(*(ImageHandler::getTablePixmap()));
 
265
    //painter.flush();
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"))));
 
270
    //painter.fillRect(
 
271
    painter.drawTiledPixmap (
 
272
                offsetX - offset,
258
273
                offsetY - offset,
259
274
                board_pixel_size + offset*2,
260
275
                board_pixel_size + offset*2,
261
 
                board);
262
 
 
263
 
   
264
 
    /*
265
 
    QColor c = QColor("darkGrey") ;   
266
 
      
267
 
    painter.setRasterOp(Qt::AndROP);
268
 
 
269
 
    painter.setPen(c.dark(145));
270
 
    painter.drawLine( offsetX - offset,
271
 
                                  offsetY - offset,
272
 
                      offsetX - offset,
273
 
                      offsetY + board_pixel_size + offset);
274
 
                      
275
 
     painter.setPen(c);
276
 
     painter.drawLine(offsetX - offset +1,
277
 
                                  offsetY - offset,
278
 
                      offsetX - offset +1,
279
 
                      offsetY + board_pixel_size + offset);                     
280
 
 
281
 
 
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);
287
 
 
288
 
     painter.setPen(c);
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 ); 
293
 
 
294
 
    painter.setRasterOp(Qt::OrROP);
295
 
 
296
 
    painter.setPen(c.light(100));
297
 
    painter.drawLine( offsetX + board_pixel_size + offset-1,
298
 
                                  offsetY - offset,
299
 
                      offsetX + board_pixel_size + offset-1,
300
 
                      offsetY + board_pixel_size + offset -1);
301
 
 
302
 
     painter.setPen(c);
303
 
     painter.drawLine(offsetX + board_pixel_size + offset-2,
304
 
                                  offsetY - offset,
305
 
                      offsetX + board_pixel_size + offset-2,
306
 
                      offsetY + board_pixel_size + offset -1);
307
 
 
308
 
 
309
 
     painter.setPen(c.light(100));
310
 
     painter.drawLine(offsetX - offset,
311
 
                                  offsetY  - offset,
312
 
                      offsetX + board_pixel_size + offset -1,
313
 
                      offsetY - offset);
314
 
 
315
 
     painter.setPen(c);
316
 
     painter.drawLine( offsetX - offset,
317
 
                                  offsetY  - offset +1,
318
 
                      offsetX + board_pixel_size + offset -1,
319
 
                      offsetY - offset +1);
320
 
    */
321
 
    painter.end();
322
 
 
323
 
 
324
 
 
325
 
  
326
 
    // Set pixmap as canvas background
327
 
    canvas->setBackgroundPixmap(all);
 
276
                *(ImageHandler::getBoardPixmap(setting->readEntry("SKIN"))));
 
277
 
 
278
        painter.end();
 
279
 
 
280
        QImage image = all.convertToImage();
 
281
        int lighter=20;
 
282
        int darker=60;
 
283
        int width = 3; 
 
284
 
 
285
        int x,y;
 
286
        for(x=0;x<width;x++)
 
287
                for (y= offsetY - offset +x ; y<offsetY + board_pixel_size + offset-x ;y++)
 
288
                {
 
289
                        image.setPixel(
 
290
                                offsetX - offset+x , 
 
291
                                y, 
 
292
                                QColor(image.pixel(offsetX - offset+x,y)).dark(int(100 + darker*(width-x)*(width-x)/width/width)).rgb());
 
293
 
 
294
                        image.setPixel(
 
295
                                offsetX + board_pixel_size + offset-x -1, 
 
296
                                y,
 
297
                                QColor(image.pixel(offsetX + board_pixel_size + offset-x-1,y)).light(100+ int(lighter*(width-x)*(width-x)/width/width)).rgb());
 
298
                }
 
299
 
 
300
        for(y=0;y<width;y++)
 
301
                for (x= offsetX - offset +y ; x<offsetX + board_pixel_size + offset-y ;x++)
 
302
                {
 
303
                        image.setPixel(
 
304
                                x,
 
305
                                offsetY - offset+y , 
 
306
                                QColor(image.pixel(x,offsetY - offset+y)).light(int(100 + lighter*(width-y)*(width-y)/width/width)).rgb());
 
307
 
 
308
                        image.setPixel(
 
309
                                x,
 
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());
 
312
                }
 
313
 
 
314
 
 
315
        width = 10;
 
316
        darker=50;
 
317
 
 
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++)
 
320
                {
 
321
                        image.setPixel(
 
322
                                offsetX - offset-1-x  , 
 
323
                                y, 
 
324
                                QColor(image.pixel(offsetX - offset-1-x,y)).dark(int(100 + darker*(width-x)/width)).rgb());
 
325
                }
 
326
 
 
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++)
 
329
                {
 
330
                        image.setPixel(
 
331
                                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());
 
334
                }
 
335
 
 
336
 
 
337
        all.convertFromImage(image);
 
338
        // Set pixmap as canvas background
 
339
        canvas->setBackgroundPixmap(all);
328
340
}
329
341
 
330
342
void Board::drawGatter()
331
343
{
332
 
        QCanvasLine *line;
333
 
        int i;
 
344
/*      QCanvasLine *line;
 
345
        int i,j;
334
346
        
 
347
        static QCanvasLine  *VGatter[361];
 
348
        static QCanvasLine  *HGatter[361];
 
349
 
335
350
        // Draw vertical lines
336
351
        for (i=0; i<board_size; i++)
337
352
        {
349
364
                        offsetX + board_pixel_size, offsetY + square_size * i);
350
365
                line->show();
351
366
        }
352
 
        
 
367
        */
 
368
        gatter->resize(offsetX,offsetY,square_size);
 
369
/*
353
370
        // Draw the little circles on the starpoints
354
371
        int edge_dist = (board_size > 12 ? 4 : 3);
355
372
        int low = edge_dist;
368
385
        drawStarPoint(low, high);
369
386
        drawStarPoint(high, low);
370
387
        drawStarPoint(high, high);
371
 
 
 
388
*/
372
389
        updateCanvas();
373
390
}
374
391
 
385
402
    
386
403
    circle = new QCanvasEllipse(canvas);
387
404
    circle->setBrush(black);
388
 
    circle->setSize((double)size, (double)size);
 
405
    circle->setSize(size, size);
389
406
    circle->setX(offsetX + square_size * (x-1));
390
407
    circle->setY(offsetY + square_size * (y-1));
391
408
    
396
413
{
397
414
    QCanvasText *coord;
398
415
    int i;
399
 
    const int off = 2,
400
 
    coord_centre = (offset - square_size/2 )/2; // centres the coordinates text within the remaining space at table edge
 
416
    //const int off = 2,
 
417
    const int coord_centre = (offset - square_size/2 )/2; // centres the coordinates text within the remaining space at table edge
 
418
    QString txt;
401
419
 
402
 
  
403
420
    // Draw vertical coordinates. Numbers
404
421
    for (i=0; i<board_size; i++)
405
422
    {
406
423
                // Left side
407
 
                coord = new QCanvasText(QString::number(board_size-i), canvas);
 
424
                if(showSGFCoords)
 
425
                        txt = QString(QChar(static_cast<const char>('a' + i)));
 
426
                else
 
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);
410
431
                coord->show();
411
432
                // Right side
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);
415
436
                coord->show();
416
437
    }
418
439
    // Draw horizontal coordinates. Letters (Note: Skip 'i')
419
440
    for (i=0; i<board_size; i++)
420
441
    {
421
 
                QString txt = QString(QChar(static_cast<const char>('A' + (i<8?i:i+1))));
 
442
                if(showSGFCoords)
 
443
                        txt = QString(QChar(static_cast<const char>('a' + i)));
 
444
                else
 
445
                        txt = QString(QChar(static_cast<const char>('A' + (i<8?i:i+1))));
422
446
                // Top
423
447
                coord = new QCanvasText(txt, canvas);
424
448
                coord->setX(offsetX + square_size * i - coord->boundingRect().width()/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)
448
 
      return NULL;
 
472
        return NULL;
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.
452
476
     {
453
 
      Stone *s = boardHandler->getStoneHandler()->getStoneAt(x, y);
454
 
                        CHECK_PTR(s);
455
 
        s->setColor(c);
456
 
                        s->setPos(x, y);
457
 
                        return s;
 
477
        Stone *s = boardHandler->getStoneHandler()->getStoneAt(x, y);
 
478
        CHECK_PTR(s);
 
479
        s->setColor(c);
 
480
        s->setPos(x, y);
 
481
        return s;
458
482
     }
459
483
      
460
484
    case 0:  // No stone existing. Create a new one
461
485
                {
462
486
                        // qDebug("*** Did not find any stone at %d, %d.", x, y);
463
487
                        
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);
 
489
                        
 
490
                        if (boardHandler->getGameData()->oneColorGo)
 
491
                                s->toggleOneColorGo(true);
467
492
              
468
493
                        CHECK_PTR(s);
469
494
                        
470
495
                        s->setX(offsetX + square_size * (x-1));
471
496
                        s->setY(offsetY + square_size * (y-1));
 
497
 
472
498
                        
473
499
                        // Change color of a mark on this spot to white, if we have a black stone
474
500
                        if (c == stoneBlack)
566
592
                return;
567
593
        
568
594
    // Update the statusbar coords tip
569
 
    emit coordsChanged(x, y, board_size);
 
595
    emit coordsChanged(x, y, board_size,showSGFCoords);
570
596
        
571
597
    // Remember if the cursor was hidden meanwhile.
572
598
    // If yes, we need to repaint it at the old position.
586
612
    curStone->setX(offsetX + square_size * (x-1));
587
613
    curStone->setY(offsetY + square_size * (y-1));
588
614
    curStone->setPos(x, y);
 
615
 
 
616
    bool notMyTurn =    (curStone->getColor() == stoneBlack && !myColorIsBlack ||
 
617
                         curStone->getColor() == stoneWhite && myColorIsBlack);
 
618
    
 
619
    if (navIntersectionStatus ||              
 
620
        boardHandler->getGameMode() == modeObserve ||
 
621
        ( boardHandler->getGameMode() == modeMatch && notMyTurn) ||
 
622
        ( boardHandler->getGameMode() == modeComputer && notMyTurn))
589
623
        
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();
597
625
    else
598
 
      curStone->show();
 
626
                curStone->show();
599
627
    
600
628
    canvas->update();
601
629
}
613
641
                return;
614
642
        
615
643
    // Needs an extra check on variable mouseState as state() does not work on Windows.
616
 
    if (e->delta() == -120)
 
644
    if (e->delta() == 120)
617
645
    {
618
646
                if (e->state() == RightButton || mouseState == RightButton)
619
647
                        nextVariation();
635
663
    e->accept();
636
664
}
637
665
 
638
 
void Board::contentsMouseReleaseEvent(QMouseEvent*)
 
666
void Board::contentsMouseReleaseEvent(QMouseEvent* e)
639
667
{
640
 
    mouseState = NoButton;
 
668
        mouseState = NoButton;
 
669
    
 
670
        int     x = convertCoordsToPoint(e->x(), offsetX),
 
671
                y = convertCoordsToPoint(e->y(), offsetY);
 
672
        
 
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());
 
675
        
 
676
        if (    (boardHandler->getGameMode()==modeMatch) && 
 
677
                (QTime::currentTime() > wheelTime))
 
678
        {       
 
679
                
 
680
                if (boardHandler->getBlackTurn())
 
681
                {
 
682
                        if (myColorIsBlack)
 
683
                        {
 
684
                                boardHandler->addStone(stoneBlack, x, y);
 
685
                                emit signal_addStone(stoneBlack, x, y);
 
686
                        }
 
687
                }
 
688
                else
 
689
                {
 
690
                        if (!myColorIsBlack)
 
691
                        {
 
692
                                boardHandler->addStone(stoneWhite, x, y);
 
693
                                emit signal_addStone(stoneWhite, x, y);
 
694
                        }
 
695
                }  
 
696
        
 
697
        }
 
698
        
 
699
        
 
700
         
641
701
}
642
702
 
643
703
void Board::contentsMousePressEvent(QMouseEvent *e)
689
749
//      this->topLevelWidget()->setCursor(ArrowCursor);
690
750
//   *** Therefore we apply thick method :
691
751
 
692
 
        QApplication::restoreOverrideCursor();
693
 
             
 
752
        QApplication::restoreOverrideCursor();  
694
753
        boardHandler->findMoveByPos(x, y);                                 //SL added eb 11
695
 
                                return;
696
 
                }                         // end add eb 11
 
754
        return;
 
755
        }                         // end add eb 11
697
756
 
698
757
 
699
758
    // resume normal proceeding
705
764
                case LeftButton:
706
765
                        if (e->state() == ShiftButton)   // Shift: Find move in main branch
707
766
                        {
708
 
        navIntersectionStatus = false;
709
 
        boardHandler->findMoveByPos(x, y);                                 //SL added eb 11
 
767
                                navIntersectionStatus = false;
 
768
                                boardHandler->findMoveByPos(x, y);                                 //SL added eb 11
710
769
                                return;
711
770
                        }
712
771
                        else if (e->state() == ControlButton)  // Control: Find move in all following variations
731
790
                                boardHandler->addStone(stoneWhite, x, y);
732
791
                        
733
792
                        break;
 
793
                        
734
794
                case RightButton:
735
795
                        if (e->state() == ShiftButton)  // Shift: Find move in this branch
736
796
                        {
738
798
                                return;
739
799
                        }
740
800
                        break;
 
801
                        
741
802
                default:
742
803
                        break;
743
804
                }
811
872
                break;
812
873
                
813
874
        case modeMatch:
814
 
                if (boardHandler->getBlackTurn())
 
875
                // Delay of 250 msecs to avoid clickos
 
876
                wheelTime = QTime::currentTime();
 
877
                //qDebug("Mouse pressed at time %d,%03d", wheelTime.second(),wheelTime.msec());
 
878
                if (antiClicko)
 
879
                        wheelTime = wheelTime.addMSecs(250);
 
880
                
 
881
                
 
882
                /*if (boardHandler->getBlackTurn())
815
883
                {
816
884
                        if (myColorIsBlack)
817
885
                        {
826
894
                                boardHandler->addStone(stoneWhite, x, y);
827
895
                                emit signal_addStone(stoneWhite, x, y);
828
896
                        }
829
 
                }
 
897
                }*/
830
898
                break;
831
899
 
832
900
        case modeComputer:                          //added eb 12
 
901
        
 
902
 
833
903
                if (boardHandler->getBlackTurn())
834
904
                {
835
905
                        if (myColorIsBlack)
836
906
                        {
837
907
                                boardHandler->addStone(stoneBlack, x, y);
838
 
//        boardHandler->updateMove(boardHandler->getTree()->getCurrent());
839
908
                                emit signal_Stone_Computer(stoneBlack, x, y);
840
909
                        }
841
910
                }
844
913
                        if (!myColorIsBlack)
845
914
                        {
846
915
                                boardHandler->addStone(stoneWhite, x, y);
847
 
//        boardHandler->updateMove(boardHandler->getTree()->getCurrent());
848
916
                                emit signal_Stone_Computer(stoneWhite, x, y);
849
917
                        }
850
918
                }
910
978
{
911
979
    MarkText::maxLength = 1;
912
980
    marks->clear();
 
981
                
 
982
    gatter->showAll();
 
983
 
913
984
    for (int i=0; i<400; i++)
914
985
    {
915
986
                if (i < 52)
986
1057
                return;
987
1058
        
988
1059
    Mark *m;
989
 
        
 
1060
 
990
1061
    // We already have a mark on this spot? If it is of the same type,
991
1062
    // do nothing, else overwrite with the new mark.
992
1063
    if ((m = hasMark(x, y)) != NULL)
1019
1090
                break;
1020
1091
                
1021
1092
    case markCircle:
1022
 
                m = new MarkCircle(x, y, square_size, canvas, col, setting->readBoolEntry("SMALL_STONES"));
 
1093
                m = new MarkCircle(x, y, square_size, canvas, col, true);//setting->readBoolEntry("SMALL_STONES"));
1023
1094
        break;
1024
1095
                
1025
1096
    case markTriangle:
1056
1127
                                letterPool[n] = true;
1057
1128
                }
1058
1129
                m = new MarkText(imageHandler, x, y, square_size, txt, canvas, col, n, false, overlay);
1059
 
                setMarkText(x, y, txt);
 
1130
                gatter->hide(x,y);//setMarkText(x, y, txt);
1060
1131
                break;
1061
1132
                
1062
1133
    case markNumber:
1076
1147
                numberPool[n] = true;
1077
1148
                m = new MarkNumber(imageHandler, x, y, square_size, n, canvas, col, false);
1078
1149
                setMarkText(x, y, txt);
 
1150
                gatter->hide(x,y);
1079
1151
                break;
1080
1152
                
1081
1153
    case markTerrBlack:
1083
1155
                if (boardHandler->hasStone(x, y) == 1)
1084
1156
                {
1085
1157
                        boardHandler->getStoneHandler()->getStoneAt(x, y)->setDead(true);
1086
 
                        boardHandler->getStoneHandler()->getStoneAt(x, y)->
1087
 
                                setSequence(imageHandler->getGhostPixmaps());
 
1158
                        boardHandler->getStoneHandler()->getStoneAt(x, y)->setSequence(imageHandler->getGhostPixmaps());
 
1159
                        boardHandler->getStoneHandler()->getStoneAt(x, y)->shadow->hide();
1088
1160
                        boardHandler->markedDead = true;
1089
1161
                }
1090
1162
                boardHandler->getTree()->getCurrent()->setScored(true);
1095
1167
                if (boardHandler->hasStone(x, y) == 1)
1096
1168
                {
1097
1169
                        boardHandler->getStoneHandler()->getStoneAt(x, y)->setDead(true);
1098
 
                        boardHandler->getStoneHandler()->getStoneAt(x, y)->
1099
 
                                setSequence(imageHandler->getGhostPixmaps());
 
1170
                        boardHandler->getStoneHandler()->getStoneAt(x, y)->setSequence(imageHandler->getGhostPixmaps());
 
1171
                        boardHandler->getStoneHandler()->getStoneAt(x, y)->shadow->hide();
1100
1172
                        boardHandler->markedDead = true;
1101
1173
                }
1102
1174
                boardHandler->getTree()->getCurrent()->setScored(true);
1140
1212
                        }
1141
1213
                        
1142
1214
                        marks->remove(m);
 
1215
                        gatter->show(x,y);
1143
1216
                        if (update)
1144
1217
                                boardHandler->editMark(x, y, markNone);
1145
1218
                        return;
1161
1234
    m->setSize((double)square_size, (double)square_size);
1162
1235
    m->setX(offsetX + square_size * (x-1) - m->getSizeX()/2);
1163
1236
    m->setY(offsetY + square_size * (y-1) - m->getSizeY()/2);
 
1237
        
1164
1238
}
1165
1239
 
1166
1240
Mark* Board::hasMark(int x, int y)
1319
1393
                changeSize();  // Redraw the board if the value changed.
1320
1394
}
1321
1395
 
 
1396
void Board::setShowSGFCoords(bool b)
 
1397
{
 
1398
        bool old = showSGFCoords;
 
1399
        showSGFCoords = b;
 
1400
        if(old != showSGFCoords)
 
1401
                changeSize();  // Redraw the board if the value changed.
 
1402
}
 
1403
 
1322
1404
void Board::initGame(GameData *d, bool sgf)
1323
1405
{
1324
1406
    CHECK_PTR(d);
1514
1596
 
1515
1597
}
1516
1598
 
 
1599
void Board::doResign()
 
1600
{
 
1601
        emit signal_resign();
 
1602
}
 
1603
 
1517
1604
void Board::set_isLocalGame(bool isLocal)
1518
1605
{
1519
1606
        isLocalGame = isLocal;
1524
1611
                ((MainWindow*)topLevelWidget())->getListView_observers()->show();
1525
1612
}
1526
1613
 
1527
 
void Board::navIntersection()             //added eb 11
 
1614
void Board::navIntersection()          
1528
1615
{
1529
1616
   
1530
1617
 /***** several unsuccessful tries with clean method
1562
1649
� **/
1563
1650
QString Board::getCandidateFileName()
1564
1651
{
1565
 
  GameData data = getGameData();
1566
 
  QString result = data.playerBlack + "-" + data.playerWhite;
1567
 
  return result;
1568
 
}
1569
 
 
1570
 
 
1571
 
 
1572
 
 
1573
 
 
1574
 
    
 
 
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 ;
 
1655
        QString dir= "" ;
 
1656
 
 
1657
        if (setting->readBoolEntry("REM_DIR"))
 
1658
                        dir = setting->readEntry("LAST_DIR");
 
1659
        int i = 1;
 
1660
        while (QFile(dir + result+".sgf").exists())
 
1661
        {
 
1662
                //number = Q.number(i++);
 
1663
                result = base + "-"+ QString::number(i++);
 
1664
                //fileName = fileName + ".sgf";
 
1665
        } 
 
1666
        return dir + result + ".sgf";
 
1667
}
 
1668
 
 
1669
 /**
 
1670
� * Initialises the gatter intersections and hoshis points
 
1671
� **/
 
1672
Gatter::Gatter(QCanvas *Canvas, int size)
 
1673
{
 
1674
        int i,j;
 
1675
 
 
1676
        board_size = size;
 
1677
        canvas=Canvas;  
 
1678
 
 
1679
        VGatter.reserve(board_size);
 
1680
        HGatter.reserve(board_size);
 
1681
        for (i=0; i<board_size; i++)
 
1682
        {       
 
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);
 
1688
                
 
1689
                for (j=0; j<board_size; j++)
 
1690
                {
 
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]);
 
1695
                }
 
1696
        }
 
1697
        
 
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)
 
1703
        {
 
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));
 
1709
        }
 
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));
 
1714
 
 
1715
        QIntDictIterator<QCanvasEllipse> it( hoshisList );
 
1716
        for ( ; it.current(); ++it )
 
1717
                it.current()->setBrush(Qt::black);
 
1718
 
 
1719
        showAll();
 
1720
}
 
1721
 
 
1722
 /**
 
1723
� * Calculates the gatter intersections and hoshis position
 
1724
� **/
 
1725
void Gatter::resize(int offsetX, int offsetY, int square_size)
 
1726
{
 
1727
        int i,j;
 
1728
        QCanvasEllipse *e;
 
1729
 
 
1730
        int size = square_size / 5;
 
1731
        // Round size top be even
 
1732
        if (size % 2 > 0)
 
1733
                size--;
 
1734
        if (size < 6)
 
1735
                size = 6;
 
1736
 
 
1737
 
 
1738
        for (i=0; i<board_size; i++)
 
1739
                for (j=0; j<board_size; j++)
 
1740
                {
 
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 );
 
1745
                        
 
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)))); 
 
1750
                        
 
1751
                        e=hoshisList.find(board_size*(i+1)+j+1);
 
1752
                        if (e)
 
1753
                        {
 
1754
                                e->setSize(size, size);
 
1755
                                e->setX(offsetX + square_size * i);
 
1756
                                e->setY(offsetY + square_size * j);
 
1757
                        }
 
1758
                }
 
1759
 
 
1760
}
 
1761
 
 
1762
 /**
 
1763
� * Resets all interctions and hoshis to be shown
 
1764
� **/
 
1765
void Gatter::showAll()
 
1766
{
 
1767
        int i,j;
 
1768
        QCanvasEllipse *e;
 
1769
 
 
1770
        for (i=0; i<board_size; i++)
 
1771
                for (j=0; j<board_size; j++)
 
1772
                {
 
1773
                        VGatter[i][j]->show();
 
1774
                        HGatter[i][j]->show();
 
1775
                }
 
1776
 
 
1777
        QIntDictIterator<QCanvasEllipse> it( hoshisList );
 
1778
        for ( ; it.current(); ++it )
 
1779
                it.current()->show();
 
1780
}
 
1781
 
 
1782
 /**
 
1783
� * Hides an intersection (when placing a letter mark)
 
1784
� **/
 
1785
void Gatter::hide(int i, int j)
 
1786
{
 
1787
        QCanvasEllipse *e;
 
1788
        
 
1789
        if (( i<1) || (i > board_size) || ( j<1) || (j > board_size))
 
1790
                return;
 
1791
 
 
1792
        VGatter[i-1][j-1]->hide();
 
1793
        HGatter[i-1][j-1]->hide();
 
1794
 
 
1795
        e=hoshisList.find(board_size*i+j);
 
1796
        if (e)
 
1797
                e->hide();
 
1798
 
 
1799
}
 
1800
 
 
1801
 /**
 
1802
� * shows an intersection (when removing a letter mark)
 
1803
� **/
 
1804
void Gatter::show(int i, int j)
 
1805
{
 
1806
        QCanvasEllipse *e;
 
1807
 
 
1808
        if (( i<1) || (i > board_size) || ( j<1) || (j > board_size))
 
1809
                return;
 
1810
 
 
1811
        VGatter[i-1][j-1]->show();
 
1812
        HGatter[i-1][j-1]->show();
 
1813
 
 
1814
        e=hoshisList.find(board_size*i+j);
 
1815
        if (e)
 
1816
                e->show();
 
1817
 
 
1818
}
 
1819