OSDN Git Service

パネル自体の背景色を変更
[gefu/Gefu.git] / operationdialog.cpp
index 5cc4287..120ff7e 100644 (file)
@@ -1,15 +1,17 @@
 #include "operationdialog.h"\r
 #include "ui_operationdialog.h"\r
+\r
 #include <QThread>\r
 \r
 OperationDialog::OperationDialog(QWidget *parent) :\r
     QDialog(parent),\r
     ui(new Ui::OperationDialog),\r
     m_worker(NULL),\r
-    m_Error(false),\r
-    m_Cancel(false)\r
+    m_Error(false)\r
 {\r
     ui->setupUi(this);\r
+    ui->textEdit->setVisible(false);\r
+    resize(parent->width() * 0.8, height());\r
 }\r
 \r
 OperationDialog::~OperationDialog()\r
@@ -17,28 +19,17 @@ OperationDialog::~OperationDialog()
     delete ui;\r
 }\r
 \r
-void OperationDialog::showEvent(QShowEvent *event)\r
+void OperationDialog::setAutoClose(bool yes)\r
 {\r
-    ui->textEdit->setVisible(false);\r
-\r
-    QThread *thread = new QThread();\r
-    m_worker->moveToThread(thread);\r
-    m_worker->setProgressText(ui->label);\r
-    connect(thread, SIGNAL(started()), m_worker, SLOT(operate()));\r
-    connect(m_worker, SIGNAL(finished()), thread, SLOT(quit()));\r
-\r
-    connect(thread, SIGNAL(finished()), this, SLOT(onFinished()));\r
-    connect(thread, SIGNAL(finished()), m_worker, SLOT(deleteLater()));\r
-    connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));\r
-\r
-    connect(m_worker, SIGNAL(operation(QString)), this, SLOT(onOperation(QString)));\r
-    connect(m_worker, SIGNAL(success(QString)), this, SLOT(onSuccess(QString)));\r
-    connect(m_worker, SIGNAL(error(QString)), this, SLOT(onError(QString)));\r
+    ui->chkAutoClose->setChecked(yes);\r
+}\r
 \r
-    thread->start();\r
+bool OperationDialog::autoClose() const\r
+{\r
+    return ui->chkAutoClose->isChecked();\r
 }\r
 \r
-void OperationDialog::onOperation(const QString &msg)\r
+void OperationDialog::onProgress(const QString &msg)\r
 {\r
     ui->textEdit->append(msg + " ... ");\r
 }\r
@@ -54,14 +45,14 @@ void OperationDialog::onError(const QString &msg)
     ui->textEdit->append("<font color='red'><strong>" + msg + "</strong></font>");\r
 }\r
 \r
-void OperationDialog::onFinished()\r
+void OperationDialog::onFinished(bool abort)\r
 {\r
     ui->progressBar->setMaximum(1);\r
     ui->progressBar->setValue(1);\r
     ui->btnCloseCancel->setText(tr("閉じる"));\r
 \r
     ui->textEdit->append("");\r
-    if (m_Cancel) {\r
+    if (abort) {\r
         ui->textEdit->append(tr("操作は途中でキャンセルされました。"));\r
     }\r
     else {\r
@@ -78,8 +69,7 @@ void OperationDialog::on_btnCloseCancel_clicked()
         QDialog::accept();\r
     }\r
     else {\r
-        m_Cancel = true;\r
-        m_worker->requestStop();\r
+        m_worker->abort();\r
     }\r
 }\r
 \r
@@ -94,3 +84,16 @@ void OperationDialog::on_btnShowDetail_clicked()
         ui->btnShowDetail->setText(tr("詳細を隠す"));\r
     }\r
 }\r
+\r
+int OperationDialog::exec()\r
+{\r
+    connect(m_worker, SIGNAL(finished(bool)), this, SLOT(onFinished(bool)));\r
+    connect(m_worker, SIGNAL(error(QString)), this, SLOT(onError(QString)));\r
+    connect(m_worker, SIGNAL(progress(QString)), this, SLOT(onProgress(QString)));\r
+    connect(m_worker, SIGNAL(success(QString)), this, SLOT(onSuccess(QString)));\r
+    connect(m_worker, SIGNAL(information(QString)), ui->label, SLOT(setText(QString)));\r
+\r
+    ui->label->setText(m_worker->initialText());\r
+    m_worker->start();\r
+    return QDialog::exec();\r
+}\r