]> git.sesse.net Git - kdenlive/commitdiff
rotoscoping: make it easier to select points on the spline
authorTill Theato <root@ttill.de>
Sun, 20 Feb 2011 14:24:03 +0000 (14:24 +0000)
committerTill Theato <root@ttill.de>
Sun, 20 Feb 2011 14:24:03 +0000 (14:24 +0000)
svn path=/trunk/kdenlive/; revision=5438

src/onmonitoritems/rotoscoping/bpointitem.cpp
src/onmonitoritems/rotoscoping/bpointitem.h
src/onmonitoritems/rotoscoping/splineitem.cpp
src/onmonitoritems/rotoscoping/splineitem.h

index 292ccad9aad9463360578ef7160fbdf766c07254..1635e54627902a4f47108b47cf5192d7df0a5d72 100644 (file)
@@ -22,6 +22,8 @@
 #include <QPainter>
 #include <QGraphicsSceneMouseEvent>
 #include <QCursor>
+#include <QGraphicsScene>
+#include <QGraphicsView>
 
 
 BPointItem::BPointItem(BPoint point, QGraphicsItem* parent) :
@@ -37,6 +39,8 @@ 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()
@@ -105,14 +109,13 @@ void BPointItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option
 
 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;
 }
index 5dfddfadbcb8f036c4b4b1549da49175fcebfce0..794bc8b503b7927f6a5cc17b9735c60d647df979 100644 (file)
@@ -24,6 +24,8 @@
 #include <QtCore>
 #include <QAbstractGraphicsShapeItem>
 
+class QGraphicsView;
+
 class BPointItem : public QAbstractGraphicsShapeItem
 {
 public:
@@ -47,6 +49,7 @@ protected:
 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);
index f9a7d57963dc9f7645758e32f9d163852f3419ab..508f69dcb6557ee5b71f2f45fe45955a6af76daf 100644 (file)
@@ -24,6 +24,7 @@
 #include <QGraphicsScene>
 #include <QCursor>
 #include <QGraphicsSceneMouseEvent>
+#include <QGraphicsView>
 
 
 inline QPointF closestPointInRect(QPointF point, QRectF rect)
@@ -63,6 +64,8 @@ SplineItem::SplineItem(const QList< BPoint >& points, QGraphicsItem* parent, QGr
     setBrush(Qt::NoBrush);
     setAcceptHoverEvents(true);
 
+    m_view = scene->views()[0];
+
     setPoints(points);
 }
 
@@ -146,7 +149,8 @@ void SplineItem::mousePressEvent(QGraphicsSceneMouseEvent* event)
         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;
@@ -230,7 +234,8 @@ void SplineItem::hoverMoveEvent(QGraphicsSceneHoverEvent* event)
 {
     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
index 4b3599d4b4792ecf6688197461d498967e23d83a..fec4dfd1ee2f7d33c31342eb44550cd0de2b322e 100644 (file)
@@ -23,6 +23,7 @@
 #include <QGraphicsPathItem>
 
 class BPoint;
+class QGraphicsView;
 
 class SplineItem : public QObject, public QGraphicsPathItem
 {
@@ -54,6 +55,7 @@ private:
 
     bool m_closed;
     bool m_editing;
+    QGraphicsView *m_view;
 
 signals:
     void changed(bool editing);