Engauge Digitizer 2
Loading...
Searching...
No Matches
SegmentLine.cpp
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 "Logger.h"
11#include <QGraphicsScene>
12#include <QPen>
13#include "Segment.h"
14#include "SegmentLine.h"
15
16const double ZVALUE_SEGMENT = 50; // Less than z value for GraphicsPoint
17
18SegmentLine::SegmentLine(QGraphicsScene &scene,
19 const DocumentModelSegments &modelSegments,
20 Segment *segment) :
21 m_modelSegments (modelSegments),
22 m_segment (segment)
23{
24 LOG4CPP_DEBUG_S ((*mainCat)) << "SegmentLine::SegmentLine"
25 << " address=0x" << std::hex << (quintptr) this;
26
27 setData (DATA_KEY_GRAPHICS_ITEM_TYPE, QVariant (GRAPHICS_ITEM_TYPE_SEGMENT));
28
29 // Make this transparent now, but always visible so hover events work
30 scene.addItem (this);
31 setPen (QPen (Qt::transparent));
32 setZValue (ZVALUE_SEGMENT);
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
41SegmentLine::~SegmentLine ()
42{
43 LOG4CPP_DEBUG_S ((*mainCat)) << "SegmentLine::~SegmentLine"
44 << " address=0x" << std::hex << (quintptr) 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 if (hover) {
76
77 QColor color (ColorPaletteToQColor (m_modelSegments.lineColor()));
78
79 setPen (QPen (QBrush (color),
80 m_modelSegments.lineWidth()));
81
82 } else {
83
84 setPen (QPen (Qt::transparent));
85
86 }
87}
88
90{
91 LOG4CPP_INFO_S ((*mainCat)) << "SegmentLine::updateModelSegment";
92
93 m_modelSegments = modelSegments;
94}
Model for DlgSettingsSegments and CmdSettingsSegments.
ColorPalette lineColor() const
Get method for line color.
double lineWidth() const
Get method for line width.
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
void forwardMousePress()
Forward mouse press event from a component SegmentLine that was just clicked on.
Definition Segment.cpp:301