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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
/*
KCalc
Copyright (C) Bernd Johannes Wuebben
[email protected]
[email protected]
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _D_KCALCDISPLAY_H_
#define _D_KCALCDISPLAY_H_
#include <stdlib.h>
#include <qlabel.h>
#include <qtimer.h>
#include "knumber.h"
#include "kcalctype.h"
#if defined HAVE_LONG_DOUBLE && defined HAVE_L_FUNCS
#define PRINT_FLOAT "%.*Lf"
#define PRINT_LONG_BIG "%.*Lg"
#define PRINT_LONG "%Lg"
#else
#define PRINT_FLOAT "%.*f"
#define PRINT_LONG_BIG "%.*g"
#define PRINT_LONG "%g"
#endif
#ifdef HAVE_LONG_LONG
#define PRINT_OCTAL "%llo"
#define PRINT_HEX "%llX"
#else
#define PRINT_OCTAL "%lo"
#define PRINT_HEX "%lX"
#endif
#define NUM_STATUS_TEXT 4
/*
This class provides a pocket calculator display. The display has
implicitely two major modes: One is for editing and one is purely
for displaying.
When one uses "setAmount", the given amount is displayed, and the
amount which was possibly typed in before is lost. At the same time
this new value can not be modified.
On the other hand, "addNewChar" adds a new digit to the amount that
is being typed in. If "setAmount" was used before, the display is
cleared and a new input starts.
TODO: Check overflows, number of digits and such...
*/
enum NumBase {
NB_BINARY = 2,
NB_OCTAL = 8,
NB_DECIMAL = 10,
NB_HEX = 16
};
class KCalcDisplay : public QLabel
{
Q_OBJECT
public:
KCalcDisplay(QWidget *parent=0, const char *name=0);
~KCalcDisplay();
protected:
void mousePressEvent ( QMouseEvent *);
virtual void drawContents(QPainter *p);
public:
enum Event {
EventReset, // resets display
EventClear, // if no _error reset display
EventError,
EventChangeSign
};
bool sendEvent(Event const event);
void deleteLastDigit(void);
KNumber const & getAmount(void) const;
void newCharacter(char const new_char);
bool setAmount(KNumber const & new_amount);
int setBase(NumBase new_base);
void setBeep(bool flag);
void setGroupDigits(bool flag);
void setFixedPrecision(int precision);
void setPrecision(int precision);
void setText(QString const &string);
QString text() const;
bool updateDisplay(void);
void setStatusText(uint i, const QString& text);
virtual QSize sizeHint() const;
private:
bool _beep;
bool _groupdigits;
int _button;
bool _lit;
NumBase _num_base;
int _precision;
int _fixed_precision; // "-1" = no fixed_precision
KNumber _display_amount;
private:
bool changeSign(void);
void invertColors(void);
// only used for input of new numbers
bool _eestate;
bool _period;
bool _neg_sign;
QString _str_int;
QString _str_int_exp;
QString _str_status[NUM_STATUS_TEXT];
QTimer* selection_timer;
signals:
void clicked(void);
void changedText(QString const &);
public slots:
void slotCut(void);
void slotCopy(void);
void slotPaste(bool bClipboard=true);
private slots:
void slotSelectionTimedOut(void);
void slotDisplaySelected(void);
};
#endif // _KCALCDISPLAY_H_
|