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 15
27 #define LITTLE_MARK_X1 13
28 #define MIDDLE_MARK_X1 9
29 #define MIDDLE_MARK_X2 15
33 #include "smallruler.h"
36 SmallRuler::SmallRuler(QWidget *parent)
40 setShowBigMarks(false);
41 setShowTinyMarks(false);
43 setRulerMetricStyle(KRuler::Custom);
47 void SmallRuler::setPixelPerMark ( double rate )
49 kDebug()<<" RULER SET RATE: "<<rate;
51 setLittleMarkDistance(25);
52 setMediumMarkDistance(5 * 25);
54 else if (rate > 0.09) {
55 setLittleMarkDistance(5 * 25);
56 setMediumMarkDistance(30 * 25);
59 setLittleMarkDistance(30 * 25);
60 setMediumMarkDistance(60 * 25);
63 KRuler::setPixelPerMark( rate );
67 void SmallRuler::mousePressEvent ( QMouseEvent * event )
70 //slotNewValue( pos );
71 emit seekRenderer(pos);
76 void SmallRuler::mouseMoveEvent ( QMouseEvent * event )
79 //slotNewValue( pos );
80 emit seekRenderer(pos);
84 void SmallRuler::slotNewValue ( int _value )
86 m_cursorPosition = _value / pixelPerMark();
87 KRuler::slotNewValue(_value);
91 void SmallRuler::paintEvent(QPaintEvent * /*e*/)
93 // debug ("KRuler::drawContents, %s",(horizontal==dir)?"horizontal":"vertical");
95 QStylePainter p(this);
98 int value = this->value(),
102 + offset() - endOffset();
104 //ioffsetval = value-offset;
105 // pixelpm = (int)ppm;
106 // left = clip.left(),
107 // right = clip.right();
109 offsetmin=(double)(minval-offset()),
110 offsetmax=(double)(maxval-offset()),
111 fontOffset = (((double)minval)>offsetmin)?(double)minval:offsetmin;
114 QFont font = p.font();
115 font.setPointSize(LABEL_SIZE);
118 if (showLittleMarks()) {
119 // draw the little marks
120 fend = pixelPerMark()*littleMarkDistance();
121 if (fend > 2) for ( f=offsetmin; f<offsetmax; f+=fend ) {
122 p.drawLine((int)f, LITTLE_MARK_X1, (int)f, LITTLE_MARK_X2);
125 if (showMediumMarks()) {
127 fend = pixelPerMark()*mediumMarkDistance();
128 if (fend > 2) for ( f=offsetmin; f<offsetmax; f+=fend ) {
129 p.drawLine((int)f, MIDDLE_MARK_X1, (int)f, MIDDLE_MARK_X2);
135 if (d->dir == Qt::Horizontal) {
136 p.drawLine(minval-d->offset, END_MARK_X1, minval-d->offset, END_MARK_X2);
137 p.drawLine(maxval-d->offset, END_MARK_X1, maxval-d->offset, END_MARK_X2);
140 p.drawLine(END_MARK_X1, minval-d->offset, END_MARK_X2, minval-d->offset);
141 p.drawLine(END_MARK_X1, maxval-d->offset, END_MARK_X2, maxval-d->offset);
148 pa.setPoints(3, value-6, 9, value+6, 9, value/*+0*/, 16);
149 p.setBrush( QBrush(Qt::yellow) );
155 #include "smallruler.moc"