kstars
timeunitbox.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <stdlib.h>
00019 #include <kdebug.h>
00020 #include "timeunitbox.h"
00021 #include "timeunitbox.moc"
00022 #include <qpushbutton.h>
00023
00024
00025 TimeUnitBox::TimeUnitBox(QWidget *parent, const char *name, bool daysonly )
00026 : QVBox( parent, name ) {
00027
00028 UpButton = new QPushButton( "+", this );
00029 UpButton->setMaximumWidth( 22 );
00030 UpButton->setMaximumHeight( 10 );
00031 DownButton = new QPushButton( "-", this );
00032 DownButton->setMaximumWidth( 22 );
00033 DownButton->setMaximumHeight( 10 );
00034
00035 setDaysOnly( daysonly );
00036
00037 connect( UpButton, SIGNAL( clicked() ), this, SLOT( increase() ) );
00038 connect( DownButton, SIGNAL( clicked() ), this, SLOT( decrease() ) );
00039 }
00040
00041 TimeUnitBox::~TimeUnitBox(){
00042 }
00043
00044 void TimeUnitBox::setDaysOnly( bool daysonly ) {
00045 if ( daysonly ) {
00046 setMinValue( 1-DAYUNITS );
00047 setMaxValue( DAYUNITS-1 );
00048 setValue( 1 );
00049
00050 UnitStep[0] = 0;
00051 UnitStep[1] = 1;
00052 UnitStep[2] = 5;
00053 UnitStep[3] = 8;
00054 UnitStep[4] = 14;
00055 } else {
00056 setMinValue( 1-ALLUNITS );
00057 setMaxValue( ALLUNITS-1 );
00058 setValue( 1 );
00059
00060 UnitStep[0] = 0;
00061 UnitStep[1] = 4;
00062 UnitStep[2] = 10;
00063 UnitStep[3] = 16;
00064 UnitStep[4] = 21;
00065 UnitStep[5] = 25;
00066 UnitStep[6] = 28;
00067 UnitStep[7] = 34;
00068 }
00069 }
00070
00071 void TimeUnitBox::increase() {
00072 if ( value() < maxValue() ) {
00073 setValue( value()+1 );
00074 emit valueChanged( value() );
00075 }
00076 }
00077
00078 void TimeUnitBox::decrease() {
00079 if ( value() > minValue() ) {
00080 setValue( value()-1 );
00081 emit valueChanged( value() );
00082 }
00083 }
00084
00085 int TimeUnitBox::unitValue() {
00086 int uval;
00087 if ( value() >= 0 ) uval = UnitStep[ value() ];
00088 else uval = -1*UnitStep[ abs( value() ) ];
00089 return uval;
00090 }
00091
00092 int TimeUnitBox::getUnitValue( int val ) {
00093 if ( val >= 0 ) return UnitStep[ val ];
00094 else return -1*UnitStep[ abs( val ) ];
00095 }