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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/*
* stepprogresswidget.cc -
* Implementation of a widget for displaying progress through a series of steps
* horizon-qt5, the Qt 5 user interface for
* Project Horizon
*
* Copyright (c) 2020 Adélie Linux and contributors. All rights reserved.
* This code is licensed under the AGPL 3.0 license, as noted in the
* LICENSE-code file in the root directory of this repository.
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
#include "stepprogresswidget.hh"
#include "horizonwizardpage.hh"
#include <QVBoxLayout>
StepProgressWidget::StepProgressWidget(QWidget *parent) : QWidget(parent) {
overview = new QLabel(tr("Please wait while System Installation "
"performs the following tasks:"));
overview->setWordWrap(true);
/* Initialise the normal and bold fonts using the overview label. */
QFont myFont = overview->font();
myFont.setBold(false);
normalFont = myFont;
myFont.setBold(true);
boldFont = myFont;
stepGrid = new QGridLayout;
stepGrid->setColumnStretch(1, 100);
QVBoxLayout *overallLayout = new QVBoxLayout;
overallLayout->addWidget(overview);
overallLayout->addSpacing(40);
overallLayout->addLayout(stepGrid);
setLayout(overallLayout);
}
QString StepProgressWidget::overviewText() {
return overview->text();
}
void StepProgressWidget::setOverviewText(QString text) {
overview->setText(text);
}
int16_t StepProgressWidget::addStep(QString stepInfo) {
QLabel *status = new QLabel;
QLabel *info = new QLabel(stepInfo);
statuses.push_back(status);
infos.push_back(info);
int16_t row = infos.size();
stepGrid->addWidget(status, row, 0);
stepGrid->addWidget(info, row, 1);
return row;
}
QPixmap StepProgressWidget::loadDPIAwarePixmap(QString pixmap, QString type) {
QString path = ":/wizard_pixmaps/resources/";
path += pixmap;
path += "-";
if(this->devicePixelRatioF() <= 1.0) {
path += "low";
} else {
path += "high";
}
path += type;
return QPixmap(path);
}
void StepProgressWidget::setStepStatus(int16_t step, Status status) {
QLabel *stat = statuses.at(step);
QLabel *info = infos.at(step);
switch(status) {
case NotStarted:
stat->clear();
info->setFont(normalFont);
break;
case InProgress:
stat->setPixmap(loadDPIAwarePixmap("status-current", ".svg"));
info->setFont(boldFont);
break;
case Finished:
stat->setPixmap(loadDPIAwarePixmap("status-success", ".svg"));
info->setFont(normalFont);
break;
case Failed:
stat->setPixmap(loadDPIAwarePixmap("status-issue", ".svg"));
info->setFont(boldFont);
break;
}
}
void StepProgressWidget::stepPassed(int16_t step) {
setStepStatus(step, Finished);
if(step + 1 < statuses.size()) {
setStepStatus(step + 1, InProgress);
}
}
|