]> git.sesse.net Git - kdenlive/blob - src/smallruler.cpp
Reindent all source files
[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     int pos = event->x();
65     //slotNewValue( pos );
66     emit seekRenderer(pos);
67     kDebug() << pos;
68 }
69
70 // virtual
71 void SmallRuler::mouseMoveEvent(QMouseEvent * event) {
72     int pos = event->x();
73     //slotNewValue( pos );
74     emit seekRenderer(pos);
75     kDebug() << pos;
76 }
77
78 void SmallRuler::slotNewValue(int _value) {
79     m_cursorPosition = _value / pixelPerMark();
80     KRuler::slotNewValue(_value);
81 }
82
83 // virtual
84 void SmallRuler::paintEvent(QPaintEvent *e) {
85     //  debug ("KRuler::drawContents, %s",(horizontal==dir)?"horizontal":"vertical");
86
87     QStylePainter p(this);
88     p.fillRect(e->rect(), QBrush(QColor(Qt::white)));
89
90
91     int value  = this->value(),
92                  minval = minimum(),
93                           maxval;
94     maxval = maximum()
95              + offset() - endOffset();
96
97     //ioffsetval = value-offset;
98     //    pixelpm = (int)ppm;
99     //    left  = clip.left(),
100     //    right = clip.right();
101     double f, fend,
102     offsetmin = (double)(minval - offset()),
103                 offsetmax = (double)(maxval - offset()),
104                             fontOffset = (((double)minval) > offsetmin) ? (double)minval : offsetmin;
105
106     // draw labels
107     QFont font = p.font();
108     font.setPointSize(LABEL_SIZE);
109     p.setFont(font);
110
111     if (showLittleMarks()) {
112         // draw the little marks
113         fend = pixelPerMark() * littleMarkDistance();
114         if (fend > 2) for (f = offsetmin; f < offsetmax; f += fend) {
115                 p.drawLine((int)f, LITTLE_MARK_X1, (int)f, LITTLE_MARK_X2);
116             }
117     }
118     if (showMediumMarks()) {
119         // draw medium marks
120         fend = pixelPerMark() * mediumMarkDistance();
121         if (fend > 2) for (f = offsetmin; f < offsetmax; f += fend) {
122                 p.drawLine((int)f, MIDDLE_MARK_X1, (int)f, MIDDLE_MARK_X2);
123             }
124     }
125
126     /*   if (d->showem) {
127          // draw end marks
128          if (d->dir == Qt::Horizontal) {
129            p.drawLine(minval-d->offset, END_MARK_X1, minval-d->offset, END_MARK_X2);
130            p.drawLine(maxval-d->offset, END_MARK_X1, maxval-d->offset, END_MARK_X2);
131          }
132          else {
133            p.drawLine(END_MARK_X1, minval-d->offset, END_MARK_X2, minval-d->offset);
134            p.drawLine(END_MARK_X1, maxval-d->offset, END_MARK_X2, maxval-d->offset);
135          }
136        }*/
137
138     // draw pointer
139     if (showPointer()) {
140         QPolygon pa(3);
141         pa.setPoints(3, value - 6, 0, value + 6, 0, value/*+0*/, 8);
142         p.setBrush(QBrush(Qt::yellow));
143         p.drawPolygon(pa);
144     }
145
146 }
147
148 #include "smallruler.moc"