ProgressDialog.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007     * Redistributions of source code must retain the above copyright
00008       notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright
00010       notice, this list of conditions and the following disclaimer in the
00011       documentation and/or other materials provided with the distribution.
00012     * Neither the name of the Universite de Sherbrooke nor the
00013       names of its contributors may be used to endorse or promote products
00014       derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
00020 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 {
00047         _text = new QLabel(this);
00048         _text->setWordWrap(true);
00049         _progressBar = new QProgressBar(this);
00050         _progressBar->setMaximum(1);
00051         _detailedText  = new QTextEdit(this);
00052         _detailedText->setReadOnly(true);
00053         _detailedText->setLineWrapMode(QTextEdit::NoWrap);
00054         _closeButton = new QPushButton(this);
00055         _closeButton->setText("Close");
00056         _closeWhenDoneCheckBox = new QCheckBox(this);
00057         _closeWhenDoneCheckBox->setChecked(true);
00058         _closeWhenDoneCheckBox->setText("Close when done.");
00059         _endMessage = "Finished!";
00060         this->clear();
00061         connect(_closeButton, SIGNAL(clicked()), this, SLOT(close()));
00062 
00063         QVBoxLayout * layout = new QVBoxLayout(this);
00064         layout->addWidget(_text);
00065         layout->addWidget(_progressBar);
00066         layout->addWidget(_detailedText);
00067         QHBoxLayout * hLayout = new QHBoxLayout();
00068         layout->addLayout(hLayout);
00069         hLayout->addWidget(_closeWhenDoneCheckBox);
00070         hLayout->addWidget(_closeButton);
00071         this->setLayout(layout);
00072 
00073         this->setModal(true);
00074 }
00075 
00076 ProgressDialog::~ProgressDialog()
00077 {
00078 
00079 }
00080 
00081 void ProgressDialog::setAutoClose(bool on, int delayedClosingTimeSec)
00082 {
00083         if(delayedClosingTimeSec >= 0)
00084         {
00085                 _delayedClosingTime = delayedClosingTimeSec;
00086         }
00087         _closeWhenDoneCheckBox->setChecked(on);
00088 }
00089 
00090 void ProgressDialog::appendText(const QString & text, const QColor & color)
00091 {
00092         _text->setText(text);
00093         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);
00094         _detailedText->append(html);
00095         _detailedText->ensureCursorVisible();
00096         _detailedText->horizontalScrollBar()->setSliderPosition(0);
00097         _detailedText->verticalScrollBar()->setSliderPosition(_detailedText->verticalScrollBar()->maximum());
00098 }
00099 void ProgressDialog::setValue(int value)
00100 {
00101         _progressBar->setValue(value);
00102         if(value == _progressBar->maximum())
00103         {
00104                 _text->setText(_endMessage);
00105                 _closeButton->setEnabled(true);
00106                 if(_closeWhenDoneCheckBox->isChecked() && _delayedClosingTime == 0)
00107                 {
00108                         this->close();
00109                 }
00110                 else if(_closeWhenDoneCheckBox->isChecked())
00111                 {
00112                         QTimer::singleShot(_delayedClosingTime*1000, this, SLOT(closeDialog()));
00113                 }
00114         }
00115 }
00116 int ProgressDialog::maximumSteps() const
00117 {
00118         return _progressBar->maximum();
00119 }
00120 void ProgressDialog::setMaximumSteps(int steps)
00121 {
00122         _progressBar->setMaximum(steps);
00123 }
00124 
00125 void ProgressDialog::incrementStep()
00126 {
00127         //incremental progress bar (if we don't know how many items will be added)
00128         if(_progressBar->value() == _progressBar->maximum()-1)
00129         {
00130                 _progressBar->setMaximum(_progressBar->maximum()+1);
00131         }
00132         _progressBar->setValue(_progressBar->value()+1);
00133 }
00134 
00135 void ProgressDialog::clear()
00136 {
00137         _text->clear();
00138         _progressBar->reset();
00139         _detailedText->clear();
00140         _closeButton->setEnabled(false);
00141 }
00142 
00143 void ProgressDialog::resetProgress()
00144 {
00145         _progressBar->reset();
00146         _closeButton->setEnabled(false);
00147 }
00148 
00149 void ProgressDialog::closeDialog()
00150 {
00151         if(_closeWhenDoneCheckBox->isChecked())
00152         {
00153                 close();
00154         }
00155 }
00156 
00157 void ProgressDialog::closeEvent(QCloseEvent *event)
00158 {
00159         if(_progressBar->value() == _progressBar->maximum())
00160         {
00161                 event->accept();
00162         }
00163         else
00164         {
00165                 event->ignore();
00166         }
00167 }
00168 
00169 }


rtabmap
Author(s): Mathieu Labbe
autogenerated on Sat Jul 23 2016 11:44:17