]> git.sesse.net Git - kdenlive/blobdiff - src/smallruler.cpp
* Cleanup monitor / MLT communication
[kdenlive] / src / smallruler.cpp
index de1e2119b08839e981f52a9838506cc4fe08f197..f138b972c5e11275439720f9d4fc484b78e4e27b 100644 (file)
 #include <QMouseEvent>
 #include <QStylePainter>
 
-SmallRuler::SmallRuler(QWidget *parent) :
+SmallRuler::SmallRuler(MonitorManager *manager, QWidget *parent) :
         QWidget(parent),
         m_scale(1),
-        m_maxval(25)
+        m_maxval(25),
+        m_manager(manager)
 {
     m_zoneStart = 10;
     m_zoneEnd = 60;
     m_zoneColor = QColor(133, 255, 143);
+    setMouseTracking(true);
 }
 
 void SmallRuler::adjustScale(int maximum)
@@ -108,18 +110,28 @@ void SmallRuler::mouseMoveEvent(QMouseEvent * event)
 {
     const int pos = event->x() / m_scale;
     if (event->buttons() & Qt::LeftButton) emit seekRenderer((int) pos);
+    else {
+        if (qAbs((pos - m_zoneStart) * m_scale) < 4) {
+            setToolTip(i18n("Zone start: %1", m_manager->timecode().getTimecodeFromFrames(m_zoneStart)));
+        } else if (qAbs((pos - m_zoneEnd) * m_scale) < 4) {
+            setToolTip(i18n("Zone end: %1", m_manager->timecode().getTimecodeFromFrames(m_zoneEnd)));
+        } else if (pos > m_zoneStart && pos < m_zoneEnd) {
+            setToolTip(i18n("Zone duration: %1", m_manager->timecode().getTimecodeFromFrames(m_zoneEnd - m_zoneStart)));
+        } else setToolTip(i18n("Position: %1", m_manager->timecode().getTimecodeFromFrames(pos)));
+    }
 }
 
-void SmallRuler::slotNewValue(int value)
+bool SmallRuler::slotNewValue(int value)
 {
     m_cursorFramePosition = value;
     int oldPos = m_cursorPosition;
     m_cursorPosition = value * m_scale;
-    if (oldPos == m_cursorPosition) return;
+    if (oldPos == m_cursorPosition) return false;
     const int offset = 6;
     const int x = qMin(oldPos, m_cursorPosition);
     const int w = qAbs(oldPos - m_cursorPosition);
     update(x - offset, 4, w + 2 * offset, 6);
+    return true;
 }
 
 //virtual
@@ -138,7 +150,7 @@ 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);
-    
+
     // draw markers
     if (!m_markers.isEmpty()) {
         p.setPen(Qt::red);
@@ -150,14 +162,14 @@ void SmallRuler::updatePixmap()
     // 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);
+        }
     p.end();
     update();
 }