forked from linuxdeepin/deepin-diskmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwaterloadingwidget.cpp
More file actions
80 lines (65 loc) · 2.09 KB
/
waterloadingwidget.cpp
File metadata and controls
80 lines (65 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-only
#include "waterloadingwidget.h"
#include <QVBoxLayout>
#if QT_VERSION_MAJOR > 5
#include <random>
#endif
#include <QDebug>
WaterLoadingWidget::WaterLoadingWidget(QWidget *parent) : QWidget(parent)
{
qDebug() << "WaterLoadingWidget constructor";
initUi();
initConnection();
}
void WaterLoadingWidget::initUi()
{
qDebug() << "WaterLoadingWidget::initUi called.";
m_waterProgress = new DWaterProgress(this);
m_waterProgress->setFixedSize(98, 98);
m_waterProgress->setValue(0);
m_time = new QTimer(this);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(m_waterProgress, 0, Qt::AlignCenter);
mainLayout->setSpacing(0);
mainLayout->setContentsMargins(0, 0, 0, 0);
setLayout(mainLayout);
qDebug() << "UI initialized";
}
void WaterLoadingWidget::initConnection()
{
qDebug() << "WaterLoadingWidget::initConnection called.";
connect(m_time, &QTimer::timeout,this, &WaterLoadingWidget::onStartWaterProgress);
}
void WaterLoadingWidget::onStartWaterProgress()
{
qDebug() << "WaterLoadingWidget::onStartWaterProgress called.";
#if QT_VERSION_MAJOR > 5
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> distrib(0, 9);
int value = (m_waterProgress->value() + distrib(gen));
qDebug() << "QT_VERSION_MAJOR > 5, generated value:" << value;
#else
int value = (m_waterProgress->value() + qrand() % 10);
qDebug() << "QT_VERSION_MAJOR <= 5, generated value:" << value;
#endif
value > 99 ? value = 99 : value;
m_waterProgress->setValue(value);
qDebug() << "Water progress value set to:" << value;
}
void WaterLoadingWidget::setStartTime(int msec)
{
qDebug() << "Starting water progress with interval:" << msec << "ms";
m_waterProgress->start();
m_waterProgress->setValue(1);
m_time->start(msec);
}
void WaterLoadingWidget::stopTimer()
{
qDebug() << "Stopping water progress";
m_waterProgress->setValue(100);
m_waterProgress->stop();
m_time->stop();
}