X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fguide.cpp;h=47ba15e20a775508899cc7ea155242a7a358b764;hb=cbf0c0c6e3ecf82381e9a7fd41154f600c2456f4;hp=49b304c71cc03693c0befda83ac9885dddcd847b;hpb=97d1d53cd0d87776569622a47c2aceb8da270a7b;p=kdenlive diff --git a/src/guide.cpp b/src/guide.cpp index 49b304c7..47ba15e2 100644 --- a/src/guide.cpp +++ b/src/guide.cpp @@ -26,6 +26,8 @@ #include #include #include +#include +#include Guide::Guide(CustomTrackView *view, GenTime pos, QString label, double height) : QGraphicsLineItem(), @@ -40,6 +42,7 @@ Guide::Guide(CustomTrackView *view, GenTime pos, QString label, double height) : #endif setToolTip(label); setLine(0, 0, 0, height); + if (m_position < GenTime()) m_position = GenTime(); setPos(m_position.frames(m_view->fps()), 0); m_pen.setWidthF(0); m_pen.setColor(QColor(0, 0, 200, 180)); @@ -67,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); @@ -113,6 +116,7 @@ QVariant Guide::itemChange(GraphicsItemChange change, const QVariant &value) QPointF newPos = value.toPointF(); newPos.setY(0); newPos.setX(m_view->getSnapPointForPos(newPos.x())); + if (newPos.x() < 0.0) newPos.setX(0.0); return newPos; } return QGraphicsItem::itemChange(change, value); @@ -125,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; } @@ -137,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; @@ -149,15 +155,23 @@ 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 + ' '); + + // 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); + // draw the text on a rect with a arc appended QPainterPath path; - path.addRoundedRect(txtBounding, 3, 3); + path.moveTo(txtBounding.bottomRight()); + path.arcTo(txtBounding.right() - txtBounding.height() - 2, txtBounding.top() - txtBounding.height(), txtBounding.height() * 2, txtBounding.height() * 2, 270, 90); + path.lineTo(txtBounding.topLeft()); + path.lineTo(txtBounding.bottomLeft()); painter->fillPath(path, m_pen.color()); painter->setPen(Qt::white); - painter->drawText(txtBounding, Qt::AlignCenter, m_label); + painter->drawText(txtBounding.adjusted(1, 0, 1, 0), Qt::AlignCenter, m_label); } }