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 ***************************************************************************/
28 #include "customtrackview.h"
29 #include "customtrackscene.h"
30 #include "kdenlivesettings.h"
32 Guide::Guide(CustomTrackView *view, GenTime pos, QString label, double fps, double height)
33 : QGraphicsLineItem(), m_view(view), m_position(pos), m_label(label), m_fps(fps) {
34 setFlags(QGraphicsItem::ItemIsMovable);
36 setLine(0, 0, 0, height);
37 setPos(m_position.frames(m_fps), 0);
38 setPen(QPen(QBrush(QColor(0, 0, 200, 180)), 1));
40 setAcceptsHoverEvents(true);
41 const QFontMetrics metric = m_view->fontMetrics();
42 m_width = metric.width(" " + m_label + " ") + 2;
43 prepareGeometryChange();
46 QString Guide::label() const {
50 GenTime Guide::position() const {
54 CommentedTime Guide::info() const {
55 return CommentedTime(m_position, m_label);
58 void Guide::updateGuide(const GenTime newPos, const QString &comment) {
60 setPos(m_position.frames(m_fps), 0);
61 if (comment != QString()) {
64 const QFontMetrics metric = m_view->fontMetrics();
65 m_width = metric.width(" " + m_label + " ") + 2;
66 prepareGeometryChange();
71 int Guide::type() const {
76 void Guide::hoverEnterEvent(QGraphicsSceneHoverEvent *) {
77 setPen(QPen(QBrush(QColor(200, 0, 0, 180)), 2));
81 void Guide::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
82 setPen(QPen(QBrush(QColor(0, 0, 200, 180)), 2));
86 QVariant Guide::itemChange(GraphicsItemChange change, const QVariant &value) {
87 if (change == ItemPositionChange && scene()) {
88 // value is the new position.
89 QPointF newPos = value.toPointF();
91 newPos.setX(m_view->getSnapPointForPos(newPos.x()));
94 return QGraphicsItem::itemChange(change, value);
98 QRectF Guide::boundingRect() const {
99 if (KdenliveSettings::showmarkers()) {
100 QRectF rect = QGraphicsLineItem::boundingRect();
101 rect.setLeft(line().x1());
102 rect.setWidth(m_width / static_cast <CustomTrackScene*>(scene())->scale());
104 } else return QGraphicsLineItem::boundingRect();
108 void Guide::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *w) {
109 painter->setMatrixEnabled(false);
110 QLineF guideline = painter->matrix().map(line());
111 painter->setPen(pen());
112 painter->drawLine(guideline);
113 //painter->fillRect(painter->matrix().mapRect(boundingRect()), QColor(200, 100, 100, 100));
114 //QGraphicsLineItem::paint(painter, option, w);
115 if (KdenliveSettings::showmarkers()) {
116 QPointF p1 = guideline.p1() + QPointF(1, 0);
117 QRectF txtBounding = painter->boundingRect(p1.x(), p1.y() + 10, m_width, 50, Qt::AlignLeft | Qt::AlignTop, " " + m_label + " ");
119 path.addRoundedRect(txtBounding, 3, 3);
120 painter->fillPath(path, QBrush(pen().color()));
121 painter->setPen(Qt::white);
122 painter->drawText(txtBounding, Qt::AlignCenter, m_label);