]> git.sesse.net Git - kdenlive/commitdiff
Cleanup & fix painting of timeline ruler when seeking:
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 9 Sep 2012 16:26:17 +0000 (18:26 +0200)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 9 Sep 2012 16:26:17 +0000 (18:26 +0200)
http://kdenlive.org/mantis/view.php?id=2724

src/customruler.cpp
src/customruler.h
src/customtrackview.cpp
src/customtrackview.h
src/trackview.cpp

index 67401a34ca7cf17d79d359638baf15747999830e..e0c262511aaa98694f18723f5cd7d95a201b7209 100644 (file)
@@ -56,6 +56,7 @@ CustomRuler::CustomRuler(Timecode tc, CustomTrackView *parent) :
         m_view(parent),
         m_duration(0),
         m_offset(0),
+        m_lastSeekPosition(SEEK_INACTIVE),
         m_clickedGuide(-1),
         m_rate(-1),
         m_mouseMove(NO_MOVE)
@@ -210,7 +211,6 @@ void CustomRuler::mouseMoveEvent(QMouseEvent * event)
             m_zoneStart += move;
             m_zoneEnd += move;
         }
-
         int min = qMin(m_zoneStart, zoneStart);
         int max = qMax(m_zoneEnd, zoneEnd);
         update(min * m_factor - m_offset - 2, 0, (max - min) * m_factor + 4, height());
@@ -277,9 +277,27 @@ void CustomRuler::slotCursorMoved(int oldpos, int newpos)
     } else update(qMin(oldpos, newpos) * m_factor - offset() - 6, BIG_MARK_X, qAbs(oldpos - newpos) * m_factor + 14, MAX_HEIGHT - BIG_MARK_X);
 }
 
-void CustomRuler::updateRuler(int min, int max)
+void CustomRuler::updateRuler()
 {
-    update(min * m_factor - offset(), 0, max - min, height());
+    // Update requested seek position
+    int min = SEEK_INACTIVE;
+    int max = SEEK_INACTIVE;
+    if (m_lastSeekPosition != SEEK_INACTIVE) {
+       min = max = m_lastSeekPosition;
+    }
+    m_lastSeekPosition = m_view->seekPosition();
+    if (m_lastSeekPosition != SEEK_INACTIVE) {
+       if (min == SEEK_INACTIVE) {
+           min = max = m_lastSeekPosition;
+       }
+       else {
+           min = qMin(min, m_lastSeekPosition);
+           max = qMax(max, m_lastSeekPosition);
+       }
+    }
+    if (min != SEEK_INACTIVE) {
+       update(min * m_factor - offset() - 3, BIG_MARK_X, (max - min) * m_factor + 6, MAX_HEIGHT - BIG_MARK_X);
+    }
 }
 
 void CustomRuler::setPixelPerMark(int rate)
