#include "ProgressView.h" #include "qprogressdialog.h" #include "qicon.h" #include "qfiledialog.h" #include "qcoreapplication.h" #pragma execution_character_set("utf-8") /*进度条类*/ ProgressView::ProgressView(QWidget* parent) { nCancel = false; m_pProgressDialog = new QProgressDialog(parent); connect(m_pProgressDialog, SIGNAL(canceled()), this, SIGNAL(cancel())); m_pProgressDialog->setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); m_pProgressDialog->setWindowIcon(QIcon(":/image/leaper")); m_pProgressDialog->setWindowModality(Qt::ApplicationModal); m_pProgressDialog->setAttribute(Qt::WA_ShowModal, true); } ProgressView::ProgressView(QString strTitle, QString strLabel, int nMax, QString strIcon) { nCancel = false; m_pProgressDialog = new QProgressDialog; m_pProgressDialog->setWindowFlags(Qt::Dialog); connect(m_pProgressDialog, SIGNAL(canceled()), this, SIGNAL(cancel())); m_pProgressDialog->hide(); show(strTitle, strLabel, nMax, strIcon); } ProgressView::~ProgressView() { finish(); if (m_pProgressDialog){ bool bhide= m_pProgressDialog->isHidden(); if (!bhide){ m_pProgressDialog->close(); m_pProgressDialog->deleteLater(); } delete m_pProgressDialog; m_pProgressDialog = NULL; } } bool ProgressView::show(QString strTitle, QString strLabel, int nMax, QString strIcon) { m_pProgressDialog->setWindowTitle(strTitle); m_pProgressDialog->setWindowIcon(QIcon(strIcon)); m_pProgressDialog->setLabelText(strLabel); m_pProgressDialog->setRange(0, nMax); if (nCancel==false) m_pProgressDialog->setCancelButton(0); m_pProgressDialog->setCancelButtonText(tr("取消")); m_pProgressDialog->show(); return true; } bool ProgressView::setValue(int nValue) { m_pProgressDialog->setValue(nValue); qApp->processEvents(); return true; } bool ProgressView::finish() { if (m_pProgressDialog) { //m_pProgressDialog->finished(1); if (!m_pProgressDialog->isHidden()) { m_pProgressDialog->close(); } // m_pProgressDialog->deleteLater(); // m_pProgressDialog = NULL; } //qApp->processEvents(); return true; } bool ProgressView::setTitle(QString strTitle) { if (m_pProgressDialog) { m_pProgressDialog->setWindowTitle(strTitle); } return true; } void ProgressView::setLabel(QString strText) { if (m_pProgressDialog) { m_pProgressDialog->setLabelText(strText); } } void ProgressView::setRange(int nMax, int nMin /*= 0*/) { if (m_pProgressDialog) { m_pProgressDialog->setRange(nMin, nMax); } } void ProgressView::hide() { if (m_pProgressDialog) { m_pProgressDialog->hide(); } } QStringList FileOper::selectFiles(QString strTitle, QString strFilter, QString strDir) { QFileDialog fileDialog; fileDialog.setDirectory(strDir); fileDialog.setWindowTitle(strTitle); fileDialog.setNameFilter(strFilter); fileDialog.setFileMode(QFileDialog::ExistingFiles); if (fileDialog.exec() == QDialog::Accepted) { return fileDialog.selectedFiles(); } return QStringList(); }