]> git.sesse.net Git - kdenlive/blobdiff - src/smallruler.cpp
Integrate with the required MLT hooks for getting Movit to work.
[kdenlive] / src / smallruler.cpp
index 0cf185b05a76c7eaccb4d8128ac5db60f5c3b46c..d5b99032b95fa3b8b4cb6461491193260fde748a 100644 (file)
@@ -23,7 +23,7 @@
 
 #include <KDebug>
 #include <KColorScheme>
-#include <KLocale>
+#include <KLocalizedString>
 
 #include <QMouseEvent>
 #include <QStylePainter>
 #define SEEK_INACTIVE (-1)
 
 
-SmallRuler::SmallRuler(MonitorManager *manager, Render *render, QWidget *parent) :
+SmallRuler::SmallRuler(Monitor *monitor, Render *render, QWidget *parent) :
         QWidget(parent)
         ,m_cursorFramePosition(0)
-        ,m_scale(1)
-        ,m_maxval(25)
-        ,m_manager(manager)
+        ,m_maxval(2)
+        ,m_monitor(monitor)
        ,m_render(render)
        ,m_lastSeekPosition(SEEK_INACTIVE)
+       ,m_cursorColor(palette().text())
 {
     m_zoneStart = 10;
     m_zoneEnd = 60;
     KSharedConfigPtr config = KSharedConfig::openConfig(KdenliveSettings::colortheme());
-    m_zoneBrush = KStatefulBrush(KColorScheme::View, KColorScheme::PositiveBackground, config);
+    m_zoneColor = KStatefulBrush(KColorScheme::View, KColorScheme::FocusColor, config).brush(this).color();
+    m_zoneColor.setAlpha(180);
 
     setMouseTracking(true);
-    setMinimumHeight(10);
+    setMinimumHeight(QFontInfo(font()).pixelSize());
+    adjustScale(m_maxval);
 }
 
 
@@ -106,13 +108,13 @@ void SmallRuler::setZone(int start, int end)
     updatePixmap();
 }
 
-void SmallRuler::setMarkers(QList < CommentedTime > list)
+void SmallRuler::setMarkers(const QList<CommentedTime> &list)
 {
     m_markers = list;
     updatePixmap();
 }
 
-QPoint SmallRuler::zone()
+QPoint SmallRuler::zone() const
 {
     return QPoint(m_zoneStart, m_zoneEnd);
 }
@@ -120,6 +122,7 @@ QPoint SmallRuler::zone()
 // virtual
 void SmallRuler::mousePressEvent(QMouseEvent * event)
 {
+    m_render->setActiveMonitor();
     const int pos = event->x() / m_scale;
     if (event->button() == Qt::RightButton) {
         // Right button clicked, move selection zone
@@ -128,32 +131,77 @@ void SmallRuler::mousePressEvent(QMouseEvent * event)
         emit zoneChanged(QPoint(m_zoneStart, m_zoneEnd));
         updatePixmap();
 
-    } else {
+    } else if (pos != m_lastSeekPosition && pos != m_cursorFramePosition) {
        m_render->seekToFrame(pos);
        m_lastSeekPosition = pos;
        update();
     }
+    event->accept();
+}
+
+// virtual
+void SmallRuler::mouseReleaseEvent(QMouseEvent * event)
+{
+    event->accept();
 }
 
 
+// virtual
+void SmallRuler::leaveEvent(QEvent * event)
+{
+    QWidget::leaveEvent(event);
+    if (m_cursorColor == palette().link()) {
+       m_cursorColor = palette().text();
+       update();
+    }
+}
+
 // virtual
 void SmallRuler::mouseMoveEvent(QMouseEvent * event)
 {
     const int pos = event->x() / m_scale;
     if (event->buttons() & Qt::LeftButton) {
-       m_render->seekToFrame(pos);
-       m_lastSeekPosition = pos;
-       update();
+       if (pos != m_lastSeekPosition && pos != m_cursorFramePosition) {
+           m_render->seekToFrame(pos);
+           m_lastSeekPosition = pos;
+           update();
+       }
     }
     else {
+       if (m_cursorColor == palette().text() && qAbs(pos - m_cursorFramePosition) * m_scale < 7) {
+           // Mouse is over cursor
+           m_cursorColor = palette().link();
+           update();
+       }
+       else if (m_cursorColor == palette().link() && qAbs(pos - m_cursorFramePosition) * m_scale >= 7) {
+           m_cursorColor = palette().text();
+           update();
+       }
         if (qAbs((pos - m_zoneStart) * m_scale) < 4) {
-            setToolTip(i18n("Zone start: %1", m_manager->timecode().getTimecodeFromFrames(m_zoneStart)));
+            setToolTip(i18n("Zone start: %1", m_monitor->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)));
+            setToolTip(i18n("Zone end: %1", m_monitor->getTimecodeFromFrames(m_zoneEnd)));
+        } 
+       for (int i = 0; i < m_markers.count(); ++i) {
+           if (qAbs((pos - m_markers.at(i).time().frames(m_monitor->fps())) * m_scale) < 4) {
+               // We are on a marker
+               QString markerxt = m_monitor->getMarkerThumb(m_markers.at(i).time());
+               if (!markerxt.isEmpty()) {
+                   markerxt.prepend("<img src=\"");
+                   markerxt.append("\"><p align=\"center\">");
+               }
+               markerxt.append(m_markers.at(i).comment());
+               setToolTip(markerxt);
+               event->accept();
+               return;
+           }
+       }
+       if (pos > m_zoneStart && pos < m_zoneEnd) {
+            setToolTip(i18n("Zone duration: %1", m_monitor->getTimecodeFromFrames(m_zoneEnd - m_zoneStart)));
+       }
+       else setToolTip(i18n("Position: %1", m_monitor->getTimecodeFromFrames(pos)));
     }
