code format

This commit is contained in:
2022-12-14 14:14:33 +03:00
parent 09e5342956
commit cdb02fc9be
278 changed files with 15371 additions and 12176 deletions

View File

@@ -1,14 +1,16 @@
#include "evalspinbox.h"
#include "qad_types.h"
#include "qpievaluator_p.h"
#include <QLineEdit>
#include <QLabel>
#include <QDebug>
#include <QLabel>
#include <QLineEdit>
#include <QMouseEvent>
#include <QPainter>
#include <QTimer>
#include <QStyle>
#include <QStyleOptionSpinBox>
#include <QMouseEvent>
#include <QTimer>
#if QT_VERSION_MAJOR <= 5
# include <QRegExp>
#else
@@ -17,10 +19,10 @@
EvalSpinBox::EvalSpinBox(QWidget * parent): QAbstractSpinBox(parent) {
status = new QWidget(lineEdit());
cw = new QWidget(lineEdit());
label = new QLabel(lineEdit());
eval = new QPIEvaluator();
status = new QWidget(lineEdit());
cw = new QWidget(lineEdit());
label = new QLabel(lineEdit());
eval = new QPIEvaluator();
precision_ = -1;
clear_im.load(":/icons/edit-clear-locationbar-rtl.png");
icon_ok.load(":/icons/dialog-ok-apply.png");
@@ -33,7 +35,7 @@ EvalSpinBox::EvalSpinBox(QWidget * parent): QAbstractSpinBox(parent) {
cw->setCursor(Qt::ArrowCursor);
cw->setToolTip(tr("Clear"));
cw->hide();
cw_visible = false;
cw_visible = false;
calc_visible = true;
cw->installEventFilter(this);
status->installEventFilter(this);
@@ -66,7 +68,7 @@ bool EvalSpinBox::eventFilter(QObject * o, QEvent * e) {
cwPaintEvent();
}
break;
default : break;
default: break;
}
return QAbstractSpinBox::eventFilter(o, e);
}
@@ -77,13 +79,13 @@ void EvalSpinBox::resizeIcons() {
int tm = (lineEdit()->height() - is + 1) / 2;
QStyleOptionFrame so;
so.initFrom(lineEdit());
QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &so, lineEdit());
QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &so, lineEdit());
QMargins m = lineEdit()->textMargins();
int lwh = label->sizeHint().width();
int lwh = label->sizeHint().width();
label->setGeometry(lineEdit()->width() - m.left() - lwh + r.x() - 2,
m.top() + r.y() + (r.height() - fontMetrics().height() + 1) / 2,
lwh,// - 2*tm - (is * 1.2) * ((status->isVisible() ? 1 : 0) + (cw->isVisible() ? 1 : 0)),
lineEdit()->height() - 2*tm);
m.top() + r.y() + (r.height() - fontMetrics().height() + 1) / 2,
lwh, // - 2*tm - (is * 1.2) * ((status->isVisible() ? 1 : 0) + (cw->isVisible() ? 1 : 0)),
lineEdit()->height() - 2 * tm);
status->setGeometry(lineEdit()->width() - (is + tm) * (cw->isVisible() ? 2 : 1), tm, is, is);
cw->setGeometry(lineEdit()->width() - (is + tm) * 1, tm, is, is);
m.setRight((is * 1.2) * ((status->isVisible() ? 1 : 0) + (cw->isVisible() ? 1 : 0)));
@@ -139,10 +141,10 @@ void EvalSpinBox::textChanged_(const QString & text) {
eval->evaluate();
if (td) {
icon = icon_calc;
status->setToolTip("Enter to calc -> "+QString::number(value(), 'G', 10));
status->setToolTip("Enter to calc -> " + QString::number(value(), 'G', 10));
} else {
icon = icon_ok;
status->setToolTip("OK -> "+QString::number(value(), 'G', 10));
status->setToolTip("OK -> " + QString::number(value(), 'G', 10));
}
if (pv != value()) {
emit valueChanged(value());
@@ -156,7 +158,7 @@ void EvalSpinBox::textChanged_(const QString & text) {
void EvalSpinBox::setExpressionSlot() {
bool td = false;
bool td = false;
double pv = value();
QString t = text();
if (t.endsWith('=')) {
@@ -174,8 +176,10 @@ void EvalSpinBox::setExpressionSlot() {
status->setToolTip(eval->error());
}
if (!label->isHidden()) {
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>");
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);
@@ -265,8 +269,10 @@ void EvalSpinBox::focusInEvent(QFocusEvent * event) {
void EvalSpinBox::focusOutEvent(QFocusEvent * event) {
QAbstractSpinBox::focusOutEvent(event);
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>");
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("");
}
@@ -274,8 +280,10 @@ void EvalSpinBox::focusOutEvent(QFocusEvent * event) {
label->show();
}
lineEdit()->blockSignals(true);
if (!eval->isCorrect()) lineEdit()->setStyleSheet("color: darkred;");
else status->hide();
if (!eval->isCorrect())
lineEdit()->setStyleSheet("color: darkred;");
else
status->hide();
lineEdit()->blockSignals(false);
resizeIcons();
}
@@ -285,11 +293,13 @@ void EvalSpinBox::wheelEvent(QWheelEvent * event) {
if (event->modifiers().testFlag(Qt::ShiftModifier)) {
stepByDouble(
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
event->delta()
event->delta()
#else
event->angleDelta().y()
event->angleDelta().y()
#endif
> 0 ? 0.1 : -0.1);
> 0
? 0.1
: -0.1);
} else {
QAbstractSpinBox::wheelEvent(event);
}
@@ -311,20 +321,20 @@ void EvalSpinBox::stepByDouble(double steps) {
t.insert(pos, QString::number(v));
} else {
double v = steps;
t = QString::number(v) + t;
t = QString::number(v) + t;
}
#else
QRegularExpression re("[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)");
QRegularExpressionMatchIterator i = re.globalMatch(t);
if (i.hasNext()) {
QRegularExpressionMatch match = i.next();
double v = t.mid(match.capturedStart(), match.capturedLength()).toDouble();
double v = t.mid(match.capturedStart(), match.capturedLength()).toDouble();
v += steps;
t.remove(match.capturedStart(), match.capturedLength());
t.insert(match.capturedStart(), QString::number(v));
} else {
double v = steps;
t = QString::number(v) + t;
t = QString::number(v) + t;
}
#endif
eval->check(t);