Engauge Digitizer 2
Loading...
Searching...
No Matches
GuidelineAbstract.h
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#ifndef GUIDELINE_ABSTRACT_H
8#define GUIDELINE_ABSTRACT_H
9
11#include <QColor>
12#include <QGraphicsItem>
13#include <QObject>
14
15class QGraphicsScene;
16class QMouseEvent;
17class QPainter;
18class QPointF;
19class QStyleOptionGraphicsItem;
20class QWidget;
21
68class GuidelineAbstract : public QObject
69{
70 Q_OBJECT;
71
72public:
74 GuidelineAbstract(QGraphicsScene &scene);
76
79
81 virtual bool getGraphicsItemAcceptHover () const = 0;
82
84 virtual bool getGraphicsItemSelected () const = 0;
85
87 virtual QGraphicsItem::GraphicsItemFlags graphicsItemFlags () const = 0;
88
90 void handleActiveChange (bool active);
91
93 void handleGuidelineMode (bool visible,
94 bool locked);
95
98
101
103 void handleMouseMoveEvent (const QPointF &posScene);
104
106 void handleMousePressEvent(const QPointF &posScene);
107
109 void handleMouseReleaseEvent (const QPointF &posScene);
110
112 virtual QString identifier () const = 0;
113
115 QPointF posCursorGraph () const;
116
118 virtual void removeFromScene (QGraphicsScene *scene) = 0;
119
121 void sacrificeHandleAndVisibleGuidelines (const QPointF &posScene,
122 GuidelineState guidelineStateForReplacement);
123
125 QGraphicsScene &scene ();
126
128 virtual void setGraphicsItemAcceptHoverEvents (bool accept) = 0;
129
131 virtual void setGraphicsItemFlags (QGraphicsItem::GraphicsItemFlags flags) = 0;
132
134 virtual void setGraphicsItemLine (const QLineF &line) = 0;
135
137 virtual void setGraphicsItemPen (const QColor &color,
138 double lineWidth) = 0;
139
141 virtual void setGraphicsItemVisible (bool visible) = 0;
142
144 virtual void setGraphicsItemZValue (double z) = 0;
145
147 QString stateDump () const;
148
150 QString stateName () const;
151
155 void updateActive (bool active);
156
158 virtual void updateColor () = 0;
159
161 virtual void updateGeometry (double valueGraph) = 0;
162
164 virtual void updateGeometry (const QPointF &posScreen) = 0;
165
168
169signals:
170
173 double,
174 bool,
176
178 void signalHandleMoved (QPointF);
179
180public slots:
181
183 void slotHandleMoved (QPointF posScreen);
184
185protected:
188
190 const GuidelineStateContext *context () const;
191
194
195private:
197
198 QGraphicsScene &m_scene;
199
200 // Context is allocated as a final step in the constructor, at which point
201 // this class has registered with the QGraphicsScene
202 GuidelineStateContext *m_context;
203
204 // After binding to visible Guideline
205 GuidelineAbstract *m_guidelineVisible;
206
207};
208
209#endif // GUIDELINE_ABSTRACT_H
GuidelineState
Set of possible Guideline states. See class Guideline for more information.
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.
virtual void updateGeometry(const QPointF &posScreen)=0
Update the geometry so it passes through the specified point in screen coordinates.
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 void setGraphicsItemVisible(bool visible)=0
Wrapper for QGraphicsItem::setVisible.
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.
virtual void setGraphicsItemLine(const QLineF &line)=0
Wrapper for QGraphicsLineItem::setLine.
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.
virtual void removeFromScene(QGraphicsScene *scene)=0
Make graphics item remove itself from the scene.
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.
virtual void setGraphicsItemAcceptHoverEvents(bool accept)=0
Wrapper for QGraphicsItem::setAcceptHoverEvents.
void updateActive(bool active)
Update active versus inactive state.
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.
virtual void setGraphicsItemZValue(double z)=0
Wrapper for QGraphicsItem::setZValue.
virtual void updateColor()=0
Force a color update.
virtual void setGraphicsItemPen(const QColor &color, double lineWidth)=0
Wrapper for QGraphicsItem::setPen.
virtual void setGraphicsItemFlags(QGraphicsItem::GraphicsItemFlags flags)=0
Wrapper for QGraphicsItem::setFlags.
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.