X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fguide.cpp;h=ba05ec6aef126841aa744ae0cbe494b013b5c1d9;hb=c3302003093710ee247ad84c0fe2ef3c579d417f;hp=1cf781e211e30cec6f73ec7f6a9284fc8fa3efd4;hpb=7b455016c894c4338cbd777f62abe9e9b90b1b67;p=kdenlive diff --git a/src/guide.cpp b/src/guide.cpp index 1cf781e2..ba05ec6a 100644 --- a/src/guide.cpp +++ b/src/guide.cpp @@ -17,73 +17,156 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ - -#include -#include +#include "guide.h" +#include "customtrackview.h" +#include "kdenlivesettings.h" #include -#include "guide.h" -#include "customtrackview.h" +#include +#include +#include +#include +#include -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) { - setFlags(QGraphicsItem::ItemIsMovable); +Guide::Guide(CustomTrackView *view, const GenTime &pos, const QString &label, double height) : + QGraphicsLineItem(), + m_position(pos), + m_label(label), + m_view(view), + m_pen(QPen()) +{ + 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) * scale, 0); - setPen(QPen(QBrush(QColor(0, 0, 200, 180)), 2)); + 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(); + m_width = metric.width(' ' + m_label + ' ') + 2; + prepareGeometryChange(); } - -void Guide::updatePosition(double scale) { - setPos(m_position.frames(m_fps) * scale, 0); - m_scale = scale; -} - -QString Guide::label() const { +QString Guide::label() const +{ return m_label; } -GenTime Guide::position() const { +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; - if (comment != QString()) { + setPos(m_position.frames(m_view->fps()), 0); + if (!comment.isEmpty()) { m_label = comment; setToolTip(m_label); + const QFontMetrics metric = m_view->fontMetrics(); + m_width = metric.width(' ' + m_label + ' ') + 2; + prepareGeometryChange(); } } +void Guide::updatePos() +{ + setPos(m_position.frames(m_view->fps()), 0); +} + //virtual -int Guide::type() const { +int Guide::type() const +{ return GUIDEITEM; } //virtual -void Guide::hoverEnterEvent(QGraphicsSceneHoverEvent *) { - setPen(QPen(QBrush(QColor(200, 0, 0, 180)), 2)); +void Guide::hoverEnterEvent(QGraphicsSceneHoverEvent *) +{ + 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)); +void Guide::hoverLeaveEvent(QGraphicsSceneHoverEvent *) +{ + m_pen.setColor(QColor(0, 0, 200, 180)); + setPen(m_pen); } //virtual -QVariant Guide::itemChange(GraphicsItemChange change, const QVariant &value) { +QVariant Guide::itemChange(GraphicsItemChange change, const QVariant &value) +{ if (change == ItemPositionChange && scene()) { // 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())); + if (newPos.x() < 0.0) newPos.setX(0.0); return newPos; } return QGraphicsItem::itemChange(change, 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()) { + // +3 to cover the arc at the end of the comment + rect.setWidth(width + m_width + 3); + } + 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() && scene()->views().count()) { + const QFontMetrics metric = m_view->fontMetrics(); + int offset = scene()->views()[0]->verticalScrollBar()->value(); + QRectF txtBounding(line().x1(), line().y1() + offset, m_width, metric.height()); + path.addRect(txtBounding); + } + return path; +} + +// virtual +void Guide::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget */*w*/) +{ + QGraphicsLineItem::paint(painter, option); + if (KdenliveSettings::showmarkers() && scene() && scene()->views().count()) { + QPointF p1 = line().p1(); + const QFontMetrics metric = m_view->fontMetrics(); + 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.adjusted(1, 0, 1, 0), Qt::AlignCenter, m_label); + } +} +