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 "DetailedProgressDialog.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 DetailedProgressDialog::DetailedProgressDialog(QWidget *parent, Qt::WindowFlags flags) :
00044 QDialog(parent, flags),
00045 _autoClose(false),
00046 _delayedClosingTime(0)
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 _closeWhenDoneCheckBox = new QCheckBox(this);
00058 _closeWhenDoneCheckBox->setChecked(false);
00059 _closeWhenDoneCheckBox->setText("Close when done.");
00060 _endMessage = "Finished!";
00061 this->clear();
00062 connect(_closeButton, SIGNAL(clicked()), this, SLOT(close()));
00063
00064 QVBoxLayout * layout = new QVBoxLayout(this);
00065 layout->addWidget(_text);
00066 layout->addWidget(_progressBar);
00067 layout->addWidget(_detailedText);
00068 QHBoxLayout * hLayout = new QHBoxLayout();
00069 layout->addLayout(hLayout);
00070 hLayout->addWidget(_closeWhenDoneCheckBox);
00071 hLayout->addWidget(_closeButton);
00072 this->setLayout(layout);
00073 }
00074
00075 DetailedProgressDialog::~DetailedProgressDialog()
00076 {
00077
00078 }
00079
00080 void DetailedProgressDialog::setAutoClose(bool on, int delayedClosingTimeSec)
00081 {
00082 _delayedClosingTime = delayedClosingTimeSec;
00083 _closeWhenDoneCheckBox->setChecked(on);
00084 }
00085
00086 void DetailedProgressDialog::appendText(const QString & text, const QColor & color)
00087 {
00088 _text->setText(text);
00089 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);
00090 _detailedText->append(html);
00091 _detailedText->ensureCursorVisible();
00092 _detailedText->horizontalScrollBar()->setSliderPosition(0);
00093 }
00094 void DetailedProgressDialog::setValue(int value)
00095 {
00096 _progressBar->setValue(value);
00097 if(value == _progressBar->maximum())
00098 {
00099 _text->setText(_endMessage);
00100 _closeButton->setEnabled(true);
00101 if(_closeWhenDoneCheckBox->isChecked() && _delayedClosingTime == 0)
00102 {
00103 this->close();
00104 }
00105 else if(_closeWhenDoneCheckBox->isChecked())
00106 {
00107 QTimer::singleShot(_delayedClosingTime*1000, this, SLOT(close()));
00108 }
00109 }
00110 }
00111 int DetailedProgressDialog::maximumSteps() const
00112 {
00113 return _progressBar->maximum();
00114 }
00115 void DetailedProgressDialog::setMaximumSteps(int steps)
00116 {
00117 _progressBar->setMaximum(steps);
00118 }
00119
00120 void DetailedProgressDialog::incrementStep()
00121 {
00122
00123 if(_progressBar->value() == _progressBar->maximum()-1)
00124 {
00125 _progressBar->setMaximum(_progressBar->maximum()+1);
00126 }
00127 _progressBar->setValue(_progressBar->value()+1);
00128 }
00129
00130 void DetailedProgressDialog::clear()
00131 {
00132 _text->clear();
00133 _progressBar->reset();
00134 _detailedText->clear();
00135 _closeButton->setEnabled(false);
00136 }
00137
00138 void DetailedProgressDialog::resetProgress()
00139 {
00140 _progressBar->reset();
00141 _closeButton->setEnabled(false);
00142 }
00143
00144 void DetailedProgressDialog::closeEvent(QCloseEvent *event)
00145 {
00146 if(_progressBar->value() == _progressBar->maximum())
00147 {
00148 event->accept();
00149 }
00150 else
00151 {
00152 event->ignore();
00153 }
00154 }
00155
00156 }