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.
whellvalue/tpvs17/tpMain/QAlgParamDlg.cpp

140 lines
4.3 KiB
C++

#include "QAlgParamDlg.h"
#include "qshowimg.h"
#include <QFileDialog>
#include <QMessageBox>
#include "lpGlobalConfig.h"
#pragma execution_character_set("utf-8")
QAlgParamDlg::QAlgParamDlg(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
connect(ui.m_pbShowBackImage, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
connect(ui.m_pbApply, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
connect(ui.m_pbExit, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
ui.label->setVisible(false);
}
QAlgParamDlg::~QAlgParamDlg()
{
}
Q_SLOT void QAlgParamDlg::onButtonClicked()
{
QString strObj = sender()->objectName();
if (strObj == "m_pbShowBackImage")
{
QShowImg m_showImgDlg(this);
m_showImgDlg.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
m_showImgDlg.setWindowModality(Qt::ApplicationModal);
m_showImgDlg.setAttribute(Qt::WA_ShowModal, true);
m_showImgDlg.setWindowIcon(QIcon(":/image/leaper"));
QString DstPath = ".\\user\\background.png";
connect(&m_showImgDlg, SIGNAL(sgChangeImg()), this, SLOT(onChangeBG()));
connect(this, SIGNAL(sgChangeBG(QString)), &m_showImgDlg, SLOT(setPicPath(QString)));
m_showImgDlg.setPicPath(DstPath);
m_showImgDlg.exec();
}
else if (strObj == "m_pbApply")
{
getParam();
ui.label->setVisible(true);
m_timeID = startTimer(1000);
emit sgParamChange();
}
else if (strObj == "m_pbExit")
{
close();
}
}
void QAlgParamDlg::showEvent(QShowEvent *event)
{
setParam();
}
void QAlgParamDlg::timerEvent(QTimerEvent *event)
{
if (m_timeID == event->timerId())
{
killTimer(m_timeID);
m_timeID = 0;
ui.label->setVisible(false);
}
}
void QAlgParamDlg::changeEvent(QEvent *event)
{
if (event->type() == QEvent::LanguageChange)
{
ui.retranslateUi(this);
}
}
void QAlgParamDlg::setParam()
{
ui.checkBox->setChecked(lpGlobalConfig::instance()->algParam.m_UseBackground == 0 ? false : true);
ui.checkBox_equal->setChecked(lpGlobalConfig::instance()->algParam.m_bUseEqual);
ui.spinBox_filterSize->setValue(lpGlobalConfig::instance()->algParam.m_filterSize);
ui.spinBox_circle_ACThres->setValue(lpGlobalConfig::instance()->algParam.m_Circle_ACThres);
ui.spinBox_circle_EdgeWidth->setValue(lpGlobalConfig::instance()->algParam.m_Circle_EdgeWidth);
ui.comboBox_transform->setCurrentIndex(lpGlobalConfig::instance()->algParam.m_Circle_Polarity);
//ui.checkBox_ratio->setChecked(lpGlobalConfig::instance()->algParam.m_RatioDetectType==0?false:true);
}
void QAlgParamDlg::getParam()
{
lpGlobalConfig::instance()->algParam.m_UseBackground = ui.checkBox->isChecked();
lpGlobalConfig::instance()->algParam.m_bUseEqual = ui.checkBox_equal->isChecked();
lpGlobalConfig::instance()->algParam.m_filterSize = ui.spinBox_filterSize->value();
lpGlobalConfig::instance()->algParam.m_Circle_ACThres = ui.spinBox_circle_ACThres->value();
lpGlobalConfig::instance()->algParam.m_Circle_EdgeWidth = ui.spinBox_circle_EdgeWidth->value();
lpGlobalConfig::instance()->algParam.m_Circle_Polarity = ui.comboBox_transform->currentIndex();
//lpGlobalConfig::instance()->algParam.m_RatioDetectType = ui.checkBox_ratio->isChecked();
lpGlobalConfig::instance()->save();
}
Q_SLOT void QAlgParamDlg::onChangeBG()
{
QFileDialog fileDialog;
fileDialog.setWindowTitle(tr("请选择您的背景图"));
fileDialog.setNameFilter("Picture(*.bmp *.jpg *.png)");
fileDialog.setFileMode(QFileDialog::ExistingFiles);
if (fileDialog.exec() == QDialog::Accepted)
{
QStringList backgroundFile = fileDialog.selectedFiles();
if (backgroundFile.size() > 0)
{
QString DstPath = QApplication::applicationDirPath() + "\\user\\background.png";
QString sourcePath = backgroundFile.at(0);
DstPath.replace("\\", "/");
if (sourcePath == DstPath) {
// //return;
// //return true;
}
if (!QFile::exists(sourcePath)) {
//return false;
}
QDir *createfile = new QDir;
bool exist = createfile->exists(DstPath);
if (exist) {
//if (converFileIfExist){
createfile->remove(DstPath);
//}
}
if (!QFile::copy(sourcePath, DstPath)) {
//return false;
}
//emit sgChangeBG(DstPath);
QMessageBox infobox(QMessageBox::Information, tr("提示"), tr("背景图更新完成,请重启本软件."), QMessageBox::Yes, NULL);
infobox.setWindowIcon(QIcon(":/image/leaper"));
infobox.setButtonText(QMessageBox::Yes, tr("确认"));
infobox.exec();
}
}
}