• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kblackbox

kbbgraphicsitemray.cpp

Go to the documentation of this file.
00001 //
00002 // KBlackBox
00003 //
00004 // A simple game inspired by an emacs module
00005 //
00006 /***************************************************************************
00007  *   Copyright (c) 1999-2000, Robert Cimrman                               *
00008  *   cimrman3@students.zcu.cz                                              *
00009  *                                                                         *
00010  *   Copyright (c) 2007, Nicolas Roffet                                    *
00011  *   nicolas-kde@roffet.com                                                *
00012  *                                                                         *
00013  *                                                                         *
00014  *   This program is free software; you can redistribute it and/or modify  *
00015  *   it under the terms of the GNU General Public License as published by  *
00016  *   the Free Software Foundation; either version 2 of the License, or     *
00017  *   (at your option) any later version.                                   *
00018  *                                                                         *
00019  *   This program is distributed in the hope that it will be useful,       *
00020  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00021  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00022  *   GNU General Public License for more details.                          *
00023  *                                                                         *
00024  *   You should have received a copy of the GNU General Public License     *
00025  *   along with this program; if not, write to the                         *
00026  *   Free Software Foundation, Inc.,                                       *
00027  *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA               *
00028  ***************************************************************************/
00029 
00030 
00031 #include "kbbgraphicsitemray.h"
00032 
00033 #include <QGraphicsScene>
00034 #include <QList>
00035 #include <QPainterPath>
00036 #include <QPen>
00037 
00038 
00039 #include "kbbballsonboard.h"
00040 #include "kbbgamedoc.h"
00041 #include "kbbgraphicsitemborder.h"
00042 #include "kbbscalablegraphicwidget.h"
00043 #include "kbbthememanager.h"
00044 
00045 
00046 
00047 //
00048 // Constructor / Destructor
00049 //
00050 
00051 KBBGraphicsItemRay::KBBGraphicsItemRay(KBBScalableGraphicWidget::itemType itemType, QGraphicsScene* scene, KBBThemeManager* themeManager) : KBBGraphicsItemBorder(0, 1, 1, KBBScalableGraphicWidget::BORDER_SIZE/2), QGraphicsPathItem (0, scene)
00052 {
00053     QPen pen;
00054     
00055     pen.setColor(themeManager->color(itemType));
00056     pen.setStyle(themeManager->style(itemType));
00057     pen.setWidthF(themeManager->width(itemType));
00058     setZValue(themeManager->zValue(itemType));
00059     
00060     pen.setJoinStyle(Qt::RoundJoin);
00061     pen.setCapStyle(Qt::RoundCap);
00062     
00063     setPen(pen);
00064 }
00065 
00066 
00067 
00068 //
00069 // Public
00070 //
00071 
00072 void KBBGraphicsItemRay::draw(KBBBallsOnBoard* ballsOnBoard, const int borderPosition)
00073 {
00074     const int columns = ballsOnBoard->columns();
00075     const int rows = ballsOnBoard->rows();
00076     
00077     QList<int> points;
00078     const int oppositeBorderPosition = ballsOnBoard->oppositeBorderPositionWithPoints(borderPosition, points);
00079     
00080     QPainterPath path;
00081     setSize(borderPosition, columns, rows);
00082     path.moveTo(m_centerX, m_centerY);
00083 
00084     const float b = (float) KBBScalableGraphicWidget::BORDER_SIZE;
00085     const float r = (float) KBBScalableGraphicWidget::RATIO;
00086     float x;
00087     float y;
00088     for (int i=0; i<points.count(); i++) {
00089         x = b - r/2 + r*((points[i] % columns) + 1);
00090         y = b - r/2 + r*((points[i] / columns) + 1);
00091         path.lineTo(x,y);
00092     }
00093     
00094     if (oppositeBorderPosition!=KBBGameDoc::HIT_POSITION) {
00095         float x1;
00096         float y1;
00097         centerCoordinate(oppositeBorderPosition, x1, y1, b/2.);
00098         path.lineTo(x1,y1);
00099     }
00100     
00101     setPath(path);
00102 }
00103 
00104 
00105 void KBBGraphicsItemRay::hide()
00106 {
00107     setPath(QPainterPath());
00108 }

kblackbox

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

API Reference

Skip menu "API Reference"
  • kblackbox
  • kgoldrunner
  • kmahjongg
  • ksquares
  • libkdegames
  •   highscore
  •   kgame
  •   kggzgames
  •   kggzmod
  •   kggznet
  • libkmahjongg
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal