]> git.sesse.net Git - kdenlive/blobdiff - src/graphicsscenerectmove.cpp
default Composite transition to use progressive rendering (bug 730)
[kdenlive] / src / graphicsscenerectmove.cpp
index 7fba479ba5117771305f8ebc5718645b9c848b7e..9a4071c42e544d6a5f690c3be699429efd0379e0 100644 (file)
@@ -1,3 +1,24 @@
+/***************************************************************************
+ *   copyright (C) 2008 by Marco Gittler (g.marco@freenet.de)                                 *
+ *   Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+#include "graphicsscenerectmove.h"
 
 #include <KDebug>
 #include <QGraphicsSceneMouseEvent>
 #include <QApplication>
 #include <QTextBlock>
 
-#include "graphicsscenerectmove.h"
 
-GraphicsSceneRectMove::GraphicsSceneRectMove(QObject *parent): QGraphicsScene(parent), m_selectedItem(NULL), resizeMode(NoResize), m_tool(TITLE_RECTANGLE) {
+GraphicsSceneRectMove::GraphicsSceneRectMove(QObject *parent) :
+        QGraphicsScene(parent),
+        m_selectedItem(NULL),
+        m_resizeMode(NoResize),
+        m_tool(TITLE_RECTANGLE)
+{
     //grabMouse();
-    zoom = 1.0;
+    m_zoom = 1.0;
     setBackgroundBrush(QBrush(Qt::transparent));
 }
 
-void GraphicsSceneRectMove::setSelectedItem(QGraphicsItem *item) {
+void GraphicsSceneRectMove::setSelectedItem(QGraphicsItem *item)
+{
     clearSelection();
     m_selectedItem = item;
     item->setSelected(true);
     update();
 }
 
-TITLETOOL GraphicsSceneRectMove::tool() {
+TITLETOOL GraphicsSceneRectMove::tool()
+{
     return m_tool;
 }
 
-void GraphicsSceneRectMove::setTool(TITLETOOL tool) {
+void GraphicsSceneRectMove::setTool(TITLETOOL tool)
+{
     m_tool = tool;
     switch (m_tool) {
     case TITLE_RECTANGLE:
@@ -45,7 +73,8 @@ void GraphicsSceneRectMove::setTool(TITLETOOL tool) {
 }
 
 //virtual
-void GraphicsSceneRectMove::keyPressEvent(QKeyEvent * keyEvent) {
+void GraphicsSceneRectMove::keyPressEvent(QKeyEvent * keyEvent)
+{
     if (m_selectedItem == NULL) {
         QGraphicsScene::keyPressEvent(keyEvent);
         return;
@@ -89,10 +118,11 @@ void GraphicsSceneRectMove::keyPressEvent(QKeyEvent * keyEvent) {
 }
 
 //virtual
-void GraphicsSceneRectMove::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* e) {
+void GraphicsSceneRectMove::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* e)
+{
     QPointF p = e->scenePos();
     p += QPoint(-2, -2);
-    resizeMode = NoResize;
+    m_resizeMode = NoResize;
     m_selectedItem = NULL;
     QGraphicsItem* g = items(QRectF(p , QSizeF(4, 4)).toRect()).at(0);
     if (g) {
@@ -105,17 +135,19 @@ void GraphicsSceneRectMove::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* e) {
     QGraphicsScene::mouseDoubleClickEvent(e);
 }
 
-void GraphicsSceneRectMove::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
+void GraphicsSceneRectMove::mouseReleaseEvent(QGraphicsSceneMouseEvent *e)
+{
     if (m_tool == TITLE_RECTANGLE && m_selectedItem) setSelectedItem(m_selectedItem);
     QGraphicsScene::mouseReleaseEvent(e);
     emit actionFinished();
 }
 
-void GraphicsSceneRectMove::mousePressEvent(QGraphicsSceneMouseEvent* e) {
+void GraphicsSceneRectMove::mousePressEvent(QGraphicsSceneMouseEvent* e)
+{
     m_clickPoint = e->screenPos();
     QPointF p = e->scenePos();
     p += QPoint(-2, -2);
-    resizeMode = NoResize;
+    m_resizeMode = NoResize;
     const QList <QGraphicsItem *> list = items(QRectF(p , QSizeF(4, 4)).toRect());
     QGraphicsItem *item = NULL;
     bool hasSelected = false;
@@ -166,22 +198,22 @@ void GraphicsSceneRectMove::mousePressEvent(QGraphicsSceneMouseEvent* e) {
                 } else r = m_selectedItem->boundingRect();
 
                 r.translate(item->scenePos());
-                if ((r.toRect().topLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
-                    resizeMode = TopLeft;
-                } else if ((r.toRect().bottomLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
-                    resizeMode = BottomLeft;
-                } else if ((r.toRect().topRight() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
-                    resizeMode = TopRight;
-                } else if ((r.toRect().bottomRight() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
-                    resizeMode = BottomRight;
-                } else if (qAbs(r.toRect().left() - e->scenePos().toPoint().x()) < 3 / zoom) {
-                    resizeMode = Left;
-                } else if (qAbs(r.toRect().right() - e->scenePos().toPoint().x()) < 3 / zoom) {
-                    resizeMode = Right;
-                } else if (qAbs(r.toRect().top() - e->scenePos().toPoint().y()) < 3 / zoom) {
-                    resizeMode = Up;
-                } else if (qAbs(r.toRect().bottom() - e->scenePos().toPoint().y()) < 3 / zoom) {
-                    resizeMode = Down;
+                if ((r.toRect().topLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / m_zoom) {
+                    m_resizeMode = TopLeft;
+                } else if ((r.toRect().bottomLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / m_zoom) {
+                    m_resizeMode = BottomLeft;
+                } else if ((r.toRect().topRight() - e->scenePos().toPoint()).manhattanLength() < 6 / m_zoom) {
+                    m_resizeMode = TopRight;
+                } else if ((r.toRect().bottomRight() - e->scenePos().toPoint()).manhattanLength() < 6 / m_zoom) {
+                    m_resizeMode = BottomRight;
+                } else if (qAbs(r.toRect().left() - e->scenePos().toPoint().x()) < 3 / m_zoom) {
+                    m_resizeMode = Left;
+                } else if (qAbs(r.toRect().right() - e->scenePos().toPoint().x()) < 3 / m_zoom) {
+                    m_resizeMode = Right;
+                } else if (qAbs(r.toRect().top() - e->scenePos().toPoint().y()) < 3 / m_zoom) {
+                    m_resizeMode = Up;
+                } else if (qAbs(r.toRect().bottom() - e->scenePos().toPoint().y()) < 3 / m_zoom) {
+                    m_resizeMode = Down;
                 } else setCursor(Qt::ClosedHandCursor);
             }
         }
@@ -198,11 +230,12 @@ void GraphicsSceneRectMove::mousePressEvent(QGraphicsSceneMouseEvent* e) {
         QGraphicsScene::mousePressEvent(e);
     }
 
-    kDebug() << "//////  MOUSE CLICK, RESIZE MODE: " << resizeMode;
+    kDebug() << "//////  MOUSE CLICK, RESIZE MODE: " << m_resizeMode;
 
 }
 
-void GraphicsSceneRectMove::clearTextSelection() {
+void GraphicsSceneRectMove::clearTextSelection()
+{
     if (m_selectedItem && m_selectedItem->type() == 8) {
         // disable text editing
         QGraphicsTextItem *t = static_cast<QGraphicsTextItem *>(m_selectedItem);
@@ -216,7 +249,8 @@ void GraphicsSceneRectMove::clearTextSelection() {
 }
 
 //virtual
-void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e) {
+void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e)
+{
     if ((e->screenPos() - m_clickPoint).manhattanLength() < QApplication::startDragDistance()) {
         e->accept();
         return;
@@ -230,7 +264,7 @@ void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e) {
 
             QPointF newpoint = e->scenePos();
             //newpoint -= m_selectedItem->scenePos();
-            switch (resizeMode) {
+            switch (m_resizeMode) {
             case TopLeft:
                 newrect.setBottomRight(newrect.bottomRight() + m_selectedItem->pos() - newpoint);
                 m_selectedItem->setPos(newpoint);
@@ -266,7 +300,7 @@ void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e) {
                 m_selectedItem->moveBy(diff.x(), diff.y());
                 break;
             }
-            if (m_selectedItem->type() == 3 && resizeMode != NoResize) {
+            if (m_selectedItem->type() == 3 && m_resizeMode != NoResize) {
                 QGraphicsRectItem *gi = (QGraphicsRectItem*)m_selectedItem;
                 gi->setRect(newrect);
             }
@@ -296,7 +330,7 @@ void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e) {
     } else if (m_tool == TITLE_SELECT) {
         QPointF p = e->scenePos();
         p += QPoint(-2, -2);
-        resizeMode = NoResize;
+        m_resizeMode = NoResize;
         bool itemFound = false;
         foreach(const QGraphicsItem* g, items(QRectF(p , QSizeF(4, 4)).toRect())) {
             if ((g->type() == 13 || g->type() == 7) && g->zValue() > -1000) {
@@ -304,24 +338,24 @@ void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e) {
                 setCursor(Qt::OpenHandCursor);
                 break;
             } else if (g->type() == 3 && g->zValue() > -1000) {
-                QRectF r = ((QGraphicsRectItem*)g)->rect();
+                QRectF r = ((const QGraphicsRectItem*)g)->rect();
                 r.translate(g->scenePos());
                 itemFound = true;
-                if ((r.toRect().topLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
+                if ((r.toRect().topLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / m_zoom) {
                     setCursor(QCursor(Qt::SizeFDiagCursor));
-                } else if ((r.toRect().bottomLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
+                } else if ((r.toRect().bottomLeft() - e->scenePos().toPoint()).manhattanLength() < 6 / m_zoom) {
                     setCursor(QCursor(Qt::SizeBDiagCursor));
-                } else if ((r.toRect().topRight() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
+                } else if ((r.toRect().topRight() - e->scenePos().toPoint()).manhattanLength() < 6 / m_zoom) {
                     setCursor(QCursor(Qt::SizeBDiagCursor));
-                } else if ((r.toRect().bottomRight() - e->scenePos().toPoint()).manhattanLength() < 6 / zoom) {
+                } else if ((r.toRect().bottomRight() - e->scenePos().toPoint()).manhattanLength() < 6 / m_zoom) {
                     setCursor(QCursor(Qt::SizeFDiagCursor));
-                } else if (qAbs(r.toRect().left() - e->scenePos().toPoint().x()) < 3 / zoom) {
+                } else if (qAbs(r.toRect().left() - e->scenePos().toPoint().x()) < 3 / m_zoom) {
                     setCursor(Qt::SizeHorCursor);
-                } else if (qAbs(r.toRect().right() - e->scenePos().toPoint().x()) < 3 / zoom) {
+                } else if (qAbs(r.toRect().right() - e->scenePos().toPoint().x()) < 3 / m_zoom) {
                     setCursor(Qt::SizeHorCursor);
-                } else if (qAbs(r.toRect().top() - e->scenePos().toPoint().y()) < 3 / zoom) {
+                } else if (qAbs(r.toRect().top() - e->scenePos().toPoint().y()) < 3 / m_zoom) {
                     setCursor(Qt::SizeVerCursor);
-                } else if (qAbs(r.toRect().bottom() - e->scenePos().toPoint().y()) < 3 / zoom) {
+                } else if (qAbs(r.toRect().bottom() - e->scenePos().toPoint().y()) < 3 / m_zoom) {
                     setCursor(Qt::SizeVerCursor);
                 } else setCursor(Qt::OpenHandCursor);
                 break;
@@ -336,45 +370,48 @@ void GraphicsSceneRectMove::mouseMoveEvent(QGraphicsSceneMouseEvent* e) {
             emit newRect((QGraphicsRectItem *) m_selectedItem);
             m_selectedItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
             m_selectedItem->setPos(m_sceneClickPoint);
-            resizeMode = BottomRight;
+            m_resizeMode = BottomRight;
             QGraphicsScene::mouseMoveEvent(e);
         }
     }
 }
 
-void GraphicsSceneRectMove::wheelEvent(QGraphicsSceneWheelEvent * wheelEvent) {
+void GraphicsSceneRectMove::wheelEvent(QGraphicsSceneWheelEvent * wheelEvent)
+{
     QList<QGraphicsView*> viewlist = views();
     //kDebug() << wheelEvent->delta() << " " << zoom;
-    double scale = 1.0;
     if (viewlist.size() > 0) {
         if (wheelEvent->delta() < 0) emit sceneZoom(true);
         else emit sceneZoom(false);
     }
 }
 
-void GraphicsSceneRectMove::setScale(double s) {
-    if (zoom < 1.0 / 7.0 && s < 1.0) return;
-    else if (zoom > 10.0 / 7.9 && s > 1.0) return;
+void GraphicsSceneRectMove::setScale(double s)
+{
+    if (m_zoom < 1.0 / 7.0 && s < 1.0) return;
+    else if (m_zoom > 10.0 / 7.9 && s > 1.0) return;
     QList<QGraphicsView*> viewlist = views();
     if (viewlist.size() > 0) {
         viewlist[0]->scale(s, s);
-        zoom = zoom * s;
+        m_zoom = m_zoom * s;
     }
     //kDebug()<<"//////////  ZOOM: "<<zoom;
 }
 
-void GraphicsSceneRectMove::setZoom(double s) {
+void GraphicsSceneRectMove::setZoom(double s)
+{
     QList<QGraphicsView*> viewlist = views();
     if (viewlist.size() > 0) {
         viewlist[0]->resetTransform();
         viewlist[0]->scale(s, s);
-        zoom = s;
+        m_zoom = s;
     }
 
     //kDebug()<<"//////////  ZOOM: "<<zoom;
 }
 
-void GraphicsSceneRectMove::setCursor(QCursor c) {
+void GraphicsSceneRectMove::setCursor(QCursor c)
+{
     const QList<QGraphicsView*> l = views();
     foreach(QGraphicsView* v, l) {
         v->setCursor(c);