]> git.sesse.net Git - kdenlive/blobdiff - src/graphicsscenerectmove.cpp
set project to modified when moving clip in project tree
[kdenlive] / src / graphicsscenerectmove.cpp
index 5274a461f2ac2025a82181d3989795ae30ddab56..6df26d742c9800fd6d1271fea5fe1e07e0f3e9aa 100644 (file)
@@ -72,10 +72,9 @@ void GraphicsSceneRectMove::setTool(TITLETOOL tool)
     }
 }
 
-//virtual
 void GraphicsSceneRectMove::keyPressEvent(QKeyEvent * keyEvent)
 {
-    if (m_selectedItem == NULL) {
+    if (m_selectedItem == NULL || !(m_selectedItem->flags() & QGraphicsItem::ItemIsMovable)) {
         QGraphicsScene::keyPressEvent(keyEvent);
         return;
     }
@@ -117,14 +116,18 @@ void GraphicsSceneRectMove::keyPressEvent(QKeyEvent * keyEvent)
     emit actionFinished();
 }
 
-//virtual
 void GraphicsSceneRectMove::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* e)
 {
     QPointF p = e->scenePos();
     p += QPoint(-2, -2);
     m_resizeMode = NoResize;
     m_selectedItem = NULL;
-    QGraphicsItem* g = items(QRectF(p , QSizeF(4, 4)).toRect()).at(0);
+
+    // http://www.kdenlive.org/mantis/view.php?id=1035
+    QList<QGraphicsItem*> i = items(QRectF(p , QSizeF(4, 4)).toRect());
+    if (i.size() <= 0) return;
+
+    QGraphicsItem* g = i.at(0);
     if (g) {
         if (g->type() == 8) {
             QGraphicsTextItem *t = static_cast<QGraphicsTextItem *>(g);
@@ -162,7 +165,7 @@ void GraphicsSceneRectMove::mousePressEvent(QGraphicsSceneMouseEvent* e)
                 break;
             }
         }
-        if (item == NULL) {
+        if (item == NULL  || !(item->flags() & QGraphicsItem::ItemIsSelectable)) {
             if (m_selectedItem && m_selectedItem->type() == 8) {
                 // disable text editing
                 QGraphicsTextItem *t = static_cast<QGraphicsTextItem *>(m_selectedItem);
@@ -179,7 +182,7 @@ void GraphicsSceneRectMove::mousePressEvent(QGraphicsSceneMouseEvent* e)
                 }
             }
         }
-        if (item != NULL) {
+        if (item != NULL && item->flags() & QGraphicsItem::ItemIsMovable) {
             m_sceneClickPoint = e->scenePos();
             m_selectedItem = item;
             kDebug() << "/////////  ITEM TYPE: " << item->type();
@@ -267,7 +270,6 @@ void GraphicsSceneRectMove::clearTextSelection()
     clearSelection();
 }
 
-//virtual
 void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e)
 {
     if ((e->screenPos() - m_clickPoint).manhattanLength() < QApplication::startDragDistance()) {
@@ -404,6 +406,15 @@ void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e)
             }
             if (m_selectedItem->type() == 3 && m_resizeMode != NoResize) {
                 QGraphicsRectItem *gi = (QGraphicsRectItem*)m_selectedItem;
+                // Resize using aspect ratio
+                if (!m_selectedItem->data(0).isNull()) {
+                    // we want to keep aspect ratio
+                    double hRatio = (double) newrect.width() / m_selectedItem->data(0).toInt();
+                    double vRatio = (double) newrect.height() / m_selectedItem->data(1).toInt();
+                    if (hRatio < vRatio) newrect.setHeight(m_selectedItem->data(1).toInt() * hRatio);
+                    else newrect.setWidth(m_selectedItem->data(0).toInt() * vRatio);
+                }
+
                 gi->setRect(newrect);
             }
             /*else {
@@ -461,9 +472,9 @@ void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e)
                 QPainterPath mouseArea;
                 mouseArea.addRect(e->scenePos().toPoint().x() - 4 / m_zoom, e->scenePos().toPoint().y() - 4 / m_zoom, 8 / m_zoom, 8 / m_zoom);
                 // Check for collisions between the mouse and the borders
-                if (borderLeft.collidesWithPath(mouseArea) && borderTop.collidesWithPath(mouseArea) || borderRight.collidesWithPath(mouseArea) && borderBottom.collidesWithPath(mouseArea))
+                if ((borderLeft.collidesWithPath(mouseArea) && borderTop.collidesWithPath(mouseArea)) || (borderRight.collidesWithPath(mouseArea) && borderBottom.collidesWithPath(mouseArea)))
                     setResizeCursor(borderLeft.line().angle() - 45);
-                else if (borderLeft.collidesWithPath(mouseArea) && borderBottom.collidesWithPath(mouseArea) || borderRight.collidesWithPath(mouseArea) && borderTop.collidesWithPath(mouseArea))
+                else if ((borderLeft.collidesWithPath(mouseArea) && borderBottom.collidesWithPath(mouseArea)) || (borderRight.collidesWithPath(mouseArea) && borderTop.collidesWithPath(mouseArea)))
                     setResizeCursor(borderLeft.line().angle() + 45);
                 else if (borderLeft.collidesWithPath(mouseArea) || borderRight.collidesWithPath(mouseArea))
                     setResizeCursor(borderLeft.line().angle());
@@ -477,9 +488,11 @@ void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e)
         }
         QGraphicsScene::mouseMoveEvent(e);
     } else if (m_tool == TITLE_RECTANGLE && e->buttons() & Qt::LeftButton) {
-        if (m_selectedItem == NULL && (m_clickPoint - e->screenPos()).manhattanLength() >= QApplication::startDragDistance()) {
+        if (m_selectedItem == NULL) {
             // create new rect item
-            m_selectedItem = addRect(0, 0, e->scenePos().x() - m_sceneClickPoint.x(), e->scenePos().y() - m_sceneClickPoint.y());
+            QRectF r(0, 0, e->scenePos().x() - m_sceneClickPoint.x(), e->scenePos().y() - m_sceneClickPoint.y());
+            r = r.normalized();
+            m_selectedItem = addRect(QRectF(0, 0, r.width(), r.height()));
             emit newRect((QGraphicsRectItem *) m_selectedItem);
             m_selectedItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
             m_selectedItem->setPos(m_sceneClickPoint);
@@ -491,12 +504,14 @@ void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e)
 
 void GraphicsSceneRectMove::wheelEvent(QGraphicsSceneWheelEvent * wheelEvent)
 {
-    QList<QGraphicsView*> viewlist = views();
-    //kDebug() << wheelEvent->delta() << " " << zoom;
-    if (viewlist.size() > 0) {
-        if (wheelEvent->delta() < 0) emit sceneZoom(true);
-        else emit sceneZoom(false);
-    }
+    if (wheelEvent->modifiers() == Qt::ControlModifier) {
+        QList<QGraphicsView*> viewlist = views();
+        //kDebug() << wheelEvent->delta() << " " << zoom;
+        if (viewlist.size() > 0) {
+            if (wheelEvent->delta() > 0) emit sceneZoom(true);
+            else emit sceneZoom(false);
+        }
+    } else wheelEvent->setAccepted(false);
 }
 
 void GraphicsSceneRectMove::setScale(double s)