Engauge Digitizer  2
GraphicsPointEllipse.cpp
Go to the documentation of this file.
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 (nullptr)
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 != nullptr) {
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 
72 void GraphicsPointEllipse::setRadius(int radius)
73 {
74  // Resize assuming symmetry about the origin, and an aspect ratio of 1:1 (so x and y scales are the same)
75  if (boundingRect().width() > 0) {
76  double scale = (2 * radius) / boundingRect().width();
77  setScale (scale);
78  }
79 }
80 
82 {
83  m_shadow = shadow;
84 }
GraphicsPointEllipse::signalPointHoverEnter
void signalPointHoverEnter(QString)
Signal for geometry window to highlight the current point upon hover enter.
GraphicsPointEllipse::hoverEnterEvent
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
Accept hover so point can be highlighted when cursor is over it as a guide to user.
Definition: GraphicsPointEllipse.cpp:23
GraphicsPointEllipse::GraphicsPointEllipse
GraphicsPointEllipse(GraphicsPoint &graphicsPoint, const QRect &rect)
Single constructor.
Definition: GraphicsPointEllipse.cpp:14
GraphicsPointEllipse::signalPointHoverLeave
void signalPointHoverLeave(QString)
Signal for geometry window to unhighlight the current point upon hover leave.
GraphicsPointEllipse::hoverLeaveEvent
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Unhighlight this point.
Definition: GraphicsPointEllipse.cpp:33
GraphicsPointEllipse::setShadow
void setShadow(GraphicsPointEllipse *shadow)
Bind this graphics item to its shadow.
Definition: GraphicsPointEllipse.cpp:80
Logger.h
DATA_KEY_POSITION_HAS_CHANGED
Item type (i.e. image versus point)
Definition: DataKey.h:18
GraphicsPointEllipse::setRadius
void setRadius(int radius)
Update the radius.
Definition: GraphicsPointEllipse.cpp:71
LOG4CPP_INFO_S
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
GraphicsPoint.h
DataKey.h
GraphicsPointEllipse::itemChange
QVariant itemChange(GraphicsItemChange change, const QVariant &value)
Intercept moves by dragging so moved items can be identified. This replaces unreliable hit tests.
Definition: GraphicsPointEllipse.cpp:43
mainCat
log4cpp::Category * mainCat
Definition: Logger.cpp:14
GraphicsPoint::highlightOpacity
double highlightOpacity() const
Get method for highlight opacity.
Definition: GraphicsPoint.cpp:210
MAX_OPACITY
const double MAX_OPACITY
Definition: GraphicsPoint.cpp:28
DATA_KEY_IDENTIFIER
Definition: DataKey.h:16
GraphicsPoint
Graphics item for drawing a circular or polygonal Point.
Definition: GraphicsPoint.h:42
LOG4CPP_DEBUG_S
#define LOG4CPP_DEBUG_S(logger)
Definition: convenience.h:20
QtToString.h
GraphicsPointEllipse.h
GraphicsPointEllipse
This class add event handling to QGraphicsEllipseItem.
Definition: GraphicsPointEllipse.h:16