summaryrefslogtreecommitdiffstats
path: root/krecipes/src/widgets/fractioninput.h
blob: 37a9b761962c6b45bd1b4c7726e7dda4191da070 (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
/***************************************************************************
*   Copyright (C) 2003 by                                                 *
*   Jason Kivlighn (jkivlighn@gmail.com)                                  *
*                                                                         *
*   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.                                   *
***************************************************************************/

#ifndef FRACTIONINPUT_H
#define FRACTIONINPUT_H

#include <klineedit.h>

#include "datablocks/mixednumber.h"

class TQTimer;

/** A KLineEdit widget extended to allow input of decimals and fractions or ranges of such.
  * Input is returned as a @ref MixedNumber class.
  * @author Jason Kivlighn
  */
class FractionInput : public KLineEdit
{
Q_OBJECT

public:
	FractionInput( TQWidget *parent = 0, MixedNumber::Format = MixedNumber::MixedNumberFormat );
	~FractionInput();

	void setAllowRange( bool b ){ m_allowRange = b; }

	void setValue( double amount, double amount_offset );
	void setValue( const MixedNumber &, double amount_offset );

	void value( MixedNumber &amount, double &amount_offset ) const;
	void value( double &amount, double &amount_offset ) const;
	MixedNumber minValue() const;
	MixedNumber maxValue() const;
	MixedNumber value() const;

	bool isInputValid() const;
	bool isEmpty() const;

signals:
	void valueChanged( const MixedNumber & );

public slots:
	void validate();

private slots:
	void slotStartValidateTimer();

private:
	bool m_allowRange;
	TQTimer *m_validateTimer;
	MixedNumber::Format m_format;
};

#endif //FRACTIONINPUT_H