X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fguide.cpp;h=299a82b07f8b4f4b7659f855232601fe38ccbd65;hb=0ad3e5e4cf6722cd53ed63e51608b2da2640b240;hp=80ade91236291d912fcf14e9eb545a6e74043f94;hpb=c42a026234a44a2d766e57bc64a6ac7bbd094000;p=kdenlive diff --git a/src/guide.cpp b/src/guide.cpp index 80ade912..299a82b0 100644 --- a/src/guide.cpp +++ b/src/guide.cpp @@ -19,22 +19,33 @@ #include "guide.h" #include "customtrackview.h" -#include "customtrackscene.h" #include "kdenlivesettings.h" #include #include #include +#include -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) +Guide::Guide(CustomTrackView *view, GenTime pos, QString label, double height) : + QGraphicsLineItem(), + m_position(pos), + m_label(label), + m_view(view), + m_pen(QPen()) { - setFlags(QGraphicsItem::ItemIsMovable); + setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIgnoresTransformations); +#if QT_VERSION >= 0x040600 + setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); +#endif setToolTip(label); setLine(0, 0, 0, height); - setPos(m_position.frames(m_fps), 0); - setPen(QPen(QBrush(QColor(0, 0, 200, 180)), 1)); + 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)); + //m_pen.setCosmetic(true); + setPen(m_pen); setZValue(999); setAcceptsHoverEvents(true); const QFontMetrics metric = m_view->fontMetrics(); @@ -60,7 +71,7 @@ CommentedTime Guide::info() const void Guide::updateGuide(const GenTime newPos, const QString &comment) { m_position = newPos; - setPos(m_position.frames(m_fps), 0); + setPos(m_position.frames(m_view->fps()), 0); if (!comment.isEmpty()) { m_label = comment; setToolTip(m_label); @@ -70,6 +81,11 @@ void Guide::updateGuide(const GenTime newPos, const QString &comment) } } +void Guide::updatePos() +{ + setPos(m_position.frames(m_view->fps()), 0); +} + //virtual int Guide::type() const { @@ -79,13 +95,15 @@ int Guide::type() const //virtual void Guide::hoverEnterEvent(QGraphicsSceneHoverEvent *) { - setPen(QPen(QBrush(QColor(200, 0, 0, 180)), 2)); + m_pen.setColor(QColor(200, 0, 0, 180)); + setPen(m_pen); } //virtual void Guide::hoverLeaveEvent(QGraphicsSceneHoverEvent *) { - setPen(QPen(QBrush(QColor(0, 0, 200, 180)), 2)); + m_pen.setColor(QColor(0, 0, 200, 180)); + setPen(m_pen); } //virtual @@ -96,6 +114,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); @@ -104,29 +123,41 @@ QVariant Guide::itemChange(GraphicsItemChange change, const QVariant &value) // virtual QRectF Guide::boundingRect() const { + double scale = m_view->matrix().m11(); + 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); + } + return rect; +} + +// virtual +QPainterPath Guide::shape() const +{ + QPainterPath path; + 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()) { - QRectF rect = QGraphicsLineItem::boundingRect(); - rect.setLeft(line().x1()); - rect.setWidth(m_width / static_cast (scene())->scale()); - return rect; - } else return QGraphicsLineItem::boundingRect(); + const QFontMetrics metric = m_view->fontMetrics(); + QRectF txtBounding(line().x1(), line().y1() + 10, m_width, metric.height()); + path.addRect(txtBounding); + } + return path; } // virtual -void Guide::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*w*/) +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); + QGraphicsLineItem::paint(painter, option); 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 + ' '); + QPointF p1 = line().p1() + QPointF(1, 0); + 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, QBrush(pen().color())); + painter->fillPath(path, m_pen.color()); painter->setPen(Qt::white); painter->drawText(txtBounding, Qt::AlignCenter, m_label); }