00001
00002
00003
00004
00005
00006
00007 #include "CurveStyle.h"
00008 #include "DataKey.h"
00009 #include "EnumsToQt.h"
00010 #include "GeometryWindow.h"
00011 #include "GraphicsItemType.h"
00012 #include "GraphicsPoint.h"
00013 #include "GraphicsPointEllipse.h"
00014 #include "GraphicsPointPolygon.h"
00015 #include "Logger.h"
00016 #include "PointStyle.h"
00017 #include <QGraphicsEllipseItem>
00018 #include <QGraphicsPolygonItem>
00019 #include <QGraphicsScene>
00020 #include <QGraphicsSceneContextMenuEvent>
00021 #include <QObject>
00022 #include <QPen>
00023 #include <QTextStream>
00024 #include "QtToString.h"
00025 #include "ZValues.h"
00026
00027 const double DEFAULT_HIGHLIGHT_OPACITY = 0.35;
00028 const double MAX_OPACITY = 1.0;
00029 const double ZERO_WIDTH = 0.0;
00030
00031 GraphicsPoint::GraphicsPoint(QGraphicsScene &scene,
00032 const QString &identifier,
00033 const QPointF &posScreen,
00034 const QColor &color,
00035 unsigned int radius,
00036 double lineWidth,
00037 GeometryWindow *geometryWindow) :
00038 GraphicsPointAbstractBase (),
00039 m_scene (scene),
00040 m_graphicsItemEllipse (0),
00041 m_shadowZeroWidthEllipse (0),
00042 m_graphicsItemPolygon (0),
00043 m_shadowZeroWidthPolygon (0),
00044 m_identifier (identifier),
00045 m_posScreen (posScreen),
00046 m_color (color),
00047 m_lineWidth (lineWidth),
00048 m_wanted (true),
00049 m_highlightOpacity (DEFAULT_HIGHLIGHT_OPACITY),
00050 m_geometryWindow (geometryWindow)
00051 {
00052 LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsPoint::GraphicsPoint"
00053 << " identifier=" << identifier.toLatin1 ().data ();
00054
00055 createPointEllipse (radius);
00056 }
00057
00058 GraphicsPoint::GraphicsPoint(QGraphicsScene &scene,
00059 const QString &identifier,
00060 const QPointF &posScreen,
00061 const QColor &color,
00062 const QPolygonF &polygon,
00063 double lineWidth,
00064 GeometryWindow *geometryWindow) :
00065 GraphicsPointAbstractBase (),
00066 m_scene (scene),
00067 m_graphicsItemEllipse (0),
00068 m_shadowZeroWidthEllipse (0),
00069 m_graphicsItemPolygon (0),
00070 m_shadowZeroWidthPolygon (0),
00071 m_identifier (identifier),
00072 m_posScreen (posScreen),
00073 m_color (color),
00074 m_lineWidth (lineWidth),
00075 m_wanted (true),
00076 m_highlightOpacity (DEFAULT_HIGHLIGHT_OPACITY),
00077 m_geometryWindow (geometryWindow)
00078 {
00079 LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsPoint::GraphicsPoint "
00080 << " identifier=" << identifier.toLatin1 ().data ();
00081
00082 createPointPolygon (polygon);
00083 }
00084
00085 GraphicsPoint::~GraphicsPoint()
00086 {
00087 LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsPoint::~GraphicsPoint";
00088
00089 if (m_graphicsItemEllipse == 0) {
00090
00091 QGraphicsScene *scene = m_graphicsItemPolygon->scene();
00092
00093
00094 scene->removeItem (m_graphicsItemPolygon);
00095 delete m_graphicsItemPolygon;
00096 m_graphicsItemPolygon = 0;
00097 m_shadowZeroWidthPolygon = 0;
00098
00099
00100 } else {
00101
00102 QGraphicsScene *scene = m_graphicsItemEllipse->scene();
00103
00104
00105 scene->removeItem (m_graphicsItemEllipse);
00106 delete m_graphicsItemEllipse;
00107 m_graphicsItemEllipse = 0;
00108 m_shadowZeroWidthEllipse = 0;
00109
00110 }
00111 }
00112
00113 void GraphicsPoint::createPointEllipse (unsigned int radius)
00114 {
00115 LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsPoint::createPointEllipse";
00116
00117 const int radiusSigned = radius;
00118 m_graphicsItemEllipse = new GraphicsPointEllipse (*this,
00119 QRect (- radiusSigned,
00120 - radiusSigned,
00121 2 * radiusSigned + 1,
00122 2 * radiusSigned + 1));
00123 m_scene.addItem (m_graphicsItemEllipse);
00124
00125 m_graphicsItemEllipse->setZValue (Z_VALUE_POINT);
00126 m_graphicsItemEllipse->setData (DATA_KEY_IDENTIFIER, m_identifier);
00127 m_graphicsItemEllipse->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
00128 m_graphicsItemEllipse->setPos (m_posScreen.x (),
00129 m_posScreen.y ());
00130 m_graphicsItemEllipse->setPen (QPen (QBrush (m_color), m_lineWidth));
00131 m_graphicsItemEllipse->setEnabled (true);
00132 m_graphicsItemEllipse->setFlags (QGraphicsItem::ItemIsSelectable |
00133 QGraphicsItem::ItemIsMovable |
00134 QGraphicsItem::ItemSendsGeometryChanges);
00135 m_graphicsItemEllipse->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
00136 if (m_geometryWindow != 0) {
00137 QObject::connect (m_graphicsItemEllipse, SIGNAL (signalPointHoverEnter (QString)), m_geometryWindow, SLOT (slotPointHoverEnter (QString)));
00138 QObject::connect (m_graphicsItemEllipse, SIGNAL (signalPointHoverLeave (QString)), m_geometryWindow, SLOT (slotPointHoverLeave (QString)));
00139 }
00140
00141
00142
00143 m_shadowZeroWidthEllipse = new GraphicsPointEllipse (*this,
00144 QRect (- radiusSigned,
00145 - radiusSigned,
00146 2 * radiusSigned + 1,
00147 2 * radiusSigned + 1));
00148 m_shadowZeroWidthEllipse->setParentItem(m_graphicsItemPolygon);
00149
00150 m_shadowZeroWidthEllipse->setPen (QPen (QBrush (m_color), ZERO_WIDTH));
00151 m_shadowZeroWidthEllipse->setEnabled (true);
00152
00153 m_graphicsItemEllipse->setShadow (m_shadowZeroWidthEllipse);
00154 }
00155
00156 void GraphicsPoint::createPointPolygon (const QPolygonF &polygon)
00157 {
00158 LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsPoint::createPointPolygon";
00159
00160 m_graphicsItemPolygon = new GraphicsPointPolygon (*this,
00161 polygon);
00162 m_scene.addItem (m_graphicsItemPolygon);
00163
00164 m_graphicsItemPolygon->setZValue (Z_VALUE_POINT);
00165 m_graphicsItemPolygon->setData (DATA_KEY_IDENTIFIER, m_identifier);
00166 m_graphicsItemPolygon->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
00167 m_graphicsItemPolygon->setPos (m_posScreen.x (),
00168 m_posScreen.y ());
00169 m_graphicsItemPolygon->setPen (QPen (QBrush (m_color), m_lineWidth));
00170 m_graphicsItemPolygon->setEnabled (true);
00171 m_graphicsItemPolygon->setFlags (QGraphicsItem::ItemIsSelectable |
00172 QGraphicsItem::ItemIsMovable |
00173 QGraphicsItem::ItemSendsGeometryChanges);
00174 m_graphicsItemPolygon->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_POINT);
00175 if (m_geometryWindow != 0) {
00176 QObject::connect (m_graphicsItemPolygon, SIGNAL (signalPointHoverEnter (QString)), m_geometryWindow, SLOT (slotPointHoverEnter (QString)));
00177 QObject::connect (m_graphicsItemPolygon, SIGNAL (signalPointHoverLeave (QString)), m_geometryWindow, SLOT (slotPointHoverLeave (QString)));
00178 }
00179
00180
00181
00182 m_shadowZeroWidthPolygon = new GraphicsPointPolygon (*this,
00183 polygon);
00184 m_shadowZeroWidthPolygon->setParentItem(m_graphicsItemPolygon);
00185
00186 m_shadowZeroWidthPolygon->setPen (QPen (QBrush (m_color), ZERO_WIDTH));
00187 m_shadowZeroWidthPolygon->setEnabled (true);
00188
00189 m_graphicsItemPolygon->setShadow (m_shadowZeroWidthPolygon);
00190 }
00191
00192 QVariant GraphicsPoint::data (int key) const
00193 {
00194 if (m_graphicsItemEllipse == 0) {
00195 return m_graphicsItemPolygon->data (key);
00196 } else {
00197 return m_graphicsItemEllipse->data (key);
00198 }
00199 }
00200
00201 double GraphicsPoint::highlightOpacity () const
00202 {
00203 return m_highlightOpacity;
00204 }
00205
00206 QPointF GraphicsPoint::pos () const
00207 {
00208 if (m_graphicsItemEllipse == 0) {
00209 return m_graphicsItemPolygon->pos ();
00210 } else {
00211 return m_graphicsItemEllipse->pos ();
00212 }
00213 }
00214
00215 void GraphicsPoint::printStream (QString indentation,
00216 QTextStream &str,
00217 double ordinalKey) const
00218 {
00219 str << indentation << "GraphicsPoint\n";
00220
00221 indentation += INDENTATION_DELTA;
00222
00223 QString identifier;
00224 QString pointType;
00225 QPointF pos;
00226 if (m_graphicsItemEllipse == 0) {
00227 identifier = m_graphicsItemPolygon->data (DATA_KEY_IDENTIFIER).toString ();
00228 pointType = "polygon";
00229 pos = m_graphicsItemPolygon->pos();
00230 } else {
00231 identifier = m_graphicsItemEllipse->data (DATA_KEY_IDENTIFIER).toString ();
00232 pointType = "ellipse";
00233 pos = m_graphicsItemEllipse->pos();
00234 }
00235
00236 DataKey type = (DataKey) data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt();
00237
00238 str << indentation << identifier
00239 << " ordinalKey=" << ordinalKey
00240 << " dataIdentifier=" << data (DATA_KEY_IDENTIFIER).toString().toLatin1().data()
00241 << " dataType=" << dataKeyToString (type).toLatin1().data()
00242 << " " << pointType << "Pos=" << QPointFToString (pos) << "\n";
00243 }
00244
00245 void GraphicsPoint::reset ()
00246 {
00247 m_wanted = false;
00248 }
00249
00250 void GraphicsPoint::setData (int key, const QVariant &data)
00251 {
00252 LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsPoint::setData"
00253 << " key=" << dataKeyToString ((DataKey) key).toLatin1().data()
00254 << " data=" << data.toString().toLatin1().data();
00255
00256 if (m_graphicsItemEllipse == 0) {
00257 m_graphicsItemPolygon->setData (key, data);
00258 } else {
00259 m_graphicsItemEllipse->setData (key, data);
00260 }
00261 }
00262
00263 void GraphicsPoint::setHighlightOpacity (double highlightOpacity)
00264 {
00265 LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsPoint::setHighlightOpacity"
00266 << " identifier=" << m_identifier.toLatin1().data()
00267 << " highlightOpacity=" << highlightOpacity;
00268
00269 m_highlightOpacity = highlightOpacity;
00270 }
00271
00272 void GraphicsPoint::setPointStyle(const PointStyle &pointStyle)
00273 {
00274
00275
00276 if (m_graphicsItemEllipse == 0) {
00277 if (pointStyle.shape() == POINT_SHAPE_CIRCLE) {
00278
00279
00280 delete m_graphicsItemPolygon;
00281 m_graphicsItemPolygon = 0;
00282 m_shadowZeroWidthPolygon = 0;
00283
00284 createPointEllipse (pointStyle.radius());
00285
00286 } else {
00287
00288
00289 m_graphicsItemPolygon->setPen (QPen (ColorPaletteToQColor(pointStyle.paletteColor()),
00290 pointStyle.lineWidth()));
00291 m_shadowZeroWidthPolygon->setPen (QPen (ColorPaletteToQColor(pointStyle.paletteColor()),
00292 pointStyle.lineWidth()));
00293 m_graphicsItemPolygon->setPolygon (pointStyle.polygon());
00294 m_shadowZeroWidthPolygon->setPolygon (pointStyle.polygon());
00295
00296 }
00297 } else {
00298 if (pointStyle.shape() != POINT_SHAPE_CIRCLE) {
00299
00300
00301 delete m_graphicsItemEllipse;
00302 m_graphicsItemEllipse = 0;
00303 m_shadowZeroWidthEllipse = 0;
00304
00305 createPointPolygon (pointStyle.polygon());
00306
00307 } else {
00308
00309
00310 m_graphicsItemEllipse->setPen (QPen (ColorPaletteToQColor(pointStyle.paletteColor()),
00311 pointStyle.lineWidth()));
00312 m_shadowZeroWidthEllipse->setPen (QPen (ColorPaletteToQColor(pointStyle.paletteColor()),
00313 pointStyle.lineWidth()));
00314 m_graphicsItemEllipse->setRadius (pointStyle.radius());
00315 m_shadowZeroWidthEllipse->setRadius (pointStyle.radius());
00316 }
00317 }
00318 }
00319
00320 void GraphicsPoint::setPos (const QPointF pos)
00321 {
00322 if (m_graphicsItemEllipse == 0) {
00323 return m_graphicsItemPolygon->setPos (pos);
00324 } else {
00325 return m_graphicsItemEllipse->setPos (pos);
00326 }
00327 }
00328
00329 void GraphicsPoint::setWanted ()
00330 {
00331 m_wanted = true;
00332 }
00333
00334 void GraphicsPoint::updateCurveStyle (const CurveStyle &curveStyle)
00335 {
00336 setPointStyle (curveStyle.pointStyle());
00337 }
00338
00339 bool GraphicsPoint::wanted () const
00340 {
00341 return m_wanted;
00342 }