Engauge Digitizer
2
Toggle main menu visibility
Loading...
Searching...
No Matches
Graphics
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
"
9
#include "
GraphicsPointPolygon.h
"
10
#include "
Logger.h
"
11
#include <QGraphicsScene>
12
#include "
QtToString.h
"
13
14
GraphicsPointPolygon::GraphicsPointPolygon
(
GraphicsPoint
&graphicsPoint,
15
const
QPolygonF &polygon) :
16
QGraphicsPolygonItem (polygon),
17
m_graphicsPoint (graphicsPoint),
18
m_shadow (nullptr)
19
{
20
qCInfo(ENGAUGE_LOG) <<
"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
qCDebug(ENGAUGE_LOG) <<
"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 !=
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
71
void
GraphicsPointPolygon::setRadius
(
int
radius)
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
80
void
GraphicsPointPolygon::setShadow
(
GraphicsPointPolygon
*shadow)
81
{
82
m_shadow = shadow;
83
}
DataKey.h
DATA_KEY_POSITION_HAS_CHANGED
@ DATA_KEY_POSITION_HAS_CHANGED
Definition
DataKey.h:16
DATA_KEY_IDENTIFIER
@ DATA_KEY_IDENTIFIER
Definition
DataKey.h:14
GraphicsPointPolygon.h
MAX_OPACITY
const double MAX_OPACITY
Definition
GraphicsPoint.cpp:28
GraphicsPoint.h
Logger.h
QtToString.h
GraphicsPointPolygon::setRadius
void setRadius(int radius)
Update the radius.
Definition
GraphicsPointPolygon.cpp:71
GraphicsPointPolygon::hoverLeaveEvent
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Unhighlight this point.
Definition
GraphicsPointPolygon.cpp:33
GraphicsPointPolygon::hoverEnterEvent
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
Accept hover so point can be highlighted when cursor is over it as a guide to user.
Definition
GraphicsPointPolygon.cpp:23
GraphicsPointPolygon::itemChange
QVariant itemChange(GraphicsItemChange change, const QVariant &value)
Intercept moves by dragging so moved items can be identified. This replaces unreliable hit tests.
Definition
GraphicsPointPolygon.cpp:43
GraphicsPointPolygon::signalPointHoverEnter
void signalPointHoverEnter(QString)
Signal for geometry window to highlight the current point upon hover enter.
GraphicsPointPolygon::GraphicsPointPolygon
GraphicsPointPolygon(GraphicsPoint &graphicsPoint, const QPolygonF &polygon)
Single constructor.
Definition
GraphicsPointPolygon.cpp:14
GraphicsPointPolygon::signalPointHoverLeave
void signalPointHoverLeave(QString)
Signal for geometry window to unhighlight the current point upon hover leave.
GraphicsPointPolygon::setShadow
void setShadow(GraphicsPointPolygon *shadow)
Bind this graphics item to its shadow.
Definition
GraphicsPointPolygon.cpp:80
GraphicsPoint
Graphics item for drawing a circular or polygonal Point.
Definition
GraphicsPoint.h:44
Generated on
for Engauge Digitizer by
1.17.0