SVN_SILENT made messages (.desktop file)
[kdegames.git] / kblackbox / kbbgraphicsitemray.cpp
blobfe1d5cdac0a1b9243025bfe86daf0c08d8d4bacf
1 //
2 // KBlackBox
3 //
4 // A simple game inspired by an emacs module
5 //
6 /***************************************************************************
7 * Copyright (c) 1999-2000, Robert Cimrman *
8 * cimrman3@students.zcu.cz *
9 * *
10 * Copyright (c) 2007, Nicolas Roffet *
11 * nicolas-kde@roffet.com *
12 * *
13 * *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. *
18 * *
19 * This program is distributed in the hope that it will be useful, *
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22 * GNU General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU General Public License *
25 * along with this program; if not, write to the *
26 * Free Software Foundation, Inc., *
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA *
28 ***************************************************************************/
31 #include "kbbgraphicsitemray.h"
33 #include <QGraphicsScene>
34 #include <QList>
35 #include <QPainterPath>
36 #include <QPen>
39 #include "kbbballsonboard.h"
40 #include "kbbgamedoc.h"
41 #include "kbbgraphicsitemborder.h"
42 #include "kbbscalablegraphicwidget.h"
43 #include "kbbthememanager.h"
48 // Constructor / Destructor
51 KBBGraphicsItemRay::KBBGraphicsItemRay(KBBScalableGraphicWidget::itemType itemType, QGraphicsScene* scene, KBBThemeManager* themeManager) : KBBGraphicsItemBorder(0, 1, 1, KBBScalableGraphicWidget::BORDER_SIZE/2), QGraphicsPathItem (0, scene)
53 QPen pen;
55 pen.setColor(themeManager->color(itemType));
56 pen.setStyle(themeManager->style(itemType));
57 pen.setWidthF(themeManager->width(itemType));
58 setZValue(themeManager->zValue(itemType));
60 pen.setJoinStyle(Qt::RoundJoin);
61 pen.setCapStyle(Qt::RoundCap);
63 setPen(pen);
69 // Public
72 void KBBGraphicsItemRay::draw(KBBBallsOnBoard* ballsOnBoard, const int borderPosition)
74 const int columns = ballsOnBoard->columns();
75 const int rows = ballsOnBoard->rows();
77 QList<int> points;
78 const int oppositeBorderPosition = ballsOnBoard->oppositeBorderPositionWithPoints(borderPosition, points);
80 QPainterPath path;
81 setSize(borderPosition, columns, rows);
82 path.moveTo(m_centerX, m_centerY);
84 const float b = (float) KBBScalableGraphicWidget::BORDER_SIZE;
85 const float r = (float) KBBScalableGraphicWidget::RATIO;
86 float x;
87 float y;
88 for (int i=0; i<points.count(); i++) {
89 x = b - r/2 + r*((points[i] % columns) + 1);
90 y = b - r/2 + r*((points[i] / columns) + 1);
91 path.lineTo(x,y);
94 if (oppositeBorderPosition!=KBBGameDoc::HIT_POSITION) {
95 float x1;
96 float y1;
97 centerCoordinate(oppositeBorderPosition, x1, y1, b/2.);
98 path.lineTo(x1,y1);
101 setPath(path);
105 void KBBGraphicsItemRay::hide()
107 setPath(QPainterPath());