]> git.sesse.net Git - kdenlive/blobdiff - src/customruler.cpp
Render zone: fix color issues & snapping
[kdenlive] / src / customruler.cpp
index 6606b77024bc8b666351fe24a767d29b63db194c..2d07ee52ce46b9d5a9e29e17655877f8a4580c60 100644 (file)
@@ -24,6 +24,7 @@
 #include <KIcon>
 #include <KCursor>
 #include <KGlobalSettings>
+#include <KColorScheme>
 
 #include <QApplication>
 #include <QMouseEvent>
@@ -67,7 +68,7 @@ CustomRuler::CustomRuler(Timecode tc, CustomTrackView *parent) :
     QFontMetricsF fontMetrics(font());
     LABEL_SIZE = fontMetrics.ascent() - 2;
     m_scale = 3;
-    m_zoneColor = QColor(133, 255, 143);
+    m_zoneColor = KStatefulBrush(KColorScheme::View, KColorScheme::PositiveBackground, KSharedConfig::openConfig(KdenliveSettings::colortheme())).brush(this).color();
     littleMarkDistance = FRAME_SIZE;
     mediumMarkDistance = FRAME_SIZE * m_timecode.fps();
     bigMarkDistance = FRAME_SIZE * m_timecode.fps() * 60;
@@ -108,6 +109,7 @@ void CustomRuler::slotDeleteGuide()
 
 void CustomRuler::slotGoToGuide(QAction *act)
 {
+    m_view->setCursorPos(act->data().toInt(), true);
     m_view->initCursorPos(act->data().toInt());
 }
 
@@ -154,7 +156,10 @@ void CustomRuler::mousePressEvent(QMouseEvent * event)
 void CustomRuler::mouseMoveEvent(QMouseEvent * event)
 {
     if (event->buttons() == Qt::LeftButton) {
-        int pos = (int)((event->x() + offset()) / m_factor);
+        int pos;
+        if (m_moveCursor == RULER_START || m_moveCursor == RULER_END) {
+            pos = m_view->getSnapPointForPos((int)((event->x() + offset()) / m_factor));
+        } else pos = (int)((event->x() + offset()) / m_factor);
         int zoneStart = m_zoneStart;
         int zoneEnd = m_zoneEnd;
         if (pos < 0) pos = 0;
@@ -335,18 +340,23 @@ void CustomRuler::paintEvent(QPaintEvent *e)
     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;
+    if (minval < 0)
+        minval = 0;
 
     double f, fend;
     const int offsetmax = maxval * FRAME_SIZE;
 
-    p.setPen(palette().dark().color());
+    p.setPen(palette().text().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));
+        QString lab;
+        if (KdenliveSettings::frametimecode())
+            lab = QString::number((int)(f / m_factor + 0.5));
+        else
+            lab = m_timecode.getTimecodeFromFrames((int)(f / m_factor + 0.5));
         p.drawText(f - m_offset + 2, LABEL_SIZE, lab);
     }
 
@@ -354,22 +364,28 @@ void CustomRuler::paintEvent(QPaintEvent *e)
     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)
+    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)
+    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)
+    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();