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 height) :
37 setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIgnoresTransformations);
38 #if QT_VERSION >= 0x040600
39 setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
42 setLine(0, 0, 0, height);
43 setPos(m_position.frames(m_view->fps()), 0);
45 m_pen.setColor(QColor(0, 0, 200, 180));
46 //m_pen.setCosmetic(true);
49 setAcceptsHoverEvents(true);
50 const QFontMetrics metric = m_view->fontMetrics();
51 m_width = metric.width(' ' + m_label + ' ') + 2;
52 prepareGeometryChange();
55 QString Guide::label() const
60 GenTime Guide::position() const
65 CommentedTime Guide::info() const
67 return CommentedTime(m_position, m_label);
70 void Guide::updateGuide(const GenTime newPos, const QString &comment)
73 setPos(m_position.frames(m_view->fps()), 0);
74 if (!comment.isEmpty()) {
77 const QFontMetrics metric = m_view->fontMetrics();
78 m_width = metric.width(' ' + m_label + ' ') + 2;
79 prepareGeometryChange();
83 void Guide::updatePos()
85 setPos(m_position.frames(m_view->fps()), 0);
89 int Guide::type() const
95 void Guide::hoverEnterEvent(QGraphicsSceneHoverEvent *)
97 m_pen.setColor(QColor(200, 0, 0, 180));
102 void Guide::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
104 m_pen.setColor(QColor(0, 0, 200, 180));
109 QVariant Guide::itemChange(GraphicsItemChange change, const QVariant &value)
111 if (change == ItemPositionChange && scene()) {
112 // value is the new position.
113 QPointF newPos = value.toPointF();
115 newPos.setX(m_view->getSnapPointForPos(newPos.x()));
118 return QGraphicsItem::itemChange(change, value);
122 QRectF Guide::boundingRect() const
124 double scale = m_view->matrix().m11();
125 double width = m_pen.widthF() / scale * 2;
126 QRectF rect(line().x1() - width / 2 , line().y1(), width, line().y2() - line().y1());
127 if (KdenliveSettings::showmarkers()) {
128 rect.setWidth(width + m_width);
134 QPainterPath Guide::shape() const
137 if (!scene()) return path;
138 double width = m_pen.widthF() * 2;
139 path.addRect(line().x1() - width / 2 , line().y1(), width, line().y2() - line().y1());
140 if (KdenliveSettings::showmarkers()) {
141 const QFontMetrics metric = m_view->fontMetrics();
142 QRectF txtBounding(line().x1(), line().y1() + 10, m_width, metric.height());
143 path.addRect(txtBounding);
149 void Guide::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget */*w*/)
151 QGraphicsLineItem::paint(painter, option);
152 if (KdenliveSettings::showmarkers()) {
153 QPointF p1 = line().p1() + QPointF(1, 0);
154 const QFontMetrics metric = m_view->fontMetrics();
155 QRectF txtBounding = painter->boundingRect(p1.x(), p1.y() + 10, m_width, metric.height(), Qt::AlignLeft | Qt::AlignTop, ' ' + m_label + ' ');
157 path.addRoundedRect(txtBounding, 3, 3);
158 painter->fillPath(path, m_pen.color());
159 painter->setPen(Qt::white);
160 painter->drawText(txtBounding, Qt::AlignCenter, m_label);