@@ -352,18 +370,16 @@ void CustomRuler::setDuration(int d)
 void CustomRuler::paintEvent(QPaintEvent *e)
 {
     QStylePainter p(this);
-    p.setClipRect(e->rect());
-    
-    // Draw background
-    //p.fillRect(0, 0, m_duration * m_factor - m_offset, MAX_HEIGHT, palette().alternateBase().color());
+    const QRect &paintRect = e->rect();
+    p.setClipRect(paintRect);
 
     // Draw zone background
     const int zoneStart = (int)(m_zoneStart * m_factor);
     const int zoneEnd = (int)(m_zoneEnd * m_factor);
     p.fillRect(zoneStart - m_offset, LABEL_SIZE + 2, zoneEnd - zoneStart, MAX_HEIGHT - LABEL_SIZE - 2, m_zoneColor);
     
-    int minval = (e->rect().left() + m_offset) / FRAME_SIZE - 1;
-    const int maxval = (e->rect().right() + m_offset) / FRAME_SIZE + 1;
+    int minval = (paintRect.left() + m_offset) / FRAME_SIZE - 1;
+    const int maxval = (paintRect.right() + m_offset) / FRAME_SIZE + 1;
     if (minval < 0)
         minval = 0;
 
@@ -374,8 +390,8 @@ void CustomRuler::paintEvent(QPaintEvent *e)
     p.setPen(palette().text().color());
 
     // draw time labels
-    if (e->rect().y() < LABEL_SIZE) {
-        offsetmin = (e->rect().left() + m_offset) / m_textSpacing;
+    if (paintRect.y() < LABEL_SIZE) {
+        offsetmin = (paintRect.left() + m_offset) / m_textSpacing;
         offsetmin = offsetmin * m_textSpacing;
         for (f = offsetmin; f < offsetmax; f += m_textSpacing) {
             QString lab;
@@ -387,7 +403,7 @@ void CustomRuler::paintEvent(QPaintEvent *e)
         }
     }
 
-    offsetmin = (e->rect().left() + m_offset) / littleMarkDistance;
+    offsetmin = (paintRect.left() + m_offset) / littleMarkDistance;
     offsetmin = offsetmin * littleMarkDistance;
     // draw the little marks
     fend = m_scale * littleMarkDistance;
@@ -396,7 +412,7 @@ void CustomRuler::paintEvent(QPaintEvent *e)
             p.drawLine((int)f, LITTLE_MARK_X, (int)f, MAX_HEIGHT);
     }
 
-    offsetmin = (e->rect().left() + m_offset) / mediumMarkDistance;
+    offsetmin = (paintRect.left() + m_offset) / mediumMarkDistance;
     offsetmin = offsetmin * mediumMarkDistance;
     // draw medium marks
     fend = m_scale * mediumMarkDistance;
@@ -405,7 +421,7 @@ void CustomRuler::paintEvent(QPaintEvent *e)
             p.drawLine((int)f, MIDDLE_MARK_X, (int)f, MAX_HEIGHT);
     }
 
-    offsetmin = (e->rect().left() + m_offset) / bigMarkDistance;
+    offsetmin = (paintRect.left() + m_offset) / bigMarkDistance;
     offsetmin = offsetmin * bigMarkDistance;
     // draw big marks
     fend = m_scale * bigMarkDistance;
@@ -434,17 +450,17 @@ void CustomRuler::paintEvent(QPaintEvent *e)
     }
     
     // draw pointer
-    int pos = m_view->seekPosition();
-    if (pos != SEEK_INACTIVE) {
-       pos  = pos * m_factor - m_offset;
-       p.fillRect(pos - 1, 0, 3, height(), palette().highlight());
-    }
-    
-    const int value  = m_view->cursorPos() * m_factor - m_offset;
+    const int value  =  m_view->cursorPos() * m_factor - m_offset;
     QPolygon pa(3);
     pa.setPoints(3, value - 6, BIG_MARK_X, value + 6, BIG_MARK_X, value, MAX_HEIGHT - 1);
-    p.setBrush(palette().highlight());
+    p.setBrush(palette().text());
+    p.setPen(Qt::NoPen);
     p.drawPolygon(pa);
+    
+    if (m_lastSeekPosition != SEEK_INACTIVE) {
+       p.fillRect(m_lastSeekPosition * m_factor - m_offset - 1, BIG_MARK_X, 3, MAX_HEIGHT - 1, palette().highlight());
+    }
+
 }
 
 #include "customruler.moc"
index 6659c7a249f9df9aaa3b9c1914493115f27d681c..da91fb6bb93f89e29018b38ddbae3d2ee375877e 100644 (file)
@@ -71,6 +71,7 @@ private:
     double m_factor;
     double m_scale;
     int m_offset;
+    int m_lastSeekPosition;
     RULER_MOVE m_moveCursor;
     QMenu *m_contextMenu;
     QAction *m_editGuide;
@@ -87,7 +88,7 @@ private:
 public slots:
     void slotMoveRuler(int newPos);
     void slotCursorMoved(int oldpos, int newpos);
-    void updateRuler(int min, int max);
+    void updateRuler();
 
 private slots:
     void slotEditGuide();
