X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fguide.cpp;h=bbc2a6bd10ff1eca5d31fcb95c8287c1cfd296a1;hb=7bdee3646c2dfbd8366093c8c9c6b8d675fa5bf1;hp=1cf781e211e30cec6f73ec7f6a9284fc8fa3efd4;hpb=7b455016c894c4338cbd777f62abe9e9b90b1b67;p=kdenlive diff --git a/src/guide.cpp b/src/guide.cpp index 1cf781e2..bbc2a6bd 100644 --- a/src/guide.cpp +++ b/src/guide.cpp @@ -20,27 +20,27 @@ #include #include +#include #include #include "guide.h" #include "customtrackview.h" +#include "customtrackscene.h" +#include "kdenlivesettings.h" -Guide::Guide(CustomTrackView *view, GenTime pos, QString label, double scale, double fps, double height) - : QGraphicsLineItem(), m_view(view), m_position(pos), m_label(label), m_scale(scale), m_fps(fps) { +Guide::Guide(CustomTrackView *view, GenTime pos, QString label, double fps, double height) + : QGraphicsLineItem(), m_view(view), m_position(pos), m_label(label), m_fps(fps) { setFlags(QGraphicsItem::ItemIsMovable); setToolTip(label); setLine(0, 0, 0, height); - setPos(m_position.frames(m_fps) * scale, 0); - setPen(QPen(QBrush(QColor(0, 0, 200, 180)), 2)); + setPos(m_position.frames(m_fps), 0); + setPen(QPen(QBrush(QColor(0, 0, 200, 180)), 1)); setZValue(999); setAcceptsHoverEvents(true); -} - - -void Guide::updatePosition(double scale) { - setPos(m_position.frames(m_fps) * scale, 0); - m_scale = scale; + const QFontMetrics metric = m_view->fontMetrics(); + m_width = metric.width(" " + m_label + " ") + 2; + prepareGeometryChange(); } QString Guide::label() const { @@ -51,11 +51,19 @@ GenTime Guide::position() const { return m_position; } -void Guide::update(const GenTime newPos, const QString &comment) { +CommentedTime Guide::info() const { + return CommentedTime(m_position, m_label); +} + +void Guide::updateGuide(const GenTime newPos, const QString &comment) { m_position = newPos; + setPos(m_position.frames(m_fps), 0); if (comment != QString()) { m_label = comment; setToolTip(m_label); + const QFontMetrics metric = m_view->fontMetrics(); + m_width = metric.width(" " + m_label + " ") + 2; + prepareGeometryChange(); } } @@ -80,10 +88,38 @@ QVariant Guide::itemChange(GraphicsItemChange change, const QVariant &value) { // value is the new position. QPointF newPos = value.toPointF(); newPos.setY(0); - const double offset = m_position.frames(m_fps) * m_scale; - newPos.setX(m_view->getSnapPointForPos(offset + newPos.x()) - offset); + newPos.setX(m_view->getSnapPointForPos(newPos.x())); return newPos; } return QGraphicsItem::itemChange(change, value); } +// virtual +QRectF Guide::boundingRect() const { + if (KdenliveSettings::showmarkers()) { + QRectF rect = QGraphicsLineItem::boundingRect(); + rect.setLeft(line().x1()); + rect.setWidth(m_width / static_cast (scene())->scale()); + return rect; + } else return QGraphicsLineItem::boundingRect(); +} + +// virtual +void Guide::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *w) { + painter->setMatrixEnabled(false); + QLineF guideline = painter->matrix().map(line()); + painter->setPen(pen()); + painter->drawLine(guideline); + //painter->fillRect(painter->matrix().mapRect(boundingRect()), QColor(200, 100, 100, 100)); + //QGraphicsLineItem::paint(painter, option, w); + if (KdenliveSettings::showmarkers()) { + QPointF p1 = guideline.p1() + QPointF(1, 0); + QRectF txtBounding = painter->boundingRect(p1.x(), p1.y() + 10, m_width, 50, Qt::AlignLeft | Qt::AlignTop, " " + m_label + " "); + QPainterPath path; + path.addRoundedRect(txtBounding, 3, 3); + painter->fillPath(path, QBrush(pen().color())); + painter->setPen(Qt::white); + painter->drawText(txtBounding, Qt::AlignCenter, m_label); + } +} +