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 ***************************************************************************/
30 #include "kbbgraphicsitemrayresult.h"
35 #include <QGraphicsScene>
38 #include "kbbgraphicsitem.h"
39 #include "kbbgraphicsitemborder.h"
40 #include "kbbitemwithposition.h"
41 #include "kbbscalablegraphicwidget.h"
42 #include "kbbthememanager.h"
47 // Constructor / Destructor
50 KBBGraphicsItemRayResult::KBBGraphicsItemRayResult( KBBScalableGraphicWidget
* parent
, KBBThemeManager
* themeManager
, QGraphicsScene
* scene
, const int borderPosition
, const int columns
, const int rows
, const int rayNumber
) : KBBGraphicsItemBorder( borderPosition
, columns
, rows
, KBBScalableGraphicWidget::BORDER_SIZE
/2), KBBGraphicsItem(KBBScalableGraphicWidget::resultBackground
, scene
, themeManager
), KBBItemWithPosition()
54 m_elementIdResultBackground
= themeManager
->elementId(KBBScalableGraphicWidget::resultBackground
);
55 m_elementIdResultBackgroundHighlight
= themeManager
->elementId(KBBScalableGraphicWidget::resultBackgroundHighlight
);
60 float centerRadius
= 3*KBBScalableGraphicWidget::RATIO
/8.;
61 float radius
= KBBScalableGraphicWidget::BORDER_SIZE
/4.;
65 setPos(m_centerX
- radius
, m_centerY
- radius
);
70 m_notNumber
= new KBBGraphicsItem(KBBScalableGraphicWidget::resultReflection
, m_scene
, themeManager
);
72 m_notNumber
= new KBBGraphicsItem(KBBScalableGraphicWidget::resultHit
, m_scene
, themeManager
);
73 m_notNumber
->translate(radius
,radius
);
74 m_notNumber
->rotate(rotation());
75 m_notNumber
->translate(-radius
,-radius
);
76 m_notNumber
->setPos(m_centerX
- radius
, m_centerY
- radius
);
79 text
.setNum(rayNumber
);
81 m_number
= new QGraphicsSimpleTextItem ( text
, this, scene
);
83 font
.setStyleHint(QFont::SansSerif
);
84 font
.setWeight(QFont::DemiBold
);
87 font
.setPixelSize((int)(3*centerRadius
/2));
90 font
.setPixelSize((int)(5*centerRadius
/4));
91 offset
= 1.*centerRadius
/6;
93 m_number
->setFont(font
);
94 m_number
->setPos(radius
- centerRadius
/2 - 2*offset
, radius
- centerRadius
+ offset
);
95 m_number
->setZValue(themeManager
->zValue(KBBScalableGraphicWidget::resultText
));
97 setAcceptsHoverEvents(true);
106 void KBBGraphicsItemRayResult::cleanDelete()
114 void KBBGraphicsItemRayResult::highlight(bool state
)
116 if (state
&& !m_pause
)
117 setElementId(m_elementIdResultBackgroundHighlight
);
119 setElementId(m_elementIdResultBackground
);
123 void KBBGraphicsItemRayResult::highlightBoth(bool state
)
125 m_opposite
->highlight(state
);
130 int KBBGraphicsItemRayResult::position ()
132 return m_borderPosition
;
136 void KBBGraphicsItemRayResult::setOpposite(KBBGraphicsItemRayResult
* opposite
)
138 m_opposite
= opposite
;
142 void KBBGraphicsItemRayResult::setPause(bool state
)
145 m_number
->setVisible(!state
);
146 if (m_notNumber
!=NULL
)
147 m_notNumber
->setVisible(!state
);
158 void KBBGraphicsItemRayResult::hoverEnterEvent (QGraphicsSceneHoverEvent
*)
161 m_widget
->drawRay(position());
165 void KBBGraphicsItemRayResult::hoverLeaveEvent (QGraphicsSceneHoverEvent
*)
167 highlightBoth(false);
168 m_widget
->removeRay();