16#include <QGraphicsEllipseItem>
17#include <QGraphicsScene>
18#include <QGraphicsSceneMouseEvent>
38 guidelineStateInitial));
51 Qt::ItemSelectionMode mode)
const
53 const double RATIO = 1000.0;
54 bool collides =
false;
56 if (QGraphicsEllipseItem::collidesWithPath (path,
64 double a = rect().width() / 2.0;
65 double b = rect().height() / 2.0;
68 QPolygonF poly = path.toFillPolygon();
69 QPolygonF::const_iterator itr;
70 for (itr = poly.begin(); (itr != poly.end()) && !collides; itr++) {
73 const QPointF &pointAligned = *itr;
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)) {
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;
90 double distance = qSqrt ((xProjected - xGot) * (xProjected - xGot) +
91 (yProjected - yGot) * (yProjected - yGot));
107 return acceptHoverEvents();
112 return QGraphicsEllipseItem::isSelected ();
117 return QGraphicsEllipseItem::flags ();
124 QGraphicsEllipseItem::hoverEnterEvent (event);
131 QGraphicsEllipseItem::hoverLeaveEvent (event);
143 QGraphicsEllipseItem::mouseMoveEvent (event);
150 QGraphicsEllipseItem::mousePressEvent (event);
163 QGraphicsEllipseItem::mouseReleaseEvent (event);
167 const QStyleOptionGraphicsItem *option,
172 QGraphicsEllipseItem::paint (painter,
183 scene->removeItem (
this);
188 QGraphicsEllipseItem::setAcceptHoverEvents (accept);
193 QGraphicsEllipseItem::setFlags (flags);
204 QBrush brush (color);
212 QGraphicsEllipseItem::setVisible (visible);
217 QGraphicsEllipseItem::setZValue (z);
224 QPen p = QGraphicsEllipseItem::pen();
225 QBrush br = p.brush();
226 double alphaF = br.color().alphaF();
227 double lineWidth = p.width ();
230 color.setAlphaF (alphaF);
246 <<
" rotation(deg)=" << rotation();
250 QPointF posCenter = ellipseParameters.
posCenter();
252 double a = ellipseParameters.
a();
253 double b = ellipseParameters.
b();
255 setRect (QRectF (- QPointF (a, b),
260 setRotation (qRadiansToDegrees (ellipseParameters.
angleRadians()));
@ DATA_KEY_GRAPHICS_ITEM_TYPE
QColor ColorPaletteToQColor(ColorPalette color)
@ GRAPHICS_ITEM_TYPE_GUIDELINE
GuidelineState
Set of possible Guideline states. See class Guideline for more information.
log4cpp::Category * mainCat
Parameters that define an ellipse about the specified center, at the specified angle from alignment w...
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.
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.
GuidelineAbstract(QGraphicsScene &scene)
Single constructor.
virtual void setGraphicsItemPen(const QColor &color, double lineWidth)
Wrapper for QGraphicsItem::setPen.
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
Forward movements to visible Guideline.
virtual QString identifier() const
Unique identifier from QGraphicsItem.
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Cleanup after being dragged.
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
Forward press event to state machine.
virtual void setGraphicsItemFlags(QGraphicsItem::GraphicsItemFlags flags)
Wrapper for QGraphicsItem::setFlags.
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Unset highlighting triggered by hover enter.
virtual void setGraphicsItemAcceptHoverEvents(bool accept)
Wrapper for QGraphicsItem::setAcceptHoverEvents.
virtual void removeFromScene(QGraphicsScene *scene)
Make graphics item remove itself from the scene.
virtual QGraphicsItem::GraphicsItemFlags graphicsItemFlags() const
Wraps QGraphicsItem::flags.
virtual void setGraphicsItemVisible(bool visible)
Wrapper for QGraphicsItem::setVisible.
virtual void updateGeometry(double valueGraph)
Update the geometry so it passes through the specified coordinate value in graph coordinates.
virtual void setGraphicsItemZValue(double z)
Wrapper for QGraphicsItem::setZValue.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=Q_NULLPTR)
Override painting so this disappears when selected. Selected Guidelines are never visible.
GuidelineEllipse(QGraphicsScene &scene, Guidelines &guidelines, GuidelineState guidelineStateInitial, const QString &identifier)
Single constructor.
virtual void updateColor()
Force a color update.
virtual void setGraphicsItemLine(const QLineF &line)
Wrapper for QGraphicsLineItem::setLine.
virtual bool getGraphicsItemSelected() const
Wrapper for QGraphicsItem::isSelected.
virtual bool collidesWithPath(const QPainterPath &path, Qt::ItemSelectionMode mode=Qt::IntersectsItemShape) const
Override normal QGraphicsEllipseItem collision detection that covers ellipse boundary and entire inte...
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
Highlight this Guideline upon hover enter.
virtual bool getGraphicsItemAcceptHover() const
Return true if accepting hover events.
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...
EllipseParameters pointToEllipse(const QPointF &posScreen) const
Return ellipse representing constant range, that passes through the specified point.
void handleMousePress(const QPointF &posScene)
At the start of dragging, convert the original Guideline into an invisible handle and visible slaved ...
This class contains all Guideline objects.
#define LOG4CPP_INFO_S(logger)
#define LOG4CPP_DEBUG_S(logger)