30 #include "../../core/pattern/mvc/ItemController.h"
31 #include "../../core/AbstractScene.h"
32 #include "../../core/pattern/mvc/Observable.h"
33 #include "../../../color/RGBAColor.h"
34 #include "../../../qt/widgets/Utils.h"
35 #include "../../../geometry/Envelope.h"
36 #include "../../../common/STLUtils.h"
37 #include "../../item/GridMapModel.h"
41 #include <QStyleOptionGraphicsItem>
42 #include "../../core/WorldTransformer.h"
48 m_onePointMM(0.3527777778),
51 m_nameClass = std::string(this->metaObject()->className());
70 drawBackground(painter);
75 if (option->state & QStyle::State_Selected)
77 drawSelection(painter);
91 QRectF parentBound = boundingRect();
95 parentBound = parentItem()->boundingRect();
98 QPainterPath gridMapPath;
99 gridMapPath.setFillRule(Qt::WindingFill);
101 int heightRect = (int)parentBound.height();
102 int widgetRect = (int)parentBound.width();
111 painter->setFont(ft);
113 m_maxHeigthTextMM = m_onePointMM * ft.pointSize();
117 for (
int i = 0; i <= heightRect; i+=10)
119 QLineF lineOne = QLineF(parentBound.topLeft().x(), parentBound.topLeft().y() + i, parentBound.topRight().x(), parentBound.topRight().y() + i);
121 QPointF pointInit(parentBound.topLeft().x(), parentBound.topLeft().y() + i - (m_maxHeigthTextMM/2));
123 QPointF pointFinal(parentBound.topRight().x(), parentBound.topRight().y() + i - (m_maxHeigthTextMM/2));
126 painter->drawLine(lineOne);
128 for (
int j = 0; j <= widgetRect; j+=10)
130 QLineF lineTwo = QLineF(parentBound.topLeft().x() + j, parentBound.topLeft().y(), parentBound.bottomLeft().x() + j, parentBound.bottomLeft().y());
132 QPointF pointInit(parentBound.topLeft().x() + j + (m_maxWidthTextMM/2), boundingRect().topLeft().y());
134 QPointF pointFinal(parentBound.bottomLeft().x() + j - (m_maxWidthTextMM/2), parentBound.bottomLeft().y());
137 painter->drawLine(lineTwo);
148 QTransform t = painter->transform();
149 QPointF p = t.map(point);
153 QFont ft = painter->font();
154 ft.setPointSize(ft.pointSize() * zoomFactor);
155 painter->setFont(ft);
158 int width = fm.width(text.c_str());
160 QPointF newPoint (p);
164 newPoint.setX(newPoint.x() - width);
167 if(displacementRight)
169 newPoint.setX(newPoint.x() + width);
172 QTransform copyT = painter->transform().inverted();
173 QPointF copyP = copyT.map(newPoint);
174 double widthMM = point.x() - copyP.x();
176 if(widthMM > m_maxWidthTextMM)
178 m_maxWidthTextMM = widthMM;
183 painter->setMatrixEnabled(
false);
184 painter->drawText(newPoint, text.c_str());
185 painter->setMatrixEnabled(
true);
194 return parentItem()->boundingRect();
206 QRectF parentBoundRect = parentItem()->boundingRect();
207 if(parentBoundRect.isValid())
209 QRectF boundRect = boundingRect();
210 double w = parentBoundRect.width() + (m_maxWidthTextMM*2);
211 double h = parentBoundRect.height() + (m_maxHeigthTextMM*2);
212 if(boundRect.width() != w || boundRect.height() != h)
214 prepareGeometryChange();
215 QRectF rect(0., 0., w, h);
220 box.
m_urx = box.m_llx + w;
221 box.m_ury = box.m_lly + h;
222 m_controller->setBox(box);
226 m_changeSize =
false;
231 if(change == QGraphicsItem::ItemParentHasChanged)
249 return QGraphicsItem::itemChange(change, value);
Abstract class to represent an observable. "Model" part of MVC component.
virtual te::color::RGBAColor getLineColor()
virtual int getTextPointSize()
Class that represents a "Model" part of GridMap MVC component. Its coordinate system is the same of s...
int getRed() const
It returns the red component color value (a value from 0 to 255).
GridMapItem(ItemController *controller, Observable *o)
Constructor.
virtual void drawGrid(QPainter *painter)
int getBlue() const
It returns the blue component color value (a value from 0 to 255).
double m_urx
Upper right corner x-coordinate.
int getGreen() const
It returns the green component color value (a value from 0 to 255).
virtual QRectF boundingRect() const
Reimplemented from ParentItem.
Abstract class to represent a controller. "Controller" part of MVC component. All classes representin...
virtual ~GridMapItem()
Destructor.
virtual QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
Reimplemented from QGraphicsItem.
Abstract class that represents a graphic item. This object is of type QGraphicsObject.
static Context & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
int getAlpha() const
It returns the alpha component color value (a value from 0 to 255).
std::string m_nameClass
Class name.
Class that represents a graphic GridMap. Its coordinate system is the same of scene (millimeters)...
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Reimplemented from QGraphicsItem.
virtual void recalculateBoundingRect()
The default implementation does nothing.
virtual void drawText(QPointF point, QPainter *painter, std::string text, bool displacementLeft=false, bool displacementRight=false)
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Reimplemented from QGraphicsItem.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
virtual Observable * getModel()
Returns the "Model" part of the MVC.
virtual std::string getFontFamily()
virtual void setMapName(std::string name)
double getZoomFactor()
Returns current zoom factor. Ex.: 0.5 (50%)
virtual std::string getName()=0
Method that returns the name of the MVC component. Reimplement this function in a Observable subclass...
This class is a proxy MapDisplay. This makes it possible to add a MapDisplay as item of a scene...