]> git.sesse.net Git - kdenlive/blobdiff - src/monitorscene.cpp
Do not allow to change x position of first point in curve widget, as this is not...
[kdenlive] / src / monitorscene.cpp
index 7048f12b3d83e51f240a410a015ce77fde23a373..857caab990d0a56ee7b64c9bfda77f659efc5ada 100644 (file)
@@ -34,7 +34,9 @@ MonitorScene::MonitorScene(Render *renderer, QObject* parent) :
         m_resizeMode(NoResize),
         m_clickPoint(0, 0),
         m_backgroundImage(QImage()),
-        m_enabled(true)
+        m_enabled(true),
+        m_modified(false),
+        m_zoom(1.0)
 {
     setBackgroundBrush(QBrush(QColor(KdenliveSettings::window_background().name())));
 
@@ -71,8 +73,12 @@ void MonitorScene::setUp()
         m_view = NULL;
 
     m_view->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
+}
 
-    slotUpdateBackground(true);
+void MonitorScene::resetProfile()
+{
+    const QRectF border(0, 0, m_renderer->renderWidth(), m_renderer->renderHeight());
+    m_frameBorder->setRect(border);
 }
 
 void MonitorScene::setEnabled(bool enabled)
@@ -80,29 +86,71 @@ void MonitorScene::setEnabled(bool enabled)
     m_enabled = enabled;
 }
 
-void MonitorScene::slotUpdateBackground(bool fit)
+void MonitorScene::slotUpdateBackground()
 {
     if (m_view && m_view->isVisible()) {
         if (m_lastUpdate.elapsed() > 200) {
             m_background->setPixmap(QPixmap::fromImage(m_backgroundImage, Qt::ThresholdDither));
-            if (fit) {
-                m_view->fitInView(m_frameBorder, Qt::KeepAspectRatio);
-                m_view->centerOn(m_frameBorder);
-            }
             m_lastUpdate.start();
         }
     }
 }
 
-void MonitorScene::slotSetBackgroundImage(QImage image)
+void MonitorScene::slotSetDirectUpdate(bool directUpdate)
+{
+    KdenliveSettings::setMonitorscene_directupdate(directUpdate);
+}
+
+void MonitorScene::slotSetBackgroundImage(const QImage &image)
+{
+    if (m_view && m_view->isVisible()) {
+        m_backgroundImage = image;
+        slotUpdateBackground();
+    }
+}
+
+
+void MonitorScene::slotZoom(int value)
 {
-    m_backgroundImage = image;
-    slotUpdateBackground();
+    if (m_view) {
+        m_zoom = value / 100.0;
+        m_view->resetTransform();
+        m_view->scale(m_zoom, m_zoom);
+        emit zoomChanged(value);
+    }
 }
 
