]> git.sesse.net Git - kdenlive/blobdiff - src/smallruler.cpp
Merge branch 'audioAlign'
[kdenlive] / src / smallruler.cpp
index c0c20d581b9e774c7229b2b3c7e18f01d66f6c7e..89d876d8cc7cbdc3305254d9f2448c31e5faf29a 100644 (file)
 
 #include <KDebug>
 #include <KColorScheme>
+#include <KLocale>
 
 #include <QMouseEvent>
 #include <QStylePainter>
 
 
 SmallRuler::SmallRuler(MonitorManager *manager, QWidget *parent) :
-        QWidget(parent),
-        m_scale(1),
-        m_maxval(25),
-        m_manager(manager)
+        QWidget(parent)
+        ,m_cursorFramePosition(0)
+        ,m_scale(1)
+        ,m_maxval(25)
+        ,m_manager(manager)
+        ,m_overCursor(false)
 {
     m_zoneStart = 10;
     m_zoneEnd = 60;
-    m_zoneColor = KStatefulBrush(KColorScheme::View, KColorScheme::PositiveBackground, KSharedConfig::openConfig(KdenliveSettings::colortheme())).brush(this).color();
+    KSharedConfigPtr config = KSharedConfig::openConfig(KdenliveSettings::colortheme());
+    m_zoneBrush = KStatefulBrush(KColorScheme::View, KColorScheme::PositiveBackground, config);
+
     setMouseTracking(true);
+    setMinimumHeight(10);
 }
 
 void SmallRuler::adjustScale(int maximum)
@@ -108,11 +114,35 @@ void SmallRuler::mousePressEvent(QMouseEvent * event)
     } else emit seekRenderer((int) pos);
 }
 
+void SmallRuler::leaveEvent( QEvent * event )
+{
+    Q_UNUSED(event);
+    if (m_overCursor) {
+        m_overCursor = false;
+        update();
+    }
+}
+
 // virtual
 void SmallRuler::mouseMoveEvent(QMouseEvent * event)
 {
     const int pos = event->x() / m_scale;
-    if (event->buttons() & Qt::LeftButton) emit seekRenderer((int) pos);
+    if (event->button() == Qt::NoButton) {
+        if (qAbs(pos * m_scale - m_cursorPosition) < 6) {
+            if (!m_overCursor) {
+                m_overCursor = true;
+                update();
+            }
+        }
+        else if (m_overCursor) {
+            m_overCursor = false;
+            update();
+        }
+    }
+    if (event->buttons() & Qt::LeftButton) {
+        m_overCursor = true;
+        emit seekRenderer((int) pos);
+    }
     else {
         if (qAbs((pos - m_zoneStart) * m_scale) < 4) {
             setToolTip(i18n("Zone start: %1", m_manager->timecode().getTimecodeFromFrames(m_zoneStart)));
@@ -137,6 +167,11 @@ bool SmallRuler::slotNewValue(int value)
     return true;
 }
 
+int SmallRuler::position() const
+{
+    return m_cursorFramePosition;
+}
+
 //virtual
 void SmallRuler::resizeEvent(QResizeEvent *)
 {
@@ -152,27 +187,30 @@ void SmallRuler::updatePixmap()
 
     const int zoneStart = (int)(m_zoneStart * m_scale);
     const int zoneEnd = (int)(m_zoneEnd * m_scale);
-    p.fillRect(zoneStart, height() / 2 - 1, zoneEnd - zoneStart, height() / 2, m_zoneColor);
+    p.setPen(Qt::NoPen);
+    p.setBrush(m_zoneBrush.brush(this));
+    p.drawRect(zoneStart, height() / 2 - 1, zoneEnd - zoneStart, height() / 2);
 
-    // draw markers
-    if (!m_markers.isEmpty()) {
-        p.setPen(Qt::red);
-        for (int i = 0; i < m_markers.count(); i++) {
-            p.drawLine(m_markers.at(i) * m_scale, 0, m_markers.at(i) * m_scale, 9);
-        }
-    }
+    // draw ruler
     p.setPen(palette().text().color());
     // draw the little marks
     fend = m_scale * m_small;
     if (fend > 2) for (f = 0; f < width(); f += fend) {
-            p.drawLine((int)f, 0, (int)f, 3);
-        }
+        p.drawLine((int)f, 0, (int)f, 3);
+    }
 
     // draw medium marks
     fend = m_scale * m_medium;
     if (fend > 2) for (f = 0; f < width(); f += fend) {
-            p.drawLine((int)f, 0, (int)f, 6);
+       p.drawLine((int)f, 0, (int)f, 6);
+    }
+    // draw markers
+    if (!m_markers.isEmpty()) {
+        p.setPen(Qt::red);
+        for (int i = 0; i < m_markers.count(); i++) {
+            p.drawLine(m_markers.at(i) * m_scale, 0, m_markers.at(i) * m_scale, 9);
         }
+    }
     p.end();
     update();
 }
@@ -188,10 +226,18 @@ void SmallRuler::paintEvent(QPaintEvent *e)
 
     // draw pointer
     QPolygon pa(3);
-    pa.setPoints(3, m_cursorPosition - 5, 10, m_cursorPosition + 5, 10, m_cursorPosition/*+0*/, 5);
-    p.setBrush(palette().text().color());
+    pa.setPoints(3, m_cursorPosition - 6, 10, m_cursorPosition + 6, 10, m_cursorPosition/*+0*/, 4);
+    if (m_overCursor) p.setBrush(palette().highlight());
+    else p.setBrush(palette().text().color());
     p.setPen(Qt::NoPen);
     p.drawPolygon(pa);
 }
 
+void SmallRuler::updatePalette()
+{
+    KSharedConfigPtr config = KSharedConfig::openConfig(KdenliveSettings::colortheme());
+    m_zoneBrush = KStatefulBrush(KColorScheme::View, KColorScheme::PositiveBackground, config);
+    updatePixmap();
+}
+
 #include "smallruler.moc"