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 "customtrackscene.h"
23 #include "kdenlivesettings.h"
30 Guide::Guide(CustomTrackView *view, GenTime pos, QString label, double fps, double height) :
37 setFlags(QGraphicsItem::ItemIsMovable);
39 setLine(0, 0, 0, height);
40 setPos(m_position.frames(m_fps), 0);
41 setPen(QPen(QBrush(QColor(0, 0, 200, 180)), 1));
43 setAcceptsHoverEvents(true);
44 const QFontMetrics metric = m_view->fontMetrics();
45 m_width = metric.width(' ' + m_label + ' ') + 2;
46 prepareGeometryChange();
49 QString Guide::label() const
54 GenTime Guide::position() const
59 CommentedTime Guide::info() const
61 return CommentedTime(m_position, m_label);
64 void Guide::updateGuide(const GenTime newPos, const QString &comment)
67 setPos(m_position.frames(m_fps), 0);
68 if (!comment.isEmpty()) {
71 const QFontMetrics metric = m_view->fontMetrics();
72 m_width = metric.width(' ' + m_label + ' ') + 2;
73 prepareGeometryChange();
78 int Guide::type() const
84 void Guide::hoverEnterEvent(QGraphicsSceneHoverEvent *)
86 setPen(QPen(QBrush(QColor(200, 0, 0, 180)), 2));
90 void Guide::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
92 setPen(QPen(QBrush(QColor(0, 0, 200, 180)), 2));
96 QVariant Guide::itemChange(GraphicsItemChange change, const QVariant &value)
98 if (change == ItemPositionChange && scene()) {
99 // value is the new position.
100 QPointF newPos = value.toPointF();
102 newPos.setX(m_view->getSnapPointForPos(newPos.x()));
105 return QGraphicsItem::itemChange(change, value);
109 QRectF Guide::boundingRect() const
111 if (KdenliveSettings::showmarkers()) {
112 QRectF rect = QGraphicsLineItem::boundingRect();
113 rect.setLeft(line().x1());
114 rect.setWidth(m_width / static_cast <CustomTrackScene*>(scene())->scale());
116 } else return QGraphicsLineItem::boundingRect();
120 void Guide::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*w*/)
122 painter->setMatrixEnabled(false);
123 QLineF guideline = painter->matrix().map(line());
124 painter->setPen(pen());
125 painter->drawLine(guideline);
126 //painter->fillRect(painter->matrix().mapRect(boundingRect()), QColor(200, 100, 100, 100));
127 //QGraphicsLineItem::paint(painter, option, w);
128 if (KdenliveSettings::showmarkers()) {
129 QPointF p1 = guideline.p1() + QPointF(1, 0);
130 QRectF txtBounding = painter->boundingRect(p1.x(), p1.y() + 10, m_width, 50, Qt::AlignLeft | Qt::AlignTop, ' ' + m_label + ' ');
132 path.addRoundedRect(txtBounding, 3, 3);
133 painter->fillPath(path, QBrush(pen().color()));
134 painter->setPen(Qt::white);
135 painter->drawText(txtBounding, Qt::AlignCenter, m_label);