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 ***************************************************************************/
29
30
31#include "kbbgraphicsitemlaser.h"
32
33#include <QGraphicsSceneMouseEvent>
34
35
36
37#include "kbbgraphicsitem.h"
38#include "kbbgraphicsitemborder.h"
39#include "kbbitemwithposition.h"
40#include "kbbscalablegraphicwidget.h"
41#include "kbbthememanager.h"
42
43
44
45//
46// Constructor / Destructor
47//
48
49KBBGraphicsItemLaser::KBBGraphicsItemLaser(KBBScalableGraphicWidget* parent, KBBThemeManager* themeManager, const int borderPosition, const int columns, const int rows) : KBBGraphicsItemBorder(borderPosition, columns, rows, 0), KBBGraphicsItem(((borderPosition<columns) ? KBBScalableGraphicWidget::laser0 : ((borderPosition<columns + rows) ? KBBScalableGraphicWidget::laser90 : ((borderPosition<2*columns + rows) ? KBBScalableGraphicWidget::laser180 : KBBScalableGraphicWidget::laser270))) , parent->scene(), themeManager), KBBItemWithPosition()
50{
51 m_widget = parent;
52
53 const int radius = KBBScalableGraphicWidget::RATIO/2;
54 if (rotationAngle()==90) {
55 setPos(m_centerX - 3*radius, m_centerY - radius);
56 } else if (rotationAngle()==180) {
57 setPos(m_centerX - radius, m_centerY - 3*radius);
58 } else {
59 setPos(m_centerX - radius, m_centerY - radius);
60 }
61
62 setAcceptsHoverEvents(true);
63}
64
65
66
67//
68// Public
69//
70
71int KBBGraphicsItemLaser::position ()
72{
73 return m_borderPosition;
74}
75
76
77
78//
79// Private
80//
81
82void KBBGraphicsItemLaser::hoverEnterEvent (QGraphicsSceneHoverEvent*)
83{
84 m_widget->drawRay(position());
85}
86
87
88void KBBGraphicsItemLaser::hoverLeaveEvent (QGraphicsSceneHoverEvent*)
89{
90 m_widget->removeRay();
91}
92
93
94void KBBGraphicsItemLaser::mousePressEvent (QGraphicsSceneMouseEvent* event)
95{
96 if (event->buttons()==Qt::LeftButton) {
97 m_widget->mouseBorderClick(position());
98 }
99}
100