Engauge Digitizer 2
Loading...
Searching...
No Matches
GraphicsPointPolygon.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"
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 (nullptr)
19{
20 LOG4CPP_INFO_S ((*mainCat)) << "GraphicsPointPolygon::GraphicsPointPolygon";
21}
22
23void 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
33void 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
43QVariant 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
59void GraphicsPointPolygon::setOpacityForSubtree (double opacity)
60{
61 // Set this item
62 setOpacity (opacity);
63
64 if (m_shadow != nullptr) {
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 if (boundingRect().width() > 0) {
75 double scale = (2 * radius) / boundingRect().width();
76 setScale (scale);
77 }
78}
79
81{
82 m_shadow = shadow;
83}
@ DATA_KEY_POSITION_HAS_CHANGED
Definition DataKey.h:16
@ DATA_KEY_IDENTIFIER
Definition DataKey.h:14
const double MAX_OPACITY
log4cpp::Category * mainCat
Definition Logger.cpp:14
void setRadius(int radius)
Update the radius.
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Unhighlight this point.
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 signalPointHoverEnter(QString)
Signal for geometry window to highlight the current point upon hover enter.
GraphicsPointPolygon(GraphicsPoint &graphicsPoint, const QPolygonF &polygon)
Single constructor.
void signalPointHoverLeave(QString)
Signal for geometry window to unhighlight the current point upon hover leave.
void setShadow(GraphicsPointPolygon *shadow)
Bind this graphics item to its shadow.
Graphics item for drawing a circular or polygonal Point.
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18
#define LOG4CPP_DEBUG_S(logger)
Definition convenience.h:20