459 lines
11 KiB
C++
459 lines
11 KiB
C++
#include "ConnectDialog.h"
|
|
#include "ui_ConnectDialog.h"
|
|
|
|
ConnectDialog::ConnectDialog(QWidget *parent) :
|
|
QWidget(parent),
|
|
ui(new Ui::ConnectDialog)
|
|
{
|
|
ui->setupUi(this);
|
|
setWindowTitle("ConnectDialog");
|
|
|
|
//load qss
|
|
QFile file(":/qss/ConnectDialog.qss");
|
|
file.open(QFile::ReadOnly);
|
|
QTextStream filetext(&file);
|
|
QString stylesheet = filetext.readAll();
|
|
this->setStyleSheet(stylesheet);
|
|
file.close();
|
|
|
|
|
|
|
|
serialInfo = new QSerialPortInfo();
|
|
|
|
|
|
connect(ui->pushButton_usrName,SIGNAL(clicked()),
|
|
this,SLOT(onUsrNameClicked()));
|
|
|
|
connect(ui->pushButton_type,SIGNAL(clicked()),
|
|
this,SLOT(onTypeClicked()));
|
|
|
|
connect(ui->pushButton_param1,SIGNAL(clicked()),
|
|
this,SLOT(onParam1Clicked()));
|
|
|
|
connect(ui->pushButton_param2,SIGNAL(clicked()),
|
|
this,SLOT(onParam2Clicked()));
|
|
|
|
connect(ui->pushButton_param3,SIGNAL(clicked()),
|
|
this,SLOT(onParam3Clicked()));
|
|
|
|
connect(ui->pushButton_param4,SIGNAL(clicked()),
|
|
this,SLOT(onParam4Clicked()));
|
|
|
|
connect(ui->pushButton_param5,SIGNAL(clicked()),
|
|
this,SLOT(onParam5Clicked()));
|
|
|
|
connect(ui->pushButton_Connect,SIGNAL(clicked()),
|
|
this,SLOT(onConnectClicked()));
|
|
|
|
|
|
|
|
|
|
//默认串口
|
|
m_usrName = tr("unname");
|
|
m_Type = tr("SerialPort");
|
|
|
|
|
|
foreach(QSerialPortInfo info, serialInfo->availablePorts())
|
|
{
|
|
m_Param1 = info.portName();
|
|
}
|
|
|
|
|
|
m_Param2 = tr("115200");
|
|
m_Param3 = tr("8");
|
|
m_Param4 = tr("NONE");
|
|
m_Param5 = tr("1");
|
|
|
|
emit usrNameChanged(m_usrName);
|
|
reBuildList();
|
|
|
|
}
|
|
|
|
ConnectDialog::~ConnectDialog()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
//重建列表
|
|
//usrname type local port remote port none close
|
|
//usrname type com baud Len Parity Stop close
|
|
|
|
|
|
|
|
void ConnectDialog::reBuildList(void)
|
|
{
|
|
|
|
|
|
ui->pushButton_param1->show();
|
|
ui->pushButton_param2->show();
|
|
ui->pushButton_param3->show();
|
|
ui->pushButton_param4->show();
|
|
ui->pushButton_param5->show();
|
|
|
|
if(m_Type.toString() == tr("SerialPort"))
|
|
{
|
|
ui->label_usrName->setText(tr("User Name"));
|
|
ui->label_Type->setText(tr("Type"));
|
|
ui->label_Param1->setText(tr("Port"));
|
|
ui->label_Param2->setText(tr("Baud"));
|
|
ui->label_Param3->setText(tr("Data"));
|
|
ui->label_Param4->setText(tr("Parity"));
|
|
ui->label_Param5->setText(tr("Stop"));
|
|
|
|
|
|
QString checkbusy;
|
|
foreach(QSerialPortInfo info, serialInfo->availablePorts())
|
|
{
|
|
if(info.portName() == m_Param1.toString())
|
|
{
|
|
ui->pushButton_Connect->setDisabled(false);
|
|
if(info.isBusy())
|
|
{
|
|
checkbusy.append(tr("this port is busy now\n"));
|
|
ui->pushButton_Connect->setDisabled(true);
|
|
}
|
|
else checkbusy = "";
|
|
ui->label_Description->setText(checkbusy + info.description());
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
else if(m_Type.toString() == tr("UDP"))
|
|
{
|
|
ui->label_usrName->setText(tr("User Name"));
|
|
ui->label_Type->setText(tr("Type"));
|
|
ui->label_Param1->setText(tr("Local"));
|
|
ui->label_Param2->setText(tr(""));
|
|
ui->label_Param3->setText(tr("Remote"));
|
|
ui->label_Param4->setText(tr(""));
|
|
ui->label_Param5->setText(tr(""));
|
|
|
|
ui->pushButton_param5->hide();
|
|
}
|
|
|
|
ui->pushButton_usrName->setText(m_usrName.toString());
|
|
ui->pushButton_type->setText(m_Type.toString());
|
|
ui->pushButton_param1->setText(m_Param1.toString());
|
|
ui->pushButton_param2->setText(m_Param2.toString());
|
|
ui->pushButton_param3->setText(m_Param3.toString());
|
|
ui->pushButton_param4->setText(m_Param4.toString());
|
|
ui->pushButton_param5->setText(m_Param5.toString());
|
|
|
|
emit usrNameChanged(m_usrName);
|
|
|
|
}
|
|
|
|
|
|
void ConnectDialog::setUsrName(QVariant value)
|
|
{
|
|
m_usrName = value;
|
|
reBuildList();
|
|
}
|
|
|
|
void ConnectDialog::onUsrNameClicked(void)//英文输入
|
|
{
|
|
CharInputter *inputter = new CharInputter(this);
|
|
inputter->setGeometry(0,0,this->width(),this->height());
|
|
|
|
inputter->setInitValue(ui->pushButton_usrName->text());
|
|
|
|
connect(inputter,SIGNAL(confirmValue(QVariant)),
|
|
this,SLOT(setUsrName(QVariant)));
|
|
|
|
inputter->show();
|
|
}
|
|
|
|
|
|
void ConnectDialog::setType(QVariant value)
|
|
{
|
|
m_Type = value;
|
|
//载入默认值
|
|
if(m_Type.toString() == tr("SerialPort"))
|
|
{
|
|
m_usrName = tr("Port");
|
|
|
|
QString tiltle = this->windowTitle();
|
|
tiltle = tiltle.simplified();
|
|
tiltle = tiltle.replace(" ","");
|
|
QSettings *configIni = new QSettings("./connetconfig.ini", QSettings::IniFormat);
|
|
QString LastPortName = configIni->value("/"+tiltle+"/Port").toString();
|
|
|
|
foreach(QSerialPortInfo info, serialInfo->availablePorts())
|
|
{
|
|
if(info.portName() == LastPortName)
|
|
{
|
|
m_Param1 = LastPortName;
|
|
}
|
|
else
|
|
{
|
|
m_Param1 = info.portName();
|
|
}
|
|
}
|
|
|
|
m_Param2 = tr("115200");
|
|
m_Param3 = tr("8");
|
|
m_Param4 = tr("NONE");
|
|
m_Param5 = tr("1");
|
|
}
|
|
else
|
|
{
|
|
m_usrName = tr("Net");
|
|
|
|
m_Param1 = tr("127.0.0.1");
|
|
m_Param2 = tr("6061");
|
|
m_Param3 = tr("127.0.0.1");
|
|
m_Param4 = tr("6060");
|
|
m_Param5 = "";
|
|
}
|
|
|
|
reBuildList();
|
|
}
|
|
|
|
|
|
void ConnectDialog::onTypeClicked(void)//选择器
|
|
{
|
|
Selector *selector = new Selector(this);
|
|
selector->setGeometry(0,0,this->width(),this->height());
|
|
|
|
QStringList list;
|
|
|
|
list << "SerialPort"
|
|
<< "UDP";
|
|
|
|
selector->setList(list,ui->pushButton_type->text());
|
|
|
|
connect(selector,SIGNAL(confirmValue(QVariant)),
|
|
this,SLOT(setType(QVariant)));
|
|
|
|
selector->show();
|
|
}
|
|
|
|
void ConnectDialog::setParam1(QVariant value)
|
|
{
|
|
m_Param1 = value;
|
|
reBuildList();
|
|
}
|
|
|
|
void ConnectDialog::onParam1Clicked(void)//name/localaddr 串口-选择 udp-输入
|
|
{
|
|
if(ui->pushButton_type->text() == "SerialPort")
|
|
{
|
|
Selector *selector = new Selector(this);
|
|
selector->setGeometry(0,0,this->width(),this->height());
|
|
|
|
QStringList list;
|
|
|
|
foreach(QSerialPortInfo info, serialInfo->availablePorts())
|
|
{
|
|
list.append(info.portName());
|
|
}
|
|
|
|
//检查如果存在上传连接的串口,那么就设置为当前默认的串口,如果不存在,那么就不设置默认串口
|
|
|
|
QString tiltle = this->windowTitle();
|
|
tiltle = tiltle.simplified();
|
|
tiltle = tiltle.replace(" ","");
|
|
|
|
|
|
QSettings *configIni = new QSettings("./connetconfig.ini", QSettings::IniFormat);
|
|
QString LastPortName = configIni->value("/"+tiltle+"/Port").toString();
|
|
|
|
foreach(QSerialPortInfo info, serialInfo->availablePorts())
|
|
{
|
|
if(info.portName() == LastPortName)
|
|
{
|
|
selector->setList(list,LastPortName);
|
|
}
|
|
else
|
|
{
|
|
selector->setList(list,ui->pushButton_param1->text());
|
|
}
|
|
}
|
|
|
|
connect(selector,SIGNAL(confirmValue(QVariant)),
|
|
this,SLOT(setParam1(QVariant)));
|
|
|
|
selector->show();
|
|
}
|
|
else//net
|
|
{
|
|
Inputter *inputter = new Inputter(this);
|
|
inputter->setGeometry(0,0,this->width(),this->height());
|
|
inputter->setInputType(1);
|
|
inputter->setInitValue(ui->pushButton_param1->text());
|
|
inputter->setDecimalPlaces(0);
|
|
|
|
connect(inputter,SIGNAL(confirmValue(QVariant)),
|
|
this,SLOT(setParam1(QVariant)));
|
|
|
|
inputter->show();
|
|
}
|
|
|
|
}
|
|
|
|
void ConnectDialog::setParam2(QVariant value)
|
|
{
|
|
m_Param2 = value;
|
|
reBuildList();
|
|
}
|
|
|
|
void ConnectDialog::onParam2Clicked(void)//baud/localport 串口-输入 udp-输入
|
|
{
|
|
Inputter *inputter = new Inputter(this);
|
|
inputter->setGeometry(0,0,this->width(),this->height());
|
|
inputter->setInputType(0);
|
|
inputter->setDecimalPlaces(0);
|
|
|
|
|
|
inputter->setInitValue(ui->pushButton_param2->text());
|
|
|
|
connect(inputter,SIGNAL(confirmValue(QVariant)),
|
|
this,SLOT(setParam2(QVariant)));
|
|
|
|
inputter->show();
|
|
}
|
|
|
|
void ConnectDialog::setParam3(QVariant value)
|
|
{
|
|
m_Param3 = value;
|
|
reBuildList();
|
|
}
|
|
|
|
void ConnectDialog::onParam3Clicked(void)//databit/remote addr 串口-选择 udp-输入
|
|
{
|
|
if(ui->pushButton_type->text() == "SerialPort")
|
|
{
|
|
Selector *selector = new Selector(this);
|
|
selector->setGeometry(0,0,this->width(),this->height());
|
|
|
|
QStringList list;
|
|
|
|
list << "7"
|
|
<< "8"
|
|
<< "9";
|
|
|
|
selector->setList(list,ui->pushButton_param3->text());
|
|
|
|
|
|
connect(selector,SIGNAL(confirmValue(QVariant)),
|
|
this,SLOT(setParam3(QVariant)));
|
|
|
|
selector->show();
|
|
}
|
|
else//net
|
|
{
|
|
Inputter *inputter = new Inputter(this);
|
|
inputter->setGeometry(0,0,this->width(),this->height());
|
|
inputter->setInputType(1);
|
|
inputter->setInitValue(ui->pushButton_param3->text());
|
|
inputter->setDecimalPlaces(0);
|
|
|
|
connect(inputter,SIGNAL(confirmValue(QVariant)),
|
|
this,SLOT(setParam3(QVariant)));
|
|
|
|
inputter->show();
|
|
}
|
|
}
|
|
|
|
void ConnectDialog::setParam4(QVariant value)
|
|
{
|
|
m_Param4 = value;
|
|
reBuildList();
|
|
}
|
|
|
|
void ConnectDialog::onParam4Clicked(void)//parity/remote port 串口-选择 udp-输入
|
|
{
|
|
if(ui->pushButton_type->text() == "SerialPort")
|
|
{
|
|
Selector *selector = new Selector(this);
|
|
selector->setGeometry(0,0,this->width(),this->height());
|
|
|
|
QStringList list;
|
|
|
|
list << "NONE"
|
|
<< "ODD"
|
|
<< "EVEN";
|
|
|
|
|
|
selector->setList(list,ui->pushButton_param4->text());
|
|
|
|
|
|
connect(selector,SIGNAL(confirmValue(QVariant)),
|
|
this,SLOT(setParam4(QVariant)));
|
|
|
|
selector->show();
|
|
}
|
|
else//net
|
|
{
|
|
Inputter *inputter = new Inputter(this);
|
|
inputter->setGeometry(0,0,this->width(),this->height());
|
|
|
|
inputter->setInitValue(ui->pushButton_param4->text());
|
|
inputter->setDecimalPlaces(0);
|
|
|
|
connect(inputter,SIGNAL(confirmValue(QVariant)),
|
|
this,SLOT(setParam4(QVariant)));
|
|
|
|
inputter->show();
|
|
}
|
|
}
|
|
|
|
void ConnectDialog::setParam5(QVariant value)
|
|
{
|
|
m_Param5 = value;
|
|
reBuildList();
|
|
}
|
|
|
|
void ConnectDialog::onParam5Clicked()//stopbit/remote port 串口-选择 udp-输入
|
|
{
|
|
if(ui->pushButton_type->text() == "SerialPort")
|
|
{
|
|
Selector *selector = new Selector(this);
|
|
selector->setGeometry(0,0,this->width(),this->height());
|
|
|
|
QStringList list;
|
|
list << "1"
|
|
<< "1.5"
|
|
<< "2";
|
|
|
|
selector->setList(list,ui->pushButton_param5->text());
|
|
|
|
|
|
connect(selector,SIGNAL(confirmValue(QVariant)),
|
|
this,SLOT(setParam5(QVariant)));
|
|
|
|
selector->show();
|
|
}
|
|
else//net
|
|
{
|
|
Inputter *inputter = new Inputter(this);
|
|
inputter->setGeometry(0,0,this->width(),this->height());
|
|
|
|
inputter->setInitValue(ui->pushButton_param5->text());
|
|
inputter->setDecimalPlaces(0);
|
|
|
|
connect(inputter,SIGNAL(confirmValue(QVariant)),
|
|
this,SLOT(setParam5(QVariant)));
|
|
|
|
inputter->show();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ConnectDialog::onConnectClicked(void)//关闭本条
|
|
{
|
|
emit connectSignal(true,m_usrName,m_Type,m_Param1,m_Param2,m_Param3,m_Param4,m_Param5);
|
|
|
|
|
|
//断开连接
|
|
}
|
|
|
|
void ConnectDialog::on_pushButton_Cancel_clicked()
|
|
{
|
|
emit cancelSignal();
|
|
}
|