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 "GuidelineFormat.h"
14#include "Guidelines.h"
16#include "Logger.h"
17#include <QGraphicsLineItem>
18#include <QGraphicsScene>
19#include <QGraphicsSceneMouseEvent>
20#include <QLineF>
21#include <qmath.h>
22#include <QMouseEvent>
23#include <QPen>
24#include <QTextStream>
25#include <QWidget>
26#include "Transformation.h"
27#include "ZValues.h"
28
30 m_scene (scene),
31 m_context (nullptr),
32 m_guidelineVisible (nullptr)
33{
34}
35
37{
38 delete m_context;
39}
40
42{
43 LOG4CPP_INFO_S ((*mainCat)) << "GuidelineAbstract::bindGuidelineVisibleToInvisible";
44
45 m_guidelineVisible = guidelineVisible;
46
47 connect (this, SIGNAL (signalHandleMoved (QPointF)),
48 guidelineVisible, SLOT (slotHandleMoved (QPointF)));
49}
50
52{
53 return m_context;
54}
55
57{
58 return m_context;
59}
60
62{
63 m_context->handleActiveChange (active);
64}
65
67 bool locked)
68{
69 m_context->handleGuidelineMode (visible,
70 locked);
71}
72
74{
75 m_context->handleHoverEnterEvent ();
76}
77
79{
80 m_context->handleHoverLeaveEvent ();
81}
82
83void GuidelineAbstract::handleMouseMoveEvent (const QPointF &posScene)
84{
85 LOG4CPP_INFO_S ((*mainCat)) << "GuidelineAbstract::handleMouseMoveEvent ("
86 << posScene.x() << ", " << posScene.y() << ")";
87
88 // Skip if there is no bound visible Guideline
89 if (m_guidelineVisible != nullptr) {
90
91 emit signalHandleMoved (posScene);
92 }
93}
94
95void GuidelineAbstract::handleMousePressEvent(const QPointF &posScene)
96{
97 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineAbstract::handleMousePressEvent";
98
99 m_context->handleMousePress(posScene);
100}
101
102void GuidelineAbstract::handleMouseReleaseEvent (const QPointF &posScene)
103{
104 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineAbstract::handleMouseReleaseEvent";
105
106 m_context->handleMouseRelease (posScene);
107}
108
110 GuidelineState guidelineStateForReplacement)
111{
112 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineAbstract::sacrificeHandleAndVisibleGuidelines"
113 << " keeping identifier=" << identifier().toLatin1().data()
114 << " in " << stateName ().toLatin1().data();
115
116 if (m_guidelineVisible != nullptr) {
117
118 // If scene position is off-screen then user is removing the visible Guideline
119 bool offscreen = !m_scene.sceneRect().contains (posScene);
120
121 // Remove transient Guideline, which was never registered with Guidelines
122 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineAbstract::sacrificeHandleAndVisibleGuidelines identifierDeleting="
123 << m_guidelineVisible->identifier().toLatin1().data();
124 disconnect (this, SIGNAL (signalHandleMoved (QPointF)),
125 m_guidelineVisible, SLOT (slotHandleMoved (QPointF)));
126 m_guidelineVisible->removeFromScene (&m_scene);
127 delete m_guidelineVisible;
128 m_guidelineVisible = nullptr;
129
130 // Update Guideline value from cursor position
131 double value = context()->convertScreenPointToGraphCoordinate (posScene);
132
134 value,
135 offscreen,
136 guidelineStateForReplacement);
137 }
138}
139
140QGraphicsScene &GuidelineAbstract::scene ()
141{
142 return m_scene;
143}
144
146{
147 return m_context->posCursorGraph ();
148}
149
154
156{
157 // Update geometry
158 updateGeometry (posScreen);
159}
160
162{
163 // This is used by Guidelines::stateDump and GuidelineStateContext::stateDump
164 QString out;
165 QTextStream str (&out);
166
167 str << " " << m_context->stateName ();
168 str << " (";
169 str << (getGraphicsItemSelected() ? "selected" : "unselected") << " ";
170 str << (getGraphicsItemAcceptHover() ? "hoverable" : "unhoverable") << " ";
171 str << ((graphicsItemFlags () & QGraphicsItem::ItemIsFocusable ) != 0 ? "focusable" : "unfocusable") << " ";
172 str << ((graphicsItemFlags () & QGraphicsItem::ItemIsMovable ) != 0 ? "movable" : "unmovable") << " ";
173 str << ((graphicsItemFlags () & QGraphicsItem::ItemIsSelectable) != 0 ? "selectable" : "unselectable") << " ";
174 str << ")";
175
176 return out;
177}
178
180{
181 return m_context->stateName ();
182}
183
185{
186 m_context->updateWithLatestTransformation ();
187}
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