Engauge Digitizer 2
Loading...
Searching...
No Matches
GuidelineEllipse Class Reference

Ellipse version of GuidelineAbstract. More...

#include <GuidelineEllipse.h>

Inheritance diagram for GuidelineEllipse:
Inheritance graph
Collaboration diagram for GuidelineEllipse:
Collaboration graph

Public Member Functions

 GuidelineEllipse (QGraphicsScene &scene, Guidelines &guidelines, GuidelineState guidelineStateInitial, const QString &identifier)
 Single constructor.
 ~GuidelineEllipse ()
virtual bool collidesWithPath (const QPainterPath &path, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
 Override normal QGraphicsEllipseItem collision detection that covers ellipse boundary and entire interior region, to exclude the interior region.
virtual bool getGraphicsItemSelected () const
 Wrapper for QGraphicsItem::isSelected.
virtual bool getGraphicsItemAcceptHover () const
 Return true if accepting hover events.
virtual QGraphicsItem::GraphicsItemFlags graphicsItemFlags () const
 Wraps QGraphicsItem::flags.
virtual void hoverEnterEvent (QGraphicsSceneHoverEvent *event)
 Highlight this Guideline upon hover enter.
virtual void hoverLeaveEvent (QGraphicsSceneHoverEvent *event)
 Unset highlighting triggered by hover enter.
virtual QString identifier () const
 Unique identifier from QGraphicsItem.
virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *event)
 Forward movements to visible Guideline.
virtual void mousePressEvent (QGraphicsSceneMouseEvent *event)
 Forward press event to state machine.
virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event)
 Cleanup after being dragged.
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 removeFromScene (QGraphicsScene *scene)
 Make graphics item remove itself from the scene.
virtual void setGraphicsItemAcceptHoverEvents (bool accept)
 Wrapper for QGraphicsItem::setAcceptHoverEvents.
virtual void setGraphicsItemFlags (QGraphicsItem::GraphicsItemFlags flags)
 Wrapper for QGraphicsItem::setFlags.
virtual void setGraphicsItemLine (const QLineF &line)
 Wrapper for QGraphicsLineItem::setLine.
virtual void setGraphicsItemPen (const QColor &color, double lineWidth)
 Wrapper for QGraphicsItem::setPen.
virtual void setGraphicsItemVisible (bool visible)
 Wrapper for QGraphicsItem::setVisible.
virtual void setGraphicsItemZValue (double z)
 Wrapper for QGraphicsItem::setZValue.
virtual void updateColor ()
 Force a color update.
virtual void updateGeometry (double valueGraph)
 Update the geometry so it passes through the specified coordinate value in graph coordinates.
virtual void updateGeometry (const QPointF &posScreen)
 Update the geometry so it passes through the specified point in screen coordinates.
Public Member Functions inherited from GuidelineAbstract
 GuidelineAbstract (QGraphicsScene &scene)
 Single constructor.
 ~GuidelineAbstract ()
void bindGuidelineVisibleToInvisible (GuidelineAbstract *guidelineVisible)
 Bind a newly-created visible Guideline to this Guideline, and make this one invisible.
void handleActiveChange (bool active)
 DigitizeState change so active status may (or may not) be toggled.
void handleGuidelineMode (bool visible, bool locked)
 User toggled Guideline visibility and/or locked mode.
void handleHoverEnterEvent ()
 Highlight this Guideline upon hover enter.
void handleHoverLeaveEvent ()
 Unset highlighting triggered by hover enter.
void handleMouseMoveEvent (const QPointF &posScene)
 Forward movements to visible Guideline.
void handleMousePressEvent (const QPointF &posScene)
 Forward press event to state machine.
void handleMouseReleaseEvent (const QPointF &posScene)
 Cleanup after being dragged.
QPointF posCursorGraph () const
 Get position in graph coordinates.
void sacrificeHandleAndVisibleGuidelines (const QPointF &posScene, GuidelineState guidelineStateForReplacement)
 Replace visible and handle Guidelines after click and drag.
