]> git.sesse.net Git - kdenlive/commitdiff
Cleanup drawing of monitor rulers, add Markers list in clip monitor menu
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 16 Sep 2009 22:58:36 +0000 (22:58 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 16 Sep 2009 22:58:36 +0000 (22:58 +0000)
svn path=/trunk/kdenlive/; revision=3901

src/docclipbase.cpp
src/mainwindow.cpp
src/monitor.cpp
src/monitor.h
src/smallruler.cpp
src/smallruler.h
src/widgets/monitor_ui.ui

index 66e5c7795925257d9688b3284568f3cd9015e624..71cfacb37d4b60a1dfba63dbd8cf4af1a50e3243 100644 (file)
@@ -296,7 +296,7 @@ QList < GenTime > DocClipBase::snapMarkers() const
     QList < GenTime > markers;
 
     for (int count = 0; count < m_snapMarkers.count(); ++count) {
-        markers.append(m_snapMarkers[count].time());
+        markers.append(m_snapMarkers.at(count).time());
     }
 
     return markers;
@@ -380,23 +380,23 @@ GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
 {
     int it;
     for (it = 0; it < m_snapMarkers.count(); it++) {
-        if (m_snapMarkers[it].time() >= currTime)
+        if (m_snapMarkers.at(it).time() >= currTime)
             break;
     }
     if (it == 0) return GenTime();
-    else if (it == m_snapMarkers.count() - 1 && m_snapMarkers[it].time() < currTime)
-        return m_snapMarkers[it].time();
-    else return m_snapMarkers[it-1].time();
+    else if (it == m_snapMarkers.count() - 1 && m_snapMarkers.at(it).time() < currTime)
+        return m_snapMarkers.at(it).time();
+    else return m_snapMarkers.at(it-1).time();
 }
 
 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
 {
     int it;
     for (it = 0; it < m_snapMarkers.count(); it++) {
-        if (m_snapMarkers[it].time() > currTime)
+        if (m_snapMarkers.at(it).time() > currTime)
             break;
     }
-    if (it < m_snapMarkers.count() && m_snapMarkers[it].time() > currTime) return m_snapMarkers[it].time();
+    if (it < m_snapMarkers.count() && m_snapMarkers.at(it).time() > currTime) return m_snapMarkers.at(it).time();
     return duration();
 }
 
index e64bc63436b968038c2be83b937e4ea72a18e518..a403f407e8bf36ca6e868773081445993e977a8c 100644 (file)
@@ -2011,8 +2011,9 @@ void MainWindow::slotAddClipMarker()
     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Add Marker"), this);
     if (d.exec() == QDialog::Accepted) {
         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
+        if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
+        m_clipMonitor->updateMarkers(clip);
     }
-    if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
 }
 
 void MainWindow::slotDeleteClipMarker()
@@ -2044,6 +2045,7 @@ void MainWindow::slotDeleteClipMarker()
     }
     m_activeTimeline->projectView()->slotDeleteClipMarker(comment, id, pos);
     if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
+    m_clipMonitor->updateMarkers(clip);
 
 }
 
@@ -2066,6 +2068,7 @@ void MainWindow::slotDeleteAllClipMarkers()
     }
     m_activeTimeline->projectView()->slotDeleteAllClipMarkers(clip->getId());
     if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
+    m_clipMonitor->updateMarkers(clip);
 }
 
 void MainWindow::slotEditClipMarker()
@@ -2103,6 +2106,7 @@ void MainWindow::slotEditClipMarker()
         if (d.newMarker().time() != pos) {
             // remove old marker
             m_activeTimeline->projectView()->slotAddClipMarker(id, pos, QString());
+            m_clipMonitor->updateMarkers(clip);
         }
         if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
     }
index 78acd3d76c4b334018592ddb2337fb18207c3e6d..88259bf8690f062b87b020f6ee94ad69c9b72076 100644 (file)
@@ -98,6 +98,13 @@ Monitor::Monitor(QString name, MonitorManager *manager, QWidget *parent) :
         configButton->setMenu(m_configMenu);
         configButton->setPopupMode(QToolButton::QToolButton::InstantPopup);
         toolbar->addWidget(configButton);
+
+        if (name == "clip") {
+            m_markerMenu = new QMenu(i18n("Go to marker..."), this);
+            m_markerMenu->setEnabled(false);
+            m_configMenu->addMenu(m_markerMenu);
+            connect(m_markerMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotGoToMarker(QAction *)));
+        }
         m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (100%)"), this, SLOT(slotSetSizeOneToOne()));
         m_configMenu->addAction(KIcon("transform-scale"), i18n("Resize (50%)"), this, SLOT(slotSetSizeOneToTwo()));
     }
@@ -218,6 +225,12 @@ void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMe
 
 }
 
+void Monitor::slotGoToMarker(QAction *action)
+{
+    int pos = action->data().toInt();
+    slotSeek(pos);
+}
+
 void Monitor::slotSetSizeOneToOne()
 {
     QRect r = QApplication::desktop()->screenGeometry();
@@ -268,6 +281,26 @@ DocClipBase *Monitor::activeClip()
     return m_currentClip;
 }
 
+void Monitor::updateMarkers(DocClipBase *source)
+{
+    if (source == m_currentClip) {
+        m_markerMenu->clear();
+        QList <CommentedTime> markers = m_currentClip->commentedSnapMarkers();
+        if (!markers.isEmpty()) {
+            QList <int> marks;
+            for (int i = 0; i < markers.count(); i++) {
+                int pos = (int) markers.at(i).time().frames(render->fps());
+                marks.append(pos);
+                QString position = m_monitorManager->timecode().getTimecode(markers.at(i).time()) + ' ' + markers.at(i).comment();
+                QAction *go = m_markerMenu->addAction(position);
+                go->setData(pos);
+            }
+            m_ruler->setMarkers(marks);
+        } else m_ruler->setMarkers(QList <int>());
+        m_markerMenu->setEnabled(!m_markerMenu->isEmpty());
+    }
+}
+
 void Monitor::slotSeekToPreviousSnap()
 {
     if (m_currentClip) slotSeek(getSnapForPos(true).frames(m_monitorManager->timecode().fps()));
@@ -713,6 +746,7 @@ void Monitor::slotSetXml(DocClipBase *clip, const int position)
     }
     if (clip != m_currentClip) {
         m_currentClip = clip;
+        updateMarkers(clip);        
         if (render->setProducer(clip->producer(), position) == -1) {
             // MLT CONSUMER is broken
             emit blockMonitors();
index 9d7723f381bd69a0d5ef863400604385fa44e731..3f3fe8fd394e2a46bf2a2156e2e48134289c0757 100644 (file)
@@ -82,6 +82,7 @@ public:
     GenTime position();
     void checkOverlay();
     void updateTimecodeFormat();
+    void updateMarkers(DocClipBase *source);
 
 protected:
     virtual void mousePressEvent(QMouseEvent * event);
@@ -114,6 +115,7 @@ private:
     QMenu *m_contextMenu;
     QMenu *m_configMenu;
     QMenu *m_playMenu;
+    QMenu *m_markerMenu;
     QPoint m_DragStartPosition;
 #ifdef Q_WS_MAC
     VideoGLWidget *m_glWidget;
@@ -133,6 +135,7 @@ private slots:
     void setClipZone(QPoint pos);
     void slotSwitchMonitorInfo(bool show);
     void slotSwitchDropFrames(bool show);
+    void slotGoToMarker(QAction *action);
 
 public slots:
     void slotOpenFile(const QString &);
index 8881329c08bb330997879da4bf2fcb17697d87bd..de1e2119b08839e981f52a9838506cc4fe08f197 100644 (file)
@@ -52,7 +52,7 @@ void SmallRuler::adjustScale(int maximum)
         m_medium = 60 * 25;
     }
     m_cursorPosition = m_cursorFramePosition * m_scale;
-    update();
+    updatePixmap();
 }
 
 void SmallRuler::setZone(int start, int end)
@@ -75,7 +75,13 @@ void SmallRuler::setZone(int start, int end)
             m_zoneEnd = end;
         } else m_zoneEnd = end;
     }
-    update();
+    updatePixmap();
+}
+
+void SmallRuler::setMarkers(QList < int > list)
+{
+    m_markers = list;
+    updatePixmap();
 }
 
 QPoint SmallRuler::zone()
@@ -92,7 +98,7 @@ void SmallRuler::mousePressEvent(QMouseEvent * event)
         if (qAbs(pos - m_zoneStart) < qAbs(pos - m_zoneEnd)) m_zoneStart = pos;
         else m_zoneEnd = pos;
         emit zoneChanged(QPoint(m_zoneStart, m_zoneEnd));
-        update();
+        updatePixmap();
 
     } else emit seekRenderer((int) pos);
 }
@@ -113,7 +119,7 @@ void SmallRuler::slotNewValue(int value)
     const int offset = 6;
     const int x = qMin(oldPos, m_cursorPosition);
     const int w = qAbs(oldPos - m_cursorPosition);
-    update(x - offset, 9, w + 2 * offset, 6);
+    update(x - offset, 4, w + 2 * offset, 6);
 }
 
 //virtual
@@ -122,40 +128,54 @@ void SmallRuler::resizeEvent(QResizeEvent *)
     adjustScale(m_maxval);
 }
 
-// virtual
-void SmallRuler::paintEvent(QPaintEvent *e)
+void SmallRuler::updatePixmap()
 {
-
-    QPainter p(this);
-    QRect r = e->rect();
-    p.setClipRect(r);
-
+    m_pixmap = QPixmap(width(), height());
+    m_pixmap.fill(palette().window().color());
+    QPainter p(&m_pixmap);
     double f, fend;
-    p.setPen(palette().dark().color());
 
     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);