index 97de5adb1005815898f948175a8b9cc1d259ca6d..3678d454b630b14e7a21747a59c4cc5440b82a48 100644 (file)
@@ -3348,22 +3348,8 @@ void CustomTrackView::deleteClip(const QString &clipId)
 
 void CustomTrackView::seekCursorPos(int pos)
 {
-    int current = m_document->renderer()->requestedSeekPosition;
-    int playhead = m_document->renderer()->seekFramePosition();
-    int min;
-    int max;
-    if (current != SEEK_INACTIVE) {
-       min = qMin(pos, playhead);
-       min = qMin (min, current) - 5;
-       max = qMax(pos, playhead);
-       max = qMax(max, current) + 5;
-    }
-    else {
-       min = qMin(pos, playhead) - 5;
-       max = qMax(pos, playhead) + 5;
-    }
     m_document->renderer()->seek(pos);
-    emit updateRuler(min, max);
+    emit updateRuler();
 }
 
 int CustomTrackView::seekPosition() const
@@ -3380,6 +3366,7 @@ void CustomTrackView::setCursorPos(int pos, bool seek)
        m_cursorLine->setPos(m_cursorPos, 0);
        if (m_autoScroll) checkScrolling();
     }
+    else emit updateRuler();
 }
 
 void CustomTrackView::updateCursorPos()
@@ -3395,26 +3382,14 @@ int CustomTrackView::cursorPos()
 void CustomTrackView::moveCursorPos(int delta)
 {
     int currentPos = m_document->renderer()->requestedSeekPosition;
-    int actualPos = m_document->renderer()->seekPosition().frames(m_document->fps());
-    int min;
-    int max;
     if (currentPos == SEEK_INACTIVE) {
-       currentPos = actualPos + delta;
-       if (currentPos < 0) currentPos = 0;
-       min = qMin(actualPos, currentPos) - 5;
-       max = qMax(actualPos, currentPos) + 5;
+       currentPos = m_document->renderer()->seekPosition().frames(m_document->fps()) + delta;
     }
     else {
-       min = qMin(currentPos, currentPos + delta);
-       min = qMin (min, actualPos) - 5;
-       max = qMax(currentPos, currentPos + delta);
-       max = qMax(max, actualPos) + 5;
        currentPos += delta;
-       if (currentPos < 0) currentPos = 0;
     }
-
-    m_document->renderer()->seek(currentPos);
-    emit updateRuler(min, max);
+    m_document->renderer()->seek(qMax(0, currentPos));
+    emit updateRuler();
 }
 
 void CustomTrackView::initCursorPos(int pos)
@@ -7246,8 +7221,7 @@ void CustomTrackView::slotGotFilterJobResults(const QString &/*id*/, int startPo
         EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), effect, newEffect, clip->selectedEffectIndex(), true, true);
         m_commandStack->push(command);
         emit clipItemSelected(clip);
-    }
-    
+    }    
 }
 
 
index 6067ef5c1c29a53530d822c18aa756f3f46db82c..a37f76ee74d3fd378b0f4d0421f231fc341a9aa0 100644 (file)
@@ -516,7 +516,7 @@ signals:
     /** @brief Update the track effect button that shows if a track has effects or not.*/
     void updateTrackEffectState(int);
     /** @brief Cursor position changed, repaint ruler.*/
-    void updateRuler(int min, int max);
+    void updateRuler();
 };
 
 #endif
index 1e1531910f5c9ef2f1158475aa0c81b5bd3ea24a..0bf0331acecfbcd95a26e211c8b1626e3d326e7b 100644 (file)
@@ -113,7 +113,7 @@ TrackView::TrackView(KdenliveDoc *doc, QList <QAction*> actions, bool *ok, QWidg
     if (m_doc->setSceneList() == -1) *ok = false;
     else *ok = true;
     connect(m_trackview, SIGNAL(cursorMoved(int, int)), m_ruler, SLOT(slotCursorMoved(int, int)));
-    connect(m_trackview, SIGNAL(updateRuler(int, int)), m_ruler, SLOT(updateRuler(int, int)));
+    connect(m_trackview, SIGNAL(updateRuler()), m_ruler, SLOT(updateRuler()));
 
     connect(m_trackview->horizontalScrollBar(), SIGNAL(valueChanged(int)), m_ruler, SLOT(slotMoveRuler(int)));
     connect(m_trackview->horizontalScrollBar(), SIGNAL(rangeChanged(int, int)), this, SLOT(slotUpdateVerticalScroll(int, int)));