QGraphicsScene & scene ()
 GraphicsScene that owns this class.
QString stateDump () const
 Dump of state as a string for debugging only. Context like the QGraphicsItem flags is included.
QString stateName () const
 Current state name for debugging and unit test only.
void updateActive (bool active)
 Update active versus inactive state.
void updateWithLatestTransformation ()
 Update given Transformation in GuidelineStateContext. This is called after a command has been executed.

Additional Inherited Members

Public Slots inherited from GuidelineAbstract
void slotHandleMoved (QPointF posScreen)
 Slot for signal from cloned deployed Guideline from handle Guideline.
Signals inherited from GuidelineAbstract
void signalGuidelineDragged (QString, double, bool, GuidelineState)
 Signal indicating end of Guideline drag.
void signalHandleMoved (QPointF)
 Signal for cloned deployed Guideline from handle Guideline.
Protected Member Functions inherited from GuidelineAbstract
GuidelineStateContextcontext ()
 State machine context owned by this class.
const GuidelineStateContextcontext () const
 State machine context owned by this class as a const.
void setContext (GuidelineStateContext *context)
 Create state machine after virtual methods of child classes have been defined.

Detailed Description

Ellipse version of GuidelineAbstract.

Definition at line 21 of file GuidelineEllipse.h.

Constructor & Destructor Documentation

◆ GuidelineEllipse()

GuidelineEllipse::GuidelineEllipse ( QGraphicsScene & scene,
Guidelines & guidelines,
GuidelineState guidelineStateInitial,
const QString & identifier )

Single constructor.

Definition at line 26 of file GuidelineEllipse.cpp.

29 :
31{
32 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineEllipse::GuidelineEllipse identifier=" << identifier.toLatin1().data();
33
34 // Create context after all virtual methods have been created. The transition
35 // into the initial state will position the line if it was created by a button press
36 setContext (new GuidelineStateContext (*this,
37 guidelines,
38 guidelineStateInitial));
39
41 setData (DATA_KEY_IDENTIFIER, QVariant (identifier));
42
43 scene.addItem (this);
44}
@ DATA_KEY_GRAPHICS_ITEM_TYPE
Definition DataKey.h:15
@ DATA_KEY_IDENTIFIER
Definition DataKey.h:14
@ GRAPHICS_ITEM_TYPE_GUIDELINE
log4cpp::Category * mainCat
Definition Logger.cpp:14
QGraphicsScene & scene()
GraphicsScene that owns this class.
void setContext(GuidelineStateContext *context)
Create state machine after virtual methods of child classes have been defined.
GuidelineAbstract(QGraphicsScene &scene)
Single constructor.
virtual QString identifier() const
Unique identifier from QGraphicsItem.
#define LOG4CPP_DEBUG_S(logger)
Definition convenience.h:20

◆ ~GuidelineEllipse()

GuidelineEllipse::~GuidelineEllipse ( )

Definition at line 46 of file GuidelineEllipse.cpp.

47{
48}

Member Function Documentation

◆ collidesWithPath()

bool GuidelineEllipse::collidesWithPath ( const QPainterPath & path,
Qt::ItemSelectionMode mode = Qt::IntersectsItemShape ) const
virtual

Override normal QGraphicsEllipseItem collision detection that covers ellipse boundary and entire interior region, to exclude the interior region.

Definition at line 50 of file GuidelineEllipse.cpp.

