]> git.sesse.net Git - kdenlive/blobdiff - src/customtrackview.cpp
Make communication between timeline and its ruler easier
[kdenlive] / src / customtrackview.cpp
index 56b213b58efe3e49d2b2b032ac1067b4b1b29fde..74488776aa2f2ccbf0851a5c6ef7f055f24865e7 100644 (file)
 #include "addtimelineclipcommand.h"
 #include "addeffectcommand.h"
 #include "editeffectcommand.h"
+#include "kdenlivesettings.h"
 
 CustomTrackView::CustomTrackView(KdenliveDoc *doc, QGraphicsScene * projectscene, QWidget *parent)
-        : QGraphicsView(projectscene, parent), m_tracksCount(0), m_cursorPos(0), m_dropItem(NULL), m_cursorLine(NULL), m_operationMode(NONE), m_startPos(QPointF()), m_dragItem(NULL), m_visualTip(NULL), m_moveOpMode(NONE), m_animation(NULL), m_projectDuration(0), m_scale(1.0), m_clickPoint(0), m_document(doc) {
+        : QGraphicsView(projectscene, parent), m_tracksCount(0), m_cursorPos(0), m_dropItem(NULL), m_cursorLine(NULL), m_operationMode(NONE), m_startPos(QPointF()), m_dragItem(NULL), m_visualTip(NULL), m_moveOpMode(NONE), m_animation(NULL), m_projectDuration(0), m_scale(1.0), m_clickPoint(0), m_document(doc), m_autoScroll(KdenliveSettings::autoscroll()) {
     if (doc) m_commandStack = doc->commandStack();
     else m_commandStack == NULL;
     setMouseTracking(true);
@@ -59,8 +60,8 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, QGraphicsScene * projectscene
     }
 }
 
-void CustomTrackView::initView() {
-
+void CustomTrackView::checkAutoScroll() {
+    m_autoScroll = KdenliveSettings::autoscroll();
 }
 
 // virtual
@@ -255,7 +256,6 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
             m_moveOpMode = NONE;
             if (event->buttons() != Qt::NoButton) {
                 setCursorPos((int) mapToScene(event->pos().x(), 0).x());
-                emit cursorMoved(cursorPos());
             }
             if (m_visualTip) {
                 if (m_animation) delete m_animation;
@@ -318,7 +318,6 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) {
                 itemList.at(i)->setSelected(false);
             emit clipItemSelected(NULL);
             setCursorPos((int) mapToScene(event->x(), 0).x());
-            emit cursorMoved(cursorPos());
         }
     }
     updateSnapPoints(m_dragItem);
@@ -514,16 +513,26 @@ void CustomTrackView::deleteClip(int clipId) {
 }
 
 void CustomTrackView::setCursorPos(int pos, bool seek) {
+    emit cursorMoved(m_cursorPos, pos);
     m_cursorPos = pos;
     m_cursorLine->setPos(pos, 0);
     int frame =  pos / m_scale;
     if (seek) m_document->renderer()->seek(GenTime(frame, m_document->fps()));
+    else if (m_autoScroll && m_scale < 50) checkScrolling();
 }
 
 int CustomTrackView::cursorPos() {
     return m_cursorPos;
 }
 
+void CustomTrackView::checkScrolling() {
+    QRect rectInView = viewport()->rect();
+    int delta = rectInView.width() / 3;
+    int max = rectInView.right() + horizontalScrollBar()->value() - delta;
+    //kDebug() << "CURSOR POS: "<<m_cursorPos<< "Scale: "<<m_scale;
+    if (m_cursorPos >= max) horizontalScrollBar()->setValue(horizontalScrollBar()->value() + 1 + m_scale);
+}
+
 void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
     QGraphicsView::mouseReleaseEvent(event);
     setDragMode(QGraphicsView::NoDrag);
@@ -679,12 +688,8 @@ void CustomTrackView::setScale(double scaleFactor) {
 }
 
 void CustomTrackView::drawBackground(QPainter * painter, const QRectF & rect) {
-    QRect rectInView;//this is the rect that is visible by the user
-    if (scene()->views().size() > 0) {
-        rectInView = scene()->views()[0]->viewport()->rect();
-        rectInView.moveTo(scene()->views()[0]->horizontalScrollBar()->value(), scene()->views()[0]->verticalScrollBar()->value());
-    }
-    if (rectInView.isNull()) return;
+    QRect rectInView = viewport()->rect();
+    rectInView.moveTo(horizontalScrollBar()->value(), verticalScrollBar()->value());
 
     QColor base = palette().button().color();
     painter->setClipRect(rect);