|
IVS-calculator
|
Main window class for the calculator GUI. More...
#include <gui.h>


Public Member Functions | |
| Gui (QWidget *parent=nullptr) | |
| Constructs the GUI and initializes components. | |
| ~Gui () | |
| Destructor. Frees allocated resources. | |
Private Slots | |
| void | on_btn_0_clicked () |
| Digit button handlers. | |
| void | on_btn_1_clicked () |
| void | on_btn_2_clicked () |
| void | on_btn_3_clicked () |
| void | on_btn_4_clicked () |
| void | on_btn_5_clicked () |
| void | on_btn_6_clicked () |
| void | on_btn_7_clicked () |
| void | on_btn_8_clicked () |
| void | on_btn_9_clicked () |
| void | on_btn_plus_clicked () |
| Operation button handlers. | |
| void | on_btn_minus_clicked () |
| void | on_btn_mul_clicked () |
| void | on_btn_div_clicked () |
| void | on_btn_mod_clicked () |
| void | on_btn_pow_clicked () |
| void | on_btn_root_clicked () |
| Appends square root operator. | |
| void | on_btn_fac_clicked () |
| Appends factorial operator. | |
| void | on_btn_clear_clicked () |
| Control buttons. | |
| void | on_btn_equal_clicked () |
| Evaluates the current expression. | |
| void | on_btn_dot_clicked () |
| Appends a decimal point to the current expression. | |
Private Member Functions | |
| void | updateDisplay () |
| Updates the calculator display. | |
| void | showError (mathlib::MathError err) |
| Displays an error message based on mathlib error code. | |
| void | keyPressEvent (QKeyEvent *event) override |
| Keyboard input handler. | |
| bool | endsWithOperator () const |
| Helpers for input validation. | |
| bool | hasOperator () const |
| Checks if the expression already contains a binary operator. | |
| int | findOperatorPos (QChar op) const |
| Finds the position of the binary operator in the expression. | |
| void | appendDigit (const QString &digit) |
| Appends a digit to the expression. | |
| void | appendOperator (const QString &op) |
| Appends a binary operator to the expression. | |
Private Attributes | |
| Ui::Gui * | ui |
| QString | currentExpression |
| bool | justEvaluated |
Main window class for the calculator GUI.
Handles user input, updates the display, and evaluates expressions using functions from mathlib.
|
explicit |
Constructs the GUI and initializes components.
| parent | Pointer to parent widget. |
| Gui::~Gui | ( | ) |
|
private |
Appends a digit to the expression.
If the calculator just finished an evaluation, the digit starts a new expression instead of appending to the old result.
|
private |
Appends a binary operator to the expression.
Prevents duplicate operators and enforces single-operation limit. If the user just evaluated, the result is kept and the operator is chained onto it.
Definition at line 125 of file gui.cpp.
|
private |
Helpers for input validation.
Checks if the last character in the expression is an operator.
Definition at line 73 of file gui.cpp.
|
private |
Finds the position of the binary operator in the expression.
Skips a leading minus sign so that negative first operands are handled correctly (e.g. "-5+3" splits into -5 and 3).
| op | The operator character to find. |
Definition at line 278 of file gui.cpp.
|
private |
Checks if the expression already contains a binary operator.
Skips a leading minus sign (negative number) and looks for any binary operator in the remaining characters.
Definition at line 88 of file gui.cpp.
|
overrideprivate |
Keyboard input handler.
Handles keyboard input for the calculator.
Maps keyboard keys to their corresponding button actions.
| event | The key press event. |
Definition at line 384 of file gui.cpp.
|
privateslot |
|
privateslot |
Control buttons.
Clears the current expression and resets display.
|
privateslot |
Appends a decimal point to the current expression.
Only allows one decimal point per number segment. If the calculator just evaluated, clears the expression first.
Definition at line 187 of file gui.cpp.
|
privateslot |
Evaluates the current expression.
Supports basic binary operations and simple unary operations. Displays error messages if invalid operations occur.
Definition at line 294 of file gui.cpp.
|
privateslot |
Appends factorial operator.
Only allowed at the end of a number (unary postfix operator). Prevents factorial on an empty expression or after an operator.
Definition at line 238 of file gui.cpp.
|
privateslot |
|
privateslot |
Appends square root operator.
Only allowed at the start of an expression (unary prefix operator).
Definition at line 218 of file gui.cpp.
|
private |
Displays an error message based on mathlib error code.
| err | Error type returned from mathlib. |
Definition at line 39 of file gui.cpp.
|
private |
Updates the calculator display.
If the expression is empty, displays 0.