+void MonitorScene::slotZoomFit()
+{
+    if (m_view) {
+        m_view->fitInView(m_frameBorder, Qt::KeepAspectRatio);
+        m_view->centerOn(m_frameBorder);
+        m_zoom = m_view->matrix().m11();
+        emit zoomChanged((int)(m_zoom * 100));
+    }
+}
+
+void MonitorScene::slotZoomOriginal()
+{
+    slotZoom(100);
+    if (m_view)
+        m_view->centerOn(m_frameBorder);
+}
+
+void MonitorScene::slotZoomOut()
+{
+    slotZoom(qMax(0, (int)(m_zoom * 100 - 1)));
+}
+
+void MonitorScene::slotZoomIn()
+{
+    slotZoom(qMin(300, (int)(m_zoom * 100 + 1)));
+}
+
+
 resizeModes MonitorScene::getResizeMode(QGraphicsRectItem *item, QPoint pos)
 {
-    if(!m_view)
+    if (!m_view)
         return NoResize;
 
     QRectF rect = item->rect().normalized();
@@ -171,6 +219,11 @@ void MonitorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
     if (!m_enabled)
         return;
 
+    /*if (event->buttons() != Qt::NoButton && (event->screenPos() - m_screenClickPoint).manhattanLength() < QApplication::startDragDistance()) {
+        event->accept();
+        return;
+    }*/
+
     QPointF mousePos = event->scenePos();
 
     if (m_selectedItem && event->buttons() & Qt::LeftButton) {
@@ -185,6 +238,7 @@ void MonitorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
                 if (mousePos.x() < pos.x() + rect.height() && mousePos.y() < pos.y() + rect.height()) {
                     item->setRect(rect.adjusted(0, 0, -mousePosInRect.x(), -mousePosInRect.y()));
                     item->setPos(mousePos);
+                    m_modified = true;
                 }
                 break;
             case Top:
@@ -192,6 +246,7 @@ void MonitorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
                     rect.setBottom(rect.height() - mousePosInRect.y());
                     item->setRect(rect);
                     item->setPos(QPointF(pos.x(), mousePos.y()));
+                    m_modified = true;
                 }
                 break;
             case TopRight:
@@ -199,6 +254,7 @@ void MonitorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
                     rect.setBottomRight(QPointF(mousePosInRect.x(), rect.bottom() - mousePosInRect.y()));
                     item->setRect(rect);
                     item->setPos(QPointF(pos.x(), mousePos.y()));
+                    m_modified = true;
                 }
                 break;
             case Left:
@@ -206,12 +262,14 @@ void MonitorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
                     rect.setRight(rect.width() - mousePosInRect.x());
                     item->setRect(rect);
                     item->setPos(QPointF(mousePos.x(), pos.y()));
+                    m_modified = true;
                 }
                 break;
             case Right:
                 if (mousePos.x() > pos.x()) {
                     rect.setRight(mousePosInRect.x());
                     item->setRect(rect);
+                    m_modified = true;
                 }
                 break;
             case BottomLeft:
@@ -219,24 +277,28 @@ void MonitorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
                     rect.setBottomRight(QPointF(rect.width() - mousePosInRect.x(), mousePosInRect.y()));
                     item->setRect(rect);
                     item->setPos(QPointF(mousePos.x(), pos.y()));
+                    m_modified = true;
                 }
                 break;
             case Bottom:
                 if (mousePos.y() > pos.y()) {
                     rect.setBottom(mousePosInRect.y());
                     item->setRect(rect);
+                    m_modified = true;
                 }
                 break;
             case BottomRight:
                 if (mousePos.x() > pos.x() && mousePos.y() > pos.y()) {
                     rect.setBottomRight(mousePosInRect);
                     item->setRect(rect);
+                    m_modified = true;
                 }
                 break;
             default:
                 QPointF diff = mousePos - m_clickPoint;
                 m_clickPoint = mousePos;
                 item->moveBy(diff.x(), diff.y());
+                m_modified = true;
                 break;
             }
         }
@@ -245,7 +307,7 @@ void MonitorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
         bool itemFound = false;
         QList<QGraphicsItem *> itemList = items(QRectF(mousePos, QSizeF(4, 4)).toRect());
 
-        foreach (const QGraphicsItem* item, itemList) {
+        foreach(const QGraphicsItem* item, itemList) {
             if (item->zValue() >= 0 && item->flags() &QGraphicsItem::ItemIsMovable) {
                 // Rect
                 if (item->type() == 3) {
@@ -279,11 +341,15 @@ void MonitorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
             }
         }
 
-        if (!itemFound && m_view != NULL)
+        if (!itemFound && m_view)
             m_view->setCursor(Qt::ArrowCursor);
 
         QGraphicsScene::mouseMoveEvent(event);
     }
+    if (m_modified && KdenliveSettings::monitorscene_directupdate()) {
+        emit actionFinished();
+        m_modified = false;
+    }
 }
 
 void MonitorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
@@ -292,7 +358,10 @@ void MonitorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
         return;
 
     QGraphicsScene::mouseReleaseEvent(event);
-    emit actionFinished();
+    if (m_modified) {
+        m_modified = false;
+        emit actionFinished();
+    }
 }
 
 #include "monitorscene.moc"