SVN_SILENT made messages (.desktop file)
[kdegames.git] / kblackbox / kbbgraphicsitemrayresult.cpp
blobac1a9b7c16e5afb0a15502c6cc85581b3f152eeb
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 ***************************************************************************/
30 #include "kbbgraphicsitemrayresult.h"
34 #include <QFont>
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()
52 m_widget = parent;
53 m_scene = scene;
54 m_elementIdResultBackground = themeManager->elementId(KBBScalableGraphicWidget::resultBackground);
55 m_elementIdResultBackgroundHighlight = themeManager->elementId(KBBScalableGraphicWidget::resultBackgroundHighlight);
56 m_number = NULL;
57 m_notNumber = NULL;
58 m_pause = false;
60 float centerRadius = 3*KBBScalableGraphicWidget::RATIO/8.;
61 float radius = KBBScalableGraphicWidget::BORDER_SIZE/4.;
63 m_opposite = this;
65 setPos(m_centerX - radius, m_centerY - radius);
67 if(rayNumber<=0) {
69 if (rayNumber==0)
70 m_notNumber = new KBBGraphicsItem(KBBScalableGraphicWidget::resultReflection, m_scene, themeManager);
71 else
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);
77 } else {
78 QString text;
79 text.setNum(rayNumber);
81 m_number = new QGraphicsSimpleTextItem ( text, this, scene);
82 QFont font;
83 font.setStyleHint(QFont::SansSerif);
84 font.setWeight(QFont::DemiBold);
85 float offset;
86 if (rayNumber<10) {
87 font.setPixelSize((int)(3*centerRadius/2));
88 offset = 0.;
89 } else {
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);
103 // Public
106 void KBBGraphicsItemRayResult::cleanDelete()
108 delete m_notNumber;
109 delete m_number;
110 delete this;
114 void KBBGraphicsItemRayResult::highlight(bool state)
116 if (state && !m_pause)
117 setElementId(m_elementIdResultBackgroundHighlight);
118 else
119 setElementId(m_elementIdResultBackground);
123 void KBBGraphicsItemRayResult::highlightBoth(bool state)
125 m_opposite->highlight(state);
126 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)
144 if (m_number!=NULL)
145 m_number->setVisible(!state);
146 if (m_notNumber!=NULL)
147 m_notNumber->setVisible(!state);
149 m_pause = state;
155 // Private
158 void KBBGraphicsItemRayResult::hoverEnterEvent (QGraphicsSceneHoverEvent*)
160 highlightBoth(true);
161 m_widget->drawRay(position());
165 void KBBGraphicsItemRayResult::hoverLeaveEvent (QGraphicsSceneHoverEvent*)
167 highlightBoth(false);
168 m_widget->removeRay();