19 : QMainWindow(parent),
43 QMessageBox::warning(
this,
"Error",
"Division by zero!");
46 QMessageBox::warning(
this,
"Error",
"Factorial of negative number!");
49 QMessageBox::warning(
this,
"Error",
"Invalid root operation!");
52 QMessageBox::warning(
this,
"Error",
"Invalid argument!");
77 return last ==
'+' || last ==
'-' || last ==
'*' ||
78 last ==
'/' || last ==
'%' || last ==
'^';
93 if (c ==
'+' || c ==
'*' || c ==
'/' || c ==
'%' || c ==
'^')
198 if (c ==
'+' || c ==
'-' || c ==
'*' ||
199 c ==
'/' || c ==
'%' || c ==
'^') {
207 if (!segment.contains(
'.')) {
309 bool evaluated =
false;
333 const QString ops =
"+*/%^";
334 for (QChar c : ops) {
336 if (pos != -1) { op = c;
break; }
341 if (pos != -1) op =
'-';
353 else if (op ==
'^') result =
mathlib::power(left,
static_cast<int>(right));
386 int key =
event->key();
389 if (key >= Qt::Key_0 && key <= Qt::Key_9) {
402 case Qt::Key_Asterisk:
408 case Qt::Key_Percent:
411 case Qt::Key_AsciiCircum:
432 case Qt::Key_Backspace:
450 QMainWindow::keyPressEvent(event);
Main window class for the calculator GUI.
void on_btn_plus_clicked()
Operation button handlers.
bool hasOperator() const
Checks if the expression already contains a binary operator.
void on_btn_clear_clicked()
Control buttons.
void updateDisplay()
Updates the calculator display.
QString currentExpression
int findOperatorPos(QChar op) const
Finds the position of the binary operator in the expression.
~Gui()
Destructor. Frees allocated resources.
bool endsWithOperator() const
Helpers for input validation.
void on_btn_div_clicked()
void appendOperator(const QString &op)
Appends a binary operator to the expression.
void on_btn_mul_clicked()
void on_btn_mod_clicked()
Gui(QWidget *parent=nullptr)
Constructs the GUI and initializes components.
void on_btn_root_clicked()
Appends square root operator.
void appendDigit(const QString &digit)
Appends a digit to the expression.
void on_btn_minus_clicked()
void on_btn_pow_clicked()
void on_btn_0_clicked()
Digit button handlers.
void on_btn_dot_clicked()
Appends a decimal point to the current expression.
void keyPressEvent(QKeyEvent *event) override
Keyboard input handler.
void showError(mathlib::MathError err)
Displays an error message based on mathlib error code.
void on_btn_equal_clicked()
Evaluates the current expression.
void on_btn_fac_clicked()
Appends factorial operator.
Library for the calculator GUI.
double root(double base, int n, MathError &err)
Implementation of function root.
double add(double a, double b)
Implementation of function add.
double multiply(double a, double b)
Implementation of function multiply.
double modulo(double a, double b, MathError &err)
Implementation of function modulo.
double divide(double a, double b, MathError &err)
Implementation of function divide.
double subtract(double a, double b)
Implementation of function subtract.
double factorial(int a, MathError &err)
Implementation of function factorial.
double power(double base, int exp)
Implementation of function power.