X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fguide.cpp;h=4fbc53b9bbe550177836c0b66b702a18f490894b;hb=7f755f1a7f9f357991b66af8a42e46dfbe7236cd;hp=bbc2a6bd10ff1eca5d31fcb95c8287c1cfd296a1;hpb=d5e2d9e691b22dab741ed689df6d87478ba24c9f;p=kdenlive diff --git a/src/guide.cpp b/src/guide.cpp index bbc2a6bd..4fbc53b9 100644 --- a/src/guide.cpp +++ b/src/guide.cpp @@ -17,73 +17,84 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ - -#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 fps, double height) - : QGraphicsLineItem(), m_view(view), m_position(pos), m_label(label), m_fps(fps) { +#include + +#include +#include + +Guide::Guide(CustomTrackView *view, GenTime pos, QString label, double fps, double height) : + QGraphicsLineItem(), + m_position(pos), + m_label(label), + m_fps(fps), + m_view(view) +{ setFlags(QGraphicsItem::ItemIsMovable); setToolTip(label); setLine(0, 0, 0, height); setPos(m_position.frames(m_fps), 0); - setPen(QPen(QBrush(QColor(0, 0, 200, 180)), 1)); + setPen(QPen(QBrush(QColor(0, 0, 200, 180)), 2)); setZValue(999); setAcceptsHoverEvents(true); const QFontMetrics metric = m_view->fontMetrics(); - m_width = metric.width(" " + m_label + " ") + 2; + m_width = metric.width(' ' + m_label + ' ') + 2; prepareGeometryChange(); } -QString Guide::label() const { +QString Guide::label() const +{ return m_label; } -GenTime Guide::position() const { +GenTime Guide::position() const +{ return m_position; } -CommentedTime Guide::info() const { +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_fps), 0); - if (comment != QString()) { + if (!comment.isEmpty()) { m_label = comment; setToolTip(m_label); const QFontMetrics metric = m_view->fontMetrics(); - m_width = metric.width(" " + m_label + " ") + 2; + m_width = metric.width(' ' + m_label + ' ') + 2; prepareGeometryChange(); } } //virtual -int Guide::type() const { +int Guide::type() const +{ return GUIDEITEM; } //virtual -void Guide::hoverEnterEvent(QGraphicsSceneHoverEvent *) { +void Guide::hoverEnterEvent(QGraphicsSceneHoverEvent *) +{ setPen(QPen(QBrush(QColor(200, 0, 0, 180)), 2)); } //virtual -void Guide::hoverLeaveEvent(QGraphicsSceneHoverEvent *) { +void Guide::hoverLeaveEvent(QGraphicsSceneHoverEvent *) +{ setPen(QPen(QBrush(QColor(0, 0, 200, 180)), 2)); } //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(); @@ -95,17 +106,32 @@ QVariant Guide::itemChange(GraphicsItemChange change, const QVariant &value) { } // virtual -QRectF Guide::boundingRect() const { +QRectF Guide::boundingRect() const +{ if (KdenliveSettings::showmarkers()) { QRectF rect = QGraphicsLineItem::boundingRect(); rect.setLeft(line().x1()); - rect.setWidth(m_width / static_cast (scene())->scale()); + rect.setWidth(m_width / static_cast (scene())->scale().x()); return rect; } else return QGraphicsLineItem::boundingRect(); } // virtual -void Guide::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *w) { +QPainterPath Guide::shape() const +{ + QPainterPath path; + path.addRect(line().x1() - pen().widthF() / 2, line().y1(), pen().widthF(), line().y2() - line().y1()); + if (KdenliveSettings::showmarkers()) { + const QFontMetrics metric = m_view->fontMetrics(); + int height = metric.height(); + path.addRoundedRect(line().x1(), line().y1() + 10, m_width / static_cast (scene())->scale().x(), height, 3, 3); + } + return path; +} + +// virtual +void Guide::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*w*/) +{ painter->setMatrixEnabled(false); QLineF guideline = painter->matrix().map(line()); painter->setPen(pen()); @@ -114,7 +140,7 @@ void Guide::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi //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 + " "); + 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()));