7 #include "CurveStyle.h" 10 #include "GeometryWindow.h" 11 #include "GraphicsItemType.h" 12 #include "GraphicsPoint.h" 13 #include "GraphicsPointEllipse.h" 14 #include "GraphicsPointPolygon.h" 16 #include "PointStyle.h" 17 #include <QGraphicsEllipseItem> 18 #include <QGraphicsPolygonItem> 19 #include <QGraphicsScene> 20 #include <QGraphicsSceneContextMenuEvent> 23 #include <QTextStream> 24 #include "QtToString.h" 27 const double DEFAULT_HIGHLIGHT_OPACITY = 0.35;
28 const double MAX_OPACITY = 1.0;
29 const double ZERO_WIDTH = 0.0;
32 const QString &identifier,
33 const QPointF &posScreen,
40 m_graphicsItemEllipse (0),
41 m_shadowZeroWidthEllipse (0),
42 m_graphicsItemPolygon (0),
43 m_shadowZeroWidthPolygon (0),
44 m_identifier (identifier),
45 m_posScreen (posScreen),
47 m_lineWidth (lineWidth),
49 m_highlightOpacity (DEFAULT_HIGHLIGHT_OPACITY),
50 m_geometryWindow (geometryWindow)
52 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsPoint::GraphicsPoint" 53 <<
" identifier=" << identifier.toLatin1 ().data ();
55 createPointEllipse (radius);
59 const QString &identifier,
60 const QPointF &posScreen,
62 const QPolygonF &polygon,
67 m_graphicsItemEllipse (0),
68 m_shadowZeroWidthEllipse (0),
69 m_graphicsItemPolygon (0),
70 m_shadowZeroWidthPolygon (0),
71 m_identifier (identifier),
72 m_posScreen (posScreen),
74 m_lineWidth (lineWidth),
76 m_highlightOpacity (DEFAULT_HIGHLIGHT_OPACITY),
77 m_geometryWindow (geometryWindow)
79 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsPoint::GraphicsPoint " 80 <<
" identifier=" << identifier.toLatin1 ().data ();
82 createPointPolygon (polygon);
87 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsPoint::~GraphicsPoint";
89 if (m_graphicsItemEllipse == 0) {
91 QGraphicsScene *scene = m_graphicsItemPolygon->scene();
94 scene->removeItem (m_graphicsItemPolygon);
95 delete m_graphicsItemPolygon;
96 m_graphicsItemPolygon = 0;
97 m_shadowZeroWidthPolygon = 0;
102 QGraphicsScene *scene = m_graphicsItemEllipse->scene();
105 scene->removeItem (m_graphicsItemEllipse);
106 delete m_graphicsItemEllipse;
107 m_graphicsItemEllipse = 0;
108 m_shadowZeroWidthEllipse = 0;
115 if (m_graphicsItemEllipse == 0) {
116 return m_graphicsItemPolygon->boundingRect ();
118 return m_graphicsItemEllipse->boundingRect ();
122 void GraphicsPoint::createPointEllipse (
unsigned int radius)
124 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsPoint::createPointEllipse";
126 const int radiusSigned = radius;
128 QRect (- radiusSigned,
130 2 * radiusSigned + 1,
131 2 * radiusSigned + 1));
132 m_scene.addItem (m_graphicsItemEllipse);
134 m_graphicsItemEllipse->setZValue (Z_VALUE_POINT);
135 m_graphicsItemEllipse->setData (DATA_KEY_IDENTIFIER, m_identifier);
136 m_graphicsItemEllipse->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
137 m_graphicsItemEllipse->setPos (m_posScreen.x (),
139 m_graphicsItemEllipse->setPen (QPen (QBrush (m_color), m_lineWidth));
140 m_graphicsItemEllipse->setEnabled (
true);
141 m_graphicsItemEllipse->setFlags (QGraphicsItem::ItemIsSelectable |
142 QGraphicsItem::ItemIsMovable |
143 QGraphicsItem::ItemSendsGeometryChanges);
144 m_graphicsItemEllipse->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
145 if (m_geometryWindow != 0) {
146 QObject::connect (m_graphicsItemEllipse, SIGNAL (signalPointHoverEnter (QString)), m_geometryWindow, SLOT (slotPointHoverEnter (QString)));
147 QObject::connect (m_graphicsItemEllipse, SIGNAL (signalPointHoverLeave (QString)), m_geometryWindow, SLOT (slotPointHoverLeave (QString)));
153 QRect (- radiusSigned,
155 2 * radiusSigned + 1,
156 2 * radiusSigned + 1));
157 m_shadowZeroWidthEllipse->setParentItem(m_graphicsItemPolygon);
159 m_shadowZeroWidthEllipse->setPen (QPen (QBrush (m_color), ZERO_WIDTH));
160 m_shadowZeroWidthEllipse->setEnabled (
true);
162 m_graphicsItemEllipse->
setShadow (m_shadowZeroWidthEllipse);
165 void GraphicsPoint::createPointPolygon (
const QPolygonF &polygon)
167 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsPoint::createPointPolygon";
171 m_scene.addItem (m_graphicsItemPolygon);
173 m_graphicsItemPolygon->setZValue (Z_VALUE_POINT);
174 m_graphicsItemPolygon->setData (DATA_KEY_IDENTIFIER, m_identifier);
175 m_graphicsItemPolygon->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
176 m_graphicsItemPolygon->setPos (m_posScreen.x (),
178 m_graphicsItemPolygon->setPen (QPen (QBrush (m_color), m_lineWidth));
179 m_graphicsItemPolygon->setEnabled (
true);
180 m_graphicsItemPolygon->setFlags (QGraphicsItem::ItemIsSelectable |
181 QGraphicsItem::ItemIsMovable |
182 QGraphicsItem::ItemSendsGeometryChanges);
183 m_graphicsItemPolygon->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
184 if (m_geometryWindow != 0) {
185 QObject::connect (m_graphicsItemPolygon, SIGNAL (signalPointHoverEnter (QString)), m_geometryWindow, SLOT (slotPointHoverEnter (QString)));
186 QObject::connect (m_graphicsItemPolygon, SIGNAL (signalPointHoverLeave (QString)), m_geometryWindow, SLOT (slotPointHoverLeave (QString)));
193 m_shadowZeroWidthPolygon->setParentItem(m_graphicsItemPolygon);
195 m_shadowZeroWidthPolygon->setPen (QPen (QBrush (m_color), ZERO_WIDTH));
196 m_shadowZeroWidthPolygon->setEnabled (
true);
198 m_graphicsItemPolygon->
setShadow (m_shadowZeroWidthPolygon);
203 if (m_graphicsItemEllipse == 0) {
204 return m_graphicsItemPolygon->data (key);
206 return m_graphicsItemEllipse->data (key);
212 return m_highlightOpacity;
217 if (m_graphicsItemEllipse == 0) {
218 return m_graphicsItemPolygon->pos ();
220 return m_graphicsItemEllipse->pos ();
226 double ordinalKey)
const 228 str << indentation <<
"GraphicsPoint\n";
230 indentation += INDENTATION_DELTA;
235 if (m_graphicsItemEllipse == 0) {
236 identifier = m_graphicsItemPolygon->data (DATA_KEY_IDENTIFIER).toString ();
237 pointType =
"polygon";
238 pos = m_graphicsItemPolygon->pos();
240 identifier = m_graphicsItemEllipse->data (DATA_KEY_IDENTIFIER).toString ();
241 pointType =
"ellipse";
242 pos = m_graphicsItemEllipse->pos();
245 DataKey type = (DataKey)
data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt();
247 str << indentation << identifier
248 <<
" ordinalKey=" << ordinalKey
249 <<
" dataIdentifier=" <<
data (DATA_KEY_IDENTIFIER).toString().toLatin1().data()
250 <<
" dataType=" << dataKeyToString (type).toLatin1().data()
251 <<
" " << pointType <<
"Pos=" << QPointFToString (pos) <<
"\n";
261 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsPoint::setData" 262 <<
" key=" << dataKeyToString ((DataKey) key).toLatin1().data()
263 <<
" data=" << data.toString().toLatin1().data();
265 if (m_graphicsItemEllipse == 0) {
266 m_graphicsItemPolygon->setData (key, data);
268 m_graphicsItemEllipse->setData (key, data);
274 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsPoint::setHighlightOpacity" 275 <<
" identifier=" << m_identifier.toLatin1().data()
283 if (m_graphicsItemEllipse == 0) {
284 m_graphicsItemPolygon->setFlag (QGraphicsItem::ItemIsFocusable,
false);
285 m_graphicsItemPolygon->setFlag (QGraphicsItem::ItemIsMovable,
false);
286 m_graphicsItemPolygon->setFlag (QGraphicsItem::ItemIsSelectable,
false);
288 m_graphicsItemEllipse->setFlag (QGraphicsItem::ItemIsFocusable,
false);
289 m_graphicsItemEllipse->setFlag (QGraphicsItem::ItemIsMovable,
false);
290 m_graphicsItemEllipse->setFlag (QGraphicsItem::ItemIsSelectable,
false);
298 if (m_graphicsItemEllipse == 0) {
299 if (pointStyle.
shape() == POINT_SHAPE_CIRCLE) {
302 delete m_graphicsItemPolygon;
303 m_graphicsItemPolygon = 0;
304 m_shadowZeroWidthPolygon = 0;
306 createPointEllipse (pointStyle.
radius());
311 m_graphicsItemPolygon->setPen (QPen (ColorPaletteToQColor(pointStyle.
paletteColor()),
313 m_shadowZeroWidthPolygon->setPen (QPen (ColorPaletteToQColor(pointStyle.
paletteColor()),
315 m_graphicsItemPolygon->setPolygon (pointStyle.
polygon());
316 m_shadowZeroWidthPolygon->setPolygon (pointStyle.
polygon());
320 if (pointStyle.
shape() != POINT_SHAPE_CIRCLE) {
323 delete m_graphicsItemEllipse;
324 m_graphicsItemEllipse = 0;
325 m_shadowZeroWidthEllipse = 0;
327 createPointPolygon (pointStyle.
polygon());
332 m_graphicsItemEllipse->setPen (QPen (ColorPaletteToQColor(pointStyle.
paletteColor()),
334 m_shadowZeroWidthEllipse->setPen (QPen (ColorPaletteToQColor(pointStyle.
paletteColor()),
344 if (m_graphicsItemEllipse == 0) {
345 m_graphicsItemPolygon->setPos (pos);
347 m_graphicsItemEllipse->setPos (pos);
void setPassive()
Prevent automatic focus on point (=make it passive) for scale bar so drags can be made to work proper...
void setWanted()
Mark point as wanted. Marking as unwanted is done by the reset function.
QPointF pos() const
Proxy method for QGraphicsItem::pos.
void setHighlightOpacity(double highlightOpacity)
Set method for highlight opacity.
QVariant data(int key) const
Proxy method for QGraphicsItem::data.
PointStyle pointStyle() const
Get method for PointStyle.
Base class for adding identifiers to graphics items that represent Points.
Window that displays the geometry information, as a table, for the current curve. ...
void setData(int key, const QVariant &data)
Proxy method for QGraphicsItem::setData.
void setPos(const QPointF pos)
Update the position.
void setPointStyle(const PointStyle &pointStyle)
Update the point style.
QPolygonF polygon() const
Return the polygon for creating a QGraphicsPolygonItem. The size is determined by the radius...
void updateCurveStyle(const CurveStyle &curveStyle)
Update point and line styles that comprise the curve style.
GraphicsPoint(QGraphicsScene &scene, const QString &identifier, const QPointF &posScreen, const QColor &color, unsigned int radius, double lineWidth, GeometryWindow *geometryWindow)
Constructor of circular point.
This class add event handling to QGraphicsEllipseItem.
int radius() const
Radius of point. For a circle this is all that is needed to draw a circle. For a polygon, the radius determines the size of the polygon.
Details for a specific Point.
QRectF boundingRect() const
Proxy method for QGraphicsItem::boundingRect.
double highlightOpacity() const
Get method for highlight opacity.
~GraphicsPoint()
Destructor. This remove the graphics item from the scene.
void printStream(QString indentation, QTextStream &str, double ordinalKey) const
Debugging method that supports print method of this class and printStream method of some other class(...
Container for LineStyle and PointStyle for one Curve.
PointShape shape() const
Get method for point shape.
bool wanted() const
Identify point as wanted//unwanted.
void setShadow(GraphicsPointEllipse *shadow)
Bind this graphics item to its shadow.
This class add event handling to QGraphicsPolygonItem.
ColorPalette paletteColor() const
Get method for point color.
int lineWidth() const
Get method for line width.
void setShadow(GraphicsPointPolygon *shadow)
Bind this graphics item to its shadow.
void setRadius(int radius)
Update the radius.
void reset()
Mark point as unwanted, and unbind any bound lines.