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, MainWindow &mainWindow, 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 22 of file GuidelineEllipse.h.

Constructor & Destructor Documentation

◆ GuidelineEllipse()

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

Single constructor.

Definition at line 29 of file GuidelineEllipse.cpp.

33 :
35 m_mainWindow (mainWindow)
36{
37 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineEllipse::GuidelineEllipse identifier=" << identifier.toLatin1().data();
38
39 // Create context after all virtual methods have been created. The transition
40 // into the initial state will position the line if it was created by a button press
41 setContext (new GuidelineStateContext (*this,
42 mainWindow,
43 guidelines,
44 guidelineStateInitial));
45
47 setData (DATA_KEY_IDENTIFIER, QVariant (identifier));
48
49 scene.addItem (this);
50}
@ 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 52 of file GuidelineEllipse.cpp.

53{
54}

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 56 of file GuidelineEllipse.cpp.

58{
59 const double RATIO = 1000.0; // Ratio of many pixels to few pixels, for preventing divide by zero
60 bool collides = false;
61
62 if (QGraphicsEllipseItem::collidesWithPath (path,
63 mode)) {
64
65 // Slow (but fast enough) test to count interior regions
66
67 // Bounding box of ellipse
68 double a = rect().width() / 2.0;
69 double b = rect().height() / 2.0;
70
71 // Loop through points in path polygon
72 QPolygonF poly = path.toFillPolygon();
73 QPolygonF::const_iterator itr;
74 for (itr = poly.begin(); (itr != poly.end()) && !collides; itr++) {
75
76 // This point is for the ellipse that has already been rotated to be aligned with axes
77 const QPointF &pointAligned = *itr;
78
79 // Project point onto ellipse. The projection is assumed to be the closest ellipse portion to that point.
80 // 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
81 double xGot = pointAligned.x();
82 double yGot = pointAligned.y();
83 double rGot = qSqrt (xGot * xGot + yGot * yGot);
84 if (rGot * RATIO > qAbs (xGot) || rGot * RATIO > qAbs (yGot)) {
85
86 // Check for divide by zero passed so keep going
87 double cTheta = xGot / rGot;
88 double sTheta = yGot / rGot;
89 double rProjected = qSqrt (1.0 / (cTheta * cTheta / a / a + sTheta * sTheta / b / b));
90 double xProjected = rProjected * cTheta;
91 double yProjected = rProjected * sTheta;
92
93 // Distance to projection
94 double distance = qSqrt ((xProjected - xGot) * (xProjected - xGot) +
95 (yProjected - yGot) * (yProjected - yGot));
96
97 int lineWidthHover = m_mainWindow.cmdMediator ()->document ().modelGuideline ().lineWidthActive ();
98
99 if (distance < lineWidthHover) {
100
101 // This will make the loop exit immediately for speed
102 collides = true;
103 }
104 }
105 }
106 }
107
108 return collides;
109}

◆ getGraphicsItemAcceptHover()

bool GuidelineEllipse::getGraphicsItemAcceptHover ( ) const
virtual

Return true if accepting hover events.

Implements GuidelineAbstract.

Definition at line 111 of file GuidelineEllipse.cpp.

112{
113 return acceptHoverEvents();
114}

◆ getGraphicsItemSelected()

bool GuidelineEllipse::getGraphicsItemSelected ( ) const
virtual

Wrapper for QGraphicsItem::isSelected.

Implements GuidelineAbstract.

Definition at line 116 of file GuidelineEllipse.cpp.

117{
118 return QGraphicsEllipseItem::isSelected ();
119}

◆ graphicsItemFlags()

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

Wraps QGraphicsItem::flags.

Implements GuidelineAbstract.

Definition at line 121 of file GuidelineEllipse.cpp.

122{
123 return QGraphicsEllipseItem::flags ();
124}

◆ hoverEnterEvent()

void GuidelineEllipse::hoverEnterEvent ( QGraphicsSceneHoverEvent * event)
virtual

Highlight this Guideline upon hover enter.

Definition at line 126 of file GuidelineEllipse.cpp.

127{
129
130 QGraphicsEllipseItem::hoverEnterEvent (event);
131}
void handleHoverEnterEvent()
Highlight this Guideline upon hover enter.

◆ hoverLeaveEvent()

void GuidelineEllipse::hoverLeaveEvent ( QGraphicsSceneHoverEvent * event)
virtual

Unset highlighting triggered by hover enter.

Definition at line 133 of file GuidelineEllipse.cpp.

134{
136
137 QGraphicsEllipseItem::hoverLeaveEvent (event);
138}
void handleHoverLeaveEvent()
Unset highlighting triggered by hover enter.

◆ identifier()

QString GuidelineEllipse::identifier ( ) const
virtual

Unique identifier from QGraphicsItem.

Implements GuidelineAbstract.

Definition at line 140 of file GuidelineEllipse.cpp.

141{
142 return data (DATA_KEY_IDENTIFIER).toString ();
143}

◆ mouseMoveEvent()

void GuidelineEllipse::mouseMoveEvent ( QGraphicsSceneMouseEvent * event)
virtual

Forward movements to visible Guideline.

Definition at line 145 of file GuidelineEllipse.cpp.

146{
147 handleMouseMoveEvent (event->scenePos ());
148
149 QGraphicsEllipseItem::mouseMoveEvent (event);
150}
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 152 of file GuidelineEllipse.cpp.

