]> git.sesse.net Git - kdenlive/blob - src/smallruler.cpp
indent fixes and give more info on capture failure
[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 <QMouseEvent>
22 #include <QStylePainter>
23
24 #include <KDebug>
25
26 #define LITTLE_MARK_X2 8
27 #define LITTLE_MARK_X1 5
28 #define MIDDLE_MARK_X1 3
29 #define MIDDLE_MARK_X2 8
30
31 #define LABEL_SIZE 8
32
33 #include "smallruler.h"
34
35
36 SmallRuler::SmallRuler(QWidget *parent)
37         : KRuler(parent) {
38     setShowPointer(true);
39     setShowBigMarks(false);
40     setShowTinyMarks(false);
41     slotNewOffset(0);
42     setRulerMetricStyle(KRuler::Custom);
43     setLengthFixed(true);
44 }
45
46 void SmallRuler::setPixelPerMark(double rate) {
47     kDebug() << " RULER SET RATE: " << rate;
48     if (rate > 0.5) {
49         setLittleMarkDistance(25);
50         setMediumMarkDistance(5 * 25);
51     } else if (rate > 0.09) {
52         setLittleMarkDistance(5 * 25);
53         setMediumMarkDistance(30 * 25);
54     } else {
55         setLittleMarkDistance(30 * 25);
56         setMediumMarkDistance(60 * 25);
57     }
58
59     KRuler::setPixelPerMark(rate);
60 }
61
62 // virtual
63 void SmallRuler::mousePressEvent(QMouseEvent * event) {
64     double pos = event->x() / pixelPerMark();
65     emit seekRenderer((int) pos);
66 }
67
68 // virtual
69 void SmallRuler::mouseMoveEvent(QMouseEvent * event) {
70     double pos = event->x() / pixelPerMark();
71     emit seekRenderer((int) pos);
72 }
73
74 void SmallRuler::slotNewValue(int _value) {
75     m_cursorPosition = (int)(_value);  /// pixelPerMark());
76     KRuler::slotNewValue(_value * pixelPerMark());
77 }
78
79 // virtual
80 void SmallRuler::paintEvent(QPaintEvent *e) {
81     //  debug ("KRuler::drawContents, %s",(horizontal==dir)?"horizontal":"vertical");
82
83     QStylePainter p(this);
84     p.fillRect(e->rect(), QBrush(QColor(Qt::white)));
85
86
87     int value  = this->value(),
88                  minval = minimum(),
89                           maxval;
90     maxval = maximum()
91              + offset() - endOffset();
92
93     //ioffsetval = value-offset;
94     //    pixelpm = (int)ppm;
95     //    left  = clip.left(),
96     //    right = clip.right();
97     double f, fend,
98     offsetmin = (double)(minval - offset()),
99                 offsetmax = (double)(maxval - offset()),
100                             fontOffset = (((double)minval) > offsetmin) ? (double)minval : offsetmin;
101
102     // draw labels
103     QFont font = p.font();
104     font.setPointSize(LABEL_SIZE);
105     p.setFont(font);
106
107     if (showLittleMarks()) {
108         // draw the little marks
109         fend = pixelPerMark() * littleMarkDistance();
110         if (fend > 2) for (f = offsetmin; f < offsetmax; f += fend) {
111                 p.drawLine((int)f, LITTLE_MARK_X1, (int)f, LITTLE_MARK_X2);
112             }
113     }
114     if (showMediumMarks()) {
115         // draw medium marks
116         fend = pixelPerMark() * mediumMarkDistance();
117         if (fend > 2) for (f = offsetmin; f < offsetmax; f += fend) {
118                 p.drawLine((int)f, MIDDLE_MARK_X1, (int)f, MIDDLE_MARK_X2);
119             }
120     }
121
122     /*   if (d->showem) {
123          // draw end marks
124          if (d->dir == Qt::Horizontal) {
125            p.drawLine(minval-d->offset, END_MARK_X1, minval-d->offset, END_MARK_X2);
126            p.drawLine(maxval-d->offset, END_MARK_X1, maxval-d->offset, END_MARK_X2);
127          }
128          else {
129            p.drawLine(END_MARK_X1, minval-d->offset, END_MARK_X2, minval-d->offset);
130            p.drawLine(END_MARK_X1, maxval-d->offset, END_MARK_X2, maxval-d->offset);
131          }
132        }*/
133
134     // draw pointer
135     if (showPointer()) {
136         QPolygon pa(3);
137         pa.setPoints(3, value - 6, 0, value + 6, 0, value/*+0*/, 8);
138         p.setBrush(QBrush(Qt::yellow));
139         p.drawPolygon(pa);
140     }
141
142 }
143
144 #include "smallruler.moc"