52{
53 const double RATIO = 1000.0; // Ratio of many pixels to few pixels, for preventing divide by zero
54 bool collides = false;
55
56 if (QGraphicsEllipseItem::collidesWithPath (path,
57 mode)) {
58
59 // Slow test to not count interior region
60
61 GuidelineFormat guidelineFormat (context ()->color ());
62
63 // Bounding box of ellipse
64 double a = rect().width() / 2.0;
65 double b = rect().height() / 2.0;
66
67 // Loop through points in path polygon
68 QPolygonF poly = path.toFillPolygon();
69 QPolygonF::const_iterator itr;
70 for (itr = poly.begin(); (itr != poly.end()) && !collides; itr++) {
71
72 // This point is for the ellipse that has already been rotated to be aligned with axes
73 const QPointF &pointAligned = *itr;
74
75 // Project point onto ellipse. The projection is assumed to be the closest ellipse portion to that point.
76 // Starting with (x/a)^2+(y/b)^2=1 with x=r cos(Theta) and y=r sin(Theta), we can solve to get r^2 (cT^2/a^2 + sT2/b^2) = 1
77 double xGot = pointAligned.x();
78 double yGot = pointAligned.y();
79 double rGot = qSqrt (xGot * xGot + yGot * yGot);
80 if (rGot * RATIO > qAbs (xGot) || rGot * RATIO > qAbs (yGot)) {
81
82 // Check for divide by zero passed so keep going
83 double cTheta = xGot / rGot;
84 double sTheta = yGot / rGot;
85 double rProjected = qSqrt (1.0 / (cTheta * cTheta / a / a + sTheta * sTheta / b / b));
86 double xProjected = rProjected * cTheta;
87 double yProjected = rProjected * sTheta;
88
89 // Distance to projection
90 double distance = qSqrt ((xProjected - xGot) * (xProjected - xGot) +
91 (yProjected - yGot) * (yProjected - yGot));
92
93 if (distance < guidelineFormat.lineWidthHover()) {
94
95 // This will make the loop exit immediately for speed
96 collides = true;
97 }
98 }
99 }
100 }
101
102 return collides;
103}
GuidelineStateContext * context()
State machine context owned by this class.

◆ getGraphicsItemAcceptHover()

bool GuidelineEllipse::getGraphicsItemAcceptHover ( ) const
virtual

Return true if accepting hover events.

Implements GuidelineAbstract.

Definition at line 105 of file GuidelineEllipse.cpp.

106{
107 return acceptHoverEvents();
108}

◆ getGraphicsItemSelected()

bool GuidelineEllipse::getGraphicsItemSelected ( ) const
virtual

Wrapper for QGraphicsItem::isSelected.

Implements GuidelineAbstract.

Definition at line 110 of file GuidelineEllipse.cpp.

111{
112 return QGraphicsEllipseItem::isSelected ();
113}

◆ graphicsItemFlags()

QGraphicsItem::GraphicsItemFlags GuidelineEllipse::graphicsItemFlags ( ) const
virtual

Wraps QGraphicsItem::flags.

Implements GuidelineAbstract.

Definition at line 115 of file GuidelineEllipse.cpp.

116{
117 return QGraphicsEllipseItem::flags ();
118}

◆ hoverEnterEvent()

void GuidelineEllipse::hoverEnterEvent ( QGraphicsSceneHoverEvent * event)
virtual

Highlight this Guideline upon hover enter.

Definition at line 120 of file GuidelineEllipse.cpp.

121{
123
124 QGraphicsEllipseItem::hoverEnterEvent (event);
125}
void handleHoverEnterEvent()
Highlight this Guideline upon hover enter.

◆ hoverLeaveEvent()

void GuidelineEllipse::hoverLeaveEvent ( QGraphicsSceneHoverEvent * event)
virtual

Unset highlighting triggered by hover enter.

Definition at line 127 of file GuidelineEllipse.cpp.

128{
130
131 QGraphicsEllipseItem::hoverLeaveEvent (event);
132}
void handleHoverLeaveEvent()
Unset highlighting triggered by hover enter.

◆ identifier()

QString GuidelineEllipse::identifier ( ) const
virtual

Unique identifier from QGraphicsItem.

Implements GuidelineAbstract.

Definition at line 134 of file GuidelineEllipse.cpp.

135{
136 return data (DATA_KEY_IDENTIFIER).toString ();
137}

◆ mouseMoveEvent()

void GuidelineEllipse::mouseMoveEvent ( QGraphicsSceneMouseEvent * event)
virtual

