-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindow.cpp
90 lines (63 loc) · 2.57 KB
/
Window.cpp
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
//
// Created by Riccardo Becciolini on 24/08/20.
//
#include <vector>
#include "Window.h"
#include <unistd.h>
Window::Window(LoadFiles *f, QWidget *parent) : files(f), QMainWindow(parent) {
files->subscribe(this);
this->setWindowTitle("Elaborato di laboratorio");
this->setFixedSize(QSize(1280, 720));
name = new QLabel("Riccardo Becciolini", this);
name->setGeometry(QRect(QPoint(30,30), QSize(400, 60)));
name->setAlignment(Qt::AlignLeft);
title = new QLabel("Classe che carica file di risorse e aggiorna una progress bar (con QT).", this);
title->setGeometry(QRect(QPoint(350, 60), QSize(550, 200)));
title->setWordWrap(true);
title->setAlignment(Qt::AlignCenter);
QFont font = title->font();
font.setPointSize(20);
title->setFont(font);
button = new QPushButton("Carica risorse!", this);
button->setGeometry(QRect(QPoint(520, 300), QSize(200, 30)));
progressBar = new QProgressBar(this);
progressBar->setGeometry(QRect(QPoint(470, 260), QSize(300, 30)));
text = new QTextEdit(this);
text->setGeometry(QRect(QPoint(360, 350), QSize(500, 140)));
text->setText("...Pronto a caricare i files...\n");
text->setReadOnly(true);
QTextCursor c = text->textCursor();
c.movePosition(QTextCursor::End);
text->setTextCursor(c);
progressBar->setMinimum(0);
progressBar->setMaximum(1000);
progressBar->setValue(0);
// Connette il segnale del bottone allo slot appropiato
connect(button, SIGNAL (released()), this, SLOT (loadFiles()));
}
void Window::update() {
for(auto it : files->getVector()) {
if (it->isUploaded()) {
//Aggiorna progess bar
while (progressBar->value() < 1000) {
progressBar->setValue(progressBar->value() + (10 / files->getNumberFile()));
usleep(1000);
}
//Aggiorna text
QString log = "✅ " + QString(it->getFilename()) + QString("' caricato con successo (") +
QString::number(it->getFileSize()) + QString(" bytes).") + "\n";
text->append(log);
//Aggiorna text di button
QString percentText = QString::number(progressBar->value() / 10) + QString("% files caricati!");
button->setText(percentText);
} else {
//Aggiorna text log
QString log = "❌ Non è possibile caricare il files: '" + it->getFilename() + "\n";
text->append(log);
}
}
}
void Window::loadFiles() {
text->setText("... Caricamento in corso ...\n\n\n");
files->load();
}