• 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
kbbgraphicsitemlaser.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 
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 
49 KBBGraphicsItemLaser::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 
71 int KBBGraphicsItemLaser::position ()
72 {
73  return m_borderPosition;
74 }
75 
76 
77 
78 //
79 // Private
80 //
81 
82 void KBBGraphicsItemLaser::hoverEnterEvent (QGraphicsSceneHoverEvent*)
83 {
84  m_widget->drawRay(position());
85 }
86 
87 
88 void KBBGraphicsItemLaser::hoverLeaveEvent (QGraphicsSceneHoverEvent*)
89 {
90  m_widget->removeRay();
91 }
92 
93 
94 void KBBGraphicsItemLaser::mousePressEvent (QGraphicsSceneMouseEvent* event)
95 {
96  if (event->buttons()==Qt::LeftButton) {
97  m_widget->mouseBorderClick(position());
98  }
99 }
KBBScalableGraphicWidget::mouseBorderClick
void mouseBorderClick(const int borderPosition)
Definition: kbbscalablegraphicwidget.cpp:202
kbbgraphicsitemlaser.h
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
KBBScalableGraphicWidget
Scalable graphic central widget for KBlackBox.
Definition: kbbscalablegraphicwidget.h:62
KBBItemWithPosition
Item with position.
Definition: kbbitemwithposition.h:37
KBBScalableGraphicWidget::drawRay
void drawRay(const int borderPosition)
Definition: kbbscalablegraphicwidget.cpp:191
QGraphicsSceneMouseEvent
QGraphicsItem::setPos
void setPos(const QPointF &pos)
KBBGraphicsItemBorder::m_centerX
float m_centerX
Definition: kbbgraphicsitemborder.h:60
kbbscalablegraphicwidget.h
KBBGraphicsItemBorder::rotationAngle
int rotationAngle()
Definition: kbbgraphicsitemborder.cpp:113
QGraphicsSceneHoverEvent
kbbitemwithposition.h
QGraphicsItem::setAcceptsHoverEvents
void setAcceptsHoverEvents(bool enabled)
KBBGraphicsItemLaser::KBBGraphicsItemLaser
KBBGraphicsItemLaser(KBBScalableGraphicWidget *parent, KBBThemeManager *themeManager, const int borderPosition, const int columns, const int rows)
Constructor.
Definition: kbbgraphicsitemlaser.cpp:49
QGraphicsSceneMouseEvent::buttons
Qt::MouseButtons buttons() const
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
KBBGraphicsItemLaser::position
int position()
Get the border position.
Definition: kbbgraphicsitemlaser.cpp:71
KBBGraphicsItemBorder
Any border element of the scalable graphic widget.
Definition: kbbgraphicsitemborder.h:40
KBBThemeManager
Theme manager of the scalable graphic widget.
Definition: kbbthememanager.h:51
QObject::parent
QObject * parent() const
kbbgraphicsitemborder.h
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