-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.h
221 lines (199 loc) · 6.76 KB
/
calculator.h
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/****************************************************************************
**
** Copyright (C) 2018 Alexander Taylor
**
** This file is based in part on example code from the Qt4 Toolkit.
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** All rights reserved.
**
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
** the names of its contributors may be used to endorse or promote
** products derived from this software without specific prior written
** permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
****************************************************************************/
#ifndef CALCULATOR_H
#define CALCULATOR_H
#include <QDialog>
#include <QProcess>
// Constants for QtAssistant-based cross-platform help
#define HELP_HTML_ROOT "qthelp://altsan.atcalc/help/"
#define HELP_HTML_GENERAL "atcalc.1.html"
#define HELP_HTML_KEYS "atcalc.3.html"
// Constants for OS/2 native help
#define HELP_PANEL_GENERAL 1
#define HELP_PANEL_KEYS 200
#define DEG_TO_RAD( x ) (x * ( M_PI / 180 ))
#define RAD_TO_DEG( x ) (x * ( 180 / M_PI ))
QT_BEGIN_NAMESPACE
class QMenuBar;
class QLineEdit;
class QLabel;
class QComboBox;
class QGridLayout;
class QMenu;
QT_END_NAMESPACE
class Button;
class Calculator : public QDialog
{
Q_OBJECT
public:
Calculator(QWidget *parent = 0);
~Calculator();
protected:
void closeEvent( QCloseEvent *event );
// void contextMenuEvent( QContextMenuEvent *event );
void keyPressEvent( QKeyEvent *event );
private slots:
void modeClicked();
void digitClicked();
void unaryOperatorClicked();
void additiveOperatorClicked();
void multiplicativeOperatorClicked();
void exponentialOperatorClicked();
void equalClicked();
void pointClicked();
void changeSignClicked();
void backspaceClicked();
void clear();
void clearAll();
void clearMemory();
void readMemory();
void setMemory();
void addToMemory();
void subFromMemory();
void copy();
void paste();
void modeChanged( const QString &text );
void viewChanged( const QString &text );
void onTopChanged();
void greyChanged();
void buttonFontChanged();
void displayFontChanged();
void showGeneralHelp();
void showKeysHelp();
void about();
private:
Button *createButton( const QString &text, const QString &identity, const char *member );
Button *createButton( const QString &text, const QString &identity, QKeySequence::StandardKey key, const char *member );
Button *createButton( const QString &text, const QString &identity, const QString &key, const char *member );
void setButtonFont( const QFont &font );
void setColourScheme();
void abortOperation();
long double currentDisplayValue();
void setCurrentDisplayValue( long double value );
void setCurrentDisplayValue( long long value );
bool calculate( long double rightOperand, const QString &pendingOperator );
void updateAltRepr();
int showLayout( const QLayout *layout, bool visible );
QString findFont( const QString fontFamily );
void readSettings();
void writeSettings();
void createHelp();
void launchAssistant( const QString &panel );
long double sumInMemory;
long double sumSoFar;
long double factorSoFar;
long double expSoFar;
QString pendingAdditiveOperator;
QString pendingMultiplicativeOperator;
QString pendingExponentialOperator;
bool waitingForOperand;
bool isOnTop;
bool isHexMode;
bool isGrey;
enum { Standard = 0, Scientific = 1, Programming = 2, All = 3 };
short currentView;
QLineEdit *display;
QLabel *reprName;
QLabel *reprLabel;
QComboBox *modeSelector;
QComboBox *viewSelector;
QGridLayout *sciLayout;
QGridLayout *proLayout;
QMenuBar *menuBar;
QMenu *fileMenu;
QMenu *editMenu;
QMenu *viewMenu;
QMenu *styleMenu;
QMenu *helpMenu;
QAction *quitAction;
QAction *monochromeAction;
QAction *displayFontAction;
QAction *buttonFontAction;
QAction *onTopAction;
QAction *aboutAction;
QAction *copyAction;
QAction *pasteAction;
QAction *helpGeneralAction;
QAction *helpKeysAction;
enum { NumDigitButtons = 10 };
enum { NumHexButtons = 6 };
Button *digitButtons[ NumDigitButtons ];
Button *hexButtons[ NumHexButtons ];
Button *pointButton;
Button *changeSignButton;
Button *backspaceButton;
Button *clearButton;
Button *clearAllButton;
Button *clearMemoryButton;
Button *readMemoryButton;
Button *setMemoryButton;
Button *addToMemoryButton;
Button *divisionButton;
Button *timesButton;
Button *minusButton;
Button *plusButton;
Button *equalButton;
Button *moduloButton;
Button *squareRootButton;
Button *reciprocalButton;
Button *squareButton;
Button *expButton;
Button *nRootButton;
Button *logButton;
Button *lnButton;
Button *eButton;
Button *piButton;
Button *sinButton;
Button *cosButton;
Button *tanButton;
Button *bitLeftButton;
Button *bitRightButton;
Button *bitAndButton;
Button *bitOrButton;
Button *bitXorButton;
Button *bitNotButton;
Button *bitLroButton;
Button *bitRroButton;
Button *integerButton;
// Program help (platform specific implementation)
void *helpInstance;
// QtAssistant process
QProcess *helpProcess;
};
#endif