2022-12-27 08:25:47 +00:00
|
|
|
#include "dialog_userinput.h"
|
|
|
|
#include "ui_dialog_userinput.h"
|
2022-12-28 06:57:00 +00:00
|
|
|
#include <QRegExpValidator>
|
2022-12-28 13:03:01 +00:00
|
|
|
#include <QMessageBox>
|
2022-12-27 08:25:47 +00:00
|
|
|
|
2022-12-28 13:03:01 +00:00
|
|
|
Dialog_UserInput::Dialog_UserInput(ui_helper::value_type type, const QString &title, const wchar_t* desc, QWidget *parent) :
|
2022-12-27 08:25:47 +00:00
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::Dialog_UserInput),
|
|
|
|
m_type(type),
|
2022-12-29 02:37:26 +00:00
|
|
|
m_title(title)
|
2022-12-27 08:25:47 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2022-12-28 13:03:01 +00:00
|
|
|
ui->radioButton_yes->setVisible(false);
|
|
|
|
ui->radioButton_no->setVisible(false);
|
|
|
|
ui->lineEdit->setVisible(false);
|
|
|
|
ui->comboBox->setVisible(false);
|
2022-12-27 08:25:47 +00:00
|
|
|
if (type == ui_helper::VAL_TYPE_BOOL)
|
|
|
|
{
|
2022-12-29 02:37:26 +00:00
|
|
|
ui->label->setText(QString::fromStdWString(desc));
|
2022-12-27 08:25:47 +00:00
|
|
|
ui->radioButton_yes->setVisible(true);
|
|
|
|
ui->radioButton_no->setVisible(true);
|
|
|
|
}
|
|
|
|
else if (type == ui_helper::VAL_TYPE_INT || type == ui_helper::VAL_TYPE_FLOAT || type == ui_helper::VAL_TYPE_STRING)
|
|
|
|
{
|
2022-12-29 02:37:26 +00:00
|
|
|
ui->label->setText(QString::fromStdWString(desc));
|
2022-12-27 08:25:47 +00:00
|
|
|
ui->lineEdit->setVisible(true);
|
|
|
|
}
|
2022-12-29 02:37:26 +00:00
|
|
|
else if (type == ui_helper::VAL_TYPE_TIPS_VAL)
|
2022-12-28 13:03:01 +00:00
|
|
|
{
|
2024-01-19 01:10:31 +00:00
|
|
|
ui->label->setText(QString::fromStdWString(desc));
|
2022-12-28 13:03:01 +00:00
|
|
|
ui->comboBox->setVisible(true);
|
|
|
|
}
|
2022-12-27 08:25:47 +00:00
|
|
|
|
|
|
|
setWindowTitle(m_title);
|
2022-12-28 06:57:00 +00:00
|
|
|
|
|
|
|
QFont ft;
|
|
|
|
ft.setPointSize(15);
|
|
|
|
this->setFont(ft);
|
|
|
|
|
2023-01-06 07:17:48 +00:00
|
|
|
ui->lineEdit->setValidator(new QRegExpValidator(QRegExp("^-?(([0-9]{0,16}(\\.[0-9]{1,16})$)|([a-zA-Z0-9]+$))")));
|
2022-12-27 08:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Dialog_UserInput::~Dialog_UserInput()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
parameter *Dialog_UserInput::getParam()
|
|
|
|
{
|
|
|
|
UserInputParams *param = new UserInputParams(m_type);
|
|
|
|
if (m_type == ui_helper::VAL_TYPE_BOOL)
|
|
|
|
{
|
|
|
|
if (ui->radioButton_yes->isChecked())
|
|
|
|
param->m_bData = true;
|
|
|
|
else if (ui->radioButton_no->isChecked())
|
|
|
|
param->m_bData = false;
|
|
|
|
}
|
|
|
|
else if (m_type == ui_helper::VAL_TYPE_INT)
|
|
|
|
{
|
|
|
|
param->m_iData = ui->lineEdit->text().toInt();
|
|
|
|
}
|
|
|
|
else if (m_type == ui_helper::VAL_TYPE_FLOAT)
|
|
|
|
{
|
2023-01-05 11:33:10 +00:00
|
|
|
param->m_fData = ui->lineEdit->text().toFloat();
|
2022-12-27 08:25:47 +00:00
|
|
|
}
|
|
|
|
else if (m_type == ui_helper::VAL_TYPE_STRING)
|
|
|
|
{
|
|
|
|
param->m_sData = ui->lineEdit->text().toStdWString();
|
|
|
|
}
|
2022-12-29 02:37:26 +00:00
|
|
|
else if (m_type == ui_helper::VAL_TYPE_TIPS_VAL)
|
2022-12-28 13:03:01 +00:00
|
|
|
{
|
2024-01-19 01:10:31 +00:00
|
|
|
param->m_iData = ui->comboBox->currentIndex();
|
2022-12-28 13:03:01 +00:00
|
|
|
}
|
2022-12-27 08:25:47 +00:00
|
|
|
|
|
|
|
return param;
|
|
|
|
}
|
|
|
|
|
2023-02-08 10:24:19 +00:00
|
|
|
void Dialog_UserInput::setDistortValue(double value)
|
|
|
|
{
|
|
|
|
ui->lineEdit->setText(QString::number(value, 'f'));
|
|
|
|
ui->lineEdit->selectAll();
|
|
|
|
}
|
|
|
|
|
2024-01-19 01:10:31 +00:00
|
|
|
void Dialog_UserInput::setFwLanguageMode()
|
|
|
|
{
|
|
|
|
QStringList mode = { tr("simpleCN"), tr("trodiCN"), tr("English") };
|
|
|
|
for (int i = 0; i < mode.size(); i++)
|
|
|
|
{
|
|
|
|
ui->comboBox->addItem(mode[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-11 02:08:51 +00:00
|
|
|
void Dialog_UserInput::setDefaultSkewValue()
|
|
|
|
{
|
|
|
|
ui->lineEdit->setText(QString::number(3));
|
|
|
|
ui->lineEdit->selectAll();
|
|
|
|
}
|
|
|
|
|
2022-12-27 08:25:47 +00:00
|
|
|
void Dialog_UserInput::on_pbtn_yes_clicked()
|
|
|
|
{
|
2022-12-28 13:03:01 +00:00
|
|
|
if (ui->lineEdit->text().isEmpty() && (m_type == ui_helper::VAL_TYPE_INT || m_type == ui_helper::VAL_TYPE_FLOAT || m_type == ui_helper::VAL_TYPE_STRING))
|
|
|
|
{
|
|
|
|
QMessageBox::information(this, tr("tips"), tr("please input valid contents"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-27 08:25:47 +00:00
|
|
|
getParam();
|
|
|
|
accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Dialog_UserInput::on_pbtn_no_clicked()
|
|
|
|
{
|
|
|
|
reject();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UserInputParams::UserInputParams(ui_helper::value_type type)
|
|
|
|
{
|
|
|
|
m_type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
UserInputParams::~UserInputParams()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t UserInputParams::get_size()
|
|
|
|
{
|
|
|
|
if (m_type == ui_helper::VAL_TYPE_BOOL)
|
|
|
|
return sizeof(bool);
|
2022-12-29 02:37:26 +00:00
|
|
|
if (m_type == ui_helper::VAL_TYPE_INT || m_type == ui_helper::VAL_TYPE_TIPS_VAL)
|
2022-12-27 08:25:47 +00:00
|
|
|
return sizeof(int);
|
|
|
|
if (m_type == ui_helper::VAL_TYPE_FLOAT)
|
2023-01-05 11:33:10 +00:00
|
|
|
return sizeof(float);
|
2022-12-27 08:25:47 +00:00
|
|
|
if (m_type == ui_helper::VAL_TYPE_STRING)
|
|
|
|
return m_sData.size() + 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *UserInputParams::get_data()
|
|
|
|
{
|
|
|
|
if (m_type == ui_helper::VAL_TYPE_BOOL)
|
|
|
|
return &m_bData;
|
2022-12-29 02:37:26 +00:00
|
|
|
if (m_type == ui_helper::VAL_TYPE_INT || m_type == ui_helper::VAL_TYPE_TIPS_VAL)
|
2022-12-27 08:25:47 +00:00
|
|
|
return &m_iData;
|
|
|
|
if (m_type == ui_helper::VAL_TYPE_FLOAT)
|
|
|
|
return &m_fData;
|
|
|
|
if (m_type == ui_helper::VAL_TYPE_STRING)
|
|
|
|
return (void*)m_sData.c_str();
|
|
|
|
return nullptr;
|
|
|
|
}
|