| 1 |
/* |
| 2 |
* |
| 3 |
* |
| 4 |
* Copyright (C) 2023, KylinSoft Co., Ltd. |
| 5 |
* |
| 6 |
* This library is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public |
| 8 |
* License as published by the Free Software Foundation; either |
| 9 |
* version 3 of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this library. If not, see <https://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
* Authors: Zhen Sun <[email protected]> |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
#include "widget.h" |
| 24 |
#include <QBoxLayout> |
| 25 |
#include <QDebug> |
| 26 |
#include <QProgressBar> |
| 27 |
Widget::Widget(QWidget *parent) |
| 28 |
: KWidget(parent) |
| 29 |
{ |
| 30 |
m_pTimer = new QTimer(this); |
| 31 |
m_pTimer->setInterval(50); |
| 32 |
QVBoxLayout *vLayout = new QVBoxLayout(this); |
| 33 |
QHBoxLayout *tmpLayout = new QHBoxLayout(); |
| 34 |
m_pVerticalBar = new KProgressBar(this); |
| 35 |
m_pVerticalBar->setOrientation(Qt::Vertical); // 设置KProgressBar方向 |
| 36 |
m_pVerticalBar->setTextVisible(false); |
| 37 |
m_pVerticalBar->setRange(0, 100); |
| 38 |
m_pVerticalBar->setValue(50); |
| 39 |
tmpLayout->addWidget(m_pVerticalBar); |
| 40 |
vLayout->addLayout(tmpLayout); |
| 41 |
QHBoxLayout *hLayout = new QHBoxLayout(this); |
| 42 |
m_pHorizontalBar = new KProgressBar(this); |
| 43 |
m_pHorizontalBar->setRange(0, 100); |
| 44 |
m_pHorizontalBar->setValue(50); |
| 45 |
hLayout->addWidget(m_pHorizontalBar); |
| 46 |
vLayout->addLayout(hLayout); |
| 47 |
hLayout = new QHBoxLayout(this); |
| 48 |
m_pStartBtn = new QPushButton(this); |
| 49 |
m_pStartBtn->setText("开始"); |
| 50 |
m_pStopBtn = new QPushButton(this); |
| 51 |
m_pStopBtn->setText("停止"); |
| 52 |
m_pRestoreBtn = new QPushButton(this); |
| 53 |
m_pRestoreBtn->setText("恢复"); |
| 54 |
hLayout->addStretch(); |
| 55 |
hLayout->addWidget(m_pStartBtn); |
| 56 |
hLayout->addWidget(m_pStopBtn); |
| 57 |
hLayout->addWidget(m_pRestoreBtn); |
| 58 |
hLayout->addStretch(); |
| 59 |
vLayout->addLayout(hLayout); |
| 60 |
baseBar()->setLayout(vLayout); |
| 61 |
connect(m_pTimer, &QTimer::timeout, this, [=]() { |
| 62 |
if (m_pVerticalBar->value() != m_pVerticalBar->maximum()) |
| 63 |
m_pVerticalBar->setValue(m_pVerticalBar->value() + 1); |
| 64 |
else { |
| 65 |
m_pVerticalBar->setValue(m_pVerticalBar->minimum()); |
| 66 |
m_pVerticalBar->setState(ProgressBarState::NormalProgress); // 设置KprogressBar状态 |
| 67 |
} |
| 68 |
if (m_pHorizontalBar->value() != m_pHorizontalBar->maximum()) |
| 69 |
m_pHorizontalBar->setValue(m_pHorizontalBar->value() + 1); |
| 70 |
else { |
| 71 |
m_pHorizontalBar->setValue(m_pHorizontalBar->minimum()); |
| 72 |
m_pHorizontalBar->setState(ProgressBarState::NormalProgress); |
| 73 |
} |
| 74 |
}); |
| 75 |
connect(m_pStartBtn, &QPushButton::clicked, this, [=]() { |
| 76 |
if (!m_pTimer->isActive()) |
| 77 |
m_pTimer->start(); |
| 78 |
// qDebug() << m_pVerticalBar->text(); //获取文本值 |
| 79 |
}); |
| 80 |
connect(m_pStopBtn, &QPushButton::clicked, this, [=]() { |
| 81 |
m_pTimer->stop(); |
| 82 |
m_pVerticalBar->setState(ProgressBarState::FailedProgress); |
| 83 |
m_pHorizontalBar->setState(ProgressBarState::FailedProgress); |
| 84 |
}); |
| 85 |
connect(m_pRestoreBtn, &QPushButton::clicked, this, [=]() { |
| 86 |
m_pTimer->start(); |
| 87 |
m_pVerticalBar->setValue(0); |
| 88 |
m_pVerticalBar->setState(ProgressBarState::NormalProgress); |
| 89 |
m_pHorizontalBar->setValue(0); |
| 90 |
m_pHorizontalBar->setState(ProgressBarState::NormalProgress); |
| 91 |
}); |
| 92 |
} |
| 93 |
|
| 94 |
Widget::~Widget() |
| 95 |
{ |
| 96 |
} |