Forward movements to visible Guideline.

Definition at line 139 of file GuidelineEllipse.cpp.

140{
141 handleMouseMoveEvent (event->scenePos ());
142
143 QGraphicsEllipseItem::mouseMoveEvent (event);
144}
void handleMouseMoveEvent(const QPointF &posScene)
Forward movements to visible Guideline.

◆ mousePressEvent()

void GuidelineEllipse::mousePressEvent ( QGraphicsSceneMouseEvent * event)
virtual

Forward press event to state machine.

Definition at line 146 of file GuidelineEllipse.cpp.

147{
148 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineEllipse::mousePressEvent";
149
150 QGraphicsEllipseItem::mousePressEvent (event);
151
152 handleMousePressEvent (event->scenePos ());
153
154 context()->handleMousePress(event->scenePos());
155}
void handleMousePressEvent(const QPointF &posScene)
Forward press event to state machine.
void handleMousePress(const QPointF &posScene)
At the start of dragging, convert the original Guideline into an invisible handle and visible slaved ...

◆ mouseReleaseEvent()

void GuidelineEllipse::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event)
virtual

Cleanup after being dragged.

Definition at line 157 of file GuidelineEllipse.cpp.

158{
159 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineEllipse::mouseReleaseEvent";
160
161 handleMouseReleaseEvent (event->scenePos());
162
163 QGraphicsEllipseItem::mouseReleaseEvent (event);
164}
void handleMouseReleaseEvent(const QPointF &posScene)
Cleanup after being dragged.

◆ paint()

void GuidelineEllipse::paint ( QPainter * painter,
const QStyleOptionGraphicsItem * option,
QWidget * widget = Q_NULLPTR )
virtual

Override painting so this disappears when selected. Selected Guidelines are never visible.

Definition at line 166 of file GuidelineEllipse.cpp.

169{
170 if (context()->doPaint ()) {
171
172 QGraphicsEllipseItem::paint (painter,
173 option,
174 widget);
175 }
176}

◆ removeFromScene()

void GuidelineEllipse::removeFromScene ( QGraphicsScene * scene)
virtual

Make graphics item remove itself from the scene.

Implements GuidelineAbstract.

Definition at line 178 of file GuidelineEllipse.cpp.

179{
180 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineLine::removeFromScene identifier="
181 << identifier().toLatin1().data();
182
183 scene->removeItem (this);
184}

◆ setGraphicsItemAcceptHoverEvents()

void GuidelineEllipse::setGraphicsItemAcceptHoverEvents ( bool accept)
virtual

Wrapper for QGraphicsItem::setAcceptHoverEvents.

Implements GuidelineAbstract.

Definition at line 186 of file GuidelineEllipse.cpp.

187{
188 QGraphicsEllipseItem::setAcceptHoverEvents (accept);
189}

◆ setGraphicsItemFlags()

void GuidelineEllipse::setGraphicsItemFlags ( QGraphicsItem::GraphicsItemFlags flags)
virtual

Wrapper for QGraphicsItem::setFlags.

Implements GuidelineAbstract.

Definition at line 191 of file GuidelineEllipse.cpp.

192{
193 QGraphicsEllipseItem::setFlags (flags);
194}

◆ setGraphicsItemLine()

void GuidelineEllipse::setGraphicsItemLine ( const QLineF & line)
virtual

Wrapper for QGraphicsLineItem::setLine.

Implements GuidelineAbstract.

Definition at line 196 of file GuidelineEllipse.cpp.

197{
198 // Noop
199}

◆ setGraphicsItemPen()

void GuidelineEllipse::setGraphicsItemPen ( const QColor & color,
double lineWidth )
virtual

Wrapper for QGraphicsItem::setPen.

Implements GuidelineAbstract.

Definition at line 201 of file GuidelineEllipse.cpp.

203{
204 QBrush brush (color);
205
206 setPen (QPen (brush,
207 lineWidth));
208}

