rock_widget_collection  0.1
PaintWidget.cc
Go to the documentation of this file.
1 #include <PaintWidget.h>
2 
3 
4 #include<ArrowItem.h>
5 #include<DrawItem.h>
6 #include<EllipseItem.h>
7 #include<FillItem.h>
8 #include<LineItem.h>
9 #include<PointItem.h>
10 #include<PolygonItem.h>
11 #include<PolylineItem.h>
12 #include<RectangleItem.h>
13 #include<TextItem.h>
14 
15 
16 PaintWidget::PaintWidget(QWidget *parent):
17 QWidget(parent),
18 isOpenGL(false)
19 //image(0, 0, QImage::Format_RGB888)
20 {
21 };
22 
24 {
25 };
26 
27 QObject* PaintWidget::addText(int xPos, int yPos, int groupNr, const QString &text)
28 {
29  TextItem* textItem = new TextItem(xPos, yPos, groupNr, text);
30  if(isOpenGL)
31  textItem->openGL(true);
32  items.push_back(textItem);
33  return textItem;
34 }
35 
36 QObject* PaintWidget::addLine(int xPos, int yPos, int groupNr, const QColor &color, int endX, int endY)
37 {
38  LineItem* item = new LineItem(xPos, yPos, groupNr, color, endX, endY);
39  if(isOpenGL)
40  item->openGL(true);
41 
42  items.push_back(item);
43  return item;
44 }
45 
46 QObject* PaintWidget::addEllipse(int xPos, int yPos, int groupNr, const QColor &color, int width, int height)
47 {
48  EllipseItem* item = new EllipseItem(xPos, yPos, groupNr, color, width, height);
49  if(isOpenGL)
50  item->openGL(true);
51 
52  items.push_back(item);
53  return item;
54 }
55 
56 QObject* PaintWidget::addRectangle(int xPos, int yPos, int groupNr, const QColor &color, int width, int height)
57 {
58  RectangleItem* item = new RectangleItem(xPos, yPos, groupNr, color, width, height);
59  if(isOpenGL)
60  item->openGL(true);
61 
62  items.push_back(item);
63  return item;
64 }
65 QObject* PaintWidget::addPolyline(int groupNr, const QColor &color, const QList<QPoint> &points)
66 {
67  PolylineItem* item = new PolylineItem(color, groupNr, points);
68  if(isOpenGL)
69  item->openGL(true);
70 
71  items.push_back(item);
72  return item;
73 }
74 
75 QObject* PaintWidget::addPolygon(int groupNr, const QColor &color, const QList<QPoint> &points)
76 {
77  PolygonItem* item = new PolygonItem(color, groupNr, points);
78  if(isOpenGL)
79  item->openGL(true);
80 
81  items.push_back(item);
82  return item;
83 }
84 
85 QObject* PaintWidget::addItem(QObject* object)
86 {
87  DrawItem* drawItem = dynamic_cast<DrawItem*>(object);
88  if(isOpenGL)
89  drawItem->openGL(true);
90 
91  items.push_back(drawItem);
92  return object;
93 }
94 
95 QObject* PaintWidget::addPoints(const QList<int> &points_x,const QList<int> &points_y,int groupNr, const QColor &color)
96 {
97  DrawItem* drawItem = new PointItem(points_x,points_y,groupNr,color);
98  if(isOpenGL)
99  drawItem->openGL(true);
100  items.push_back(drawItem);
101  return drawItem;
102 }
103 
104  QObject* PaintWidget::removeItem(QObject* object,bool delete_object)
105 {
106  DrawItem *draw_item = dynamic_cast<DrawItem*>(object);
107  items.removeAll(draw_item);
108  if(delete_object)
109  {
110  delete object;
111  object = NULL;
112  }
113  return object;
114 }
115 
116 void PaintWidget::removeAllItems(bool delete_objects)
117 {
118  if(delete_objects)
119  {
120  QList<DrawItem*>::iterator iter = items.begin();
121  for(;iter != items.end();++iter)
122  delete(*iter);
123  }
124  items.clear();
125 }
126 
127 
128 void PaintWidget::paintEvent(QPaintEvent *)
129 {
130  QPainter painter(this);
131  drawDrawItemsToPainter(painter,true);
132 }
133 
134 void PaintWidget::drawDrawItemsToPainter(QPainter &painter,bool all)
135 {
136  if(!isOpenGL)
137  all = true;
138 
139  QRectF target = painter.viewport();
140 
141  if(!items.empty())
142  {
143  painter.setRenderHint(QPainter::TextAntialiasing, true);
144  QList<DrawItem*>::iterator iter = items.begin();
145  for(;iter != items.end();++iter)
146  {
147  if(!disabledGroups.contains((*iter)->getGroupNr()))
148  if(!(*iter)->onOpenGL() || all == true)
149  (*iter)->draw(&painter,target,target);
150  }
151  }
152 }
153 
QObject * addItem(QObject *object)
Definition: PaintWidget.cc:85
QList< DrawItem * > items
Definition: PaintWidget.h:127
QObject * addPolyline(int groupNr, const QColor &color, const QList< QPoint > &points)
Definition: PaintWidget.cc:65
void paintEvent(QPaintEvent *event)
Definition: PaintWidget.cc:128
QObject * addLine(int xPos, int yPos, int groupNr, const QColor &color, int endX, int endY)
Definition: PaintWidget.cc:36
QObject * addPoints(const QList< int > &points_x, const QList< int > &points_y, int groupNr, const QColor &color)
Definition: PaintWidget.cc:95
PaintWidget(QWidget *parent)
Definition: PaintWidget.cc:16
QObject * addText(int xPos, int yPos, int groupNr, const QString &text)
Definition: PaintWidget.cc:27
QObject * removeItem(QObject *drawItem, bool delete_object)
Definition: PaintWidget.cc:104
QObject * addPolygon(int groupNr, const QColor &color, const QList< QPoint > &points)
Definition: PaintWidget.cc:75
QList< int > disabledGroups
Definition: PaintWidget.h:129
void drawDrawItemsToPainter(QPainter &painter, bool all=false)
Definition: PaintWidget.cc:134
QObject * addRectangle(int xPos, int yPos, int groupNr, const QColor &color, int width, int height)
Definition: PaintWidget.cc:56
QObject * addEllipse(int xPos, int yPos, int groupNr, const QColor &color, int width, int height)
Definition: PaintWidget.cc:46
void openGL(bool value)
Definition: DrawItem.h:157
void removeAllItems(bool delete_objects)
Definition: PaintWidget.cc:116