Engauge Digitizer  2
GraphicsPointPolygon.cpp
1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
7 #include "DataKey.h"
8 #include "GraphicsPoint.h"
9 #include "GraphicsPointPolygon.h"
10 #include "Logger.h"
11 #include <QGraphicsScene>
12 #include "QtToString.h"
13 
15  const QPolygonF &polygon) :
16  QGraphicsPolygonItem (polygon),
17  m_graphicsPoint (graphicsPoint),
18  m_shadow (0)
19 {
20  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsPointPolygon::GraphicsPointPolygon";
21 }
22 
23 void GraphicsPointPolygon::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
24 {
25  // Highlighted
26  setOpacityForSubtree (m_graphicsPoint.highlightOpacity ());
27 
28  emit signalPointHoverEnter (data (DATA_KEY_IDENTIFIER).toString ());
29 
30  QGraphicsPolygonItem::hoverEnterEvent (event);
31 }
32 
33 void GraphicsPointPolygon::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
34 {
35  // Unhighlighted
36  setOpacityForSubtree (MAX_OPACITY);
37 
38  emit signalPointHoverLeave (data (DATA_KEY_IDENTIFIER).toString ());
39 
40  QGraphicsPolygonItem::hoverLeaveEvent (event);
41 }
42 
43 QVariant GraphicsPointPolygon::itemChange(GraphicsItemChange change,
44  const QVariant &value)
45 {
46  if (change == QGraphicsItem::ItemPositionHasChanged) {
47 
48  LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsPointPolygon::itemChange"
49  << " identifier=" << data (DATA_KEY_IDENTIFIER).toString().toLatin1().data()
50  << " positionHasChanged";
51 
52  setData (DATA_KEY_POSITION_HAS_CHANGED, QVariant (true));
53  }
54 
55  return QGraphicsPolygonItem::itemChange(change,
56  value);
57 }
58 
59 void GraphicsPointPolygon::setOpacityForSubtree (double opacity)
60 {
61  // Set this item
62  setOpacity (opacity);
63 
64  if (m_shadow != 0) {
65 
66  // Set the child item. Opacity < MAX_OPACITY is too dark so child is set to totally transparent
67  m_shadow->setOpacity (opacity < MAX_OPACITY ? 0.0 : opacity);
68  }
69 }
70 
72 {
73  // Resize assuming symmetry about the origin, and an aspect ratio of 1:1 (so x and y scales are the same)
74  double scale = (2 * radius) / boundingRect().width();
75  setScale (scale);
76 }
77 
79 {
80  m_shadow = shadow;
81 }
QVariant itemChange(GraphicsItemChange change, const QVariant &value)
Intercept moves by dragging so moved items can be identified. This replaces unreliable hit tests...
void setRadius(int radius)
Update the radius.
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Unhighlight this point.
double highlightOpacity() const
Get method for highlight opacity.
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
Accept hover so point can be highlighted when cursor is over it as a guide to user.
Graphics item for drawing a circular or polygonal Point.
Definition: GraphicsPoint.h:43
This class add event handling to QGraphicsPolygonItem.
void signalPointHoverLeave(QString)
Signal for geometry window to unhighlight the current point upon hover leave.
GraphicsPointPolygon(GraphicsPoint &graphicsPoint, const QPolygonF &polygon)
Single constructor.
void signalPointHoverEnter(QString)
Signal for geometry window to highlight the current point upon hover enter.
void setShadow(GraphicsPointPolygon *shadow)
Bind this graphics item to its shadow.