rock_widget_collection  0.1
GraphicsPointsItem.cc
Go to the documentation of this file.
1 #include "GraphicsPointsItem.h"
2 #include <limits>
3 
4 #include <base-logging/Logging.hpp>
5 
6 GraphicsPointsItem::GraphicsPointsItem(const QList<QPoint> &points):points(points)
7 {
8 }
9 
10 QRectF GraphicsPointsItem::calcBoundingRect() const
11 {
12  QPoint left_top(std::numeric_limits< int >::max(),
13  std::numeric_limits< int >::max());
14  QPoint right_bottom(0,0);
15  QList<QPoint>::const_iterator iter = points.begin();
16  for(;iter != points.end();++iter)
17  {
18  if(iter->x() < left_top.x())
19  left_top.setX(iter->x());
20  if(iter->y() < left_top.y())
21  left_top.setY(iter->y());
22  if(iter->x() > right_bottom.x())
23  right_bottom.setX(iter->x());
24  if(iter->y() > right_bottom.y())
25  right_bottom.setY(iter->y());
26  }
27 // LOG_DEBUG_S << "GraphicsPointsItem: calculated bounding rect to left_top: (" << left_top.x() << "," << left_top.y() << ")/(" <<
28 // right_bottom.x() << ", " << right_bottom.y() << ") right bottom";
29 
30  QRect rect(left_top,right_bottom);
31 
32  // Adjust rect to pen width
33  int penwidth = pen.width();
34 // LOG_DEBUG_S << "GraphicsPointsItem: pen width: " << penwidth;
35  rect = QRect(left_top.x()-penwidth/2, left_top.y()-penwidth/2,
36  rect.width()+penwidth, rect.height()+penwidth);
37 
38 // LOG_DEBUG_S << "GraphicsPointsItem: corrected bounding rect to left_top: (" << left_top.x() << "," << left_top.y() << ")/(" <<
39 // right_bottom.x() << ", " << right_bottom.y() << ") right bottom";
40 
41  return rect;
42 }
43 
45 {
46  return calcBoundingRect();
47 }
48 
49 void GraphicsPointsItem::setPen(const QPen &pen)
50 {
51  this->pen = pen;
52 }
53 
54 void GraphicsPointsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
55 {
56  painter->setPen(pen);
57  QList<QPoint>::iterator iter = points.begin();
58  for(;iter != points.end();++iter)
59  painter->drawPoint(*iter);
60 }
61 
void setPen(const QPen &pen)
GraphicsPointsItem(const QList< QPoint > &points)
QRectF boundingRect() const
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)