]> git.sesse.net Git - kdenlive/commitdiff
Use current color scheme to draw timeline, fix ruler repaint issues
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 14 Apr 2009 11:49:44 +0000 (11:49 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 14 Apr 2009 11:49:44 +0000 (11:49 +0000)
svn path=/trunk/kdenlive/; revision=3298

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

index b47bed2e0df7f9d09a6dd96c54f3f126fee7b390..045a2be04fee07d61579ae024bd47b9425bf1cbf 100644 (file)
@@ -50,7 +50,7 @@ static int bigMarkDistance;
 
 #include "definitions.h"
 
-const int CustomRuler::comboScale[] = { 1, 2, 5, 10, 25, 50, 125, 250, 500, 725, 1500, 3000, 6000, 12000};
+const int CustomRuler::comboScale[] = { 1, 2, 5, 10, 25, 50, 125, 250, 500, 750, 1500, 3000, 6000, 12000};
 
 CustomRuler::CustomRuler(Timecode tc, CustomTrackView *parent) :
         QWidget(parent),
@@ -61,7 +61,6 @@ CustomRuler::CustomRuler(Timecode tc, CustomTrackView *parent) :
 {
     setFont(KGlobalSettings::toolBarFont());
     m_scale = 3;
-    m_bgColor = QColor(245, 245, 245);
     m_zoneColor = QColor(133, 255, 143);
     littleMarkDistance = FRAME_SIZE;
     mediumMarkDistance = FRAME_SIZE * m_timecode.fps();
@@ -179,10 +178,10 @@ int CustomRuler::offset() const
 
 void CustomRuler::slotCursorMoved(int oldpos, int newpos)
 {
-    if (qAbs(oldpos - newpos) * m_factor > 40) {
-        update(oldpos * m_factor - offset() - 6, 7, 17, 16);
-        update(newpos * m_factor - offset() - 6, 7, 17, 16);
-    } else update(qMin(oldpos, newpos) * m_factor - offset() - 6, 7, qAbs(oldpos - newpos) * m_factor + 17, 16);
+    if (qAbs(oldpos - newpos) * m_factor > m_textSpacing) {
+        update(oldpos * m_factor - offset() - 6, 0, 17, height());
+        update(newpos * m_factor - offset() - 6, 0, 17, height());
+    } else update(qMin(oldpos, newpos) * m_factor - offset() - 6, 0, qAbs(oldpos - newpos) * m_factor + 17, height());
 }
 
 void CustomRuler::setPixelPerMark(double rate)
@@ -191,6 +190,22 @@ void CustomRuler::setPixelPerMark(double rate)
     m_factor = 1.0 / (double) scale * FRAME_SIZE;
     m_scale = 1.0 / (double) scale;
     double fend = m_scale * littleMarkDistance;
+    if (rate > 8) {
+       mediumMarkDistance = (double) FRAME_SIZE * m_timecode.fps() * 60;
+       bigMarkDistance = (double) FRAME_SIZE * m_timecode.fps() * 300;
+    }
+    else if (rate > 6) {
+       mediumMarkDistance = (double) FRAME_SIZE * m_timecode.fps() * 10;
+       bigMarkDistance = (double) FRAME_SIZE * m_timecode.fps() * 30;
+    }
+    else if (rate > 3) {
+       mediumMarkDistance = (double) FRAME_SIZE * m_timecode.fps();
+       bigMarkDistance = (double) FRAME_SIZE * m_timecode.fps() * 5;
+    }
+    else {
+       mediumMarkDistance = (double) FRAME_SIZE * m_timecode.fps();
+       bigMarkDistance = (double) FRAME_SIZE * m_timecode.fps() * 60;
+    }
     switch ((int) rate) {
     case 0:
         m_textSpacing = fend;
@@ -214,15 +229,17 @@ void CustomRuler::setPixelPerMark(double rate)
         break;
     case 8:
     case 9:
+        m_textSpacing = fend * m_timecode.fps() * 40;
+        break;
     case 10:
-        m_textSpacing = fend * m_timecode.fps() * 60;
+        m_textSpacing = fend * m_timecode.fps() * 80;
         break;
     case 11:
     case 12:
-        m_textSpacing = fend * m_timecode.fps() * 300;
+        m_textSpacing = fend * m_timecode.fps() * 400;
         break;
     case 13:
-        m_textSpacing = fend * m_timecode.fps() * 600;
+        m_textSpacing = fend * m_timecode.fps() * 800;
         break;
     }
     update();
@@ -240,17 +257,16 @@ void CustomRuler::paintEvent(QPaintEvent *e)
 {
     QStylePainter p(this);
     p.setClipRect(e->rect());
-
     const int projectEnd = (int)(m_duration * m_factor);
-    p.fillRect(0, 0, projectEnd - m_offset, height(), m_bgColor);
+    p.fillRect(0, 0, projectEnd - m_offset, height(), palette().alternateBase().color());
 
     const int zoneStart = (int)(m_zoneStart * m_factor);
     const int zoneEnd = (int)(m_zoneEnd * m_factor);
     const QRect zoneRect();
 
-    p.fillRect(zoneStart - offset(), height() / 2, zoneEnd - zoneStart, height() / 2, m_zoneColor);
+    p.fillRect(zoneStart - m_offset, height() / 2, zoneEnd - zoneStart, height() / 2, m_zoneColor);
 
-    const int value  = m_view->cursorPos() * m_factor - offset();
+    const int value  = m_view->cursorPos() * m_factor - m_offset;
     int minval = (e->rect().left() + m_offset) / FRAME_SIZE - 1;
     const int maxval = (e->rect().right() + m_offset) / FRAME_SIZE + 1;
     if (minval < 0) minval = 0;
@@ -258,40 +274,38 @@ void CustomRuler::paintEvent(QPaintEvent *e)
     double f, fend;
     const int offsetmax = maxval * FRAME_SIZE;
 
-    QPalette palette;
-    p.setPen(palette.dark().color());
+    p.setPen(palette().dark().color());
+
+    // draw time labels
     int offsetmin = (e->rect().left() + m_offset) / m_textSpacing;
     offsetmin = offsetmin * m_textSpacing;
     for (f = offsetmin; f < offsetmax; f += m_textSpacing) {
-        QString lab = m_timecode.getTimecodeFromFrames((int)((f) / m_factor + 0.5));
-        p.drawText((int)f - m_offset + 2, LABEL_SIZE, lab);
-    }
+        QString lab = m_timecode.getTimecodeFromFrames((int)(f / m_factor + 0.5));
 
-    if (true) {
-        offsetmin = (e->rect().left() + m_offset) / littleMarkDistance;
-        offsetmin = offsetmin * littleMarkDistance;
-        // draw the little marks
-        fend = m_scale * littleMarkDistance;
-        if (fend > 5) for (f = offsetmin - m_offset; f < offsetmax - m_offset; f += fend)
-                p.drawLine((int)f, LITTLE_MARK_X1, (int)f, LITTLE_MARK_X2);
-    }
-    if (true) {
-        offsetmin = (e->rect().left() + m_offset) / mediumMarkDistance;
-        offsetmin = offsetmin * mediumMarkDistance;
-        // draw medium marks
-        fend = m_scale * mediumMarkDistance;
-        if (fend > 5) for (f = offsetmin - m_offset - fend; f < offsetmax - m_offset + fend; f += fend)
-                p.drawLine((int)f, MIDDLE_MARK_X1, (int)f, MIDDLE_MARK_X2);
-    }
-    if (true) {
-        offsetmin = (e->rect().left() + m_offset) / bigMarkDistance;
-        offsetmin = offsetmin * bigMarkDistance;
-        // draw big marks
-        fend = m_scale * bigMarkDistance;
-        if (fend > 5) for (f = offsetmin - m_offset; f < offsetmax - m_offset; f += fend)
-                p.drawLine((int)f, BIG_MARK_X1, (int)f, BIG_MARK_X2);
+        p.drawText(f - m_offset + 2, LABEL_SIZE, lab);
     }
 
+    offsetmin = (e->rect().left() + m_offset) / littleMarkDistance;
+    offsetmin = offsetmin * littleMarkDistance;
+    // draw the little marks
+    fend = m_scale * littleMarkDistance;
+    if (fend > 5) for (f = offsetmin - m_offset; f < offsetmax - m_offset; f += fend)
+       p.drawLine((int)f, LITTLE_MARK_X1, (int)f, LITTLE_MARK_X2);
+
+    offsetmin = (e->rect().left() + m_offset) / mediumMarkDistance;
+    offsetmin = offsetmin * mediumMarkDistance;
+    // draw medium marks
+    fend = m_scale * mediumMarkDistance;
+    if (fend > 5) for (f = offsetmin - m_offset - fend; f < offsetmax - m_offset + fend; f += fend)
+       p.drawLine((int)f, MIDDLE_MARK_X1, (int)f, MIDDLE_MARK_X2);
+
+    offsetmin = (e->rect().left() + m_offset) / bigMarkDistance;
+    offsetmin = offsetmin * bigMarkDistance;
+    // draw big marks
+    fend = m_scale * bigMarkDistance;
+    if (fend > 5) for (f = offsetmin - m_offset; f < offsetmax - m_offset; f += fend)
+       p.drawLine((int)f, BIG_MARK_X1, (int)f, BIG_MARK_X2);
+
     // draw zone cursors
     int off = offset();
     if (zoneStart > 0) {
@@ -312,8 +326,8 @@ void CustomRuler::paintEvent(QPaintEvent *e)
 
     // draw pointer
     QPolygon pa(3);
-    pa.setPoints(3, value - 6, 7, value + 6, 7, value, 16);
-    p.setBrush(QBrush(Qt::yellow));
+    pa.setPoints(3, value - 6, 8, value + 6, 8, value, 16);
+    p.setBrush(palette().highlight());
     p.drawPolygon(pa);
 }
 
index 9b3aa020c2bf55fea40efa9a6857beb03017851e..c7a992807aa76bb8e1c386918d35cf825d656322 100644 (file)
@@ -54,6 +54,7 @@ private:
     int m_zoneEnd;
     int m_duration;
     QColor m_bgColor;
+    QColor m_cursorColor;
     QColor m_zoneColor;
     double m_textSpacing;
     double m_factor;
index c74204daabbfb2cb824379bd8a76c3f71b096fcf..fe33b3c4ea9d5f2dcda6cb9effa918e9efa86ac4 100644 (file)
@@ -63,6 +63,7 @@
 #include <KUrl>
 #include <KIcon>
 #include <KCursor>
+#include <KColorScheme>
 
 #include <QMouseEvent>
 #include <QStylePainter>
@@ -2066,6 +2067,7 @@ void CustomTrackView::deleteClip(const QString &clipId)
 
 void CustomTrackView::setCursorPos(int pos, bool seek)
 {
+    if (pos == m_cursorPos) return;
     emit cursorMoved((int)(m_cursorPos), (int)(pos));
     m_cursorPos = pos;
     m_cursorLine->setPos(pos, 0);
@@ -3614,15 +3616,18 @@ void CustomTrackView::slotRefreshGuides()
 
 void CustomTrackView::drawBackground(QPainter * painter, const QRectF & rect)
 {
-    QColor base = palette().button().color();
     QRectF r = rect;
     r.setWidth(r.width() + 1);
     painter->setClipRect(r);
     painter->drawLine(r.left(), 0, r.right(), 0);
     uint max = m_document->tracksCount();
+    KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window);
+    QColor lockedColor = scheme.background(KColorScheme::NegativeBackground).color();
+    QColor audioColor = palette().alternateBase().color();
+    QColor base = scheme.background(KColorScheme::NormalBackground).color();
     for (uint i = 0; i < max;i++) {
-        if (m_document->trackInfoAt(max - i - 1).isLocked == true) painter->fillRect(r.left(), m_tracksHeight * i + 1, r.right() - r.left() + 1, m_tracksHeight - 1, QBrush(QColor(250, 250, 100)));
-        else if (m_document->trackInfoAt(max - i - 1).type == AUDIOTRACK) painter->fillRect(r.left(), m_tracksHeight * i + 1, r.right() - r.left() + 1, m_tracksHeight - 1, QBrush(QColor(240, 240, 255)));
+        if (m_document->trackInfoAt(max - i - 1).isLocked == true) painter->fillRect(r.left(), m_tracksHeight * i + 1, r.right() - r.left() + 1, m_tracksHeight - 1, QBrush(lockedColor));
+        else if (m_document->trackInfoAt(max - i - 1).type == AUDIOTRACK) painter->fillRect(r.left(), m_tracksHeight * i + 1, r.right() - r.left() + 1, m_tracksHeight - 1, QBrush(audioColor));
         painter->drawLine(r.left(), m_tracksHeight * (i + 1), r.right(), m_tracksHeight * (i + 1));
     }
     int lowerLimit = m_tracksHeight * m_document->tracksCount() + 1;