Engauge Digitizer 2
Loading...
Searching...
No Matches
SegmentLine.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 "EnumsToQt.h"
9#include "GraphicsItemType.h"
10#include "InactiveOpacity.h"
11#include "Logger.h"
12#include <QGraphicsScene>
13#include <QPen>
14#include "Segment.h"
15#include "SegmentLine.h"
16#include "ZValues.h"
17
18SegmentLine::SegmentLine(QGraphicsScene &scene,
19 const DocumentModelSegments &modelSegments,
21 m_modelSegments (modelSegments),
22 m_segment (segment)
23{
24 LOG4CPP_DEBUG_S ((*mainCat)) << "SegmentLine::SegmentLine"
25 << " address=0x" << std::hex << static_cast<void *> (this);
26
28
29 // Make this transparent now, but always visible so hover events work
30 scene.addItem (this);
31 setPen (QPen (Qt::transparent));
32 setZValue (Z_VALUE_CURVE);
33 setVisible (true);
34 setAcceptHoverEvents (true);
35 setHover (false); // Initially the cursor is not hovering over this object. Later a hover event will change this state
36 setFlags (QGraphicsItem::ItemIsFocusable);
37
38 connect (this, SIGNAL (signalHover (bool)), segment, SLOT (slotHover (bool)));
39}
40
42{
43 LOG4CPP_DEBUG_S ((*mainCat)) << "SegmentLine::~SegmentLine"
44 << " address=0x" << std::hex << static_cast<void *> (this);
45}
46
47void SegmentLine::hoverEnterEvent(QGraphicsSceneHoverEvent * /* event */)
48{
49 LOG4CPP_INFO_S ((*mainCat)) << "SegmentLine::hoverEnterEvent";
50
51 emit (signalHover (true));
52}
53
54void SegmentLine::hoverLeaveEvent(QGraphicsSceneHoverEvent * /* event */)
55{
56 LOG4CPP_INFO_S ((*mainCat)) << "SegmentLine::hoverLeaveEvent";
57
58 emit (signalHover (false));
59}
60
61void SegmentLine::mousePressEvent(QGraphicsSceneMouseEvent * /* event */)
62{
63 LOG4CPP_INFO_S ((*mainCat)) << "SegmentLine::mousePressEvent";
64
65 m_segment->forwardMousePress();
66}
67
69{
70 return m_segment;
71}
72
73void SegmentLine::setHover (bool hover)
74{
75 QColor colorOpaque (ColorPaletteToQColor (m_modelSegments.lineColor()));
76
77 if (hover) {
78
79 setPen (QPen (QBrush (colorOpaque),
80 m_modelSegments.lineWidthActive()));
81
82 } else {
83
84 QColor colorSoft (colorOpaque.red (),
85 colorOpaque.green (),
86 colorOpaque.blue (),
87 inactiveOpacityEnumToAlpha (m_modelSegments.inactiveOpacity()));
88
89 setPen (QPen (QBrush (colorSoft),
90 m_modelSegments.lineWidthInactive()));
91
92 }
93}
94
96{
97 LOG4CPP_INFO_S ((*mainCat)) << "SegmentLine::updateModelSegment";
98
99 m_modelSegments = modelSegments;
100}
@ DATA_KEY_GRAPHICS_ITEM_TYPE
Definition DataKey.h:15
QColor ColorPaletteToQColor(ColorPalette color)
Definition EnumsToQt.cpp:16
@ GRAPHICS_ITEM_TYPE_SEGMENT
int inactiveOpacityEnumToAlpha(InactiveOpacity inactiveOpacity)
Map InactiveOpacity enum to corresponding alpha value.
log4cpp::Category * mainCat
Definition Logger.cpp:14
const int Z_VALUE_CURVE
Definition ZValues.cpp:10
Model for DlgSettingsSegments and CmdSettingsSegments.
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
Create points along this curve.
void signalHover(bool)
Pass hover enter/leave events to Segment that owns this.
SegmentLine(QGraphicsScene &scene, const DocumentModelSegments &modelSegments, Segment *segment)
Single constructor.
void setHover(bool hover)
Apply/remove highlighting triggered by hover enter/leave.
Segment * segment() const
Segment that owns this line.
void updateModelSegment(const DocumentModelSegments &modelSegments)
Update this segment line with new settings.
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
Highlight this and all other SegmentLines belonging to the same Segment upon hover enter.
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Unset highlighting triggered by hover enter.
Selectable piecewise-defined line that follows a filtered line in the image.
Definition Segment.h:22
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18
#define LOG4CPP_DEBUG_S(logger)
Definition convenience.h:20