kblackbox
kbbgraphicsitemray.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
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
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 }