summaryrefslogtreecommitdiffstats
path: root/kstars/kstars/timeunitbox.cpp
blob: 4305fbd03d25289fd0dffb8d10c09b24f8ad7917 (plain)
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
/***************************************************************************
                          timeunitbox.cpp  -  description
                             -------------------
    begin                : Sat Apr 27 2002
    copyright            : (C) 2002 by Jason Harris
    email                : kstars@30doradus.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include <stdlib.h>
#include <kdebug.h>
#include "timeunitbox.h"
#include "timeunitbox.moc"
#include <tqpushbutton.h>


TimeUnitBox::TimeUnitBox(TQWidget *parent, const char *name, bool daysonly )
	: TQVBox( parent, name ) {

	UpButton = new TQPushButton( "+", this );
	UpButton->setMaximumWidth( 22 );
	UpButton->setMaximumHeight( 10 );
	DownButton = new TQPushButton( "-", this );
	DownButton->setMaximumWidth( 22 );
	DownButton->setMaximumHeight( 10 );

	setDaysOnly( daysonly );

	connect( UpButton, TQ_SIGNAL( clicked() ), this, TQ_SLOT( increase() ) );
	connect( DownButton, TQ_SIGNAL( clicked() ), this, TQ_SLOT( decrease() ) );
}

TimeUnitBox::~TimeUnitBox(){
}

void TimeUnitBox::setDaysOnly( bool daysonly ) {
	if ( daysonly ) {
		setMinValue( 1-DAYUNITS );
		setMaxValue( DAYUNITS-1 );
		setValue( 1 ); // Start out with days units
	
		UnitStep[0] = 0;
		UnitStep[1] = 1;
		UnitStep[2] = 5;
		UnitStep[3] = 8;
		UnitStep[4] = 14;
	} else {
		setMinValue( 1-ALLUNITS );
		setMaxValue( ALLUNITS-1 );
		setValue( 1 ); // Start out with seconds units
	
		UnitStep[0] = 0;
		UnitStep[1] = 4;
		UnitStep[2] = 10;
		UnitStep[3] = 16;
		UnitStep[4] = 21;
		UnitStep[5] = 25;
		UnitStep[6] = 28;
		UnitStep[7] = 34;
	}
}

void TimeUnitBox::increase() {
	if ( value() < maxValue() ) {
		setValue( value()+1 );
		emit valueChanged( value() );
	}
}

void TimeUnitBox::decrease() {
	if ( value() > minValue() ) {
		setValue( value()-1 );
		emit valueChanged( value() );
	}
}

int TimeUnitBox::unitValue() {
	int uval;
	if ( value() >= 0 ) uval = UnitStep[ value() ];
	else uval = -1*UnitStep[ abs( value() ) ];
	return uval;
}

int TimeUnitBox::getUnitValue( int val ) {
	if ( val >= 0 ) return UnitStep[ val ];
	else return -1*UnitStep[ abs( val ) ];
}