Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
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 QVariant GraphicsPointPolygon::itemChange(GraphicsItemChange change,
24  const QVariant &value)
25 {
26  if (change == QGraphicsItem::ItemPositionHasChanged) {
27 
28  LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsPointPolygon::itemChange"
29  << " identifier=" << data (DATA_KEY_IDENTIFIER).toString().toLatin1().data()
30  << " positionHasChanged";
31 
32  setData (DATA_KEY_POSITION_HAS_CHANGED, QVariant (true));
33  }
34 
35  return QGraphicsPolygonItem::itemChange(change,
36  value);
37 }
38 
39 void GraphicsPointPolygon::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
40 {
41  // Highlighted
42  setOpacityForSubtree (m_graphicsPoint.highlightOpacity ());
43 
44  emit signalPointHoverEnter (data (DATA_KEY_IDENTIFIER).toString ());
45 
46  QGraphicsPolygonItem::hoverEnterEvent (event);
47 }
48 
49 void GraphicsPointPolygon::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
50 {
51  // Unhighlighted
52  setOpacityForSubtree (MAX_OPACITY);
53 
54  emit signalPointHoverLeave (data (DATA_KEY_IDENTIFIER).toString ());
55 
56  QGraphicsPolygonItem::hoverLeaveEvent (event);
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:42
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.