Windows works

This commit is contained in:
2020-09-06 21:46:06 +03:00
parent 32707fbd4d
commit b1536eb16a
12 changed files with 81 additions and 63 deletions

View File

@@ -8,12 +8,14 @@
#include <QStyle>
#include <QStyleOptionSpinBox>
#include "qad_types.h"
#include "qpievaluator_p.h"
EvalSpinBox::EvalSpinBox(QWidget * parent): QAbstractSpinBox(parent) {
status = new QWidget(lineEdit());
cw = new QWidget(lineEdit());
label = new QLabel(lineEdit());
eval = new QPIEvaluator();
precision_ = -1;
// label->hide();
clear_im.load(":/icons/edit-clear-locationbar-rtl.png");
@@ -40,9 +42,10 @@ EvalSpinBox::EvalSpinBox(QWidget * parent): QAbstractSpinBox(parent) {
EvalSpinBox::~EvalSpinBox() {
delete eval;
delete label;
delete cw;
delete status;
delete label;
}
@@ -124,9 +127,9 @@ void EvalSpinBox::textChanged_(const QString & text) {
td = true;
t.chop(1);
}
bool ok = eval.check(t);
bool ok = eval->check(t);
if (ok) {
eval.evaluate();
eval->evaluate();
if (td) {
icon = icon_calc;
status->setToolTip("Enter to calc -> "+QString::number(value(), 'G', 10));
@@ -138,7 +141,7 @@ void EvalSpinBox::textChanged_(const QString & text) {
if (pv != value()) emit valueChanged(value());
} else {
icon = icon_fail;
status->setToolTip(eval.error());
status->setToolTip(eval->error());
}
resizeIcons();
}
@@ -152,16 +155,16 @@ void EvalSpinBox::setExpression_() {
td = true;
t.chop(1);
}
if (eval.check(t)) {
if (eval->check(t)) {
/*if (eval.expression() == "0") lineEdit()->clear();
else*/ lineEdit()->setText(eval.expression());
eval.evaluate();
else*/ lineEdit()->setText(eval->expression());
eval->evaluate();
if (td) lineEdit()->setText(QString::number(value(), 'G', precision_ > 0 ? precision_ : 16));
status->setToolTip("OK -> " + QString::number(value(), 'G', 10));
icon = icon_ok;
} else {
icon = icon_fail;
status->setToolTip(eval.error());
status->setToolTip(eval->error());
// qDebug() << eval.expression();
}
if (!label->isHidden()) {
@@ -169,12 +172,12 @@ void EvalSpinBox::setExpression_() {
// label->setText("<html><head/><body><p>" + eval.expression() + " <span style=\"color:#005500;\">-&gt; " + QString::number(value(), 'G', 10) + "</span></p></body></html>");
// else
// label->setText(eval.expression());
if (eval.expression() != QString::number(value(), 'G', 10) && eval.expression() != QString::number(value(), 'G', 11) && eval.isCorrect())
if (eval->expression() != QString::number(value(), 'G', 10) && eval->expression() != QString::number(value(), 'G', 11) && eval->isCorrect())
label->setText("<html><head/><body><p><span style=\"color:#005500;\">-&gt; " + QString::number(value(), 'G', 10) + "</span></p></body></html>");
else
label->setText("");
lineEdit()->blockSignals(true);
if (!eval.isCorrect()) {
if (!eval->isCorrect()) {
lineEdit()->setStyleSheet("color: darkred;");
status->show();
} else {
@@ -222,20 +225,20 @@ void EvalSpinBox::clear() {
double EvalSpinBox::value() const {
if (eval.isCorrect()) {
return eval.lastResult().real();
if (eval->isCorrect()) {
return eval->lastResult().real();
}
return 0.;
}
const QString & EvalSpinBox::expression() const {
return eval.expression();
return eval->expression();
}
bool EvalSpinBox::isCleared() const {
return (dt == eval.expression() || (value() == 0 && dt.isEmpty()));
return (dt == eval->expression() || (value() == 0 && dt.isEmpty()));
}
@@ -257,7 +260,7 @@ void EvalSpinBox::focusInEvent(QFocusEvent * event) {
status->show();
lineEdit()->blockSignals(true);
lineEdit()->setStyleSheet("");
if (eval.expression() == "0") lineEdit()->clear();
if (eval->expression() == "0") lineEdit()->clear();
lineEdit()->blockSignals(false);
QAbstractSpinBox::focusInEvent(event);
resizeIcons();
@@ -271,13 +274,13 @@ void EvalSpinBox::focusOutEvent(QFocusEvent * event) {
// label->setText("<html><head/><body><p>" + eval.expression() + " <span style=\"color:#005500;\">-&gt; " + QString::number(value(), 'G', 10) + "</span></p></body></html>");
// else
// label->setText(eval.expression());
if (eval.expression() != QString::number(value(), 'G', 10) && eval.expression() != QString::number(value(), 'G', 11) && eval.isCorrect())
if (eval->expression() != QString::number(value(), 'G', 10) && eval->expression() != QString::number(value(), 'G', 11) && eval->isCorrect())
label->setText("<html><head/><body><p><span style=\"color:#005500;\">-&gt; " + QString::number(value(), 'G', 10) + "</span></p></body></html>");
else
label->setText("");
label->show();
lineEdit()->blockSignals(true);
if (!eval.isCorrect()) lineEdit()->setStyleSheet("color: darkred;");
if (!eval->isCorrect()) lineEdit()->setStyleSheet("color: darkred;");
else status->hide();
// lineEdit()->setText(eval.expression() + " -> " + QString::number(value(), 'G', 10));
//lineEdit()->clear();
@@ -298,8 +301,8 @@ void EvalSpinBox::stepByDouble(double steps) {
//qDebug() << "step" << steps;
if (isReadOnly()) return;
QString t = text();
if (eval.check(t)) {
t = eval.expression();
if (eval->check(t)) {
t = eval->expression();
//QRegExp re("(\\-?\\d+)");
QRegExp re("[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)");
int pos = 0;
@@ -312,8 +315,8 @@ void EvalSpinBox::stepByDouble(double steps) {
double v = steps;
t = QString::number(v) + t;
}
eval.check(t);
lineEdit()->setText(eval.expression());
eval->check(t);
lineEdit()->setText(eval->expression());
}
}
@@ -326,13 +329,13 @@ void EvalSpinBox::setDefaultText(const QString & t) {
// setExpression_();
// }
//if (t == eval.expression() || (value() == 0 && t.isEmpty())) clear();
cw->setVisible((eval.expression() != dt || (dt.isEmpty() && eval.expression() == "0")) && cw_visible);
cw->setVisible((eval->expression() != dt || (dt.isEmpty() && eval->expression() == "0")) && cw_visible);
resizeIcons();
}
void EvalSpinBox::setClearButtonVisible(bool visible) {
cw_visible = visible;
cw->setVisible((eval.expression() != dt || (dt.isEmpty() && eval.expression() == "0")) && cw_visible);
cw->setVisible((eval->expression() != dt || (dt.isEmpty() && eval->expression() == "0")) && cw_visible);
resizeIcons();
}