diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | e2de64d6f1beb9e492daf5b886e19933c1fa41dd (patch) | |
tree | 9047cf9e6b5c43878d5bf82660adae77ceee097a /kmid/qslidertime.cpp | |
download | tdemultimedia-e2de64d6f1beb9e492daf5b886e19933c1fa41dd.tar.gz tdemultimedia-e2de64d6f1beb9e492daf5b886e19933c1fa41dd.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdemultimedia@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kmid/qslidertime.cpp')
-rw-r--r-- | kmid/qslidertime.cpp | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/kmid/qslidertime.cpp b/kmid/qslidertime.cpp new file mode 100644 index 00000000..be5fdab2 --- /dev/null +++ b/kmid/qslidertime.cpp @@ -0,0 +1,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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Send comments and bug fixes to larrosa@kde.org + or to Antonio Larrosa, Rio Arnoya, 10 5B, 29006 Malaga, Spain + +***************************************************************************/ +#include "qslidertime.h" +#include <qwidget.h> +#include <qpainter.h> +#include <stdio.h> + +#define ARROW_LENGTH 13 + +QSliderTime::QSliderTime( QSlider *ksl, QWidget *parent, const char *name) + : QWidget (parent,name) +{ +kslider=ksl; + +QPainter painter; +QFontMetrics 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( QPaintEvent * ) +{ + QPainter 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(QPainter *painter) +{ +if (kslider==NULL) return; + int i; + int maxV = kslider->maxValue(); + QFontMetrics 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,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,tmp); + } + + pos = width()- 5; + formatMillisecs(maxV,tmp); + deltapos=qfmt.width(tmp); + + painter->drawText( pos-deltapos, posy,tmp); + +} + + +QSize QSliderTime::sizeHint() +{ + return QSize(10,fontheight+2); +} + +QSizePolicy QSliderTime::sizePolicy() +{ + return QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed); +} +#include "qslidertime.moc" |