📄 calcwindow.cpp
字号:
try {
__rep.setExpression(inputLineEdit->text());
__rep.calculate();
postCalculate();
outputLineEdit->setText(__rep.baseResultString());
}
catch (Exception& e) {
statusLabel->setText(QString("<font color=red>") +
tr(e.debugPrint()) + QString("</font>"));
}
}
void CalculatorWindow::baseClicked()
{
QRadioButton* clickedButton = qobject_cast<QRadioButton*>(sender());
if (clickedButton == baseHexRadioButton)
__rep.setOutputBase(CalculatorRep::Hex);
else if (clickedButton == baseDecRadioButton)
__rep.setOutputBase(CalculatorRep::Dec);
else if (clickedButton == baseOctRadioButton)
__rep.setOutputBase(CalculatorRep::Oct);
outputLineEdit->setText(__rep.baseResultString());
}
void CalculatorWindow::formatClicked()
{
QRadioButton* clickedButton = qobject_cast<QRadioButton*>(sender());
if (clickedButton == normRadioButton)
__rep.setOutputFormat(CalculatorRep::Normal);
else if (clickedButton == sciRadioButton)
__rep.setOutputFormat(CalculatorRep::Scientific);
else if (clickedButton == fixRadioButton)
__rep.setOutputFormat(CalculatorRep::Fixed);
outputLineEdit->setText(__rep.resultString());
baseDecRadioButton->setChecked(true);
}
void CalculatorWindow::triangleToggled()
{
Qt::CheckState arcState = arcCheckBox->checkState();
Qt::CheckState hypState = hyperCheckBox->checkState();
if (arcState == Qt::Checked && hypState == Qt::Unchecked) {
sinButton->setText("asin");
cosButton->setText("acos");
tanButton->setText("atan");
}
else if (arcState == Qt::Unchecked && hypState == Qt::Checked) {
sinButton->setText("sinh");
cosButton->setText("cosh");
tanButton->setText("tanh");
}
else if (arcState == Qt::Checked && hypState == Qt::Checked) {
sinButton->setText("asinh");
cosButton->setText("acosh");
tanButton->setText("atanh");
}
else {
sinButton->setText("sin");
cosButton->setText("cos");
tanButton->setText("tan");
}
}
void CalculatorWindow::statisticClicked()
{
QPushButton* clickedButton = qobject_cast<QPushButton*>(sender());
if (clickedButton == staStoreButton)
{
__rep.staStore();
QString str = QString("%1").arg(__rep.result(), 0, 'g', 15);
staDialog->add(str);
}
else if (clickedButton == staClearButton)
{
__rep.staClear();
staDialog->clearList();
}
else if (clickedButton == staNumButton) {
__rep.staNum();
outputLineEdit->setText(__rep.resultString());
}
else if (clickedButton == staSumButton) {
__rep.staSum();
outputLineEdit->setText(__rep.resultString());
}
else if (clickedButton == staAverageButton) {
__rep.staAverage();
outputLineEdit->setText(__rep.resultString());
}
else if (clickedButton == staStdDiffButton) {
__rep.staStdDiff();
outputLineEdit->setText(__rep.resultString());
}
else if (clickedButton == staMinButton) {
__rep.staMin();
outputLineEdit->setText(__rep.resultString());
}
else if (clickedButton == staMaxButton) {
__rep.staMax();
outputLineEdit->setText(__rep.resultString());
}
}
void CalculatorWindow::memoryClicked()
{
QPushButton* clickedButton = qobject_cast<QPushButton*>(sender());
if (clickedButton == memClearButton)
__rep.memClear();
else if (clickedButton == memSubtractButton)
__rep.memSubtract();
else if (clickedButton == memPlusButton)
__rep.memPlus();
else if (clickedButton == memRecallButton) {
__rep.memRecall();
outputLineEdit->setText(__rep.resultString());
}
}
void CalculatorWindow::createActions()
{
copyAct = new QAction(QIcon(":/images/copy.png"), tr("&Copy from output"), this);
copyAct->setShortcut(tr("F2"));
connect(copyAct, SIGNAL(triggered()), this, SLOT(copyClicked()));
pasteAct = new QAction(QIcon(":/images/paste.png"), tr("&Paste to input"), this);
pasteAct->setShortcut(tr("F3"));
connect(pasteAct, SIGNAL(triggered()), this, SLOT(inputPaste()));
undoAct = new QAction(QIcon(":/images/undo.png"), tr("&Undo"), this);
undoAct->setShortcut(tr("Ctrl+Z"));
connect(undoAct, SIGNAL(triggered()), inputLineEdit, SLOT(undo()));
redoAct = new QAction(QIcon(":/images/redo.png"), tr("&Redo"), this);
redoAct->setShortcut(tr("Ctrl+Y"));
connect(redoAct, SIGNAL(triggered()), inputLineEdit, SLOT(redo()));
aboutAct = new QAction(QIcon(":/images/calculator.png"), tr("&About..."), this);
connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
aboutQtAct = new QAction(QIcon(":/images/qt.png"), tr("About &Qt..."), this);
connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
helpAct = new QAction(tr("DIS Calculator &Help"), this);
helpAct->setShortcut(tr("F1"));
connect(helpAct, SIGNAL(triggered()), this, SLOT(help()));
}
void CalculatorWindow::createMenus()
{
editMenu = menuBar()->addMenu(tr("&Edit"));
editMenu->addAction(undoAct);
editMenu->addAction(redoAct);
editMenu->addSeparator();
editMenu->addAction(copyAct);
editMenu->addAction(pasteAct);
connect(editMenu, SIGNAL(aboutToShow()), this, SLOT(editClicked()));
helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(helpAct);
helpMenu->addSeparator();
helpMenu->addAction(aboutAct);
helpMenu->addAction(aboutQtAct);
}
void CalculatorWindow::editClicked()
{
undoAct->setEnabled(inputLineEdit->isUndoAvailable());
redoAct->setEnabled(inputLineEdit->isRedoAvailable());
}
void CalculatorWindow::copyClicked()
{
outputLineEdit->selectAll();
outputLineEdit->copy();
outputLineEdit->deselect();
inputLineEdit->setFocus();
}
void CalculatorWindow::inputPaste()
{
clearClicked();
inputLineEdit->paste();
inputLineEdit->setFocus();
}
void CalculatorWindow::about()
{
AboutDialog dialog(this);
connect(&dialog, SIGNAL(help()), this, SLOT(help()));
dialog.exec();
}
void CalculatorWindow::help()
{
if (!helpWindow) {
helpWindow = new HelpWindow(this);
}
helpWindow->show();
helpWindow->raise();
helpWindow->activateWindow();
}
void CalculatorWindow::toggleStaDialog(bool on)
{
if (on) {
if (!staDialog) {
staDialog = new StatisticDialog(this);
connect(staDialog, SIGNAL(staReturn()), this, SLOT(returnMainwindow()));
connect(staDialog, SIGNAL(staLoad(int)), this, SLOT(staLoad(int)));
connect(staDialog, SIGNAL(staDelete(int)), this, SLOT(staDelete(int)));
connect(staDialog, SIGNAL(staClearAll()), this, SLOT(staClearAll()));
staDialog->move(this->x() + this->width(), this->y());
}
staDialog->show();
staDialog->raise();
activateWindow();
} else
{
activateWindow();
staDialog->hide();
}
}
void CalculatorWindow::returnMainwindow()
{
this->raise();
this->activateWindow();
}
void CalculatorWindow::staLoad(const int index)
{
if (index >= 0)
{
QString str = QString("%1").arg(__rep.staLoad(index), 0, 'g', 15);
input(str);
}
}
void CalculatorWindow::staDelete(const int index)
{
__rep.staDelete(index);
}
void CalculatorWindow::staClearAll()
{
__rep.staClear();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -