1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
21 #include "customtrackview.h"
22 #include "kdenlivesettings.h"
28 #include <QStyleOptionGraphicsItem>
30 Guide::Guide(CustomTrackView *view, GenTime pos, QString label, double fps, double height) :
38 setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIgnoresTransformations);
40 setLine(0, 0, 0, height);
41 setPos(m_position.frames(m_fps), 0);
43 m_pen.setColor(QColor(0, 0, 200, 180));
44 //m_pen.setCosmetic(true);
47 setAcceptsHoverEvents(true);
48 const QFontMetrics metric = m_view->fontMetrics();
49 m_width = metric.width(' ' + m_label + ' ') + 2;
50 prepareGeometryChange();
53 QString Guide::label() const
58 GenTime Guide::position() const
63 CommentedTime Guide::info() const
65 return CommentedTime(m_position, m_label);
68 void Guide::updateGuide(const GenTime newPos, const QString &comment)
71 setPos(m_position.frames(m_fps), 0);
72 if (!comment.isEmpty()) {
75 const QFontMetrics metric = m_view->fontMetrics();
76 m_width = metric.width(' ' + m_label + ' ') + 2;
77 prepareGeometryChange();
82 int Guide::type() const
88 void Guide::hoverEnterEvent(QGraphicsSceneHoverEvent *)
90 m_pen.setColor(QColor(200, 0, 0, 180));
95 void Guide::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
97 m_pen.setColor(QColor(0, 0, 200, 180));
102 QVariant Guide::itemChange(GraphicsItemChange change, const QVariant &value)
104 if (change == ItemPositionChange && scene()) {
105 // value is the new position.
106 QPointF newPos = value.toPointF();
108 newPos.setX(m_view->getSnapPointForPos(newPos.x()));
111 return QGraphicsItem::itemChange(change, value);
115 QRectF Guide::boundingRect() const
117 double scale = m_view->matrix().m11();
118 double width = m_pen.widthF() / scale * 2;
119 QRectF rect(line().x1() - width / 2 , line().y1(), width, line().y2() - line().y1());
120 if (KdenliveSettings::showmarkers()) {
121 rect.setWidth(width + m_width / scale);
127 QPainterPath Guide::shape() const
130 if (!scene()) return path;
131 double scale = m_view->matrix().m11();
132 double width = m_pen.widthF() / scale * 2;
133 path.addRect(line().x1() - width / 2 , line().y1(), width, line().y2() - line().y1());
134 if (KdenliveSettings::showmarkers()) {
135 const QFontMetrics metric = m_view->fontMetrics();
136 QRectF txtBounding(line().x1() + 1 / scale, line().y1() + 10, m_width / scale, metric.height() / m_view->matrix().m22());
137 path.addRect(txtBounding);
143 void Guide::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget */*w*/)
145 QGraphicsLineItem::paint(painter, option);
146 if (KdenliveSettings::showmarkers()) {
147 QPointF p1 = line().p1() + QPointF(1, 0);
148 const QFontMetrics metric = m_view->fontMetrics();
149 QRectF txtBounding = painter->boundingRect(p1.x(), p1.y() + 10, m_width, metric.height(), Qt::AlignLeft | Qt::AlignTop, ' ' + m_label + ' ');
151 path.addRoundedRect(txtBounding, 3, 3);
152 painter->fillPath(path, m_pen.color());
153 painter->setPen(Qt::white);
154 painter->drawText(txtBounding, Qt::AlignCenter, m_label);