#include <QPainter>
#include <QGraphicsSceneMouseEvent>
#include <QCursor>
+#include <QGraphicsScene>
+#include <QGraphicsView>
BPointItem::BPointItem(BPoint point, QGraphicsItem* parent) :
m_point.p = mapFromScene(point.p);
m_point.h2 = mapFromScene(point.h2);
m_point.handlesLinked = false;
+
+ m_view = scene()->views()[0];
}
BPoint BPointItem::getPoint()
int BPointItem::getSelection(QPointF pos)
{
- QRectF mouseArea(pos.x() - 6, pos.y() - 6, 12, 12);
-
- if (mouseArea.contains(m_point.h1))
- return 0;
- else if (mouseArea.contains(m_point.p))
- return 1;
- else if (mouseArea.contains(m_point.h2))
- return 2;
+ QList <qreal> d;
+ d << QLineF(pos, m_point.h1).length() << QLineF(pos, m_point.p).length() << QLineF(pos, m_point.h2).length();
+ // index of point nearest to pos
+ int i = ( d[1] < d[0] && d[1] < d[2]) ? 1 : (d[0] < d[2] ? 0 : 2);
+
+ if (d[i] < 6 / m_view->matrix().m11())
+ return i;
return -1;
}
#include <QtCore>
#include <QAbstractGraphicsShapeItem>
+class QGraphicsView;
+
class BPointItem : public QAbstractGraphicsShapeItem
{
public:
private:
BPoint m_point;
int m_selection;
+ QGraphicsView *m_view;
/** @brief Gets The action mode for the area @param pos +- 4. */
int getSelection(QPointF pos);
#include <QGraphicsScene>
#include <QCursor>
#include <QGraphicsSceneMouseEvent>
+#include <QGraphicsView>
inline QPointF closestPointInRect(QPointF point, QRectF rect)
setBrush(Qt::NoBrush);
setAcceptHoverEvents(true);
+ m_view = scene->views()[0];
+
setPoints(points);
}
return;
if (m_closed) {
- QRectF r(event->scenePos() - QPointF(6, 6), QSizeF(12, 12));
+ qreal size = 12 / m_view->matrix().m11();
+ QRectF r(event->scenePos() - QPointF(size / 2, size / 2), QSizeF(size, size));
if (event->button() == Qt::LeftButton && path().intersects(r) && !path().contains(r)) {
double t = 0;
BPointItem *i1, *i2;
{
QGraphicsItem::hoverMoveEvent(event);
- QRectF r(event->scenePos() - QPointF(6, 6), QSizeF(12, 12));
+ qreal size = 12 / m_view->matrix().m11();
+ QRectF r(event->scenePos() - QPointF(size / 2, size / 2), QSizeF(size, size));
if (path().intersects(r) && !path().contains(r))
setCursor(QCursor(Qt::PointingHandCursor));
else
#include <QGraphicsPathItem>
class BPoint;
+class QGraphicsView;
class SplineItem : public QObject, public QGraphicsPathItem
{
bool m_closed;
bool m_editing;
+ QGraphicsView *m_view;
signals:
void changed(bool editing);