153{
154 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineEllipse::mousePressEvent";
155
156 QGraphicsEllipseItem::mousePressEvent (event);
157
158 handleMousePressEvent (event->scenePos ());
159
160 context()->handleMousePress(event->scenePos());
161}
void handleMousePressEvent(const QPointF &posScene)
Forward press event to state machine.
GuidelineStateContext * context()
State machine context owned by this class.
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 163 of file GuidelineEllipse.cpp.

164{
165 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineEllipse::mouseReleaseEvent";
166
167 handleMouseReleaseEvent (event->scenePos());
168
169 QGraphicsEllipseItem::mouseReleaseEvent (event);
170}
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 172 of file GuidelineEllipse.cpp.

175{
176 if (context()->doPaint ()) {
177
178 QGraphicsEllipseItem::paint (painter,
179 option,
180 widget);
181 }
182}

◆ removeFromScene()

void GuidelineEllipse::removeFromScene ( QGraphicsScene * scene)
virtual

Make graphics item remove itself from the scene.

Implements GuidelineAbstract.

Definition at line 184 of file GuidelineEllipse.cpp.

185{
186 LOG4CPP_DEBUG_S ((*mainCat)) << "GuidelineLine::removeFromScene identifier="
187 << identifier().toLatin1().data();
188
189 scene->removeItem (this);
190}

◆ setGraphicsItemAcceptHoverEvents()

void GuidelineEllipse::setGraphicsItemAcceptHoverEvents ( bool accept)
virtual

Wrapper for QGraphicsItem::setAcceptHoverEvents.

Implements GuidelineAbstract.

Definition at line 192 of file GuidelineEllipse.cpp.

193{
194 QGraphicsEllipseItem::setAcceptHoverEvents (accept);
195}

◆ setGraphicsItemFlags()

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

Wrapper for QGraphicsItem::setFlags.

Implements GuidelineAbstract.

Definition at line 197 of file GuidelineEllipse.cpp.

198{
199 QGraphicsEllipseItem::setFlags (flags);
200}

◆ setGraphicsItemLine()

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

Wrapper for QGraphicsLineItem::setLine.

Implements GuidelineAbstract.

Definition at line 202 of file GuidelineEllipse.cpp.

203{
204 // Noop
205}

◆ setGraphicsItemPen()

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

Wrapper for QGraphicsItem::setPen.

Implements GuidelineAbstract.

Definition at line 207 of file GuidelineEllipse.cpp.

209{
210 QBrush brush (color);
211
212 setPen (QPen (brush,
213 lineWidth));
214}

◆ setGraphicsItemVisible()

void GuidelineEllipse::setGraphicsItemVisible ( bool visible)
virtual

Wrapper for QGraphicsItem::setVisible.

Implements GuidelineAbstract.

Definition at line 216 of file GuidelineEllipse.cpp.

217{
218 QGraphicsEllipseItem::setVisible (visible);
219}

◆ setGraphicsItemZValue()

void GuidelineEllipse::setGraphicsItemZValue ( double z)
virtual

Wrapper for QGraphicsItem::setZValue.

Implements GuidelineAbstract.

Definition at line 221 of file GuidelineEllipse.cpp.

222{
223 QGraphicsEllipseItem::setZValue (z);
224}

◆ updateColor()

void GuidelineEllipse::updateColor ( )
virtual

Force a color update.

Implements GuidelineAbstract.

Definition at line 226 of file GuidelineEllipse.cpp.

227{
228 // Apply color to brush and pen defined in setGraphicsItemPen.
229
230 QPen p = QGraphicsEllipseItem::pen();
231 QBrush br = p.brush();
232 double alphaF = br.color().alphaF();
233 double lineWidth = p.width ();
234
235 QColor color = ColorPaletteToQColor (context()->color());
236 color.setAlphaF (alphaF);
237
238 setGraphicsItemPen (color,
239 lineWidth);
240}
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 249 of file GuidelineEllipse.cpp.

250{
251 LOG4CPP_INFO_S ((*mainCat)) << "GuidelineEllipse::updateGeometry scale=" << scale()
252 << " rotation(deg)=" << rotation();
253
254 EllipseParameters ellipseParameters = context()->pointToEllipse (posScreen);
255
256 QPointF posCenter = ellipseParameters.posCenter();
257
258 double a = ellipseParameters.a();
259 double b = ellipseParameters.b();
260
261 setRect (QRectF (- QPointF (a, b),
262 + QPointF (a, b)));
263
264 // Rotate. Originally the rectangle was centered at posCenter, the rotation center
265 // was set using setTransformOriginPoint to posCenter, but the resulting shape was not right
266 setRotation (qRadiansToDegrees (ellipseParameters.angleRadians()));
267 setPos (posCenter);
268
269 // Save the graph value for later
270 QPointF posGraph;
272 posGraph);
273 context()->setPosCursorGraph (posGraph);
274
275 CentipedeDebugPolar debugPolar;
276 debugPolar.dumpEllipseGraphicsItem ("GuidelineEllipse::updateGeometry",
277 this);
278}
void dumpEllipseGraphicsItem(const QString &callerMethod, const QGraphicsEllipseItem *ellipse) const
Dump ellipse grahics item.
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 242 of file GuidelineEllipse.cpp.

243{
244 // Convert single graph coordinate, which is range, into screen point pair,
245 // then update with the screen point
246 updateGeometry (context ()->convertGraphCoordinateToScreenPoint (valueGraph));
247}
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: