]> git.sesse.net Git - kdenlive/blob - src/smallruler.cpp
Comment out names of unused parameters [PATCH by Ray Lehtiniemi]
[kdenlive] / src / smallruler.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20
21 #include "smallruler.h"
22
23 #include <KDebug>
24
25 #include <QMouseEvent>
26 #include <QStylePainter>
27
28 SmallRuler::SmallRuler(QWidget *parent)
29         : QWidget(parent), m_scale(1), m_maxval(25) {
30     m_zoneStart = 10;
31     m_zoneEnd = 60;
32 }
33
34 void SmallRuler::adjustScale(int maximum) {
35     m_maxval = maximum;
36     m_scale = (double) width() / (double) maximum;
37     if (m_scale == 0) m_scale = 1;
38
39     if (m_scale > 0.5) {
40         m_small = 25;
41         m_medium = 5 * 25;
42     } else if (m_scale > 0.09) {
43         m_small = 5 * 25;
44         m_medium = 30 * 25;
45     } else {
46         m_small = 30 * 25;
47         m_medium = 60 * 25;
48     }
49     m_cursorPosition = m_cursorFramePosition * m_scale;
50     update();
51 }
52
53 void SmallRuler::setZone(int start, int end) {
54     if (start != -1) {
55         if (end != -1 && start >= end) {
56             m_zoneEnd = qMin(m_maxval, end + (start - m_zoneStart));
57             m_zoneStart = start;
58         } else if (end == -1 && start >= m_zoneEnd) {
59             m_zoneEnd = qMin(m_maxval, m_zoneEnd + (start - m_zoneStart));
60             m_zoneStart = start;
61         } else m_zoneStart = start;
62     }
63     if (end != -1) {
64         if (start != -1 && end <= start) {
65             m_zoneStart = qMax(0, start - (m_zoneEnd - end));
66             m_zoneEnd = end;
67         } else if (start == -1 && end <= m_zoneStart) {
68             m_zoneStart = qMax(0, m_zoneStart - (m_zoneEnd - end));
69             m_zoneEnd = end;
70         } else m_zoneEnd = end;
71     }
72     update();
73 }
74
75 QPoint SmallRuler::zone() {
76     return QPoint(m_zoneStart, m_zoneEnd);
77 }
78
79 // virtual
80 void SmallRuler::mousePressEvent(QMouseEvent * event) {
81     const int pos = event->x() / m_scale;
82     if (event->button() == Qt::RightButton) {
83         // Right button clicked, move selection zone
84         if (qAbs(pos - m_zoneStart) < qAbs(pos - m_zoneEnd)) m_zoneStart = pos;
85         else m_zoneEnd = pos;
86         emit zoneChanged(QPoint(m_zoneStart, m_zoneEnd));
87         update();
88
89     } else emit seekRenderer((int) pos);
90 }
91
92 // virtual
93 void SmallRuler::mouseMoveEvent(QMouseEvent * event) {
94     const int pos = event->x() / m_scale;
95     if (event->buttons() & Qt::LeftButton) emit seekRenderer((int) pos);
96 }
97
98 void SmallRuler::slotNewValue(int value) {
99     m_cursorFramePosition = value;
100     int oldPos = m_cursorPosition;
101     m_cursorPosition = value * m_scale;
102     if (oldPos == m_cursorPosition) return;
103     const int offset = 6;
104     const int x = qMin(oldPos, m_cursorPosition);
105     const int w = qAbs(oldPos - m_cursorPosition);
106     update(x - offset, 9, w + 2 * offset, 6);
107 }
108
109 //virtual
110 void SmallRuler::resizeEvent(QResizeEvent *) {
111     adjustScale(m_maxval);
112 }
113
114 // virtual
115 void SmallRuler::paintEvent(QPaintEvent *e) {
116
117     QPainter p(this);
118     QRect r = e->rect();
119     p.setClipRect(r);
120
121     double f, fend;
122     p.setPen(palette().dark().color());
123
124     const int zoneStart = (int)(m_zoneStart * m_scale);
125     const int zoneEnd = (int)(m_zoneEnd * m_scale);
126
127     p.fillRect(QRect(zoneStart, height() / 2, zoneEnd - zoneStart, height() / 2), QBrush(QColor(133, 255, 143)));
128
129     if (r.top() < 9) {
130         // draw the little marks
131         fend = m_scale * m_small;
132         if (fend > 2) for (f = 0; f < width(); f += fend) {
133                 p.drawLine((int)f, 1, (int)f, 3);
134             }
135
136         // draw medium marks
137         fend = m_scale * m_medium;
138         if (fend > 2) for (f = 0; f < width(); f += fend) {
139                 p.drawLine((int)f, 1, (int)f, 5);
140             }
141     }
142
143     // draw pointer
144     QPolygon pa(3);
145     pa.setPoints(3, m_cursorPosition - 5, 14, m_cursorPosition + 5, 14, m_cursorPosition/*+0*/, 9);
146     p.setBrush(palette().dark().color());
147     p.drawPolygon(pa);
148 }
149
150 #include "smallruler.moc"