Engauge Digitizer 2
Loading...
Searching...
No Matches
GuidelineAbstract.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2019 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 "EngaugeAssert.h"
9#include "EnumsToQt.h"
10#include "GraphicsItemType.h"
11#include "GuidelineAbstract.h"
12#include "GuidelineAbstract.h"
13#include "Guidelines.h"
15#include "Logger.h"
16#include <QGraphicsLineItem>
17#include <QGraphicsScene>
18#include <QGraphicsSceneMouseEvent>
19#include <QLineF>
20#include <qmath.h>
21#include <QMouseEvent>
22#include <QPen>
23#include <QTextStream>
24#include <QWidget>
25#include "Transformation.h"
26#include "ZValues.h"
27
29 m_scene (scene),
30 m_context (nullptr),
31 m_guidelineVisible (nullptr)
32{
33}
34
36{
37 delete m_context;
38}
39
41{
42 LOG4CPP_INFO_S ((*mainCat)) << "GuidelineAbstract::bindGuidelineVisibleToInvisible";
43
44 m_guidelineVisible = guidelineVisible;
45
46 connect (this, SIGNAL (signalHandleMoved (QPointF)),
47 guidelineVisible, SLOT (slotHandleMoved (QPointF)));
48}
49
51{
52 return m_context;
53}
54
56{
57 return m_context;
58}
59
61{
62 m_context->handleActiveChange (active);
63}
64
66 bool locked)
67{
68 m_context->handleGuidelineMode (visible,
69 locked);
70}
71
73{
74 m_context->handleHoverEnterEvent ();
75}
76
78{
79 m_context->handleHoverLeaveEvent ();
80}
81
82void GuidelineAbstract::handleMouseMoveEvent (const QPointF &posScene)
83{
84 LOG4CPP_INFO_S ((*mainCat)) << "GuidelineAbstract::handleMouseMoveEvent ("
85 << posScene.x() << ", " << posScene.y() << ")";
86
87 // Skip if there is no bound visible Guideline
88 if (m_guidelineVisible != nullptr) {
89
90 emit signalHandleMoved (posScene);
91 }
92}
93
94void GuidelineAbstract::handleMousePressEvent(const QPointF &posScene)
95{
96 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineAbstract::handleMousePressEvent";
97
98 m_context->handleMousePress(posScene);
99}
100
101void GuidelineAbstract::handleMouseReleaseEvent (const QPointF &posScene)
102{
103 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineAbstract::handleMouseReleaseEvent";
104
105 m_context->handleMouseRelease (posScene);
106}
107
109 GuidelineState guidelineStateForReplacement)
110{
111 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineAbstract::sacrificeHandleAndVisibleGuidelines"
112 << " keeping identifier=" << identifier().toLatin1().data()
113 << " in " << stateName ().toLatin1().data();
114
115 if (m_guidelineVisible != nullptr) {
116
117 // If scene position is off-screen then user is removing the visible Guideline
118 bool offscreen = !m_scene.sceneRect().contains (posScene);
119
120 // Remove transient Guideline, which was never registered with Guidelines
121 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineAbstract::sacrificeHandleAndVisibleGuidelines identifierDeleting="
122 << m_guidelineVisible->identifier().toLatin1().data();
123 disconnect (this, SIGNAL (signalHandleMoved (QPointF)),
124 m_guidelineVisible, SLOT (slotHandleMoved (QPointF)));
125 m_guidelineVisible->removeFromScene (&m_scene);
126 delete m_guidelineVisible;
127 m_guidelineVisible = nullptr;
128
129 // Update Guideline value from cursor position
130 double value = context()->convertScreenPointToGraphCoordinate (posScene);
131
133 value,
134 offscreen,
135 guidelineStateForReplacement);
136 }
137}
138
139QGraphicsScene &GuidelineAbstract::scene ()
140{
141 return m_scene;
142}
143
145{
146 return m_context->posCursorGraph ();
147}
148
153
155{
156 // Update geometry
157 updateGeometry (posScreen);
158}
159
161{
162 // This is used by Guidelines::stateDump and GuidelineStateContext::stateDump
163 QString out;
164 QTextStream str (&out);
165
166 str << " " << m_context->stateName ();
167 str << " (";
168 str << (getGraphicsItemSelected() ? "selected" : "unselected") << " ";
169 str << (getGraphicsItemAcceptHover() ? "hoverable" : "unhoverable") << " ";
170 str << ((graphicsItemFlags () & QGraphicsItem::ItemIsFocusable ) != 0 ? "focusable" : "unfocusable") << " ";
171 str << ((graphicsItemFlags () & QGraphicsItem::ItemIsMovable ) != 0 ? "movable" : "unmovable") << " ";
172 str << ((graphicsItemFlags () & QGraphicsItem::ItemIsSelectable) != 0 ? "selectable" : "unselectable") << " ";
173 str << ")";
174
175 return out;
176}
177
179{
180 return m_context->stateName ();
181}
182
184{
185 m_context->updateWithLatestTransformation ();
186}
GuidelineState
Set of possible Guideline states. See class Guideline for more information.
log4cpp::Category * mainCat
Definition Logger.cpp:14
void sacrificeHandleAndVisibleGuidelines(const QPointF &posScene, GuidelineState guidelineStateForReplacement)
Replace visible and handle Guidelines after click and drag.
virtual QString identifier() const =0
Unique identifier from QGraphicsItem.
QGraphicsScene & scene()
GraphicsScene that owns this class.
void handleMousePressEvent(const QPointF &posScene)
Forward press event to state machine.
void setContext(GuidelineStateContext *context)
Create state machine after virtual methods of child classes have been defined.
QPointF posCursorGraph() const
Get position in graph coordinates.
virtual void updateGeometry(double valueGraph)=0
Update the geometry so it passes through the specified coordinate value in graph coordinates.
void handleMouseMoveEvent(const QPointF &posScene)
Forward movements to visible Guideline.
void updateWithLatestTransformation()
Update given Transformation in GuidelineStateContext. This is called after a command has been execute...
void bindGuidelineVisibleToInvisible(GuidelineAbstract *guidelineVisible)
Bind a newly-created visible Guideline to this Guideline, and make this one invisible.
virtual bool getGraphicsItemAcceptHover() const =0
Return true if accepting hover events.
void handleGuidelineMode(bool visible, bool locked)
User toggled Guideline visibility and/or locked mode.
void slotHandleMoved(QPointF posScreen)
Slot for signal from cloned deployed Guideline from handle Guideline.
void signalHandleMoved(QPointF)
Signal for cloned deployed Guideline from handle Guideline.
void handleMouseReleaseEvent(const QPointF &posScene)
Cleanup after being dragged.
void handleActiveChange(bool active)
DigitizeState change so active status may (or may not) be toggled.
virtual QGraphicsItem::GraphicsItemFlags graphicsItemFlags() const =0
Wraps QGraphicsItem::flags.
QString stateDump() const
Dump of state as a string for debugging only. Context like the QGraphicsItem flags is included.
GuidelineStateContext * context()
State machine context owned by this class.
void handleHoverEnterEvent()
Highlight this Guideline upon hover enter.
virtual bool getGraphicsItemSelected() const =0
Wrapper for QGraphicsItem::isSelected.
void handleHoverLeaveEvent()
Unset highlighting triggered by hover enter.
GuidelineAbstract(QGraphicsScene &scene)
Single constructor.
void signalGuidelineDragged(QString, double, bool, GuidelineState)
Signal indicating end of Guideline drag.
QString stateName() const
Current state name for debugging and unit test only.
Context class for state machine that belongs to the Guideline class.
void handleActiveChange(bool active)
DigitizeState change so active status may (or may not) be toggled.
double convertScreenPointToGraphCoordinate(const QPointF &posScreen) const
Convert screen point pair into single graph coordinate.
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18
#define LOG4CPP_DEBUG_S(logger)
Definition convenience.h:20