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;
113 void GraphicsPoint::createPointEllipse (
unsigned int radius)
115 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsPoint::createPointEllipse";
117 const int radiusSigned = radius;
119 QRect (- radiusSigned,
121 2 * radiusSigned + 1,
122 2 * radiusSigned + 1));
123 m_scene.addItem (m_graphicsItemEllipse);
125 m_graphicsItemEllipse->setZValue (Z_VALUE_POINT);
126 m_graphicsItemEllipse->setData (DATA_KEY_IDENTIFIER, m_identifier);
127 m_graphicsItemEllipse->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
128 m_graphicsItemEllipse->setPos (m_posScreen.x (),
130 m_graphicsItemEllipse->setPen (QPen (QBrush (m_color), m_lineWidth));
131 m_graphicsItemEllipse->setEnabled (
true);
132 m_graphicsItemEllipse->setFlags (QGraphicsItem::ItemIsSelectable |
133 QGraphicsItem::ItemIsMovable |
134 QGraphicsItem::ItemSendsGeometryChanges);
135 m_graphicsItemEllipse->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
136 if (m_geometryWindow != 0) {
137 QObject::connect (m_graphicsItemEllipse, SIGNAL (signalPointHoverEnter (QString)), m_geometryWindow, SLOT (slotPointHoverEnter (QString)));
138 QObject::connect (m_graphicsItemEllipse, SIGNAL (signalPointHoverLeave (QString)), m_geometryWindow, SLOT (slotPointHoverLeave (QString)));
144 QRect (- radiusSigned,
146 2 * radiusSigned + 1,
147 2 * radiusSigned + 1));
148 m_shadowZeroWidthEllipse->setParentItem(m_graphicsItemPolygon);
150 m_shadowZeroWidthEllipse->setPen (QPen (QBrush (m_color), ZERO_WIDTH));
151 m_shadowZeroWidthEllipse->setEnabled (
true);
153 m_graphicsItemEllipse->
setShadow (m_shadowZeroWidthEllipse);
156 void GraphicsPoint::createPointPolygon (
const QPolygonF &polygon)
158 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsPoint::createPointPolygon";
162 m_scene.addItem (m_graphicsItemPolygon);
164 m_graphicsItemPolygon->setZValue (Z_VALUE_POINT);
165 m_graphicsItemPolygon->setData (DATA_KEY_IDENTIFIER, m_identifier);
166 m_graphicsItemPolygon->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
167 m_graphicsItemPolygon->setPos (m_posScreen.x (),
169 m_graphicsItemPolygon->setPen (QPen (QBrush (m_color), m_lineWidth));
170 m_graphicsItemPolygon->setEnabled (
true);
171 m_graphicsItemPolygon->setFlags (QGraphicsItem::ItemIsSelectable |
172 QGraphicsItem::ItemIsMovable |
173 QGraphicsItem::ItemSendsGeometryChanges);
174 m_graphicsItemPolygon->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
175 if (m_geometryWindow != 0) {
176 QObject::connect (m_graphicsItemPolygon, SIGNAL (signalPointHoverEnter (QString)), m_geometryWindow, SLOT (slotPointHoverEnter (QString)));
177 QObject::connect (m_graphicsItemPolygon, SIGNAL (signalPointHoverLeave (QString)), m_geometryWindow, SLOT (slotPointHoverLeave (QString)));
184 m_shadowZeroWidthPolygon->setParentItem(m_graphicsItemPolygon);
186 m_shadowZeroWidthPolygon->setPen (QPen (QBrush (m_color), ZERO_WIDTH));
187 m_shadowZeroWidthPolygon->setEnabled (
true);
189 m_graphicsItemPolygon->
setShadow (m_shadowZeroWidthPolygon);
194 if (m_graphicsItemEllipse == 0) {
195 return m_graphicsItemPolygon->data (key);
197 return m_graphicsItemEllipse->data (key);
203 return m_highlightOpacity;
208 if (m_graphicsItemEllipse == 0) {
209 return m_graphicsItemPolygon->pos ();
211 return m_graphicsItemEllipse->pos ();
217 double ordinalKey)
const
219 str << indentation <<
"GraphicsPoint\n";
221 indentation += INDENTATION_DELTA;
226 if (m_graphicsItemEllipse == 0) {
227 identifier = m_graphicsItemPolygon->data (DATA_KEY_IDENTIFIER).toString ();
228 pointType =
"polygon";
229 pos = m_graphicsItemPolygon->pos();
231 identifier = m_graphicsItemEllipse->data (DATA_KEY_IDENTIFIER).toString ();
232 pointType =
"ellipse";
233 pos = m_graphicsItemEllipse->pos();
236 DataKey type = (DataKey)
data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt();
238 str << indentation << identifier
239 <<
" ordinalKey=" << ordinalKey
240 <<
" dataIdentifier=" <<
data (DATA_KEY_IDENTIFIER).toString().toLatin1().data()
241 <<
" dataType=" << dataKeyToString (type).toLatin1().data()
242 <<
" " << pointType <<
"Pos=" << QPointFToString (pos) <<
"\n";
252 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsPoint::setData"
253 <<
" key=" << dataKeyToString ((DataKey) key).toLatin1().data()
254 <<
" data=" << data.toString().toLatin1().data();
256 if (m_graphicsItemEllipse == 0) {
257 m_graphicsItemPolygon->setData (key, data);
259 m_graphicsItemEllipse->setData (key, data);
265 LOG4CPP_DEBUG_S ((*mainCat)) <<
"GraphicsPoint::setHighlightOpacity"
266 <<
" identifier=" << m_identifier.toLatin1().data()
276 if (m_graphicsItemEllipse == 0) {
277 if (pointStyle.
shape() == POINT_SHAPE_CIRCLE) {
280 delete m_graphicsItemPolygon;
281 m_graphicsItemPolygon = 0;
282 m_shadowZeroWidthPolygon = 0;
284 createPointEllipse (pointStyle.
radius());
289 m_graphicsItemPolygon->setPen (QPen (ColorPaletteToQColor(pointStyle.
paletteColor()),
291 m_shadowZeroWidthPolygon->setPen (QPen (ColorPaletteToQColor(pointStyle.
paletteColor()),
293 m_graphicsItemPolygon->setPolygon (pointStyle.
polygon());
294 m_shadowZeroWidthPolygon->setPolygon (pointStyle.
polygon());
298 if (pointStyle.
shape() != POINT_SHAPE_CIRCLE) {
301 delete m_graphicsItemEllipse;
302 m_graphicsItemEllipse = 0;
303 m_shadowZeroWidthEllipse = 0;
305 createPointPolygon (pointStyle.
polygon());
310 m_graphicsItemEllipse->setPen (QPen (ColorPaletteToQColor(pointStyle.
paletteColor()),
312 m_shadowZeroWidthEllipse->setPen (QPen (ColorPaletteToQColor(pointStyle.
paletteColor()),
322 if (m_graphicsItemEllipse == 0) {
323 return m_graphicsItemPolygon->setPos (pos);
325 return m_graphicsItemEllipse->setPos (pos);
void setWanted()
Mark point as wanted. Marking as unwanted is done by the reset function.
void setHighlightOpacity(double highlightOpacity)
Set method for highlight opacity.
int lineWidth() const
Get method for line width.
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(...
QPolygonF polygon() const
Return the polygon for creating a QGraphicsPolygonItem. The size is determined by the radius...
Base class for adding identifiers to graphics items that represent Points.
PointStyle pointStyle() const
Get method for PointStyle.
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.
bool wanted() const
Identify point as wanted//unwanted.
void setPointStyle(const PointStyle &pointStyle)
Update the point style.
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.
Details for a specific Point.
double highlightOpacity() const
Get method for highlight opacity.
~GraphicsPoint()
Destructor. This remove the graphics item from the scene.
ColorPalette paletteColor() const
Get method for point color.
Container for LineStyle and PointStyle for one Curve.
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.
void setShadow(GraphicsPointEllipse *shadow)
Bind this graphics item to its shadow.
This class add event handling to QGraphicsPolygonItem.
QPointF pos() const
Proxy method for QGraphicsItem::pos.
QVariant data(int key) const
Proxy method for QGraphicsItem::data.
void setShadow(GraphicsPointPolygon *shadow)
Bind this graphics item to its shadow.
PointShape shape() const
Get method for point shape.
void setRadius(int radius)
Update the radius.
void reset()
Mark point as unwanted, and unbind any bound lines.