]> git.sesse.net Git - kdenlive/commitdiff
Autoscroll while playing
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 3 Mar 2008 23:12:48 +0000 (23:12 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 3 Mar 2008 23:12:48 +0000 (23:12 +0000)
svn path=/branches/KDE4/; revision=1994

src/customtrackview.cpp
src/customtrackview.h
src/kdenlivesettings.kcfg
src/mainwindow.cpp
src/trackview.cpp
src/widgets/configdisplay_ui.ui

index 56b213b58efe3e49d2b2b032ac1067b4b1b29fde..54aa7b6d8218b11dbfd62f5b2584dc40baa81549 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
@@ -518,12 +519,21 @@ void CustomTrackView::setCursorPos(int pos, bool seek) {
     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 +689,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);
index d7e66d7838d160147faf427a2fc9ea8696bb34f7..1436f3b01ccf7ba67c64a97028e528644f0b817a 100644 (file)
@@ -41,7 +41,7 @@ public:
     void addTrack();
     void removeTrack();
     int cursorPos();
-    void initView();
+    void checkAutoScroll();
     void moveClip(const QPointF &startPos, const QPointF &endPos);
     void resizeClip(const QPointF &startPos, const QPointF &endPos, bool resizeClipStart);
     void addClip(QDomElement xml, int clipId, int track, int startpos, const QRectF &rect, int duration);
@@ -97,6 +97,9 @@ private:
     void updateSnapPoints(ClipItem *selected);
     double getSnapPointForPos(double pos);
     ClipItem *getClipItemAt(int pos, int track);
+    void checkScrolling();
+    /** Should we auto scroll while playing (keep in sync with KdenliveSettings::autoscroll() */
+    bool m_autoScroll;
 
 
 signals:
index e26559863511c0491ba3dcb8a05fda95f18d2dd8..03f686a5abbfa501fefefd915b0d591e08c34888 100644 (file)
       <label>Display audio thumbnails in timeline.</label>
       <default>true</default>
     </entry>
+
+    <entry name="autoscroll" type="Bool">
+      <label>Auto scroll timeline while playing.</label>
+      <default>true</default>
+    </entry>
   </group>
 
   <group name="env">
index 29a4fcb299f4cf30f5ad9630e3db1193a2aa2712..9717f7f0c00b49a2167aa91c4379bf040e6021c9 100644 (file)
@@ -485,13 +485,16 @@ void MainWindow::slotPreferences() {
     // KConfigDialog didn't find an instance of this dialog, so lets
     // create it :
     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
-    connect( dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()) );
+    connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
     dialog->show();
 }
 
 void MainWindow::updateConfiguration() {
     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
-    if (currentTab) currentTab->refresh();
+    if (currentTab) {
+        currentTab->refresh();
+        currentTab->projectView()->checkAutoScroll();
+    }
 }
 
 void MainWindow::slotGotProgressInfo(KUrl url, int progress) {
index 147e4254e9ac0bebe21622adc6e141a43b07a4a9..fbdb7cc3381acdfed1db56d8440848ac31d759eb 100644 (file)
@@ -70,7 +70,6 @@ TrackView::TrackView(KdenliveDoc *doc, QWidget *parent)
     connect(m_trackview, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotClipItemSelected(ClipItem*)));
     view->horizontalSlider->setValue(4);
     m_currentZoom = view->horizontalSlider->value();
-    m_trackview->initView();
 }
 
 
index 0b947ee0909075ba606a48cbafc0c065f2c9fc80..5f5eca0756b609bfdec211c4105c7036a6992075 100644 (file)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>354</width>
-    <height>182</height>
+    <width>306</width>
+    <height>107</height>
    </rect>
   </property>
   <layout class="QGridLayout" name="gridLayout_2" >
         </property>
        </spacer>
       </item>
+      <item row="1" column="0" colspan="2" >
+       <widget class="QCheckBox" name="kcfg_autoscroll" >
+        <property name="text" >
+         <string>Autoscroll while playing</string>
+        </property>
+       </widget>
+      </item>
      </layout>
     </widget>
    </item>