1 | /* |
2 | SPDX-FileCopyrightText: 2001-2013 Evan Teran <evan.teran@gmail.com> |
3 | SPDX-FileCopyrightText: 1996-2000 Bernd Johannes Wuebben <wuebben@kde.org> |
4 | |
5 | SPDX-License-Identifier: GPL-2.0-or-later |
6 | */ |
7 | |
8 | #pragma once |
9 | |
10 | class Constants; |
11 | class QButtonGroup; |
12 | class QLabel; |
13 | class KToggleAction; |
14 | class ; |
15 | class KCalcStatusBar; |
16 | |
17 | /* |
18 | Kcalc basically consist of a class for the GUI (here), a class for |
19 | the display (dlabel.h), and one for the mathematics core |
20 | (kcalc_core.h). |
21 | |
22 | When for example '+' is pressed, one sends the contents of the |
23 | Display and the '+' to the core via "core.Plus(DISPLAY_AMOUNT)". |
24 | This only updates the core. To bring the changes to the display, |
25 | use afterwards "UpdateDisplay(true)". |
26 | |
27 | "UpdateDisplay(true)" means that the amount to be displayed should |
28 | be taken from the core (get the result of some operation that was |
29 | performed), "UpdateDisplay(false)" has already the information, what |
30 | to be display (e.g. user is typing in a number). Note that in the |
31 | last case the core does not know the number typed in until some |
32 | operation button is pressed, e.g. "core.Plus(display_number)". |
33 | */ |
34 | |
35 | #include "kcalc_button.h" |
36 | #include "kcalc_const_button.h" |
37 | #include "kcalc_core.h" |
38 | |
39 | #include "ui_colors.h" |
40 | #include "ui_constants.h" |
41 | #include "ui_fonts.h" |
42 | #include "ui_general.h" |
43 | #include "ui_kcalc.h" |
44 | |
45 | #include <array> |
46 | #include <kxmlguiwindow.h> |
47 | |
48 | class General : public QWidget, public Ui::General |
49 | { |
50 | Q_OBJECT |
51 | public: |
52 | explicit General(QWidget *parent) |
53 | : QWidget(parent) |
54 | { |
55 | setupUi(this); |
56 | } |
57 | }; |
58 | |
59 | class Fonts : public QWidget, public Ui::Fonts |
60 | { |
61 | Q_OBJECT |
62 | public: |
63 | explicit Fonts(QWidget *parent) |
64 | : QWidget(parent) |
65 | { |
66 | setupUi(this); |
67 | } |
68 | }; |
69 | |
70 | class Constants : public QWidget, public Ui::Constants |
71 | { |
72 | Q_OBJECT |
73 | public: |
74 | explicit Constants(QWidget *parent) |
75 | : QWidget(parent) |
76 | { |
77 | setupUi(this); |
78 | } |
79 | }; |
80 | |
81 | class Colors : public QWidget, public Ui::Colors |
82 | { |
83 | Q_OBJECT |
84 | public: |
85 | explicit Colors(QWidget *parent) |
86 | : QWidget(parent) |
87 | { |
88 | setupUi(this); |
89 | } |
90 | }; |
91 | |
92 | class KCalculator : public KXmlGuiWindow, private Ui::KCalculator |
93 | { |
94 | Q_OBJECT |
95 | |
96 | public: |
97 | explicit KCalculator(QWidget *parent = nullptr); |
98 | ~KCalculator() override; |
99 | |
100 | Q_SIGNALS: |
101 | void switchMode(ButtonModeFlags, bool); |
102 | void switchShowAccels(bool); |
103 | |
104 | public: |
105 | enum UpdateFlag { UPDATE_FROM_CORE = 1, UPDATE_STORE_RESULT = 2 }; |
106 | |
107 | Q_DECLARE_FLAGS(UpdateFlags, UpdateFlag) |
108 | |
109 | protected: |
110 | void resizeEvent(QResizeEvent* event) override; |
111 | |
112 | private: |
113 | bool eventFilter(QObject *o, QEvent *e) override; |
114 | bool event(QEvent *e) override; |
115 | void updateGeometry(); |
116 | void setupMainActions(); |
117 | void setupKeys(); |
118 | void setupNumberKeys(); |
119 | void setupRightKeypad(); |
120 | void setupNumericKeypad(); |
121 | void setupLogicKeys(); |
122 | void setupScientificKeys(); |
123 | void setupStatisticKeys(); |
124 | void setupConstantsKeys(); |
125 | void setupMiscKeys(); |
126 | void keyPressEvent(QKeyEvent *e) override; |
127 | void keyReleaseEvent(QKeyEvent *e) override; |
128 | void setPrecision(); |
129 | void setAngle(); |
130 | void setBase(); |
131 | |
132 | void setBaseFont(const QFont &font); |
133 | const QFont &baseFont() const; |
134 | bool isMinimumSize(); |
135 | void forceResizeEvent(); |
136 | void setLeftPadLayoutActive(bool active); |
137 | void setBitsetLayoutActive(bool active); |
138 | |
139 | void updateDisplay(UpdateFlags flags); |
140 | void updateHistoryWithFunction(CalcEngine::Operation); |
141 | KCalcStatusBar *statusBar(); |
142 | |
143 | // button sets |
144 | void showMemButtons(bool toggled); |
145 | void showStatButtons(bool toggled); |
146 | void showScienceButtons(bool toggled); |
147 | void showLogicButtons(bool toggled); |
148 | |
149 | KCalcConstMenu *(); |
150 | |
151 | protected Q_SLOTS: |
152 | void changeButtonNames(); |
153 | void updateSettings(); |
154 | void setColors(); |
155 | void setFonts(); |
156 | void EnterEqual(CalcEngine::Repeat allow_repeat = CalcEngine::REPEAT_ALLOW); |
157 | void showSettings(); |
158 | |
159 | // Mode |
160 | void slotSetSimpleMode(); |
161 | void slotSetScienceMode(); |
162 | void slotSetStatisticMode(); |
163 | void slotSetNumeralMode(); |
164 | |
165 | void slotHistoryshow(bool toggled); |
166 | void slotConstantsShow(bool toggled); |
167 | void slotBitsetshow(bool toggled); |
168 | void slotAngleSelected(QAbstractButton *button); |
169 | void slotBaseSelected(QAbstractButton *button); |
170 | void slotNumberclicked(QAbstractButton *button); |
171 | void slotEEclicked(); |
172 | void slotShifttoggled(bool myboolean); |
173 | void slotMemRecallclicked(); |
174 | void slotMemStoreclicked(); |
175 | void slotSinclicked(); |
176 | void slotPlusMinusclicked(); |
177 | void slotMemPlusMinusclicked(); |
178 | void slotCosclicked(); |
179 | void slotReciclicked(); |
180 | void slotTanclicked(); |
181 | void slotFactorialclicked(); |
182 | void slotLogclicked(); |
183 | void slotSquareclicked(); |
184 | void slotCubeclicked(); |
185 | void slotLnclicked(); |
186 | void slotPowerclicked(); |
187 | void slotMemClearclicked(); |
188 | void slotClearclicked(); |
189 | void slotAllClearclicked(); |
190 | void slotParenOpenclicked(); |
191 | void slotParenCloseclicked(); |
192 | void slotANDclicked(); |
193 | void slotMultiplicationclicked(); |
194 | void slotDivisionclicked(); |
195 | void slotORclicked(); |
196 | void slotXORclicked(); |
197 | void slotPlusclicked(); |
198 | void slotMinusclicked(); |
199 | void slotLeftShiftclicked(); |
200 | void slotRightShiftclicked(); |
201 | void slotPeriodclicked(); |
202 | void slotEqualclicked(); |
203 | void slotPercentclicked(); |
204 | void slotNegateclicked(); |
205 | void slotModclicked(); |
206 | void slotStatNumclicked(); |
207 | void slotStatMeanclicked(); |
208 | void slotStatStdDevclicked(); |
209 | void slotStatMedianclicked(); |
210 | void slotStatDataInputclicked(); |
211 | void slotStatClearDataclicked(); |
212 | void slotHyptoggled(bool flag); |
213 | void slotConstclicked(int); |
214 | void slotBackspaceclicked(); |
215 | |
216 | void slotConstantToDisplay(const science_constant &const_chosen); |
217 | void slotChooseScientificConst0(const science_constant &); |
218 | void slotChooseScientificConst1(const science_constant &); |
219 | void slotChooseScientificConst2(const science_constant &); |
220 | void slotChooseScientificConst3(const science_constant &); |
221 | void slotChooseScientificConst4(const science_constant &); |
222 | void slotChooseScientificConst5(const science_constant &); |
223 | |
224 | void slotBitsetChanged(quint64); |
225 | void slotUpdateBitset(const KNumber &); |
226 | |
227 | void slotBaseModeAmountChanged(const KNumber &number); |
228 | |
229 | void slotPaste(); |
230 | |
231 | private: |
232 | enum StatusField { ShiftField = 0, BaseField, AngleField, MemField }; |
233 | |
234 | enum AngleMode { DegMode = 0, RadMode, GradMode }; |
235 | |
236 | enum BaseMode { BinMode = 2, OctMode = 8, DecMode = 10, HexMode = 16 }; |
237 | |
238 | private: |
239 | bool shift_mode_ = false; |
240 | bool hyp_mode_ = false; |
241 | bool update_history_window_ = false; |
242 | KNumber memory_num_; |
243 | |
244 | int angle_mode_; // angle modes for trigonometric values |
245 | |
246 | KCalcConstMenu * = nullptr; |
247 | |
248 | Constants *constants_ = nullptr; // this is the dialog for configuring const buttons |
249 | |
250 | QButtonGroup *angle_choose_group_ = nullptr; |
251 | QButtonGroup *base_choose_group_ = nullptr; |
252 | // num_button_group_: 0-9 = digits, 0xA-0xF = hex-keys |
253 | QButtonGroup *num_button_group_ = nullptr; |
254 | |
255 | QList<QAbstractButton *> logic_buttons_; |
256 | QList<QAbstractButton *> scientific_buttons_; |
257 | QList<QAbstractButton *> stat_buttons_; |
258 | QList<QAbstractButton *> const_buttons_; |
259 | |
260 | std::array<QLabel *, 4> base_conversion_labels_; |
261 | |
262 | KToggleAction *action_history_show_ = nullptr; |
263 | KToggleAction *action_bitset_show_ = nullptr; |
264 | KToggleAction *action_constants_show_ = nullptr; |
265 | |
266 | KToggleAction *action_mode_simple_ = nullptr; |
267 | KToggleAction *action_mode_science_ = nullptr; |
268 | KToggleAction *action_mode_statistic_ = nullptr; |
269 | KToggleAction *action_mode_numeral_ = nullptr; |
270 | |
271 | QList<QAbstractButton *> function_button_list_; |
272 | QList<QAbstractButton *> stat_button_list_; |
273 | QList<QAbstractButton *> mem_button_list_; |
274 | QList<QAbstractButton *> operation_button_list_; |
275 | |
276 | QFont baseFont_; |
277 | bool is_still_in_launch_ = true; // necessary for startup at minimum size |
278 | |
279 | CalcEngine core; |
280 | }; |
281 | |
282 | Q_DECLARE_OPERATORS_FOR_FLAGS(KCalculator::UpdateFlags) |
283 | |
284 | |