/
Progression.cpp
executable file
·126 lines (112 loc) · 2.94 KB
/
Progression.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
* Copyright (C) 2012-2014 Phonations
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
*/
#include "Progression.h"
#include "ui_Progression.h"
#include <QFile>
#include <QDebug>
Progression::Progression(QWidget *parent) :
QWidget(parent),
ui(new Ui::Progression)
{
ui->setupUi(this);
vbl = new QVBoxLayout(this);
this->setMinimumSize(800, 0);
}
Progression::~Progression()
{
delete ui;
}
void Progression::addCopy(QString src, QString){
QLabel * label = new QLabel(src, this);
label->setObjectName(src);
label->setMaximumSize(780, 30);
label->setGeometry(label->x(), label->y(), 780, label->height());
QProgressBar * prog = new QProgressBar(this);
prog->setObjectName(src);
prog->setMaximum(QFile(src).size());
vbl->addWidget(label);
vbl->addWidget(prog);
ProgressBars[label->text()] = prog;
qDebug() << label->text();
this->adjustSize();
}
void Progression::updateProgressBar(QString file, qint64 pos, QString currentFile){
ProgressBars[file]->setValue((int) pos);
qDebug() << "Update" << vbl->count();
if(currentFile != "")
{
for(int i = 0; i < vbl->count(); i++)
{
QLayoutItem* item = vbl->itemAt(i);
QWidget* widget = item->widget();
if (widget) {
QLabel *label = qobject_cast<QLabel *>(widget);
if(label->text().contains(file))
{
label->setText(file + " -> " + currentFile);
label->adjustSize();
}
}
}
}
this->adjustSize();
}
void Progression::incrementProgressBar(QString file, QString currentFile){
//qDebug() << "The value was" << ProgressBars[file]->value();
if(ProgressBars[file]->value() < ProgressBars[file]->maximum())
ProgressBars[file]->setValue(ProgressBars[file]->value() + 1);
//qDebug() << "The value is" << ProgressBars[file]->value();
if(currentFile != "")
{
for(int i = 0; i < vbl->count(); i++)
{
QLayoutItem* item = vbl->itemAt(i);
QWidget* widget = item->widget();
if (widget) {
QLabel *label = qobject_cast<QLabel *>(widget);
if(label)
{
if(label->objectName() == file)
{
label->setText("Copy " + currentFile.split("/").last() + " to " + currentFile);
}
}
}
}
}
this->adjustSize();
}
void Progression::updateProgressBarMax(QString file, qint64 pos){
//qDebug() << "The maximum is : " << pos;
ProgressBars[file]->setMaximum((int) pos);
}
void Progression::onRemoveLabel(QString name)
{
qDebug() << "trying to remove label and progress bar for :" << name;
for(int i = 0; i < vbl->count(); i++)
{
QLayoutItem* item = vbl->itemAt(i);
QWidget* widget = item->widget();
if (widget) {
QLabel *label = qobject_cast<QLabel *>(widget);
if(label and label->objectName() == name )
{
label->hide();
vbl->removeItem(item);
qDebug() << "Remove Label";
i--;
}
QProgressBar * pb = qobject_cast<QProgressBar *>(widget);
if(pb and pb->objectName() == name)
{
pb->hide();
vbl->removeItem(item);
qDebug() << "Remove Progbar";
i--;
}
}
}
this->adjustSize();
}