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)
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);
96 p.fillRect(e->rect(), QBrush(QColor(Qt::white)));
99 int value = this->value(),
103 + offset() - endOffset();
105 //ioffsetval = value-offset;
106 // pixelpm = (int)ppm;
107 // left = clip.left(),
108 // right = clip.right();
110 offsetmin=(double)(minval-offset()),
111 offsetmax=(double)(maxval-offset()),
112 fontOffset = (((double)minval)>offsetmin)?(double)minval:offsetmin;
115 QFont font = p.font();
116 font.setPointSize(LABEL_SIZE);
119 if (showLittleMarks()) {
120 // draw the little marks
121 fend = pixelPerMark()*littleMarkDistance();
122 if (fend > 2) for ( f=offsetmin; f<offsetmax; f+=fend ) {
123 p.drawLine((int)f, LITTLE_MARK_X1, (int)f, LITTLE_MARK_X2);
126 if (showMediumMarks()) {
128 fend = pixelPerMark()*mediumMarkDistance();
129 if (fend > 2) for ( f=offsetmin; f<offsetmax; f+=fend ) {
130 p.drawLine((int)f, MIDDLE_MARK_X1, (int)f, MIDDLE_MARK_X2);
136 if (d->dir == Qt::Horizontal) {
137 p.drawLine(minval-d->offset, END_MARK_X1, minval-d->offset, END_MARK_X2);
138 p.drawLine(maxval-d->offset, END_MARK_X1, maxval-d->offset, END_MARK_X2);
141 p.drawLine(END_MARK_X1, minval-d->offset, END_MARK_X2, minval-d->offset);
142 p.drawLine(END_MARK_X1, maxval-d->offset, END_MARK_X2, maxval-d->offset);
149 pa.setPoints(3, value-6, 0, value+6, 0, value/*+0*/, 8);
150 p.setBrush( QBrush(Qt::yellow) );
156 #include "smallruler.moc"