Files
gcs-nf/App/ComponentUI/Inputter/Inputter.cpp
T

237 lines
4.4 KiB
C++
Raw Normal View History

2020-05-06 19:17:40 +08:00
#include "Inputter.h"
#include "ui_Inputter.h"
Inputter::Inputter(QWidget *parent) :
QWidget(parent),
ui(new Ui::Inputter)
{
ui->setupUi(this);
//load qss
2020-05-09 14:46:07 +08:00
QFile file(":/qss/Inputter.qss");
file.open(QFile::ReadOnly);
QTextStream filetext(&file);
QString stylesheet = filetext.readAll();
this->setStyleSheet(stylesheet);
file.close();
2020-05-06 19:17:40 +08:00
curentStr = "";
currentValue = 0;
inputType = 0;
2020-05-07 19:14:44 +08:00
DecimalPlaces = -1;
2020-05-06 19:17:40 +08:00
ui->lineEdit->setText(curentStr);
2020-05-08 11:29:50 +08:00
ui->lineEdit->setReadOnly(true);
2020-05-06 19:17:40 +08:00
}
Inputter::~Inputter()
{
delete ui;
}
bool Inputter::event(QEvent *event)
{
if(event->type() == QEvent::Leave)
{
this->close();
}
return QWidget::event(event);
}
void Inputter::setInputType(int Type)
{
inputType = Type;
}
2020-05-07 19:14:44 +08:00
void Inputter::setInitValue(QVariant value)
{
curentStr = value.toString();
ui->lineEdit->setText(curentStr);
}
void Inputter::setDecimalPlaces(int value)
{
DecimalPlaces = value;
}
2020-05-06 19:17:40 +08:00
void Inputter::on_NumberClicked(QString str)
{
curentStr.append(str);
ui->lineEdit->setText(curentStr);
}
void Inputter::on_pushButton_1_clicked()
{
on_NumberClicked(ui->pushButton_1->text());
}
void Inputter::on_pushButton_2_clicked()
{
on_NumberClicked(ui->pushButton_2->text());
}
void Inputter::on_pushButton_3_clicked()
{
on_NumberClicked(ui->pushButton_3->text());
}
void Inputter::on_pushButton_4_clicked()
{
on_NumberClicked(ui->pushButton_4->text());
}
void Inputter::on_pushButton_5_clicked()
{
on_NumberClicked(ui->pushButton_5->text());
}
void Inputter::on_pushButton_6_clicked()
{
on_NumberClicked(ui->pushButton_6->text());
}
void Inputter::on_pushButton_7_clicked()
{
on_NumberClicked(ui->pushButton_7->text());
}
void Inputter::on_pushButton_8_clicked()
{
on_NumberClicked(ui->pushButton_8->text());
}
void Inputter::on_pushButton_9_clicked()
{
on_NumberClicked(ui->pushButton_9->text());
}
void Inputter::on_pushButton_point_clicked()
{
if(inputType == 0)
2020-05-06 19:17:40 +08:00
{
if(curentStr.size()>0)
2020-05-06 19:17:40 +08:00
{
if(curentStr.contains('.'))
{
qDebug() << "it is illegal string";
}
else
{
2020-05-19 19:02:32 +08:00
if(DecimalPlaces != 0)
{
on_NumberClicked(ui->pushButton_point->text());
}
}
2020-05-06 19:17:40 +08:00
}
else
{
qDebug() << "point can't be set in first char";
2020-05-06 19:17:40 +08:00
}
}
else
{
on_NumberClicked(ui->pushButton_point->text());
2020-05-06 19:17:40 +08:00
}
}
void Inputter::on_pushButton_0_clicked()
{
on_NumberClicked(ui->pushButton_0->text());
}
2020-06-06 16:08:11 +08:00
void Inputter::on_pushButton_minus_clicked()
{
if(curentStr.at(0) == '-')
{
curentStr = curentStr.mid(1);
}
else
{
curentStr.insert(0,'-');
}
ui->lineEdit->setText(curentStr);
}
2020-05-06 19:17:40 +08:00
void Inputter::on_pushButton_del_clicked()
{
curentStr = curentStr.mid(0,curentStr.size() - 1);
ui->lineEdit->setText(curentStr);
}
void Inputter::on_pushButton_cancel_clicked()
{
this->close();
}
void Inputter::on_pushButton_ok_clicked()
{
if(inputType == 0)
2020-05-07 19:14:44 +08:00
{
while(curentStr.at(0) == '0')
2020-05-07 19:14:44 +08:00
{
if(curentStr.contains('.'))
2020-05-07 19:14:44 +08:00
{
if(curentStr.at(1) == '.')
{
break;
}
else
{
curentStr = curentStr.mid(1);
}
2020-05-07 19:14:44 +08:00
}
else
{
if(curentStr.size() > 1)
{
curentStr = curentStr.mid(1);
}
else
{
break;
}
2020-05-07 19:14:44 +08:00
}
}
if(curentStr.at(curentStr.size()-1) == '.')
2020-05-07 19:14:44 +08:00
{
curentStr.append('0');
2020-05-07 19:14:44 +08:00
}
//判断位数
2020-06-08 17:54:17 +08:00
if(DecimalPlaces == -1)
{
curentStr = QString::number(curentStr.toDouble());
}
else
{
curentStr = QString::number(curentStr.toDouble(),'f',DecimalPlaces);
}
}
else
2020-05-07 19:14:44 +08:00
{
//mac模式
2020-06-13 21:23:53 +08:00
//点数不能超过3个,而且间隔的数字不能大于255
2020-05-07 19:14:44 +08:00
}
2020-05-06 19:17:40 +08:00
currentValue = curentStr;
qDebug() << currentValue;
emit confirmValue(currentValue);
this->deleteLater();
this->close();
}
2020-05-07 19:14:44 +08:00
void Inputter::on_pushButton_nan_clicked()
{
curentStr = "nan";
ui->lineEdit->setText(curentStr);
}
2020-06-06 16:08:11 +08:00