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)
31 : QGraphicsLineItem(), m_view(view), m_position(pos), m_label(label), m_fps(fps) {
32 setFlags(QGraphicsItem::ItemIsMovable);
34 setLine(0, 0, 0, height);
35 setPos(m_position.frames(m_fps), 0);
36 setPen(QPen(QBrush(QColor(0, 0, 200, 180)), 1));
38 setAcceptsHoverEvents(true);
39 const QFontMetrics metric = m_view->fontMetrics();
40 m_width = metric.width(' ' + m_label + ' ') + 2;
41 prepareGeometryChange();
44 QString Guide::label() const {
48 GenTime Guide::position() const {
52 CommentedTime Guide::info() const {
53 return CommentedTime(m_position, m_label);
56 void Guide::updateGuide(const GenTime newPos, const QString &comment) {
58 setPos(m_position.frames(m_fps), 0);
59 if (!comment.isEmpty()) {
62 const QFontMetrics metric = m_view->fontMetrics();
63 m_width = metric.width(' ' + m_label + ' ') + 2;
64 prepareGeometryChange();
69 int Guide::type() const {
74 void Guide::hoverEnterEvent(QGraphicsSceneHoverEvent *) {
75 setPen(QPen(QBrush(QColor(200, 0, 0, 180)), 2));
79 void Guide::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
80 setPen(QPen(QBrush(QColor(0, 0, 200, 180)), 2));
84 QVariant Guide::itemChange(GraphicsItemChange change, const QVariant &value) {
85 if (change == ItemPositionChange && scene()) {
86 // value is the new position.
87 QPointF newPos = value.toPointF();
89 newPos.setX(m_view->getSnapPointForPos(newPos.x()));
92 return QGraphicsItem::itemChange(change, value);
96 QRectF Guide::boundingRect() const {
97 if (KdenliveSettings::showmarkers()) {
98 QRectF rect = QGraphicsLineItem::boundingRect();
99 rect.setLeft(line().x1());
100 rect.setWidth(m_width / static_cast <CustomTrackScene*>(scene())->scale());
102 } else return QGraphicsLineItem::boundingRect();
106 void Guide::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *w) {
107 painter->setMatrixEnabled(false);
108 QLineF guideline = painter->matrix().map(line());
109 painter->setPen(pen());
110 painter->drawLine(guideline);
111 //painter->fillRect(painter->matrix().mapRect(boundingRect()), QColor(200, 100, 100, 100));
112 //QGraphicsLineItem::paint(painter, option, w);
113 if (KdenliveSettings::showmarkers()) {
114 QPointF p1 = guideline.p1() + QPointF(1, 0);
115 QRectF txtBounding = painter->boundingRect(p1.x(), p1.y() + 10, m_width, 50, Qt::AlignLeft | Qt::AlignTop, ' ' + m_label + ' ');
117 path.addRoundedRect(txtBounding, 3, 3);
118 painter->fillPath(path, QBrush(pen().color()));
119 painter->setPen(Qt::white);
120 painter->drawText(txtBounding, Qt::AlignCenter, m_label);