Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "rtabmap/gui/ProgressDialog.h"
00029 #include <QLayout>
00030 #include <QProgressBar>
00031 #include <QTextEdit>
00032 #include <QLabel>
00033 #include <QPushButton>
00034 #include <QtGui/QCloseEvent>
00035 #include <QCheckBox>
00036 #include <QtCore/QTimer>
00037 #include <QtCore/QTime>
00038 #include <QScrollBar>
00039 #include "rtabmap/utilite/ULogger.h"
00040
00041 namespace rtabmap {
00042
00043 ProgressDialog::ProgressDialog(QWidget *parent, Qt::WindowFlags flags) :
00044 QDialog(parent, flags),
00045 _delayedClosingTime(1),
00046 _canceled(false)
00047 {
00048 _text = new QLabel(this);
00049 _text->setWordWrap(true);
00050 _progressBar = new QProgressBar(this);
00051 _progressBar->setMaximum(1);
00052 _detailedText = new QTextEdit(this);
00053 _detailedText->setReadOnly(true);
00054 _detailedText->setLineWrapMode(QTextEdit::NoWrap);
00055 _closeButton = new QPushButton(this);
00056 _closeButton->setText("Close");
00057 _cancelButton = new QPushButton(this);
00058 _cancelButton->setText("Cancel");
00059 _cancelButton-> setVisible(false);
00060 _closeWhenDoneCheckBox = new QCheckBox(this);
00061 _closeWhenDoneCheckBox->setChecked(true);
00062 _closeWhenDoneCheckBox->setText("Close when done.");
00063 _endMessage = "Finished!";
00064 this->clear();
00065 connect(_closeButton, SIGNAL(clicked()), this, SLOT(close()));
00066 connect(_cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
00067
00068 QVBoxLayout * layout = new QVBoxLayout(this);
00069 layout->addWidget(_text);
00070 layout->addWidget(_progressBar);
00071 layout->addWidget(_detailedText);
00072 QHBoxLayout * hLayout = new QHBoxLayout();
00073 layout->addLayout(hLayout);
00074 hLayout->addWidget(_closeWhenDoneCheckBox);
00075 hLayout->addStretch();
00076 hLayout->addWidget(_cancelButton);
00077 hLayout->addWidget(_closeButton);
00078 this->setLayout(layout);
00079
00080 this->setModal(true);
00081 }
00082
00083 ProgressDialog::~ProgressDialog()
00084 {
00085
00086 }
00087
00088 void ProgressDialog::setAutoClose(bool on, int delayedClosingTimeSec)
00089 {
00090 if(delayedClosingTimeSec >= 0)
00091 {
00092 _delayedClosingTime = delayedClosingTimeSec;
00093 }
00094 _closeWhenDoneCheckBox->setChecked(on);
00095 }
00096
00097 void ProgressDialog::setCancelButtonVisible(bool visible)
00098 {
00099 _cancelButton->setVisible(visible);
00100 }
00101
00102 void ProgressDialog::appendText(const QString & text, const QColor & color)
00103 {
00104 UDEBUG(text.toStdString().c_str());
00105 _text->setText(text);
00106 QString html = tr("<html><font color=\"#999999\">%1 </font><font color=\"%2\">%3</font></html>").arg(QTime::currentTime().toString("HH:mm:ss")).arg(color.name()).arg(text);
00107 _detailedText->append(html);
00108 _detailedText->ensureCursorVisible();
00109 _detailedText->horizontalScrollBar()->setSliderPosition(0);
00110 _detailedText->verticalScrollBar()->setSliderPosition(_detailedText->verticalScrollBar()->maximum());
00111 }
00112 void ProgressDialog::setValue(int value)
00113 {
00114 _progressBar->setValue(value);
00115 if(value == _progressBar->maximum())
00116 {
00117 _text->setText(_endMessage);
00118 _closeButton->setEnabled(true);
00119 if(_closeWhenDoneCheckBox->isChecked() && _delayedClosingTime == 0)
00120 {
00121 this->close();
00122 }
00123 else if(_closeWhenDoneCheckBox->isChecked())
00124 {
00125 QTimer::singleShot(_delayedClosingTime*1000, this, SLOT(closeDialog()));
00126 }
00127 }
00128 }
00129 int ProgressDialog::maximumSteps() const
00130 {
00131 return _progressBar->maximum();
00132 }
00133 void ProgressDialog::setMaximumSteps(int steps)
00134 {
00135 _progressBar->setMaximum(steps);
00136 }
00137
00138 void ProgressDialog::incrementStep(int steps)
00139 {
00140
00141 if(_progressBar->value() >= _progressBar->maximum()-steps)
00142 {
00143 _progressBar->setMaximum(_progressBar->maximum()+steps+1);
00144 }
00145 _progressBar->setValue(_progressBar->value()+steps);
00146 }
00147
00148 void ProgressDialog::clear()
00149 {
00150 _text->clear();
00151 _detailedText->clear();
00152 resetProgress();
00153 }
00154
00155 void ProgressDialog::resetProgress()
00156 {
00157 _progressBar->reset();
00158 _closeButton->setEnabled(false);
00159 _canceled = false;
00160 }
00161
00162 void ProgressDialog::closeDialog()
00163 {
00164 if(_closeWhenDoneCheckBox->isChecked())
00165 {
00166 close();
00167 }
00168 }
00169
00170 void ProgressDialog::closeEvent(QCloseEvent *event)
00171 {
00172 if(_progressBar->value() == _progressBar->maximum())
00173 {
00174 _canceled = false;
00175 event->accept();
00176 }
00177 else
00178 {
00179 event->ignore();
00180 }
00181 }
00182
00183 void ProgressDialog::cancel()
00184 {
00185 _canceled = true;
00186 Q_EMIT canceled();
00187 }
00188
00189 }