1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/**************************************************************************
kslidertime.cpp - A widget that displays time tags under a KSlider
Copyright (C) 1997,98 Antonio Larrosa Jimenez
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Send comments and bug fixes to [email protected]
or to Antonio Larrosa, Rio Arnoya, 10 5B, 29006 Malaga, Spain
***************************************************************************/
#include "qslidertime.h"
#include <tqwidget.h>
#include <tqpainter.h>
#include <stdio.h>
#define ARROW_LENGTH 13
QSliderTime::QSliderTime( TQSlider *ksl, TQWidget *parent, const char *name)
: TQWidget (parent,name)
{
kslider=ksl;
TQPainter painter;
TQFontMetrics qfmt(painter.font());
fontheight=qfmt.height();
}
char *QSliderTime::formatMillisecs(int ms,char *tmp)
{
if (ms<60000)
{
sprintf(tmp,"0:%02d",ms/1000);
}
else
sprintf(tmp,"%d:%02d",ms/60000,(ms%60000)/1000);
return tmp;
}
void QSliderTime::paintEvent( TQPaintEvent * )
{
TQPainter painter(this);
// erase();
drawTimeMarks(&painter);
}
int quantizeTimeStep(int t)
{
if (t<=2000) t=2000;
else if (t<=5000) t=5000;
else if (t<=10000) t=10000;
else if (t<=15000) t=15000;
else if (t<=30000) t=30000;
else if (t<=60000) t=60000;
else if (t<=120000) t=120000;
return t;
}
void QSliderTime::drawTimeMarks(TQPainter *painter)
{
if (kslider==NULL) return;
int i;
int maxV = kslider->maxValue();
TQFontMetrics qfmt(painter->font());
fontheight=qfmt.height();
int ntimetags = width()/(qfmt.width("-88:88-"));
int timestep;
if (ntimetags>1) timestep = maxV/(ntimetags);
else timestep=maxV;
timestep = quantizeTimeStep(timestep);
ntimetags = maxV/timestep;
// draw time tags (only in horizontal !!)
int posy=qfmt.height();
char *tmp=new char[100];
int pos=0;
int deltapos=0;
formatMillisecs(0,tmp);
painter->drawText( 0, posy,TQString(tmp));
for ( i = timestep; i <= maxV - timestep; i += timestep )
{
pos = (width()-10) * i / maxV + 5;
formatMillisecs(i,tmp);
deltapos=qfmt.width(tmp)/2;
painter->drawText( pos-deltapos, posy,TQString(tmp));
}
pos = width()- 5;
formatMillisecs(maxV,tmp);
deltapos=qfmt.width(tmp);
painter->drawText( pos-deltapos, posy,TQString(tmp));
}
TQSize QSliderTime::sizeHint()
{
return TQSize(10,fontheight+2);
}
TQSizePolicy QSliderTime::sizePolicy()
{
return TQSizePolicy(TQSizePolicy::Expanding,TQSizePolicy::Fixed);
}
#include "qslidertime.moc"
|