Engauge Digitizer
2
Toggle main menu visibility
Loading...
Searching...
No Matches
Graphics
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
15
GraphicsPointEllipse::GraphicsPointEllipse
(
GraphicsPoint
&graphicsPoint,
16
const
QRect &rect) :
17
QGraphicsEllipseItem (rect),
18
m_graphicsPoint (graphicsPoint),
19
m_shadow (nullptr)
20
{
21
qCInfo(ENGAUGE_LOG) <<
"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
qCDebug(ENGAUGE_LOG) <<
"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
81
void
GraphicsPointEllipse::setShadow
(
GraphicsPointEllipse
*shadow)
82
{
83
m_shadow = shadow;
84
}
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
GraphicsPointEllipse.h
MAX_OPACITY
const double MAX_OPACITY
Definition
GraphicsPoint.cpp:28
GraphicsPoint.h
Logger.h
QtToString.h
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:24
GraphicsPointEllipse::setShadow
void setShadow(GraphicsPointEllipse *shadow)
Bind this graphics item to its shadow.
Definition
GraphicsPointEllipse.cpp:81
GraphicsPointEllipse::signalPointHoverEnter
void signalPointHoverEnter(QString)
Signal for geometry window to highlight the current point upon hover enter.
GraphicsPointEllipse::signalPointHoverLeave
void signalPointHoverLeave(QString)
Signal for geometry window to unhighlight the current point upon hover leave.
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:44
GraphicsPointEllipse::GraphicsPointEllipse
GraphicsPointEllipse(GraphicsPoint &graphicsPoint, const QRect &rect)
Single constructor.
Definition
GraphicsPointEllipse.cpp:15
GraphicsPointEllipse::setRadius
void setRadius(int radius)
Update the radius.
Definition
GraphicsPointEllipse.cpp:72
GraphicsPointEllipse::hoverLeaveEvent
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Unhighlight this point.
Definition
GraphicsPointEllipse.cpp:34
GraphicsPoint
Graphics item for drawing a circular or polygonal Point.
Definition
GraphicsPoint.h:44
Generated on
for Engauge Digitizer by
1.17.0