code_app/modules/twainui/dialog_input.cpp

66 lines
1.3 KiB
C++
Raw Normal View History

2023-04-20 09:49:48 +00:00
#include "dialog_input.h"
#include "ui_dialog_input.h"
#include <qmessagebox.h>
#include <QRegularExpression>
Dialog_Input::Dialog_Input(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog_Input)
{
ui->setupUi(this);
}
Dialog_Input::~Dialog_Input()
{
delete ui;
}
void Dialog_Input::on_pushButton_clicked()
{
QString text = ui->lineEdit->text();
static QRegularExpression re("\\s");
text.remove(re);//Remove space
std::string str(text.toStdString());
int pos = 0;
while(pos < str.length() && str[pos++] == ' ');
if(--pos > 0)
str.erase(0, pos);
pos = str.length() - 1;
while(pos >= 0)
{
if(str[pos] != ' ')
break;
}
str.erase(pos + 1);
if(str.empty())
{
QString title(QString::fromStdString("\351\224\231\350\257\257")),
text(QString::fromStdString("\350\276\223\345\205\245\351\235\236\346\263\225"));
QMessageBox::warning(this, title, text);
return;
}
val_ = QString::fromStdString(str);
done(1);
}
void Dialog_Input::on_pushButton_2_clicked()
{
done(0);
}
void Dialog_Input::init_value(const QString& str)
{
val_ = str;
ui->lineEdit->setText(str);
ui->lineEdit->setSelection(0, str.length());
}
QString Dialog_Input::get_inputting_value(void)
{
return val_;
}