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 <QMouseEvent>
22 #include <QStylePainter>
26 #include "smallruler.h"
29 SmallRuler::SmallRuler(QWidget *parent)
30 : QWidget(parent), m_scale(1), m_maxval(25) {
35 void SmallRuler::adjustScale(int maximum) {
37 m_scale = (double) width() / (double) maximum;
38 if (m_scale == 0) m_scale = 1;
43 } else if (m_scale > 0.09) {
50 m_cursorPosition = m_cursorFramePosition * m_scale;
54 void SmallRuler::setZone(int start, int end) {
56 if (end != -1 && start >= end) return;
57 else if (end == -1 && start >= m_zoneEnd) return;
61 if (start != -1 && end <= start) end = m_zoneEnd;
62 else if (start == -1 && end <= m_zoneStart) end = m_zoneEnd;
68 QPoint SmallRuler::zone() {
69 return QPoint(m_zoneStart, m_zoneEnd);
73 void SmallRuler::mousePressEvent(QMouseEvent * event) {
74 const int pos = event->x() / m_scale;
75 emit seekRenderer((int) pos);
79 void SmallRuler::mouseMoveEvent(QMouseEvent * event) {
80 const int pos = event->x() / m_scale;
81 emit seekRenderer((int) pos);
84 void SmallRuler::slotNewValue(int value) {
85 m_cursorFramePosition = value;
86 int oldPos = m_cursorPosition;
87 m_cursorPosition = value * m_scale;
88 if (oldPos == m_cursorPosition) return;
90 const int x = qMin(oldPos, m_cursorPosition);
91 const int w = qAbs(oldPos - m_cursorPosition);
92 update(x - offset, 9, w + 2 * offset, 6);
96 void SmallRuler::resizeEvent(QResizeEvent *) {
97 adjustScale(m_maxval);
101 void SmallRuler::paintEvent(QPaintEvent *e) {
108 p.setPen(palette().dark().color());
110 const int zoneStart = (int)(m_zoneStart * m_scale);
111 const int zoneEnd = (int)(m_zoneEnd * m_scale);
113 p.fillRect(QRect(zoneStart, height() / 2, zoneEnd - zoneStart, height() / 2), QBrush(QColor(133, 255, 143)));
116 // draw the little marks
117 fend = m_scale * m_small;
118 if (fend > 2) for (f = 0; f < width(); f += fend) {
119 p.drawLine((int)f, 1, (int)f, 3);
123 fend = m_scale * m_medium;
124 if (fend > 2) for (f = 0; f < width(); f += fend) {
125 p.drawLine((int)f, 1, (int)f, 5);
131 pa.setPoints(3, m_cursorPosition - 5, 14, m_cursorPosition + 5, 14, m_cursorPosition/*+0*/, 9);
132 p.setBrush(palette().dark().color());
136 #include "smallruler.moc"