| 1 | /* |
| 2 | Copyright (C) 2005-2014 Mario Stephan <[email protected]> |
| 3 | |
| 4 | This library is free software; you can redistribute it and/or modify |
| 5 | it under the terms of the GNU Lesser General Public License as published |
| 6 | by the Free Software Foundation; either version 2.1 of the License, or |
| 7 | (at your option) any later version. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU Lesser General Public License |
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
| 18 | #include "progressbar.h" |
| 19 | |
| 20 | #include <QHBoxLayout> |
| 21 | #include <QtGui> |
| 22 | |
| 23 | ProgressBar::ProgressBar(QWidget* parent, const char* name) |
| 24 | : QWidget(parent) |
| 25 | { |
| 26 | |
| 27 | QHBoxLayout* mainLayout = new QHBoxLayout; |
| 28 | mainLayout->setMargin(0); |
| 29 | mainLayout->setSpacing(1); |
| 30 | |
| 31 | bar = new QProgressBar(this); |
| 32 | bar->setMinimumHeight(16); |
| 33 | bar->setRange(0, 100); |
| 34 | |
| 35 | clearButton = new QToolButton(this); |
| 36 | QPixmap pixmap(":clear_left.png"); |
| 37 | clearButton->setIcon(QIcon(pixmap)); |
| 38 | clearButton->setIconSize(QSize(18, 17)); |
| 39 | clearButton->setStyleSheet("QToolButton {max-height: 16px;min-height: 16px;margin-top: -2px;}"); |
| 40 | clearButton->resize(22, 16); |
| 41 | connect(clearButton, SIGNAL(clicked()), this, SIGNAL(stopped())); |
| 42 | |
| 43 | mainLayout->addWidget(clearButton); |
| 44 | mainLayout->addWidget(bar); |
| 45 | |
| 46 | setLayout(mainLayout); |
| 47 | } |
| 48 | |
| 49 | ProgressBar::~ProgressBar() {} |
| 50 | |
| 51 | void ProgressBar::setValue(int value) |
| 52 | { |
| 53 | bar->setValue(value); |
| 54 | if (value > 0 && value < 100) |
| 55 | this->show(); |
| 56 | else |
| 57 | this->hide(); |
| 58 | } |
| 59 | |
| 60 | int ProgressBar::value() |
| 61 | { |
| 62 | return bar->value(); |
| 63 | } |
| 64 | |
| 65 | void ProgressBar::resizeEvent(QResizeEvent* ev) |
| 66 | { |
| 67 | bar->setGeometry(0, 0, ev->size().width(), 20); |
| 68 | } |