Engauge Digitizer 2
Loading...
Searching...
No Matches
GuidelineLine.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 "GuidelineLine.h"
12#include "Guidelines.h"
14#include "Logger.h"
15#include <QGraphicsLineItem>
16#include <QGraphicsScene>
17#include <QGraphicsSceneMouseEvent>
18#include <QLineF>
19#include <qmath.h>
20#include <QMouseEvent>
21#include <QPen>
22#include <QWidget>
23#include "ZValues.h"
24
25GuidelineLine::GuidelineLine(QGraphicsScene &scene,
26 Guidelines &guidelines,
28 const QString &identifier) :
29 GuidelineAbstract (scene)
30{
31 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineLine::Guideline identifier=" << identifier.toLatin1().data();
32
33 // Create context after all virtual methods have been created
35 guidelines,
37
40
41 scene.addItem (this);
42}
43
47
52
54{
55 return QGraphicsLineItem::isSelected();
56}
57
58QGraphicsItem::GraphicsItemFlags GuidelineLine::graphicsItemFlags () const
59{
60 return QGraphicsLineItem::flags ();
61}
62
64{
66
67 QGraphicsLineItem::hoverEnterEvent (event);
68}
69
71{
73
74 QGraphicsLineItem::hoverLeaveEvent (event);
75}
76
78{
79 return data (DATA_KEY_IDENTIFIER).toString ();
80}
81
83{
84 handleMouseMoveEvent (event->scenePos ());
85
86 QGraphicsLineItem::mouseMoveEvent (event);
87}
88
90{
91 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineLine::mousePressEvent";
92
93 handleMousePressEvent (event->scenePos ());
94
95 QGraphicsLineItem::mousePressEvent (event);
96}
97
99{
100 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineLine::mouseReleaseEvent";
101
102 QGraphicsLineItem::mouseReleaseEvent (event);
103
104 handleMouseReleaseEvent (event->scenePos ());
105}
106
110{
111 if (context()->doPaint ()) {
112
113 QGraphicsLineItem::paint (painter,
114 option,
115 widget);
116 }
117}
118
119void GuidelineLine::removeFromScene (QGraphicsScene *scene)
120{
121 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineLine::removeFromScene identifier="
122 << identifier().toLatin1().data();
123
124 scene->removeItem (this);
125}
126
128{
129 QGraphicsLineItem::setAcceptHoverEvents (accept);
130}
131
132void GuidelineLine::setGraphicsItemFlags (QGraphicsItem::GraphicsItemFlags flags)
133{
134 QGraphicsLineItem::setFlags (flags);
135}
136
138{
139 QGraphicsLineItem::setLine (line);
140}
141
143 double lineWidth)
144{
145 QBrush brush (color);
146
147 setPen (QPen (brush,
148 lineWidth));
149}
150
152{
153 QGraphicsLineItem::setVisible (visible);
154}
155
157{
158 QGraphicsLineItem::setZValue (z);
159}
160
162{
163 // Apply color to brush and pen defined in setGraphicsItemPen.
164 // Alpha from alphaF() on QColor on QBrush is unused
165
166 QPen p = QGraphicsLineItem::pen();
167 QBrush br = p.brush();
168 double alphaF = br.color().alphaF();
169 double lineWidth = p.width ();
170
171 QColor color = ColorPaletteToQColor (context()->color());
172 color.setAlphaF (alphaF);
173
174 setGraphicsItemPen (color,
175 lineWidth);
176}
177
179{
180 // Convert single graph coordinate, which is range, into screen point pair,
181 // then update with the screen point
182 updateGeometry (context ()->convertGraphCoordinateToScreenPoint (valueGraph));
183}
184
186{
187 QLineF line = context()->pointToLine (posScreen);
188
189 setLine (line);
190
191 // Save the graph value for later
192 QPointF posGraph;
194 posGraph);
195 context()->setPosCursorGraph (posGraph);
196}
@ DATA_KEY_GRAPHICS_ITEM_TYPE
‍Unique identifier for QGraphicsItem object
Definition DataKey.h:15
@ DATA_KEY_IDENTIFIER
Definition DataKey.h:14
const int INNER_RADIUS_MIN
QColor ColorPaletteToQColor(ColorPalette color)
Definition EnumsToQt.cpp:16
@ GRAPHICS_ITEM_TYPE_GUIDELINE
GuidelineState
Set of possible Guideline states. See class Guideline for more information.
log4cpp::Category * mainCat
Definition Logger.cpp:14
This class is a special case of the standard QGraphicsLineItem for guidelines, and serves as the base...
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.
void handleMouseMoveEvent(const QPointF &posScene)
Forward movements to visible Guideline.
void handleMouseReleaseEvent(const QPointF &posScene)
Cleanup after being dragged.
GuidelineStateContext * context()
State machine context owned by this class.
void handleHoverEnterEvent()
Highlight this Guideline upon hover enter.
void handleHoverLeaveEvent()
Unset highlighting triggered by hover enter.
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Unset highlighting triggered by hover enter.
virtual QGraphicsItem::GraphicsItemFlags graphicsItemFlags() const
Wraps QGraphicsItem::flags.
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
Forward movements to visible Guideline.
virtual void setGraphicsItemZValue(double z)
Wrapper for QGraphicsItem::setZValue.
virtual void updateGeometry(double valueGraph)
Update the geometry so it passes through the specified coordinate value in graph coordinates.
virtual QString identifier() const
Unique identifier from QGraphicsItem.
GuidelineLine(QGraphicsScene &scene, Guidelines &guidelines, GuidelineState guidelineStateInitial, const QString &identifier)
Single constructor.
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
Highlight this Guideline upon hover enter.
virtual void setGraphicsItemFlags(QGraphicsItem::GraphicsItemFlags flags)
Wrapper for QGraphicsItem::setFlags.
virtual void removeFromScene(QGraphicsScene *scene)
Make graphics item remove itself from the scene.
virtual void updateColor()
Force a color update.
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Cleanup after being dragged.
virtual void setGraphicsItemVisible(bool visible)
Wrapper for QGraphicsItem::setVisible.
virtual void setGraphicsItemLine(const QLineF &line)
Wrapper for QGraphicsLineItem::setLine.
virtual bool getGraphicsItemAcceptHover() const
Return true if accepting hover events.
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
Forward press event to state machine.
virtual bool getGraphicsItemSelected() const
Wrapper for QGraphicsItem::isSelected.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=Q_NULLPTR)
Override painting so this disappears when selected. Selected Guidelines are never visible.
virtual void setGraphicsItemPen(const QColor &color, double lineWidth)
Wrapper for QGraphicsItem::setPen.
virtual void setGraphicsItemAcceptHoverEvents(bool accept)
Wrapper for QGraphicsItem::setAcceptHoverEvents.
Context class for state machine that belongs to the Guideline class.
Transformation transformation() const
Return copy of transformation owned by MainWindow.
void setPosCursorGraph(const QPointF &posGraph)
Pass the current cursor coordinate to the state so it can save the relevant coordinate for later adju...
QLineF pointToLine(const QPointF &posScreen) const
Return line parallel to an axis line, that passes through the specified point.
This class contains all Guideline objects.
Definition Guidelines.h:28
void transformScreenToRawGraph(const QPointF &coordScreen, QPointF &coordGraph) const
Transform from cartesian pixel screen coordinates to cartesian/polar graph coordinates.
#define LOG4CPP_DEBUG_S(logger)
Definition convenience.h:20