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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
/*
$Id$
KCalc, a scientific calculator for the X window system using the
TQt widget libraries, available at no cost at http://www.troll.no
Copyright (C) 1996 Bernd Johannes Wuebben
wuebben@math.cornell.edu
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.
*/
#include <tqglobal.h>
#include <tdeactioncollection.h>
#include <kstdaction.h>
#include "kcalc_settings.h"
#include "kcalc_core.h"
#include "dlabel.h"
#include "dlabel.moc"
DispLogic::DispLogic(TQWidget *parent, const char *name,
TDEActionCollection *coll)
:KCalcDisplay(parent,name), _history_index(0)
{
KNumber::setDefaultFloatOutput(true);
KNumber::setDefaultFractionalInput(true);
_back = KStdAction::undo(this, TQ_SLOT(history_back()), coll);
_forward = KStdAction::redo(this, TQ_SLOT(history_forward()), coll);
_forward->setEnabled(false);
_back->setEnabled(false);
}
DispLogic::~DispLogic()
{
}
void DispLogic::changeSettings()
{
TQPalette pal = palette();
pal.setColor(TQColorGroup::Text, KCalcSettings::foreColor());
pal.setColor(TQColorGroup::Foreground, KCalcSettings::foreColor());
pal.setColor(TQColorGroup::Background, KCalcSettings::backColor());
setPalette(pal);
setBackgroundColor(KCalcSettings::backColor());
setFont(KCalcSettings::font());
setPrecision(KCalcSettings::precision());
if(KCalcSettings::fixed() == false)
setFixedPrecision(-1);
else
setFixedPrecision(KCalcSettings::fixedPrecision());
setBeep(KCalcSettings::beep());
setGroupDigits(KCalcSettings::groupDigits());
updateDisplay();
}
void DispLogic::update_from_core(CalcEngine const &core,
bool store_result_in_history)
{
bool tmp_error;
KNumber const & output = core.lastOutput(tmp_error);
if(tmp_error) sendEvent(EventError);
if (setAmount(output) && store_result_in_history &&
output != KNumber::Zero)
{
// add this latest value to our history
_history_list.insert(_history_list.begin(), output);
_history_index = 0;
_back->setEnabled(true);
_forward->setEnabled(false);
}
}
void DispLogic::EnterDigit(int data)
{
char tmp;
switch(data)
{
case 0:
tmp = '0';
break;
case 1:
tmp = '1';
break;
case 2:
tmp = '2';
break;
case 3:
tmp = '3';
break;
case 4:
tmp = '4';
break;
case 5:
tmp = '5';
break;
case 6:
tmp = '6';
break;
case 7:
tmp = '7';
break;
case 8:
tmp = '8';
break;
case 9:
tmp = '9';
break;
case 0xA:
tmp = 'A';
break;
case 0xB:
tmp = 'B';
break;
case 0xC:
tmp = 'C';
break;
case 0xD:
tmp = 'D';
break;
case 0xE:
tmp = 'E';
break;
case 0xF:
tmp = 'F';
break;
default:
tmp = '?';
break;
}
newCharacter(tmp);
}
void DispLogic::history_forward()
{
Q_ASSERT(! _history_list.empty());
Q_ASSERT(_history_index > 0);
_history_index --;
setAmount(_history_list[_history_index]);
if(_history_index == 0) _forward->setEnabled(false);
_back->setEnabled(true);
}
void DispLogic::history_back()
{
Q_ASSERT(! _history_list.empty());
Q_ASSERT( _history_index < static_cast<int>(_history_list.size()) );
setAmount(_history_list[_history_index]);
_history_index ++;
if( _history_index == static_cast<int>(_history_list.size()) )
_back->setEnabled(false);
_forward->setEnabled(true);
}
|