You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
218 lines
5.6 KiB
C++
218 lines
5.6 KiB
C++
#include "lpConfigUI.h"
|
|
#include <lpConfig.h>
|
|
#include <QFileDialog>
|
|
#include <QApplication>
|
|
#include <QStandardPaths>
|
|
|
|
#pragma execution_character_set("utf-8")
|
|
/*系统参数配置页面*/
|
|
const QString gStrAppName = "识别定位系统";
|
|
|
|
lpConfigUI::lpConfigUI(QWidget *parent)
|
|
: QWidget(parent)
|
|
{
|
|
ui.setupUi(this);
|
|
setWindowIcon(QIcon(":/Resources/icon.png"));
|
|
connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
|
|
connect(ui.pushButton_2, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
|
|
connect(ui.pushButton_3, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
|
|
connect(ui.pushButton_4, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
|
|
ui.label_5->setVisible(false);
|
|
|
|
onInitCheckBox();
|
|
connect(ui.checkBox_AutoRun, SIGNAL(stateChanged(int)), this, SLOT(onCheckBoxChanged(int)));
|
|
connect(ui.checkBox_DesktopShort, SIGNAL(stateChanged(int)), this, SLOT(onCheckBoxChanged(int)));
|
|
}
|
|
|
|
lpConfigUI::~lpConfigUI()
|
|
{
|
|
}
|
|
|
|
Q_SLOT void lpConfigUI::onButtonClicked()
|
|
{
|
|
QString strObj = sender()->objectName();
|
|
if ("pushButton" == strObj)
|
|
{
|
|
QString strUrl = QFileDialog::getOpenFileName(this, "", "", "*.exe");
|
|
ui.lineEdit_APath->setText(strUrl);
|
|
}
|
|
else if ("pushButton_2" == strObj)
|
|
{
|
|
QString strUrl = QFileDialog::getOpenFileName(this, "", "", "*.exe");
|
|
ui.lineEdit_BPath->setText(strUrl);
|
|
}
|
|
else if ("pushButton_3" == strObj)
|
|
{
|
|
lpConfig::instance()->appPathA = ui.lineEdit_APath->text();
|
|
lpConfig::instance()->appPathB = ui.lineEdit_BPath->text();
|
|
lpConfig::instance()->portA = ui.lineEdit_APort->text().toInt();
|
|
lpConfig::instance()->portB = ui.lineEdit_BPort->text().toInt();
|
|
lpConfig::instance()->doubleStation = ui.checkBox_doubleStation->isChecked();
|
|
lpConfig::instance()->plcServerPort = ui.lineEdit_serverPort->text().toInt();
|
|
lpConfig::instance()->saveConfig();
|
|
ui.label_5->setVisible(true);
|
|
m_timerID = startTimer(1000);
|
|
emit sgUpdateConfig();
|
|
}
|
|
else if ("pushButton_4" == strObj)
|
|
{
|
|
this->close();
|
|
}
|
|
}
|
|
|
|
void lpConfigUI::showEvent(QShowEvent *event)
|
|
{
|
|
ui.lineEdit_APath->setText(lpConfig::instance()->appPathA);
|
|
ui.lineEdit_BPath->setText(lpConfig::instance()->appPathB);
|
|
ui.lineEdit_APort->setText(QString("%1").arg(lpConfig::instance()->portA));
|
|
ui.lineEdit_BPort->setText(QString("%1").arg(lpConfig::instance()->portB));
|
|
ui.checkBox_doubleStation->setChecked(lpConfig::instance()->doubleStation);
|
|
ui.lineEdit_serverPort->setText(QString("%1").arg(lpConfig::instance()->plcServerPort));
|
|
}
|
|
|
|
void lpConfigUI::timerEvent(QTimerEvent *event)
|
|
{
|
|
if (m_timerID == event->timerId())
|
|
{
|
|
killTimer(m_timerID);
|
|
m_timerID = 0;
|
|
ui.label_5->setVisible(false);
|
|
}
|
|
}
|
|
|
|
void lpConfigUI::onInitCheckBox()
|
|
{
|
|
bool bAutoRun = CheckAutoRunLink();
|
|
if (bAutoRun == true)
|
|
{
|
|
ui.checkBox_AutoRun->setChecked(true);
|
|
}
|
|
else {
|
|
ui.checkBox_AutoRun->setChecked(false);
|
|
}
|
|
|
|
bool bDesktop = CheckDesktopLink();
|
|
if (bDesktop == true)
|
|
{
|
|
ui.checkBox_DesktopShort->setChecked(true);
|
|
}
|
|
else
|
|
{
|
|
ui.checkBox_DesktopShort->setChecked(false);
|
|
}
|
|
}
|
|
|
|
Q_SLOT void lpConfigUI::onCheckBoxChanged(int state)
|
|
{
|
|
QString strObj = sender()->objectName();
|
|
if ("checkBox_AutoRun" == strObj)
|
|
{
|
|
if (state == 0)
|
|
{
|
|
RemoveAutoRunLink();
|
|
}
|
|
else {
|
|
CreateAutoRunLink();
|
|
}
|
|
}
|
|
else if ("checkBox_DesktopShort" == strObj)
|
|
{
|
|
if (state == 0)
|
|
{
|
|
RemoveDesktopLink();
|
|
}
|
|
else {
|
|
CreateDesktopLink();
|
|
}
|
|
}
|
|
}
|
|
|
|
bool lpConfigUI::CheckDesktopLink()
|
|
{
|
|
QString strDesktopLink = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/";
|
|
strDesktopLink += gStrAppName + ".lnk";
|
|
QFileInfo dir(strDesktopLink);
|
|
return dir.isFile();
|
|
}
|
|
|
|
void lpConfigUI::CreateDesktopLink()
|
|
{
|
|
QString strAppPath = QCoreApplication::applicationFilePath();//要创建快捷方式的应用程序绝对路径
|
|
QFile fApp(strAppPath);
|
|
|
|
//创建桌面快捷方式
|
|
QString strDesktopLink = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/";
|
|
strDesktopLink += gStrAppName + ".lnk";
|
|
QFileInfo dir(strDesktopLink);
|
|
//if (!dir.isFile())
|
|
{
|
|
fApp.link(strDesktopLink);
|
|
}
|
|
}
|
|
|
|
void lpConfigUI::RemoveDesktopLink()
|
|
{
|
|
QString strAppPath = QCoreApplication::applicationFilePath();//要创建快捷方式的应用程序绝对路径
|
|
QFile fApp(strAppPath);
|
|
|
|
//创建桌面快捷方式
|
|
QString strDesktopLink = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/";
|
|
strDesktopLink += gStrAppName + ".lnk";
|
|
QFileInfo dir(strDesktopLink);
|
|
//if (!dir.isFile())
|
|
{
|
|
fApp.remove(strDesktopLink);
|
|
}
|
|
}
|
|
|
|
bool lpConfigUI::CheckAutoRunLink()
|
|
{
|
|
QString strMenuLink = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/";
|
|
strMenuLink += "Startup/";
|
|
QDir pathDir;
|
|
pathDir.mkpath(strMenuLink);
|
|
strMenuLink += gStrAppName + ".lnk";
|
|
//判断是否已存在
|
|
QFileInfo dir(strMenuLink);
|
|
return dir.isFile();
|
|
}
|
|
|
|
void lpConfigUI::CreateAutoRunLink()
|
|
{
|
|
QString strAppPath = QCoreApplication::applicationFilePath();//要创建快捷方式的应用程序绝对路径
|
|
QFile fApp(strAppPath);
|
|
//创建开机启动快捷方式
|
|
QString strMenuLink = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/";
|
|
strMenuLink += "Startup/";
|
|
QDir pathDir;
|
|
pathDir.mkpath(strMenuLink);
|
|
strMenuLink += gStrAppName + ".lnk";
|
|
//判断是否已存在
|
|
QFileInfo dir(strMenuLink);
|
|
//if (!dir.isFile())
|
|
{
|
|
fApp.link(strMenuLink);
|
|
}
|
|
}
|
|
|
|
void lpConfigUI::RemoveAutoRunLink()
|
|
{
|
|
QString strAppPath = QCoreApplication::applicationFilePath();//要创建快捷方式的应用程序绝对路径
|
|
QFile fApp(strAppPath);
|
|
QString strMenuLink = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/";
|
|
strMenuLink += "Startup/";
|
|
QDir pathDir;
|
|
pathDir.mkpath(strMenuLink);
|
|
strMenuLink += gStrAppName + ".lnk";
|
|
//判断是否已存在
|
|
QFileInfo dir(strMenuLink);
|
|
//if (!dir.isFile())
|
|
{
|
|
fApp.remove(strMenuLink);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|