4 // A simple game inspired by an emacs module
6 /***************************************************************************
7 * Copyright (c) 1999-2000, Robert Cimrman *
8 * cimrman3@students.zcu.cz *
10 * Copyright (c) 2007, Nicolas Roffet *
11 * nicolas-kde@roffet.com *
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. *
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. *
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>
35 #include <QPainterPath>
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
)
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
);
72 void KBBGraphicsItemRay::draw(KBBBallsOnBoard
* ballsOnBoard
, const int borderPosition
)
74 const int columns
= ballsOnBoard
->columns();
75 const int rows
= ballsOnBoard
->rows();
78 const int oppositeBorderPosition
= ballsOnBoard
->oppositeBorderPositionWithPoints(borderPosition
, points
);
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
;
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);
94 if (oppositeBorderPosition
!=KBBGameDoc::HIT_POSITION
) {
97 centerCoordinate(oppositeBorderPosition
, x1
, y1
, b
/2.);
105 void KBBGraphicsItemRay::hide()
107 setPath(QPainterPath());