-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtabwidget.cpp
More file actions
216 lines (180 loc) · 7.25 KB
/
Copy pathtabwidget.cpp
File metadata and controls
216 lines (180 loc) · 7.25 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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#include "tabwidget.h"
#include "qcontainerfwd.h"
#include "qhashfunctions.h"
#include "qlabel.h"
#include "qline.h"
#include "qlineedit.h"
#include "qnamespace.h"
#include "qslider.h"
#include "qtypes.h"
#include "qwidget.h"
#include <fstream>
void Tabwidget::function(const QStringList &path){
//change the interface after the user has selected some file
file = path;
dropArea->setVisible(false);
button->setVisible(true);
if (file.length() == 1){status->setText(QFileInfo(path.first()).fileName());}
else{status->setText(QString::number(file.length()) + " files selected");}
}
void Tabwidget::processar(){
//create a new process for each file
count = 0;
if (!file.isEmpty()){
if(options_list_box != nullptr){
options_list_box->setVisible(false);
}
if(slider != nullptr){
slider->setVisible(false);
}
if(input_box != nullptr){
input_box->setVisible(false);
}
button->setVisible(false);
status->setText("Processing...");
QString exe = QStandardPaths::findExecutable(command_name);
if(exe.isEmpty()){
if (command_name == "zbarimg"){status->setText("zbar-tools not installed!");}
else{status->setText(command_name + " not installed!");}
dropArea->setVisible(true);
button->setVisible(false);
if(options_list_box != nullptr){
options_list_box->setVisible(true);
}
if(slider != nullptr){
slider->setVisible(true);
}
if(input_box != nullptr){
input_box->setVisible(true);
}
return;
}
else{
for (auto single_file : file){
QProcess *p = new QProcess;
QFileInfo info(single_file);
connect(p, &QProcess::finished, this, &Tabwidget::ProcessingDone);
connect(p, &QProcess::finished, p, &QObject::deleteLater);
if(input_box != nullptr and options_list_box != nullptr){p->start(command_name, command(info, {line_edit->text(), options_list_box->currentText()}));}
else if(slider != nullptr and options_list_box != nullptr){p->start(command_name, command(info, {QString::number(slider->value()),options_list_box->currentText()}));}
else if(options_list_box != nullptr){p->start(command_name, command(info,{options_list_box->currentText()}));}
else if(slider != nullptr){p->start(command_name, command(info, {QString::number(slider->value())}));}
else if(input_box != nullptr){p->start(command_name, command(info, {line_edit->text()}));}
else{p->start(command_name, command(info, {}));}
}
}
}
}
void Tabwidget::ProcessingDone(){
//Check if all processes finished and update the countdown
count++;
QProcess *p = qobject_cast<QProcess*>(sender());
if (command_name == "zbarimg"){
QString output = p->readAllStandardOutput();
std::ofstream out((QDir::homePath()).toStdString() + "/QR_Codes.txt", std::ios::app);
out << "------------------\n";
out << output.toStdString() << "\n\n";
}
qDebug() << p->exitCode();
qDebug() << p->readAllStandardError();
if (count == file.size()){
status->setText("Finished");
dropArea->setVisible(true);
button->setVisible(false);
if(options_list_box != nullptr){
options_list_box->setVisible(true);
}
if(slider != nullptr){
slider->setVisible(true);
}
if(input_box != nullptr){
input_box->setVisible(true);
}
}
else{
status->setText(QString::number(count) + " / " + QString::number(file.size()) + " files");
}
}
Tabwidget::Tabwidget(QWidget *parent, const QStringList &extensions, const QString &name,const std::function<QStringList(const QFileInfo &info, const QStringList &ext)> &command, QString command_name, const QStringList &options_list , const QList<int> &slider_, const QString &label, QString explanation_)
: QWidget(parent), extensions(extensions), command(command), command_name(command_name)
{
title = new QLabel(name);
title->setAlignment(Qt::AlignCenter);
if (explanation_ != ""){
QString arg_final = extensions.first();
for (qsizetype i = 1; i < (extensions.size() - 1); i ++){
arg_final += "," + extensions[i];
}
explanation = new QLabel(QString("Drop a %1 file in bottom area or click and select").arg(arg_final));
}
else {explanation = new QLabel(QString("Drop an image file in bottom area or click. The result will be saved in you home folder."));}
dropArea = new DropLabel(this, extensions);
button = new QPushButton("Run");
status = new QLabel("");
QVBoxLayout *layout = new QVBoxLayout();
layout->addWidget(title);
layout->addWidget(explanation);
layout->addWidget(dropArea);
layout->addWidget(button);
layout->addWidget(status);
if (!options_list.isEmpty()){
options_list_box = new QComboBox();
options_list_box->addItems(options_list);
layout->addWidget(options_list_box);
}
else{
options_list_box = nullptr;
}
if (!slider_.isEmpty()){
slider = new QSlider(Qt::Horizontal, this);
slider->setMinimum(slider_[0]);
slider->setMaximum(slider_[1]);
slider->setValue(80);
layout->addWidget(slider);
}
else{
slider = nullptr;
}
if (label != ""){
input_box = new QWidget();
QHBoxLayout *resolutionLayout = new QHBoxLayout(input_box);
resolutionLayout->addWidget(new QLabel(label));
line_edit = new QLineEdit();
resolutionLayout->addWidget(line_edit);
layout->addWidget(input_box);
}
else{
input_box = nullptr;
}
setLayout(layout);
connect(dropArea, &DropLabel::fileDropped, this, &Tabwidget::function);
connect(button, &QPushButton::clicked, this, &Tabwidget::processar);
button->setVisible(false);
}
Tabwidget::Tabwidget(QString explanation_, const QString &label, QWidget *parent, const QString &name, const std::function<QStringList(const QFileInfo &info, const QStringList &ext)> &command, QString command_name)
:QWidget(parent), command(command), command_name(command_name){
QVBoxLayout *layout = new QVBoxLayout();
title = new QLabel(name);
title->setAlignment(Qt::AlignCenter);
layout->addWidget(title);
explanation = new QLabel(explanation_);
button = new QPushButton("Run");
status = new QLabel("");
layout->addWidget(explanation);
layout->addWidget(button);
layout->addWidget(status);
input_box = new QWidget();
QHBoxLayout *resolutionLayout = new QHBoxLayout(input_box);
resolutionLayout->addWidget(new QLabel(label));
line_edit = new QLineEdit();
resolutionLayout->addWidget(line_edit);
layout->addWidget(input_box);
image_label = new QLabel();
image_label->setAlignment(Qt::AlignCenter);
layout->addWidget(image_label);
image_label->setVisible(true);
image = new QPixmap();
setLayout(layout);
connect(button, &QPushButton::clicked, this, &Tabwidget::processar);
count = 1;
}