~ubuntu-branches/ubuntu/quantal/kdegames/quantal

« back to all changes in this revision

Viewing changes to kigo/src/gui/graphicsview/gamescene.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac, Philip Muškovac, Felix Geyer
  • Date: 2011-12-24 17:12:20 UTC
  • mfrom: (1.3.15)
  • Revision ID: package-import@ubuntu.com-20111224171220-668s85tl3su8pejn
Tags: 4:4.7.95-0ubuntu1
[ Philip Muškovac ]
* New upstream release candidate

[ Felix Geyer ]
* Update symbol files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
namespace Kigo {
31
31
 
 
32
    const int dotPositions9[] = {2,2, 2,6, 6,2, 6,6, 4,4};
 
33
    const int dotPositions13[] = {3,3, 3,9, 9,3, 9,9, 6,6};
 
34
    const int dotPositions19[] = {3,3, 3,9, 3,15, 9,3, 9,9, 9,15, 15,3, 15,9, 15,15};
 
35
 
32
36
GameScene::GameScene(Game *game, QObject *parent)
33
37
    : QGraphicsScene(parent), m_game(game)
34
38
    , m_showLabels(Preferences::showBoardLabels()), m_showHint(false)
313
317
    ThemeRenderer::self()->renderElement(ThemeRenderer::Background, painter, sceneRect());
314
318
    ThemeRenderer::self()->renderElement(ThemeRenderer::Board, painter, m_boardRect);
315
319
 
 
320
    int width = m_cellSize / 16;
 
321
    QColor color = QColor(20, 30, 20);
 
322
    painter->setPen(QPen(color, width));
 
323
 
316
324
    for (int i = 0; i < m_boardSize; i++) {
317
325
        qreal offset = i * m_cellSize;
318
 
        painter->setPen(QPen(QColor(20, 30, 20), m_cellSize / 16));
319
326
        painter->drawLine(QPointF(m_gridRect.left(),  m_gridRect.top() + offset),
320
327
                          QPointF(m_gridRect.right(), m_gridRect.top() + offset));
321
328
        painter->drawLine(QPointF(m_gridRect.left() + offset, m_gridRect.top()),
345
352
            painter->drawText(QPointF(xHor, m_gridRect.bottom() + m_cellSize - 3), QString(c));
346
353
        }
347
354
    }
 
355
 
 
356
    // Draw thicker connections on some defined points.
 
357
    // This is extremely helpful to orientate oneself especially on the 19x19 board.
 
358
    int radius = m_cellSize / 10;
 
359
    painter->setBrush(color);
 
360
    painter->setRenderHint(QPainter::Antialiasing);
 
361
 
 
362
    // in order to center properly we need to take line width into account
 
363
    // if the line has an odd width, we shift 1/5 pixel
 
364
    qreal centerOffset = (width % 2) ? 0.5 : 0.0;
 
365
 
 
366
    // only do this for the common board sizes,
 
367
    // other sizes are a bit odd anyway
 
368
    int numDots = 0;
 
369
    const int *dotPositions;
 
370
 
 
371
    if (m_boardSize == 9) {
 
372
        numDots = 5;
 
373
        dotPositions = dotPositions9;
 
374
    } else if (m_boardSize == 13) {
 
375
        numDots = 5;
 
376
        dotPositions = dotPositions13;
 
377
    } else if (m_boardSize == 19) {
 
378
        numDots = 9;
 
379
        dotPositions = dotPositions19;
 
380
    }
 
381
 
 
382
    for (int i = 0; i < numDots; ++i) {
 
383
        painter->drawEllipse(
 
384
            QPointF(m_gridRect.left() + m_cellSize*dotPositions[i*2] + centerOffset,
 
385
                    m_gridRect.top() + m_cellSize*dotPositions[i*2+1] + centerOffset),
 
386
            radius, radius);
 
387
    }
348
388
}
349
389
 
350
390
} // End of namespace Kigo