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 #define LITTLE_MARK_X2 8
27 #define LITTLE_MARK_X1 5
28 #define MIDDLE_MARK_X1 3
29 #define MIDDLE_MARK_X2 8
33 #include "smallruler.h"
36 SmallRuler::SmallRuler(QWidget *parent)
39 setShowBigMarks(false);
40 setShowTinyMarks(false);
42 setRulerMetricStyle(KRuler::Custom);
46 void SmallRuler::setPixelPerMark(double rate) {
47 kDebug() << " RULER SET RATE: " << rate;
49 setLittleMarkDistance(25);
50 setMediumMarkDistance(5 * 25);
51 } else if (rate > 0.09) {
52 setLittleMarkDistance(5 * 25);
53 setMediumMarkDistance(30 * 25);
55 setLittleMarkDistance(30 * 25);
56 setMediumMarkDistance(60 * 25);
59 KRuler::setPixelPerMark(rate);
63 void SmallRuler::mousePressEvent(QMouseEvent * event) {
64 double pos = event->x() / pixelPerMark();
65 emit seekRenderer((int) pos);
69 void SmallRuler::mouseMoveEvent(QMouseEvent * event) {
70 double pos = event->x() / pixelPerMark();
71 emit seekRenderer((int) pos);
74 void SmallRuler::slotNewValue(int _value) {
75 m_cursorPosition = (int)(_value); /// pixelPerMark());
76 KRuler::slotNewValue(_value * pixelPerMark());
80 void SmallRuler::paintEvent(QPaintEvent *e) {
81 // debug ("KRuler::drawContents, %s",(horizontal==dir)?"horizontal":"vertical");
83 QStylePainter p(this);
84 p.fillRect(e->rect(), QBrush(QColor(Qt::white)));
87 int value = this->value(),
91 + offset() - endOffset();
93 //ioffsetval = value-offset;
94 // pixelpm = (int)ppm;
95 // left = clip.left(),
96 // right = clip.right();
98 offsetmin = (double)(minval - offset()),
99 offsetmax = (double)(maxval - offset()),
100 fontOffset = (((double)minval) > offsetmin) ? (double)minval : offsetmin;
103 QFont font = p.font();
104 font.setPointSize(LABEL_SIZE);
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);
114 if (showMediumMarks()) {
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);
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);
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);
137 pa.setPoints(3, value - 6, 0, value + 6, 0, value/*+0*/, 8);
138 p.setBrush(QBrush(Qt::yellow));
144 #include "smallruler.moc"