rock_widget_collection  0.1
LineItem.cc
Go to the documentation of this file.
1 /*
2  * File: LineItem.cc
3  * Author: blueck
4  *
5  * Created on 24. Juni 2010, 14:24
6  */
7 
8 #include <QtGui/qpainter.h>
9 
10 #include "LineItem.h"
11 
12 LineItem::LineItem(int posX, int posY, int groupNr, const QColor &color, int endX, int endY)
13  : DrawItem(posX, posY, groupNr, color)
14 {
15  this->endX = endX;
16  this->endY = endY;
17 }
18 
19 void LineItem::draw(QPainter* painter, QRectF &source, QRectF &target)
20 {
21  float factor_x = ((float)target.width())/source.width();
22  float factor_y = ((float)target.height())/source.height();
23  addPenStyle(painter);
24  painter->drawLine(factor_x*posX+target.x(),
25  posY*factor_y+target.y(),
26  target.x()+factor_x*endX,
27  target.y()+factor_y*endY);
28 }
29 
30 
31 void LineItem::renderOnGl(QGLWidget &widget,QRectF &source,QRectF &target)
32 {
33  float factor_x = ((float)target.width())/source.width();
34  float factor_y = ((float)target.height())/source.height();
35  glColor4ub(color.red(),color.green(),color.blue(),color.alpha());
36  glBegin(GL_LINES);
37  glVertex3f(factor_x*posX+target.x(), widget.height()-(posY*factor_y+target.y()), 0.0f); // ending point of the line
38  glVertex3f(target.x()+factor_x*endX, widget.height()-(target.y()+factor_y*endY), 0.0f); // ending point of the line
39  glEnd( );
40 }
void addPenStyle(QPainter *painter)
Definition: DrawItem.cc:27
int posY
Definition: DrawItem.h:182
void draw(QPainter *painter, QRectF &source, QRectF &target)
Definition: LineItem.cc:19
int posX
Definition: DrawItem.h:180
LineItem(int posX, int posY, int groupNr, const QColor &color, int endX, int endY)
Definition: LineItem.cc:12
QColor color
Definition: DrawItem.h:184
void renderOnGl(QGLWidget &widget, QRectF &source, QRectF &target)
Definition: LineItem.cc:31