• 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
kbbgraphicsitemray.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 "kbbgraphicsitemray.h"
32 
33 #include <QGraphicsScene>
34 #include <QList>
35 #include <QPainterPath>
36 #include <QPen>
37 
38 
39 #include "kbbballsonboard.h"
40 #include "kbbgamedoc.h"
41 #include "kbbgraphicsitemborder.h"
42 #include "kbbscalablegraphicwidget.h"
43 #include "kbbthememanager.h"
44 
45 
46 
47 //
48 // Constructor / Destructor
49 //
50 
51 KBBGraphicsItemRay::KBBGraphicsItemRay(KBBScalableGraphicWidget::itemType itemType, QGraphicsScene* scene, KBBThemeManager* themeManager) : KBBGraphicsItemBorder(0, 1, 1, KBBScalableGraphicWidget::BORDER_SIZE/2), QGraphicsPathItem (0, scene)
52 {
53  QPen pen;
54 
55  pen.setColor(themeManager->color(itemType));
56  pen.setStyle(themeManager->style(itemType));
57  pen.setWidthF(themeManager->width(itemType));
58  setZValue(themeManager->zValue(itemType));
59 
60  pen.setJoinStyle(Qt::RoundJoin);
61  pen.setCapStyle(Qt::RoundCap);
62 
63  setPen(pen);
64 }
65 
66 
67 
68 //
69 // Public
70 //
71 
72 void KBBGraphicsItemRay::draw(KBBBallsOnBoard* ballsOnBoard, const int borderPosition)
73 {
74  const int columns = ballsOnBoard->columns();
75  const int rows = ballsOnBoard->rows();
76 
77  QList<int> points;
78  const int oppositeBorderPosition = ballsOnBoard->oppositeBorderPositionWithPoints(borderPosition, points);
79 
80  QPainterPath path;
81  setSize(borderPosition, columns, rows);
82  path.moveTo(m_centerX, m_centerY);
83 
84  const float b = (float) KBBScalableGraphicWidget::BORDER_SIZE;
85  const float r = (float) KBBScalableGraphicWidget::RATIO;
86  float x;
87  float y;
88  for (int i=0; i<points.count(); i++) {
89  x = b - r/2 + r*((points[i] % columns) + 1);
90  y = b - r/2 + r*((points[i] / columns) + 1);
91  path.lineTo(x,y);
92  }
93 
94  if (oppositeBorderPosition!=KBBGameDoc::HIT_POSITION) {
95  float x1;
96  float y1;
97  centerCoordinate(oppositeBorderPosition, x1, y1, b/2.);
98  path.lineTo(x1,y1);
99  }
100 
101  setPath(path);
102 }
103 
104 
105 void KBBGraphicsItemRay::hide()
106 {
107  setPath(QPainterPath());
108 }
kbbgraphicsitemray.h
QGraphicsItem::x
qreal x() const
QGraphicsItem::y
qreal y() const
QPen::setStyle
void setStyle(Qt::PenStyle style)
KBBThemeManager::width
qreal width(const KBBScalableGraphicWidget::itemType itemType)
Get the width of the item.
Definition: kbbthememanager.cpp:191
QGraphicsScene
KBBGraphicsItemBorder::setSize
void setSize(int borderPosition, int columns, int rows)
Definition: kbbgraphicsitemborder.cpp:55
KBBScalableGraphicWidget
Scalable graphic central widget for KBlackBox.
Definition: kbbscalablegraphicwidget.h:62
kbbgamedoc.h
QPen::setJoinStyle
void setJoinStyle(Qt::PenJoinStyle style)
QPainterPath::moveTo
void moveTo(const QPointF &point)
KBBThemeManager::zValue
int zValue(const KBBScalableGraphicWidget::itemType itemType)
Get the relative height of the item.
Definition: kbbthememanager.cpp:197
KBBGraphicsItemRay::KBBGraphicsItemRay
KBBGraphicsItemRay(KBBScalableGraphicWidget::itemType itemType, QGraphicsScene *scene, KBBThemeManager *themeManager)
Constructor.
Definition: kbbgraphicsitemray.cpp:51
QPen::setCapStyle
void setCapStyle(Qt::PenCapStyle style)
kbbballsonboard.h
KBBGraphicsItemRay::draw
void draw(KBBBallsOnBoard *ballsOnBoard, const int borderPosition)
Definition: kbbgraphicsitemray.cpp:72
QList::count
int count(const T &value) const
KBBGraphicsItemBorder::centerCoordinate
void centerCoordinate(int borderPosition, float &centerX, float &centerY, float offset)
Definition: kbbgraphicsitemborder.cpp:76
QPainterPath::lineTo
void lineTo(const QPointF &endPoint)
QGraphicsPathItem
KBBGraphicsItemBorder::m_centerX
float m_centerX
Definition: kbbgraphicsitemborder.h:60
QPen::setWidthF
void setWidthF(qreal width)
kbbscalablegraphicwidget.h
KBBGameDoc::HIT_POSITION
static const int HIT_POSITION
When a laser ray enter the black box, it exits on a defined border position, except if the laser ray ...
Definition: kbbgamedoc.h:65
KBBScalableGraphicWidget::BORDER_SIZE
static int const BORDER_SIZE
Distance between the black box and the widget border.
Definition: kbbscalablegraphicwidget.h:74
QList< int >
QPen::setColor
void setColor(const QColor &color)
KBBThemeManager::color
QColor color(const KBBScalableGraphicWidget::itemType itemType)
Get the color of the item.
Definition: kbbthememanager.cpp:75
KBBBallsOnBoard::oppositeBorderPositionWithPoints
int oppositeBorderPositionWithPoints(const int borderPosition, QList< int > &points)
Definition: kbbballsonboard.cpp:151
QPainterPath
QAbstractGraphicsShapeItem::setPen
void setPen(const QPen &pen)
QGraphicsPathItem::setPath
void setPath(const QPainterPath &path)
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
KBBGraphicsItemBorder
Any border element of the scalable graphic widget.
Definition: kbbgraphicsitemborder.h:40
QPen
KBBThemeManager
Theme manager of the scalable graphic widget.
Definition: kbbthememanager.h:51
KBBGraphicsItemRay::hide
void hide()
Definition: kbbgraphicsitemray.cpp:105
KBBBallsOnBoard::columns
int columns()
Definition: kbbballsonboard.cpp:106
QGraphicsPathItem::path
QPainterPath path() const
QAbstractGraphicsShapeItem::pen
QPen pen() const
QGraphicsItem::setZValue
void setZValue(qreal z)
kbbgraphicsitemborder.h
KBBBallsOnBoard::rows
int rows()
Definition: kbbballsonboard.cpp:193
KBBThemeManager::style
Qt::PenStyle style(const KBBScalableGraphicWidget::itemType itemType)
Get the pen style of the item.
Definition: kbbthememanager.cpp:176
KBBScalableGraphicWidget::itemType
itemType
Every graphic items.
Definition: kbbscalablegraphicwidget.h:89
kbbthememanager.h
KBBBallsOnBoard
Set of balls (or various objects) with positions on the board.
Definition: kbbballsonboard.h:62
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