+    event->accept();
 }
 
 void SmallRuler::refreshRuler()
@@ -194,12 +242,13 @@ void SmallRuler::updatePixmap()
 
     const int zoneStart = (int)(m_zoneStart * m_scale);
     const int zoneEnd = (int)(m_zoneEnd * m_scale);
-    p.setPen(Qt::NoPen);
-    p.setBrush(m_zoneBrush.brush(this));
-    p.drawRect(zoneStart, height() / 2 - 1, zoneEnd - zoneStart, height() / 2);
+    p.fillRect(zoneStart, 0, zoneEnd - zoneStart, height(), QBrush(m_zoneColor));
 
     // draw ruler
-    p.setPen(palette().text().color());
+    p.setPen(palette().midlight().color());
+    //p.drawLine(0, 0, width(), 0);
+    p.drawLine(0, height() - 1, width(), height() - 1);
+    p.setPen(palette().dark().color());
     // draw the little marks
     fend = m_scale * m_small;
     if (fend > 2) for (f = 0; f < width(); f += fend) {
@@ -213,8 +262,8 @@ void SmallRuler::updatePixmap()
     }
     // draw markers
     if (!m_markers.isEmpty()) {
-        for (int i = 0; i < m_markers.count(); i++) {
-           int pos = m_markers.at(i).time().frames(m_manager->timecode().fps()) * m_scale;
+        for (int i = 0; i < m_markers.count(); ++i) {
+           int pos = m_markers.at(i).time().frames(m_monitor->fps()) * m_scale;
            p.setPen(CommentedTime::markerColor(m_markers.at(i).markerType()));
             p.drawLine(pos, 0, pos, 9);
         }
@@ -231,25 +280,29 @@ void SmallRuler::paintEvent(QPaintEvent *e)
     QRect r = e->rect();
     p.setClipRect(r);
     p.drawPixmap(QPointF(), m_pixmap);
+    p.setPen(palette().shadow().color());
+    //p.setRenderHint(QPainter::Antialiasing, true);
+    //p.drawRoundedRect(rect().adjusted(1,1,-2,-2), 3, 3);
 
     int cursorPos = m_cursorFramePosition * m_scale;
     // draw pointer
     QPolygon pa(3);
-    pa.setPoints(3, cursorPos - 6, 10, cursorPos + 6, 10, cursorPos/*+0*/, 4);
-    p.setBrush(palette().text());
+    pa.setPoints(3, cursorPos - 6, height() - 1, cursorPos + 6, height() - 1, cursorPos/*+0*/, height() - 8);
+    p.setBrush(m_cursorColor);
     p.setPen(Qt::NoPen);
     p.drawPolygon(pa);
 
     // Draw seeking pointer
     if (m_lastSeekPosition != SEEK_INACTIVE && m_lastSeekPosition != m_cursorFramePosition) {
-       p.fillRect(m_lastSeekPosition * m_scale - 1, 0, 3, height(), palette().highlight());
+       p.fillRect(m_lastSeekPosition * m_scale - 1, 0, 3, height(), palette().linkVisited());
     }
 }
 
 void SmallRuler::updatePalette()
 {
     KSharedConfigPtr config = KSharedConfig::openConfig(KdenliveSettings::colortheme());
-    m_zoneBrush = KStatefulBrush(KColorScheme::View, KColorScheme::PositiveBackground, config);
+    m_zoneColor = KStatefulBrush(KColorScheme::View, KColorScheme::FocusColor, config).brush(this).color();
+    m_zoneColor.setAlpha(180);
     updatePixmap();
 }