◆ setGraphicsItemVisible()

void GuidelineEllipse::setGraphicsItemVisible ( bool visible)
virtual

Wrapper for QGraphicsItem::setVisible.

Implements GuidelineAbstract.

Definition at line 210 of file GuidelineEllipse.cpp.

211{
212 QGraphicsEllipseItem::setVisible (visible);
213}

◆ setGraphicsItemZValue()

void GuidelineEllipse::setGraphicsItemZValue ( double z)
virtual

Wrapper for QGraphicsItem::setZValue.

Implements GuidelineAbstract.

Definition at line 215 of file GuidelineEllipse.cpp.

216{
217 QGraphicsEllipseItem::setZValue (z);
218}

◆ updateColor()

void GuidelineEllipse::updateColor ( )
virtual

Force a color update.

Implements GuidelineAbstract.

Definition at line 220 of file GuidelineEllipse.cpp.

221{
222 // Apply color to brush and pen defined in setGraphicsItemPen.
223
224 QPen p = QGraphicsEllipseItem::pen();
225 QBrush br = p.brush();
226 double alphaF = br.color().alphaF();
227 double lineWidth = p.width ();
228
229 QColor color = ColorPaletteToQColor (context()->color());
230 color.setAlphaF (alphaF);
231
232 setGraphicsItemPen (color,
233 lineWidth);
234}
QColor ColorPaletteToQColor(ColorPalette color)
Definition EnumsToQt.cpp:16
virtual void setGraphicsItemPen(const QColor &color, double lineWidth)
Wrapper for QGraphicsItem::setPen.

◆ updateGeometry() [1/2]

void GuidelineEllipse::updateGeometry ( const QPointF & posScreen)
virtual

Update the geometry so it passes through the specified point in screen coordinates.

Implements GuidelineAbstract.

Definition at line 243 of file GuidelineEllipse.cpp.

244{
245 LOG4CPP_INFO_S ((*mainCat)) << "GuidelineEllipse::updateGeometry scale=" << scale()
246 << " rotation(deg)=" << rotation();
247
248 EllipseParameters ellipseParameters = context()->pointToEllipse (posScreen);
249
250 QPointF posCenter = ellipseParameters.posCenter();
251
252 double a = ellipseParameters.a();
253 double b = ellipseParameters.b();
254
255 setRect (QRectF (- QPointF (a, b),
256 + QPointF (a, b)));
257
258 // Rotate. Originally the rectangle was centered at posCenter, the rotation center
259 // was set using setTransformOriginPoint to posCenter, but the resulting shape was not right
260 setRotation (qRadiansToDegrees (ellipseParameters.angleRadians()));
261 setPos (posCenter);
262
263 // Save the graph value for later
264 QPointF posGraph;
266 posGraph);
267 context()->setPosCursorGraph (posGraph);
268}
double angleRadians() const
Get method for angle in radians.
double b() const
Get method for b.
QPointF posCenter() const
Get method for center.
double a() const
Get method for a.
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...
EllipseParameters pointToEllipse(const QPointF &posScreen) const
Return ellipse representing constant range, that passes through the specified point.
void transformScreenToRawGraph(const QPointF &coordScreen, QPointF &coordGraph) const
Transform from cartesian pixel screen coordinates to cartesian/polar graph coordinates.
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18

◆ updateGeometry() [2/2]

void GuidelineEllipse::updateGeometry ( double valueGraph)
virtual

Update the geometry so it passes through the specified coordinate value in graph coordinates.

Implements GuidelineAbstract.

Definition at line 236 of file GuidelineEllipse.cpp.

237{
238 // Convert single graph coordinate, which is range, into screen point pair,
239 // then update with the screen point
240 updateGeometry (context ()->convertGraphCoordinateToScreenPoint (valueGraph));
241}
virtual void updateGeometry(double valueGraph)
Update the geometry so it passes through the specified coordinate value in graph coordinates.

The documentation for this class was generated from the following files: