]> git.sesse.net Git - kdenlive/blobdiff - src/guide.cpp
Integrate with the required MLT hooks for getting Movit to work.
[kdenlive] / src / guide.cpp
index 299a82b07f8b4f4b7659f855232601fe38ccbd65..ba05ec6aef126841aa744ae0cbe494b013b5c1d9 100644 (file)
 #include <QPen>
 #include <QBrush>
 #include <QStyleOptionGraphicsItem>
+#include <QGraphicsView>
+#include <QScrollBar>
 
-Guide::Guide(CustomTrackView *view, GenTime pos, QString label, double height) :
+Guide::Guide(CustomTrackView *view, const GenTime &pos, const QString &label, double height) :
         QGraphicsLineItem(),
         m_position(pos),
         m_label(label),
@@ -68,7 +70,7 @@ CommentedTime Guide::info() const
     return CommentedTime(m_position, m_label);
 }
 
-void Guide::updateGuide(const GenTime newPos, const QString &comment)
+void Guide::updateGuide(const GenTime &newPos, const QString &comment)
 {
     m_position = newPos;
     setPos(m_position.frames(m_view->fps()), 0);
@@ -127,7 +129,8 @@ QRectF Guide::boundingRect() const
     double width = m_pen.widthF() / scale * 2;
     QRectF rect(line().x1() - width / 2 , line().y1(), width, line().y2() - line().y1());
     if (KdenliveSettings::showmarkers()) {
-        rect.setWidth(width + m_width);
+        // +3 to cover the arc at the end of the comment
+        rect.setWidth(width + m_width + 3);
     }
     return rect;
 }
@@ -139,9 +142,10 @@ QPainterPath Guide::shape() const
     if (!scene()) return path;
     double width = m_pen.widthF() * 2;
     path.addRect(line().x1() - width / 2 , line().y1(), width, line().y2() - line().y1());
-    if (KdenliveSettings::showmarkers()) {
+    if (KdenliveSettings::showmarkers() && scene()->views().count()) {
         const QFontMetrics metric = m_view->fontMetrics();
-        QRectF txtBounding(line().x1(), line().y1() + 10, m_width, metric.height());
+        int offset = scene()->views()[0]->verticalScrollBar()->value();
+        QRectF txtBounding(line().x1(), line().y1() + offset, m_width, metric.height());
         path.addRect(txtBounding);
     }
     return path;
@@ -151,15 +155,18 @@ QPainterPath Guide::shape() const
 void Guide::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget */*w*/)
 {
     QGraphicsLineItem::paint(painter, option);
-    if (KdenliveSettings::showmarkers()) {
-        QPointF p1 = line().p1() + QPointF(1, 0);
+    if (KdenliveSettings::showmarkers() && scene() && scene()->views().count()) {
+        QPointF p1 = line().p1();
         const QFontMetrics metric = m_view->fontMetrics();
-        QRectF txtBounding = painter->boundingRect(p1.x(), p1.y() + 10, m_width, metric.height(), Qt::AlignLeft | Qt::AlignTop, ' ' + m_label + ' ');
-        QPainterPath path;
-        path.addRoundedRect(txtBounding, 3, 3);
-        painter->fillPath(path, m_pen.color());
+       painter->setClipRect(option->rect);
+        // makes sure the text stays visible when scrolling vertical
+        int offset = scene()->views()[0]->verticalScrollBar()->value();
+
+        QRectF txtBounding = painter->boundingRect(p1.x(), p1.y() + offset, m_width, metric.height(), Qt::AlignLeft | Qt::AlignTop, m_label);
+       painter->setBrush(QBrush(m_pen.color()));
+       painter->drawRoundedRect(txtBounding.adjusted(-5, -5, 2, 1), 3, 3);
         painter->setPen(Qt::white);
-        painter->drawText(txtBounding, Qt::AlignCenter, m_label);
+        painter->drawText(txtBounding.adjusted(1, 0, 1, 0), Qt::AlignCenter, m_label);
     }
 }