• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

kblackbox

  • sources
  • kde-4.14
  • kdegames
  • kblackbox
kbbgraphicsitemrayresult.cpp
Go to the documentation of this file.
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 #include "kbbgraphicsitemrayresult.h"
31 
32 
33 
34 #include <QFont>
35 #include <QGraphicsScene>
36 
37 
38 #include "kbbgraphicsitem.h"
39 #include "kbbgraphicsitemborder.h"
40 #include "kbbitemwithposition.h"
41 #include "kbbscalablegraphicwidget.h"
42 #include "kbbthememanager.h"
43 
44 
45 
46 //
47 // Constructor / Destructor
48 //
49 
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()
51 {
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;
59 
60  float centerRadius = 3*KBBScalableGraphicWidget::RATIO/8.;
61  float radius = KBBScalableGraphicWidget::BORDER_SIZE/4.;
62 
63  m_opposite = this;
64 
65  setPos(m_centerX - radius, m_centerY - radius);
66 
67  if(rayNumber<=0) {
68 
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(rotationAngle());
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);
80 
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;
92  }
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));
96  }
97  setAcceptsHoverEvents(true);
98 }
99 
100 
101 
102 //
103 // Public
104 //
105 
106 void KBBGraphicsItemRayResult::cleanDelete()
107 {
108  delete m_notNumber;
109  delete m_number;
110  delete this;
111 }
112 
113 
114 void KBBGraphicsItemRayResult::highlight(bool state)
115 {
116  if (state && !m_pause)
117  setElementId(m_elementIdResultBackgroundHighlight);
118  else
119  setElementId(m_elementIdResultBackground);
120 }
121 
122 
123 void KBBGraphicsItemRayResult::highlightBoth(bool state)
124 {
125  m_opposite->highlight(state);
126  highlight(state);
127 }
128 
129 
130 int KBBGraphicsItemRayResult::position ()
131 {
132  return m_borderPosition;
133 }
134 
135 
136 void KBBGraphicsItemRayResult::setOpposite(KBBGraphicsItemRayResult* opposite)
137 {
138  m_opposite = opposite;
139 }
140 
141 
142 void KBBGraphicsItemRayResult::setPause(bool state)
143 {
144  if (m_number!=NULL)
145  m_number->setVisible(!state);
146  if (m_notNumber!=NULL)
147  m_notNumber->setVisible(!state);
148 
149  m_pause = state;
150 }
151 
152 
153 
154 //
155 // Private
156 //
157 
158 void KBBGraphicsItemRayResult::hoverEnterEvent (QGraphicsSceneHoverEvent*)
159 {
160  highlightBoth(true);
161  m_widget->drawRay(position());
162 }
163 
164 
165 void KBBGraphicsItemRayResult::hoverLeaveEvent (QGraphicsSceneHoverEvent*)
166 {
167  highlightBoth(false);
168  m_widget->removeRay();
169 }
QGraphicsItem::translate
void translate(qreal dx, qreal dy)
QGraphicsScene
kbbgraphicsitem.h
KBBScalableGraphicWidget::removeRay
void removeRay()
Definition: kbbscalablegraphicwidget.cpp:372
KBBGraphicsItemBorder::m_borderPosition
int m_borderPosition
Definition: kbbgraphicsitemborder.h:59
KBBGraphicsItem
Graphic item of the scalable graphic widget.
Definition: kbbgraphicsitem.h:44
KBBGraphicsItemRayResult::highlightBoth
void highlightBoth(bool state)
Highlight the item and the opposite one.
Definition: kbbgraphicsitemrayresult.cpp:123
QFont
KBBScalableGraphicWidget
Scalable graphic central widget for KBlackBox.
Definition: kbbscalablegraphicwidget.h:62
KBBThemeManager::zValue
int zValue(const KBBScalableGraphicWidget::itemType itemType)
Get the relative height of the item.
Definition: kbbthememanager.cpp:197
QFont::setWeight
void setWeight(int weight)
QGraphicsItem::scene
QGraphicsScene * scene() const
KBBScalableGraphicWidget::resultBackground
Definition: kbbscalablegraphicwidget.h:98
QGraphicsSimpleTextItem
KBBItemWithPosition
Item with position.
Definition: kbbitemwithposition.h:37
QFont::setPixelSize
void setPixelSize(int pixelSize)
KBBScalableGraphicWidget::drawRay
void drawRay(const int borderPosition)
Definition: kbbscalablegraphicwidget.cpp:191
QGraphicsItem::setPos
void setPos(const QPointF &pos)
KBBGraphicsItemBorder::m_centerX
float m_centerX
Definition: kbbgraphicsitemborder.h:60
kbbscalablegraphicwidget.h
KBBScalableGraphicWidget::BORDER_SIZE
static int const BORDER_SIZE
Distance between the black box and the widget border.
Definition: kbbscalablegraphicwidget.h:74
QGraphicsSimpleTextItem::setFont
void setFont(const QFont &font)
KBBGraphicsItemBorder::rotationAngle
int rotationAngle()
Definition: kbbgraphicsitemborder.cpp:113
QString
QGraphicsSceneHoverEvent
KBBScalableGraphicWidget::resultText
Definition: kbbscalablegraphicwidget.h:102
kbbitemwithposition.h
KBBGraphicsItemRayResult::position
int position()
Get the border position.
Definition: kbbgraphicsitemrayresult.cpp:130
QFont::setStyleHint
void setStyleHint(StyleHint hint, StyleStrategy strategy)
KBBGraphicsItemRayResult
Result of a laser ray shoot in the black box.
Definition: kbbgraphicsitemrayresult.h:55
KBBScalableGraphicWidget::resultHit
Definition: kbbscalablegraphicwidget.h:101
KBBGraphicsItemRayResult::highlight
void highlight(bool state)
Highlight the item.
Definition: kbbgraphicsitemrayresult.cpp:114
QGraphicsItem::setAcceptsHoverEvents
void setAcceptsHoverEvents(bool enabled)
KBBThemeManager::elementId
QString elementId(const KBBScalableGraphicWidget::itemType itemType)
Get the XML "id" value of the item.
Definition: kbbthememanager.cpp:81
QGraphicsSvgItem::setElementId
void setElementId(const QString &id)
KBBGraphicsItemRayResult::setOpposite
void setOpposite(KBBGraphicsItemRayResult *opposite)
Define the opposite "ray result" item.
Definition: kbbgraphicsitemrayresult.cpp:136
QString::setNum
QString & setNum(short n, int base)
KBBGraphicsItemRayResult::cleanDelete
void cleanDelete()
Destructor of the class and dependent object Call this methode to destroy simultaneously this QGraphi...
Definition: kbbgraphicsitemrayresult.cpp:106
KBBGraphicsItemBorder::m_centerY
float m_centerY
Definition: kbbgraphicsitemborder.h:61
KBBScalableGraphicWidget::RATIO
static int const RATIO
Width and height of a single square on the black box.
Definition: kbbscalablegraphicwidget.h:81
KBBGraphicsItem::KBBGraphicsItem
KBBGraphicsItem(KBBScalableGraphicWidget::itemType itemType, QGraphicsScene *scene, KBBThemeManager *themeManager)
Constructor.
Definition: kbbgraphicsitem.cpp:43
KBBGraphicsItemRayResult::setPause
void setPause(bool state)
Set the pause state.
Definition: kbbgraphicsitemrayresult.cpp:142
KBBGraphicsItemBorder
Any border element of the scalable graphic widget.
Definition: kbbgraphicsitemborder.h:40
QGraphicsItem::setVisible
void setVisible(bool visible)
kbbgraphicsitemrayresult.h
KBBThemeManager
Theme manager of the scalable graphic widget.
Definition: kbbthememanager.h:51
KBBGraphicsItemRayResult::KBBGraphicsItemRayResult
KBBGraphicsItemRayResult(KBBScalableGraphicWidget *parent, KBBThemeManager *themeManager, QGraphicsScene *scene, const int borderPosition, const int columns, const int rows, const int rayNumber)
Definition: kbbgraphicsitemrayresult.cpp:50
QObject::parent
QObject * parent() const
QGraphicsItem::setZValue
void setZValue(qreal z)
kbbgraphicsitemborder.h
QGraphicsItem::rotate
void rotate(qreal angle)
KBBScalableGraphicWidget::resultBackgroundHighlight
Definition: kbbscalablegraphicwidget.h:99
KBBScalableGraphicWidget::resultReflection
Definition: kbbscalablegraphicwidget.h:100
kbbthememanager.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kblackbox

Skip menu "kblackbox"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal