]> git.sesse.net Git - kdenlive/blobdiff - src/monitorscene.cpp
Prevent crash with corrupted keyframe effect
[kdenlive] / src / monitorscene.cpp
index f705e47b9c42ae5f38a2ff4758b0eefd6a50e277..077ca6054d7e9fbb86ec5b5c8de6af730cc7fd99 100644 (file)
@@ -36,7 +36,7 @@ MonitorScene::MonitorScene(Render *renderer, QObject* parent) :
         m_backgroundImage(QImage()),
         m_enabled(true),
         m_modified(false),
-        m_directUpdate(false)
+        m_zoom(1.0)
 {
     setBackgroundBrush(QBrush(QColor(KdenliveSettings::window_background().name())));
 
@@ -73,8 +73,6 @@ void MonitorScene::setUp()
         m_view = NULL;
 
     m_view->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
-
-    slotUpdateBackground(true);
 }
 
 void MonitorScene::resetProfile()
@@ -88,15 +86,11 @@ 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();
         }
     }
@@ -104,20 +98,56 @@ void MonitorScene::slotUpdateBackground(bool fit)
 
 void MonitorScene::slotSetDirectUpdate(bool directUpdate)
 {
-    m_directUpdate = 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)
+{
+    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));
+    }
 }
 
-bool MonitorScene::getDirectUpdate()
+void MonitorScene::slotZoomOriginal()
 {
-    return m_directUpdate;
+    slotZoom(100);
+    if (m_view)
+        m_view->centerOn(m_frameBorder);
 }
 
-void MonitorScene::slotSetBackgroundImage(QImage image)
+void MonitorScene::slotZoomOut()
 {
-    m_backgroundImage = image;
-    slotUpdateBackground();
+    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)
@@ -311,7 +341,7 @@ void MonitorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
 
         QGraphicsScene::mouseMoveEvent(event);
     }
-    if (m_modified && m_directUpdate) {
+    if (m_modified && KdenliveSettings::monitorscene_directupdate()) {
         emit actionFinished();
         m_modified = false;
     }