#include "QAlgParamDlg.h" #include "DetectState.h" #include "qshowimg.h" #include #include #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(DetectState::instance()->m_algParam.m_UseBackground == 0 ? false : true); ui.checkBox_equal->setChecked(DetectState::instance()->m_algParam.m_bUseEqual); ui.spinBox_filterSize->setValue(DetectState::instance()->m_algParam.m_filterSize); ui.spinBox_circle_ACThres->setValue(DetectState::instance()->m_algParam.m_Circle_ACThres); ui.spinBox_circle_EdgeWidth->setValue(DetectState::instance()->m_algParam.m_Circle_EdgeWidth); ui.comboBox_transform->setCurrentIndex(DetectState::instance()->m_algParam.m_Circle_Polarity); ui.checkBox_ratio->setChecked(DetectState::instance()->m_algParam.m_RatioDetectType==0?false:true); } void QAlgParamDlg::getParam() { DetectState::instance()->m_algParam.m_UseBackground = ui.checkBox->isChecked(); DetectState::instance()->m_algParam.m_bUseEqual = ui.checkBox_equal->isChecked(); DetectState::instance()->m_algParam.m_filterSize = ui.spinBox_filterSize->value(); DetectState::instance()->m_algParam.m_Circle_ACThres = ui.spinBox_circle_ACThres->value(); DetectState::instance()->m_algParam.m_Circle_EdgeWidth = ui.spinBox_circle_EdgeWidth->value(); DetectState::instance()->m_algParam.m_Circle_Polarity = ui.comboBox_transform->currentIndex(); DetectState::instance()->m_algParam.m_RatioDetectType = ui.checkBox_ratio->isChecked(); DetectState::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(); } } }