moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kstars / kstars / timeunitbox.cpp
blobad0e6dbe9a168c15f7b083d3c964468939398d4b
1 /***************************************************************************
2 timeunitbox.cpp - description
3 -------------------
4 begin : Sat Apr 27 2002
5 copyright : (C) 2002 by Jason Harris
6 email : kstars@30doradus.org
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #include <stdlib.h>
19 #include <kdebug.h>
20 #include "timeunitbox.h"
21 #include "timeunitbox.moc"
22 #include <qpushbutton.h>
25 TimeUnitBox::TimeUnitBox(QWidget *parent, const char *name )
26 : QVBox( parent, name ) {
28 UpButton = new QPushButton( "+", this );
29 UpButton->setMaximumWidth( 22 );
30 UpButton->setMaximumHeight( 10 );
31 DownButton = new QPushButton( "-", this );
32 DownButton->setMaximumWidth( 22 );
33 DownButton->setMaximumHeight( 10 );
35 setMinValue( 1-NUNITS );
36 setMaxValue( NUNITS-1 );
37 setValue( 1 ); // Start out with seconds units
39 UnitStep[0] = 0;
40 UnitStep[1] = 4;
41 UnitStep[2] = 10;
42 UnitStep[3] = 16;
43 UnitStep[4] = 21;
44 UnitStep[5] = 25;
45 UnitStep[6] = 28;
46 UnitStep[7] = 34;
48 connect( UpButton, SIGNAL( clicked() ), this, SLOT( increase() ) );
49 connect( DownButton, SIGNAL( clicked() ), this, SLOT( decrease() ) );
52 TimeUnitBox::~TimeUnitBox(){
55 void TimeUnitBox::increase() {
56 if ( value() < maxValue() ) {
57 setValue( value()+1 );
58 emit valueChanged( value() );
62 void TimeUnitBox::decrease() {
63 if ( value() > minValue() ) {
64 setValue( value()-1 );
65 emit valueChanged( value() );
69 int TimeUnitBox::unitValue() {
70 int uval;
71 if ( value() >= 0 ) uval = UnitStep[ value() ];
72 else uval = -1*UnitStep[ abs( value() ) ];
73 return uval;
76 int TimeUnitBox::getUnitValue( int val ) {
77 if ( val >= 0 ) return UnitStep[ val ];
78 else return -1*UnitStep[ abs( val ) ];