Skip to content

Commit 8c93dcc

Browse files
committed
Added connection/function for Unary operation +/- and %
1 parent 0bd1eed commit 8c93dcc

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/build
22

33
# WINDOW
4+
/*.bat
5+
/.vscode
46

57
# MACOS General
68
.DS_Store

mainwindow.cpp

+47-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ MainWindow::MainWindow(QWidget *parent)
99
{
1010
ui->setupUi(this);
1111

12+
// number buttons
1213
connect(ui->pushButton_0, SIGNAL(released()), this, SLOT(digit_pressed()));
1314
connect(ui->pushButton_1, SIGNAL(released()), this, SLOT(digit_pressed()));
1415
connect(ui->pushButton_2, SIGNAL(released()), this, SLOT(digit_pressed()));
@@ -19,6 +20,10 @@ MainWindow::MainWindow(QWidget *parent)
1920
connect(ui->pushButton_7, SIGNAL(released()), this, SLOT(digit_pressed()));
2021
connect(ui->pushButton_8, SIGNAL(released()), this, SLOT(digit_pressed()));
2122
connect(ui->pushButton_9, SIGNAL(released()), this, SLOT(digit_pressed()));
23+
24+
// unary operation buttons.
25+
connect(ui->pushButton_plusMinus, SIGNAL(released()), this, SLOT(unary_operation_pressed()));
26+
connect(ui->pushButton_percent, SIGNAL(released()), this, SLOT(unary_operation_pressed()));
2227
}
2328

2429
MainWindow::~MainWindow()
@@ -30,17 +35,53 @@ void MainWindow::digit_pressed()
3035
{
3136
QPushButton * button = (QPushButton*)sender();
3237

33-
// check which button signal was received.
34-
qDebug() << button->text();
35-
3638
double labelNumber;
3739
QString newLabel;
3840

39-
// labelNumber = (button->text()).toDouble(); // without new string append.
4041
labelNumber = (ui->label->text() + button->text()).toDouble();
41-
4242
newLabel = QString::number(labelNumber, 'g', 15);
4343

44-
// ui->label->setText(button->text()); // set label text "Single character"
4544
ui->label->setText(newLabel);
4645
}
46+
47+
void MainWindow::on_pushButton_decimal_released()
48+
{
49+
ui->label->setText(ui->label->text() + ".");
50+
}
51+
52+
void MainWindow::unary_operation_pressed()
53+
{
54+
QPushButton *button = (QPushButton*)sender();
55+
QString newLabel;
56+
double labelNumber;
57+
58+
if (button->text() == "+/-")
59+
{
60+
labelNumber = ui->label->text().toDouble();
61+
labelNumber = labelNumber * -1;
62+
newLabel = QString::number(labelNumber, 'g', 15);
63+
ui->label->setText(newLabel);
64+
}
65+
if (button->text() == "%")
66+
{
67+
labelNumber = ui->label->text().toDouble();
68+
labelNumber = labelNumber * 0.01;
69+
newLabel = QString::number(labelNumber, 'g', 15);
70+
ui->label->setText(newLabel);
71+
}
72+
}
73+
74+
void MainWindow::on_pushButton_clear_released()
75+
{
76+
77+
}
78+
79+
void MainWindow::on_pushButton_equals_released()
80+
{
81+
82+
}
83+
84+
void MainWindow::binary_operation_pressed()
85+
{
86+
87+
}

mainwindow.h

+5
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,10 @@ class MainWindow : public QMainWindow
2020

2121
private slots:
2222
void digit_pressed();
23+
void on_pushButton_decimal_released();
24+
void unary_operation_pressed();
25+
void on_pushButton_clear_released();
26+
void on_pushButton_equals_released();
27+
void binary_operation_pressed();
2328
};
2429
#endif // MAINWINDOW_H

0 commit comments

Comments
 (0)