就这样吧
This commit is contained in:
parent
ad8f153aaa
commit
9b1d453853
4 changed files with 92 additions and 24 deletions
|
@ -59,9 +59,6 @@ QString inToPost(QString infix) {
|
||||||
case '.':
|
case '.':
|
||||||
postfix.push_back(current);
|
postfix.push_back(current);
|
||||||
break;
|
break;
|
||||||
case '%':
|
|
||||||
postfix.push_back(current);
|
|
||||||
break;
|
|
||||||
case '(':
|
case '(':
|
||||||
stack.push(current); //左括号直接入栈
|
stack.push(current); //左括号直接入栈
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -2,10 +2,11 @@
|
||||||
#include "cal.h"
|
#include "cal.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
#include <QDebug>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
static QString displayText;
|
static QString displayText;
|
||||||
|
static QString calcLog;
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent), ui(new Ui::MainWindow) {
|
: QMainWindow(parent), ui(new Ui::MainWindow) {
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
@ -52,13 +53,19 @@ void MainWindow::on_equalBtn_clicked() {
|
||||||
if (isFinished)
|
if (isFinished)
|
||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
result = compute(inToPost(ui->lineEdit->toPlainText().right(
|
QString s = inToPost(ui->lineEdit->toPlainText().right(
|
||||||
ui->lineEdit->toPlainText().size() -
|
ui->lineEdit->toPlainText().size() -
|
||||||
(ui->lineEdit->toPlainText().lastIndexOf("\n") + 1))));
|
(ui->lineEdit->toPlainText().lastIndexOf("\n") + 1)));
|
||||||
|
std::cout << s.toStdString() << std::endl;
|
||||||
|
result = compute(s);
|
||||||
|
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
abortOperation();
|
abortOperation();
|
||||||
}
|
}
|
||||||
|
calcLog += ui->lineEdit->toPlainText().right(
|
||||||
|
ui->lineEdit->toPlainText().size() -
|
||||||
|
(ui->lineEdit->toPlainText().lastIndexOf("\n") + 1)) +
|
||||||
|
'=' + QString::number(result) + '\n';
|
||||||
displayText += '=' + QString::number(result);
|
displayText += '=' + QString::number(result);
|
||||||
ui->lineEdit->setPlainText(displayText);
|
ui->lineEdit->setPlainText(displayText);
|
||||||
ui->lineEdit->verticalScrollBar()->setValue(
|
ui->lineEdit->verticalScrollBar()->setValue(
|
||||||
|
@ -75,7 +82,7 @@ void MainWindow::connectSlots() {
|
||||||
ui->digitBtn8, ui->digitBtn9, ui->addBtn, ui->subtractionBtn,
|
ui->digitBtn8, ui->digitBtn9, ui->addBtn, ui->subtractionBtn,
|
||||||
ui->mulBtn, ui->divisionBtn, ui->squareBtn, ui->pointBtn,
|
ui->mulBtn, ui->divisionBtn, ui->squareBtn, ui->pointBtn,
|
||||||
ui->LBtn, ui->RBtn, ui->cBtn, ui->sBtn,
|
ui->LBtn, ui->RBtn, ui->cBtn, ui->sBtn,
|
||||||
ui->perBtn};
|
ui->sciBtn};
|
||||||
for (auto btn : digitBtns)
|
for (auto btn : digitBtns)
|
||||||
connect(btn, &QPushButton::clicked, this, &MainWindow::normalClicked);
|
connect(btn, &QPushButton::clicked, this, &MainWindow::normalClicked);
|
||||||
}
|
}
|
||||||
|
@ -94,6 +101,12 @@ void MainWindow::on_actionClearHistroy_triggered() {
|
||||||
ui->lineEdit->verticalScrollBar()->maximum());
|
ui->lineEdit->verticalScrollBar()->maximum());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_actionShow_History_H_triggered() {
|
||||||
|
ui->lineEdit->setPlainText(calcLog);
|
||||||
|
ui->lineEdit->verticalScrollBar()->setValue(
|
||||||
|
ui->lineEdit->verticalScrollBar()->maximum());
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_clearLine_clicked() {
|
void MainWindow::on_clearLine_clicked() {
|
||||||
isFinished = false;
|
isFinished = false;
|
||||||
displayText.chop(displayText.size() - displayText.lastIndexOf('\n') - 1);
|
displayText.chop(displayText.size() - displayText.lastIndexOf('\n') - 1);
|
||||||
|
@ -165,15 +178,21 @@ void MainWindow::keyPressEvent(QKeyEvent *event) {
|
||||||
case Qt::Key_AsciiCircum:
|
case Qt::Key_AsciiCircum:
|
||||||
emit ui->squareBtn->clicked();
|
emit ui->squareBtn->clicked();
|
||||||
break;
|
break;
|
||||||
case Qt::Key_BracketLeft:
|
case Qt::Key_ParenLeft:
|
||||||
emit ui->LBtn->clicked();
|
emit ui->LBtn->clicked();
|
||||||
break;
|
break;
|
||||||
case Qt::Key_BracketRight:
|
case Qt::Key_ParenRight:
|
||||||
emit ui->RBtn->clicked();
|
emit ui->RBtn->clicked();
|
||||||
break;
|
break;
|
||||||
case Qt::Key_A:
|
case Qt::Key_A:
|
||||||
emit ui->ansBtn->clicked();
|
emit ui->ansBtn->clicked();
|
||||||
break;
|
break;
|
||||||
|
case Qt::Key_S:
|
||||||
|
emit ui->sBtn->clicked();
|
||||||
|
break;
|
||||||
|
case Qt::Key_C:
|
||||||
|
emit ui->cBtn->clicked();
|
||||||
|
break;
|
||||||
case Qt::Key_Equal:
|
case Qt::Key_Equal:
|
||||||
case Qt::Key_Enter:
|
case Qt::Key_Enter:
|
||||||
emit ui->equalBtn->clicked();
|
emit ui->equalBtn->clicked();
|
||||||
|
@ -190,3 +209,25 @@ void MainWindow::keyPressEvent(QKeyEvent *event) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_actionc_triggered() {
|
||||||
|
if (isFinished) {
|
||||||
|
isFinished = false;
|
||||||
|
displayText += '\n';
|
||||||
|
}
|
||||||
|
displayText += "299792458";
|
||||||
|
ui->lineEdit->setPlainText(displayText);
|
||||||
|
ui->lineEdit->verticalScrollBar()->setValue(
|
||||||
|
ui->lineEdit->verticalScrollBar()->maximum());
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_actionpi_triggered() {
|
||||||
|
if (isFinished) {
|
||||||
|
isFinished = false;
|
||||||
|
displayText += '\n';
|
||||||
|
}
|
||||||
|
displayText += "3.1415926535";
|
||||||
|
ui->lineEdit->setPlainText(displayText);
|
||||||
|
ui->lineEdit->verticalScrollBar()->setValue(
|
||||||
|
ui->lineEdit->verticalScrollBar()->maximum());
|
||||||
|
}
|
||||||
|
|
|
@ -39,5 +39,8 @@ private slots:
|
||||||
|
|
||||||
void keyPressEvent(QKeyEvent *event);
|
void keyPressEvent(QKeyEvent *event);
|
||||||
void on_ansBtn_clicked();
|
void on_ansBtn_clicked();
|
||||||
|
void on_actionc_triggered();
|
||||||
|
void on_actionpi_triggered();
|
||||||
|
void on_actionShow_History_H_triggered();
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
|
@ -6,12 +6,12 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>406</width>
|
<width>414</width>
|
||||||
<height>439</height>
|
<height>479</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Calculator_v3_4490</string>
|
<string>Calculator_v6_4490</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolButtonStyle">
|
<property name="toolButtonStyle">
|
||||||
<enum>Qt::ToolButtonTextOnly</enum>
|
<enum>Qt::ToolButtonTextOnly</enum>
|
||||||
|
@ -168,13 +168,6 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="8" column="0">
|
|
||||||
<widget class="QPushButton" name="perBtn">
|
|
||||||
<property name="text">
|
|
||||||
<string>%</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="7" column="3">
|
<item row="7" column="3">
|
||||||
<widget class="QPushButton" name="cBtn">
|
<widget class="QPushButton" name="cBtn">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -189,6 +182,13 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="8" column="2" colspan="2">
|
||||||
|
<widget class="QPushButton" name="equalBtn">
|
||||||
|
<property name="text">
|
||||||
|
<string>=</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="8" column="1">
|
<item row="8" column="1">
|
||||||
<widget class="QPushButton" name="ansBtn">
|
<widget class="QPushButton" name="ansBtn">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -196,10 +196,10 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="8" column="2" colspan="2">
|
<item row="8" column="0">
|
||||||
<widget class="QPushButton" name="equalBtn">
|
<widget class="QPushButton" name="sciBtn">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>=</string>
|
<string>*10^</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -210,7 +210,7 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>406</width>
|
<width>414</width>
|
||||||
<height>30</height>
|
<height>30</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
@ -220,8 +220,17 @@
|
||||||
</property>
|
</property>
|
||||||
<addaction name="actionPaste"/>
|
<addaction name="actionPaste"/>
|
||||||
<addaction name="actionClearHistroy"/>
|
<addaction name="actionClearHistroy"/>
|
||||||
|
<addaction name="actionShow_History_H"/>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenu" name="menuConstant">
|
||||||
|
<property name="title">
|
||||||
|
<string>Constant</string>
|
||||||
|
</property>
|
||||||
|
<addaction name="actionc"/>
|
||||||
|
<addaction name="actionpi"/>
|
||||||
</widget>
|
</widget>
|
||||||
<addaction name="menuMenu"/>
|
<addaction name="menuMenu"/>
|
||||||
|
<addaction name="menuConstant"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QStatusBar" name="statusbar"/>
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
<action name="actionPaste">
|
<action name="actionPaste">
|
||||||
|
@ -234,12 +243,30 @@
|
||||||
</action>
|
</action>
|
||||||
<action name="actionClearHistroy">
|
<action name="actionClearHistroy">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Clear Histroy(U)</string>
|
<string>Clear Buffer(U)</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut">
|
<property name="shortcut">
|
||||||
<string>Ctrl+U</string>
|
<string>Ctrl+U</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionc">
|
||||||
|
<property name="text">
|
||||||
|
<string>c</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionpi">
|
||||||
|
<property name="text">
|
||||||
|
<string>pi</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionShow_History_H">
|
||||||
|
<property name="text">
|
||||||
|
<string>Show History(H)</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+H</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|
Reference in a new issue