| 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 "kprogresscircle.h" |
| 25 |
#include <QBoxLayout> |
| 26 |
#include <QColor> |
| 27 |
|
| 28 |
Widget::Widget(QWidget *parent) |
| 29 |
: KWidget(parent) |
| 30 |
{ |
| 31 |
QVBoxLayout *vLayout = new QVBoxLayout; |
| 32 |
QHBoxLayout *hLayout = new QHBoxLayout; |
| 33 |
KProgressCircle *circle1 = new KProgressCircle(this); |
| 34 |
circle1->setValue(40); // 设置初始值 |
| 35 |
hLayout->addWidget(circle1); |
| 36 |
KProgressCircle *circle2 = new KProgressCircle(this); |
| 37 |
circle2->setValue(10); |
| 38 |
circle2->setState(ProgressBarState::FailedProgress); // 设置失败状态 |
| 39 |
hLayout->addWidget(circle2); |
| 40 |
KProgressCircle *circle3 = new KProgressCircle(this); |
| 41 |
circle3->setValue(75); |
| 42 |
circle3->setState(ProgressBarState::SuccessProgress); // 设置成功状态 |
| 43 |
hLayout->addWidget(circle3); |
| 44 |
vLayout->addLayout(hLayout); |
| 45 |
|
| 46 |
hLayout = new QHBoxLayout; |
| 47 |
KProgressCircle *circle4 = new KProgressCircle(this); |
| 48 |
circle4->setValue(40); |
| 49 |
circle4->setTextVisible(false); // 设置文本不可见 |
| 50 |
hLayout->addWidget(circle4); |
| 51 |
KProgressCircle *circle5 = new KProgressCircle(this); |
| 52 |
circle5->setValue(93); |
| 53 |
circle5->setTextVisible(false); |
| 54 |
circle5->setState(ProgressBarState::FailedProgress); |
| 55 |
hLayout->addWidget(circle5); |
| 56 |
KProgressCircle *circle6 = new KProgressCircle(this); |
| 57 |
circle6->setValue(75); |
| 58 |
circle6->setTextVisible(false); |
| 59 |
circle6->setState(ProgressBarState::SuccessProgress); |
| 60 |
hLayout->addWidget(circle6); |
| 61 |
vLayout->addLayout(hLayout); |
| 62 |
|
| 63 |
baseBar()->setLayout(vLayout); |
| 64 |
|
| 65 |
m_pTimer = new QTimer(this); |
| 66 |
m_pTimer->setInterval(20); |
| 67 |
connect(m_pTimer, &QTimer::timeout, circle1, [=]() { |
| 68 |
if (circle1->value() < circle1->maximum()) |
| 69 |
circle1->setValue(circle1->value() + 1); |
| 70 |
else { |
| 71 |
circle1->setValue(circle1->minimum()); |
| 72 |
circle1->setState(NormalProgress); |
| 73 |
} |
| 74 |
}); |
| 75 |
connect(m_pTimer, &QTimer::timeout, circle4, [=]() { |
| 76 |
if (circle4->value() < circle4->maximum()) |
| 77 |
circle4->setValue(circle4->value() + 1); |
| 78 |
else { |
| 79 |
circle4->setValue(circle4->minimum()); |
| 80 |
circle4->setState(NormalProgress); |
| 81 |
} |
| 82 |
}); |
| 83 |
m_pTimer->start(); |
| 84 |
} |
| 85 |
|
| 86 |
Widget::~Widget() |
| 87 |
{ |
| 88 |
} |