19#include <QGraphicsEllipseItem>
20#include <QGraphicsScene>
21#include <QGraphicsSceneMouseEvent>
35 m_mainWindow (mainWindow)
44 guidelineStateInitial));
57 Qt::ItemSelectionMode mode)
const
59 const double RATIO = 1000.0;
60 bool collides =
false;
62 if (QGraphicsEllipseItem::collidesWithPath (path,
68 double a = rect().width() / 2.0;
69 double b = rect().height() / 2.0;
72 QPolygonF poly = path.toFillPolygon();
73 QPolygonF::const_iterator itr;
74 for (itr = poly.begin(); (itr != poly.end()) && !collides; itr++) {
77 const QPointF &pointAligned = *itr;
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)) {
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;
94 double distance = qSqrt ((xProjected - xGot) * (xProjected - xGot) +
95 (yProjected - yGot) * (yProjected - yGot));
97 int lineWidthHover = m_mainWindow.cmdMediator ()->document ().modelGuideline ().lineWidthActive ();
99 if (distance < lineWidthHover) {
113 return acceptHoverEvents();
118 return QGraphicsEllipseItem::isSelected ();
123 return QGraphicsEllipseItem::flags ();
130 QGraphicsEllipseItem::hoverEnterEvent (event);
137 QGraphicsEllipseItem::hoverLeaveEvent (event);
149 QGraphicsEllipseItem::mouseMoveEvent (event);
156 QGraphicsEllipseItem::mousePressEvent (event);
169 QGraphicsEllipseItem::mouseReleaseEvent (event);
173 const QStyleOptionGraphicsItem *option,
178 QGraphicsEllipseItem::paint (painter,
189 scene->removeItem (
this);
194 QGraphicsEllipseItem::setAcceptHoverEvents (accept);
199 QGraphicsEllipseItem::setFlags (flags);
210 QBrush brush (color);
218 QGraphicsEllipseItem::setVisible (visible);
223 QGraphicsEllipseItem::setZValue (z);
230 QPen p = QGraphicsEllipseItem::pen();
231 QBrush br = p.brush();
232 double alphaF = br.color().alphaF();
233 double lineWidth = p.width ();
236 color.setAlphaF (alphaF);
252 <<
" rotation(deg)=" << rotation();
256 QPointF posCenter = ellipseParameters.
posCenter();
258 double a = ellipseParameters.
a();
259 double b = ellipseParameters.
b();
261 setRect (QRectF (- QPointF (a, b),
266 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
Class for collecting and then displaying debug information computed during constant R ellipse calcula...
void dumpEllipseGraphicsItem(const QString &callerMethod, const QGraphicsEllipseItem *ellipse) const
Dump ellipse grahics item.
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.
GuidelineEllipse(QGraphicsScene &scene, MainWindow &mainWindow, Guidelines &guidelines, GuidelineState guidelineStateInitial, const QString &identifier)
Single constructor.
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.
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.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
#define LOG4CPP_INFO_S(logger)
#define LOG4CPP_DEBUG_S(logger)