DetailedProgressDialog.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2010-2014, 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 "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         //incremental progress bar (if we don't know how many items will be added)
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 }


rtabmap
Author(s): Mathieu Labbe
autogenerated on Fri Aug 28 2015 12:51:31