Engauge Digitizer  2
GraphicsPointEllipse.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 "GraphicsPointEllipse.h"
10 #include "Logger.h"
11 #include <QColor>
12 #include <QGraphicsScene>
13 #include "QtToString.h"
14 
16  const QRect &rect) :
17  QGraphicsEllipseItem (rect),
18  m_graphicsPoint (graphicsPoint),
19  m_shadow (0)
20 {
21  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsPointEllipse::GraphicsPointEllipse";
22 }
23 
24 void GraphicsPointEllipse::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
25 {
26  // Highlighted
27  setOpacityForSubtree (m_graphicsPoint.highlightOpacity());
28 
29  emit signalPointHoverEnter (data (DATA_KEY_IDENTIFIER).toString ());
30 
31  QGraphicsEllipseItem::hoverEnterEvent (event);
32 }
33 
34 void GraphicsPointEllipse::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
35 {
36  // Unhighlighted
37  setOpacityForSubtree (MAX_OPACITY);
38 
39  emit signalPointHoverLeave (data (DATA_KEY_IDENTIFIER).toString ());
40 
41  QGraphicsEllipseItem::hoverLeaveEvent (event);
42 }
43 
44 QVariant GraphicsPointEllipse::itemChange(GraphicsItemChange change,
45  const QVariant &value)
46 {
47  if (change == QGraphicsItem::ItemPositionHasChanged) {
48 
49  LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsPointEllipse::itemChange"
50  << " identifier=" << data (DATA_KEY_IDENTIFIER).toString().toLatin1().data()
51  << " positionHasChanged";
52 
53  setData (DATA_KEY_POSITION_HAS_CHANGED, QVariant (true));
54  }
55 
56  return QGraphicsEllipseItem::itemChange(change,
57  value);
58 }
59 
60 void GraphicsPointEllipse::setOpacityForSubtree (double opacity)
61 {
62  // Set this item
63  setOpacity (opacity);
64 
65  if (m_shadow != 0) {
66 
67  // Set the child item. Opacity < MAX_OPACITY is too dark so child is set to totally transparent
68  m_shadow->setOpacity (opacity < MAX_OPACITY ? 0.0 : opacity);
69  }
70 }
71 
73 {
74  // Resize assuming symmetry about the origin, and an aspect ratio of 1:1 (so x and y scales are the same)
75  double scale = (2 * radius) / boundingRect().width();
76  setScale (scale);
77 }
78 
80 {
81  m_shadow = shadow;
82 }
void signalPointHoverEnter(QString)
Signal for geometry window to highlight the current point upon hover enter.
This class add event handling to QGraphicsEllipseItem.
double highlightOpacity() const
Get method for highlight opacity.
Graphics item for drawing a circular or polygonal Point.
Definition: GraphicsPoint.h:43
void setShadow(GraphicsPointEllipse *shadow)
Bind this graphics item to its shadow.
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
Accept hover so point can be highlighted when cursor is over it as a guide to user.
QVariant itemChange(GraphicsItemChange change, const QVariant &value)
Intercept moves by dragging so moved items can be identified. This replaces unreliable hit tests...
void signalPointHoverLeave(QString)
Signal for geometry window to unhighlight the current point upon hover leave.
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Unhighlight this point.
GraphicsPointEllipse(GraphicsPoint &graphicsPoint, const QRect &rect)
Single constructor.
void setRadius(int radius)
Update the radius.