+        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.setPen(palette().dark().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.fillRect(zoneStart, height() / 2, zoneEnd - zoneStart, height() / 2, m_zoneColor);
+    // 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.end();
+    update();
+}
 
-    if (r.top() < 9) {
-        // draw the little marks
-        fend = m_scale * m_small;
-        if (fend > 2) for (f = 0; f < width(); f += fend) {
-                p.drawLine((int)f, 1, (int)f, 3);
-            }
+// virtual
+void SmallRuler::paintEvent(QPaintEvent *e)
+{
 
-        // draw medium marks
-        fend = m_scale * m_medium;
-        if (fend > 2) for (f = 0; f < width(); f += fend) {
-                p.drawLine((int)f, 1, (int)f, 5);
-            }
-    }
+    QPainter p(this);
+    QRect r = e->rect();
+    p.setClipRect(r);
+    p.drawPixmap(QPointF(), m_pixmap);
 
     // draw pointer
     QPolygon pa(3);
-    pa.setPoints(3, m_cursorPosition - 5, 14, m_cursorPosition + 5, 14, m_cursorPosition/*+0*/, 9);
+    pa.setPoints(3, m_cursorPosition - 5, 10, m_cursorPosition + 5, 10, m_cursorPosition/*+0*/, 5);
     p.setBrush(palette().dark().color());
+    p.setPen(Qt::NoPen);
     p.drawPolygon(pa);
 }
 
index 2414a502edbfbfad29af60dbbfa106e5950074f0..38c466fbf889ac69ac23ec75eec42d2e046ad3ee 100644 (file)
@@ -34,6 +34,7 @@ public:
     void adjustScale(int maximum);
     void setZone(int start, int end);
     QPoint zone();
+    void setMarkers(QList < int > list);
 
 protected:
     virtual void paintEvent(QPaintEvent *e);
@@ -49,6 +50,9 @@ private:
     int m_zoneStart;
     int m_zoneEnd;
     QColor m_zoneColor;
+    QList <int> m_markers;
+    QPixmap m_pixmap;
+    void updatePixmap();
 
 public slots:
     void slotNewValue(int value);
index edf0f36b16e1b8ad3a0ffcae3323a4c977e48ed2..9a15a1000c614466d1ee99ce85af82ed59534739 100644 (file)
@@ -1,7 +1,8 @@
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
  <class>Monitor_UI</class>
- <widget class="QWidget" name="Monitor_UI" >
-  <property name="geometry" >
+ <widget class="QWidget" name="Monitor_UI">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <height>177</height>
    </rect>
   </property>
-  <layout class="QGridLayout" name="gridLayout" >
-   <property name="margin" >
+  <layout class="QGridLayout" name="gridLayout">
+   <property name="margin">
     <number>0</number>
    </property>
-   <property name="spacing" >
+   <property name="spacing">
     <number>0</number>
    </property>
-   <item row="0" column="0" colspan="2" >
-    <widget class="QFrame" name="video_frame" >
-     <property name="font" >
+   <item row="0" column="0" colspan="2">
+    <widget class="QFrame" name="video_frame">
+     <property name="font">
       <font>
        <stylestrategy>NoAntialias</stylestrategy>
       </font>
      </property>
-     <property name="lineWidth" >
+     <property name="lineWidth">
       <number>0</number>
      </property>
     </widget>
    </item>
-   <item row="1" column="0" colspan="2" >
-    <widget class="QFrame" name="ruler_frame" >
-     <property name="sizePolicy" >
-      <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
+   <item row="1" column="0" colspan="2">
+    <widget class="QFrame" name="ruler_frame">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
        <horstretch>0</horstretch>
        <verstretch>0</verstretch>
       </sizepolicy>
      </property>
-     <property name="minimumSize" >
+     <property name="minimumSize">
       <size>
        <width>16</width>
-       <height>15</height>
+       <height>10</height>
       </size>
      </property>
-     <property name="maximumSize" >
+     <property name="maximumSize">
       <size>
        <width>16777215</width>
-       <height>15</height>
+       <height>10</height>
       </size>
      </property>
-     <property name="lineWidth" >
+     <property name="lineWidth">
       <number>0</number>
      </property>
     </widget>
    </item>
-   <item row="2" column="0" colspan="2" >
-    <widget class="QFrame" name="button_frame" >
-     <property name="sizePolicy" >
-      <sizepolicy vsizetype="Maximum" hsizetype="Preferred" >
+   <item row="2" column="0" colspan="2">
+    <widget class="QFrame" name="button_frame">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Preferred" vsizetype="Maximum">
        <horstretch>0</horstretch>
        <verstretch>0</verstretch>
       </sizepolicy>
      </property>
-     <property name="minimumSize" >
+     <property name="minimumSize">
       <size>
        <width>0</width>
        <height>15</height>
       </size>
      </property>
-     <property name="lineWidth" >
+     <property name="lineWidth">
       <number>0</number>
      </property>
     </widget>