-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmangaeditor.cpp
executable file
·618 lines (537 loc) · 25.2 KB
/
mangaeditor.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
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
#include "mangaeditor.h"
#include "ui_mangaeditor.h"
#include "imageviewer.h"
#include "projarchive.h"
#include "picanalyzeresult.h"
#include <QCryptographicHash>
#include <QDir>
#include <QFileDialog>
#include <QImageReader>
#include <QMessageBox>
#include <QProgressBar>
#include <QSettings>
#include <QStatusBar>
#include <QStandardPaths>
#include <QUuid>
#define DS QDir::separator()
class MangaEditorPrivate {
Q_DECLARE_PUBLIC(MangaEditor)
public:
MangaEditorPrivate(MangaEditor * parent) : q_ptr(parent), tabModified(false)
{
excludedWidgets << "qt_spinbox_lineedit";
QWidget *kmm = 0;
for (QWidget* w : qApp->topLevelWidgets()) {
if (w->objectName() == "kmm") {
kmm = w;
break;
}
}
progressbar = kmm->findChild<QProgressBar*>("status_bar_qprogressbar");
statusbar = kmm->findChild<QStatusBar*>("kmm_qstatusbar");
}
void initMangaEditor(Ui::MangaEditor *ui, const QString& filename = QString()) {
ui->setupUi(q_ptr);
q_ptr->setFocusProxy(ui->txtName);
ui->dteDate->setDate(QDate::currentDate());
ui->tblChapters->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
ui->tblChapters->verticalHeader()->setVisible(false);
addLanguages(ui->cboLanguage);
if (filename.isEmpty())
createTemporaryFolder();
else
createTemporaryFolder(filename);
if (!filename.isEmpty()) {
loadDataToUI(ui->GeneralData);
// Load Cover
QStringList files = QDir(tmpPath).entryList({"cover-image.*"});
if (files.size()) {
coverPath = tmpPath + DS + files.at(0);
ui->btnViewCover->setEnabled(true);
ui->btnRemoveCover->setEnabled(true);
}
// Load Chapters
QSettings s(settingsPath, QSettings::IniFormat);
QStringList titles = s.value("Chapters/title", "").toString().split("::");
QStringList folders = s.value("Chapters/folders", "").toString().split("::");
QStringList toTOC = s.value("Chapters/toTOC", "").toString().split("::");
if (!folders.first().isEmpty()) {
for (int i=0; i<folders.size(); ++i) {
ui->tblChapters->insertRow(i);
QTableWidgetItem * item = new QTableWidgetItem(titles.at(i));
item->setCheckState(toTOC.at(i)=="0"?Qt::Unchecked:Qt::Checked);
item->setData(Qt::UserRole, folders.at(i));
ui->tblChapters->setItem(i, 0, item);
}
}
}
connectWidgetSignals(ui->GeneralData);
setAllValuesToTemp(ui->GeneralData);
q_ptr->connect(ui->btnISBN, &QPushButton::clicked, [=](){ ui->txtISBN->setText(generateISBN()); });
q_ptr->connect(ui->btnSelectCover, &QPushButton::clicked, [=](){ selectCover(ui); });
q_ptr->connect(ui->btnViewCover, &QPushButton::clicked, [=](){ viewCover(); });
q_ptr->connect(ui->btnRemoveCover, &QPushButton::clicked, [=](){ removeCover(ui); });
q_ptr->connect(ui->btnSelectPicFolder, &QPushButton::clicked, [=](){ selectPictureFolder(ui); });
q_ptr->connect(ui->btnAddChapter, &QPushButton::clicked, [=](){ addChapter(ui); });
q_ptr->connect(ui->btnViewChapter, &QPushButton::clicked, [=]() { viewChapterImages(ui); });
q_ptr->connect(ui->btnRemoveChapter, &QPushButton::clicked, [=](){ removeChapter(ui); });
q_ptr->connect(ui->btnUpArrow, &QPushButton::clicked, [=](){ chapterOrderUp(ui); });
q_ptr->connect(ui->btnDownArrow, &QPushButton::clicked, [=](){ chapterOrderDown(ui); });
q_ptr->connect(ui->tblChapters, &QTableWidget::cellChanged, [=](int r, int c){ updateChapterInformation(ui, r, c); });
}
void loadDataToUI(QWidget * parent) {
QSettings s(settingsPath, QSettings::IniFormat);
for (QWidget* widget : parent->findChildren<QWidget*>()) {
if (widget->inherits("QLineEdit") && !excludedWidgets.contains(widget->objectName())) {
QLineEdit* cw = qobject_cast<QLineEdit*>(widget);
cw->setText(s.value(cw->objectName(), QString()).toString());
continue;
}
if (widget->inherits("QComboBox") && !excludedWidgets.contains(widget->objectName())) {
QComboBox* cw = qobject_cast<QComboBox*>(widget);
cw->setCurrentIndex(s.value(cw->objectName(), -1).toInt());
continue;
}
if (widget->inherits("QCheckBox") && !excludedWidgets.contains(widget->objectName())) {
QCheckBox* cw = qobject_cast<QCheckBox*>(widget);
cw->setChecked(s.value(cw->objectName(), false).toBool());
continue;
}
if (widget->inherits("QPlainTextEdit") && !excludedWidgets.contains(widget->objectName())) {
QPlainTextEdit* cw = qobject_cast<QPlainTextEdit*>(widget);
cw->setPlainText(s.value(cw->objectName(), QString()).toString());
continue;
}
if (widget->inherits("QDateEdit") && !excludedWidgets.contains(widget->objectName())) {
QDateEdit* cw = qobject_cast<QDateEdit*>(widget);
cw->setDate(s.value(cw->objectName(), QDate::currentDate()).toDate());
continue;
}
}
}
void createTemporaryFolder() {
// Generate the temporary folder name
QByteArray ba = QString("%1").arg(qrand()).toUtf8();
tmpPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + DS + QString("KMM-");
tmpPath.append(QCryptographicHash::hash(ba, QCryptographicHash::Md5).toHex());
// Setting relevant variables
settingsPath = tmpPath + DS + QString("content.ini");
chaptersPath = tmpPath + DS + QString("chapters");
// Creating the temporary folder
QDir().mkdir(tmpPath);
QDir().mkdir(chaptersPath);
}
void createTemporaryFolder(const QString& filename) {
// Generate the temporary folder name
QByteArray ba = QString("%1").arg(qrand()).toUtf8();
tmpPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + DS + QString("KMM-");
tmpPath.append(QCryptographicHash::hash(ba, QCryptographicHash::Md5).toHex());
// Setting relevant variables
settingsPath = tmpPath + DS + QString("content.ini");
chaptersPath = tmpPath + DS + QString("chapters");
// Creating the temporary folder
QDir().mkdir(tmpPath);
// Extracting the filename archive to the temporary folder
statusbar->showMessage(MangaEditor::tr("Loading File: ") + filename + "...");
ProjArchive pa(filename, ProjArchive::InputMode);
pa.setProgressBar(progressbar);
if (pa.isValid()) {
pa.extract(tmpPath);
statusbar->showMessage(MangaEditor::tr("File loaded successfully!!"), 5000);
}
else
statusbar->showMessage(MangaEditor::tr("Error loading the file!!!"));
}
void removeTemporaryFolder() {
QDir(tmpPath).removeRecursively();
}
void setValueToTemp(const QLineEdit * widget, bool setModified = true) {
QSettings s(settingsPath, QSettings::IniFormat);
s.setValue(widget->objectName(), widget->text());
if (setModified) setIsModifiedTab(true);
}
void setValueToTemp(const QComboBox * widget, bool setModified = true) {
QSettings s(settingsPath, QSettings::IniFormat);
s.setValue(widget->objectName(), widget->currentIndex());
if (setModified) setIsModifiedTab(true);
}
void setValueToTemp(const QCheckBox * widget, bool setModified = true) {
QSettings s(settingsPath, QSettings::IniFormat);
s.setValue(widget->objectName(), widget->isChecked());
if (setModified) setIsModifiedTab(true);
}
void setValueToTemp(const QPlainTextEdit * widget, bool setModified = true) {
QSettings s(settingsPath, QSettings::IniFormat);
s.setValue(widget->objectName(), widget->toPlainText());
if (setModified) setIsModifiedTab(true);
}
void setValueToTemp(const QDateEdit * widget, bool setModified = true) {
QSettings s(settingsPath, QSettings::IniFormat);
s.setValue(widget->objectName(), widget->date());
if (setModified) setIsModifiedTab(true);
}
void setAllValuesToTemp(QWidget* parent) {
for (QWidget* widget : parent->findChildren<QWidget*>()) {
if (widget->inherits("QLineEdit") && !excludedWidgets.contains(widget->objectName())) {
const QLineEdit* cw = qobject_cast<const QLineEdit*>(widget);
setValueToTemp(cw, false);
continue;
}
if (widget->inherits("QComboBox") && !excludedWidgets.contains(widget->objectName())) {
const QComboBox* cw = qobject_cast<const QComboBox*>(widget);
setValueToTemp(cw, false);
continue;
}
if (widget->inherits("QCheckBox") && !excludedWidgets.contains(widget->objectName())) {
const QCheckBox* cw = qobject_cast<const QCheckBox*>(widget);
setValueToTemp(cw, false);
continue;
}
if (widget->inherits("QPlainTextEdit") && !excludedWidgets.contains(widget->objectName())) {
const QPlainTextEdit* cw = qobject_cast<const QPlainTextEdit*>(widget);
setValueToTemp(cw, false);
continue;
}
if (widget->inherits("QDateEdit") && !excludedWidgets.contains(widget->objectName())) {
const QDateEdit* cw = qobject_cast<const QDateEdit*>(widget);
setValueToTemp(cw, false);
continue;
}
}
}
void connectWidgetSignals(QWidget* parent) {
for (QWidget* widget : parent->findChildren<QWidget*>()) {
if (widget->inherits("QLineEdit") && !excludedWidgets.contains(widget->objectName())) {
const QLineEdit* cw = qobject_cast<const QLineEdit*>(widget);
cw->connect(cw, &QLineEdit::textChanged, [=](const QString&){ setValueToTemp(cw); });
continue;
}
if (widget->inherits("QComboBox") && !excludedWidgets.contains(widget->objectName())) {
const QComboBox* cw = qobject_cast<const QComboBox*>(widget);
cw->connect(cw, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [=](int){ setValueToTemp(cw); });
continue;
}
if (widget->inherits("QCheckBox") && !excludedWidgets.contains(widget->objectName())) {
const QCheckBox* cw = qobject_cast<const QCheckBox*>(widget);
cw->connect(cw, &QCheckBox::toggled, [=](bool){ setValueToTemp(cw); });
continue;
}
if (widget->inherits("QPlainTextEdit") && !excludedWidgets.contains(widget->objectName())) {
const QPlainTextEdit* cw = qobject_cast<const QPlainTextEdit*>(widget);
cw->connect(cw, &QPlainTextEdit::textChanged, [=](){ setValueToTemp(cw); });
continue;
}
if (widget->inherits("QDateEdit") && !excludedWidgets.contains(widget->objectName())) {
const QDateEdit* cw = qobject_cast<const QDateEdit*>(widget);
cw->connect(cw, &QDateEdit::dateChanged, [=](){ setValueToTemp(cw); });
continue;
}
}
}
void setIsModifiedTab(bool b) {
tabModified = b;
QTabWidget* widget = q_ptr->window()->findChild<QTabWidget*>("kmm_main_tab_widget");
int index = widget->indexOf(q_ptr);
QString tabText = widget->tabText(index);
if (b) {
if (tabText.right(4) != " [*]")
tabText.append(" [*]");
}
else {
if (tabText.right(4) == " [*]")
tabText.remove(" [*]");
}
widget->setTabText(index, tabText);
}
QString generateISBN() {
QString uuid = QUuid::createUuid().toString();
uuid.remove('{').remove('}');
return uuid;
}
void addLanguages(QComboBox* cb) {
// (PT, EN, SP, EO, DE, FR, IT, JP, CN, RS, AR, HB)
QLocale l;
QList<QLocale::Language> languages;
languages << QLocale::English << QLocale::Portuguese << QLocale::Spanish << QLocale::Esperanto
<< QLocale::German << QLocale::French << QLocale::Italian << QLocale::Japanese
<< QLocale::Chinese << QLocale::Russian << QLocale::Arabic << QLocale::Hebrew;
QStringList languageAbbrev({"en", "pt", "es", "eo", "de", "fr", "it", "ja", "zh", "ru", "ar", "he"});
for (int i=0; i<qMin(languages.size(),languageAbbrev.size()); ++i)
cb->addItem(QLocale::languageToString(languages.at(i)), languageAbbrev.at(i));
cb->setCurrentIndex(0);
}
void selectCover(Ui::MangaEditor *ui) {
QSettings s;
QList<QByteArray> supported = QImageReader::supportedImageFormats();
QString filter("All supported images (");
for (const QByteArray& ext : supported)
filter.append("*.").append(ext).append(" ");
filter.replace(filter.size()-1, 1, ")");
QString dir = s.value("DEFAULT_PATH", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)).toString();
QString fname = QFileDialog::getOpenFileName(q_ptr, MangaEditor::tr("Select Cover"),
dir,
filter, &filter);
if (!fname.isEmpty()) {
QFile f(fname);
QFileInfo fi(fname);
s.setValue("DEFAULT_PATH", fi.absoluteDir().path());
QString ext = fi.suffix();
coverPath = tmpPath + DS + "cover-image." + ext;
if (QFileInfo(coverPath).exists())
QDir(tmpPath).remove(coverPath);
f.copy(coverPath);
ui->btnViewCover->setEnabled(true);
ui->btnRemoveCover->setEnabled(true);
setIsModifiedTab(true);
}
}
void removeCover(Ui::MangaEditor *ui) {
QDir tmp(tmpPath);
QStringList files = tmp.entryList({"cover-image.*"});
if (files.size()) {
tmp.remove(files.at(0));
coverPath.clear();
ui->btnViewCover->setEnabled(false);
ui->btnRemoveCover->setEnabled(false);
setIsModifiedTab(true);
}
}
void viewCover() {
QDir tmp(tmpPath);
QStringList files = tmp.entryList({"cover-image.*"});
if (files.size()) {
ImageViewer dlg(coverPath, q_ptr);
q_ptr->connect(&dlg, &ImageViewer::imageRotated, [=](){ setIsModifiedTab(true); });
dlg.setWindowTitle(MangaEditor::tr("View Cover"));
dlg.exec();
}
}
void selectPictureFolder(Ui::MangaEditor *ui) {
QSettings s;
QString dir = s.value("DEFAULT_PATH", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)).toString();
QString folder = QFileDialog::getExistingDirectory(q_ptr, MangaEditor::tr("Select Chapter Folder"), dir);
QFileInfo fi(folder);
s.setValue("DEFAULT_PATH", fi.absoluteDir().path());
ui->txtPicFolder->setText(folder);
}
void addChapter(Ui::MangaEditor *ui) {
QString title = ui->chkChapterTitle->isChecked() ? ui->txtChapterTitle->text() : "";
QString origFolder = ui->txtPicFolder->text();
if (origFolder.isEmpty()) return;
// Create Chapter Temporary Folder
QByteArray ba = QString("%1").arg(qrand()).toUtf8();
QString chapterPath = chaptersPath + DS;
QString chapterFolder = QCryptographicHash::hash(ba, QCryptographicHash::Md5).toHex();
chapterPath.append(chapterFolder);
QDir().mkdir(chapterPath);
// Copy just the pics to Chapter Temporary Folder
QDir dOrig(origFolder);
QStringList files = dOrig.entryList(QDir::Files|QDir::NoDotAndDotDot|QDir::Readable, QDir::Name|QDir::LocaleAware);
for (const QString& f : files) {
QString fPath(origFolder + DS + f);
QImageReader reader(fPath);
if (reader.format().isEmpty()) continue; // Ignore the file if it is not an image.
QFile file(fPath);
file.copy(chapterPath + DS + f);
}
// Add Basic Information to content.ini
QSettings s(settingsPath, QSettings::IniFormat);
QString titles = s.value("Chapters/title", "").toString();
QString folders = s.value("Chapters/folders", "").toString();
QString toTOC = s.value("Chapters/toTOC", "").toString();
titles.append((titles.isEmpty() && folders.isEmpty() ? "" : "::") + title);
folders.append((folders.isEmpty() ? "" : "::") + chapterFolder);
toTOC.append((toTOC.isEmpty() ? "" : "::") + QString(title.isEmpty()?"0":"1"));
s.setValue("Chapters/title", titles);
s.setValue("Chapters/folders" , folders);
s.setValue("Chapters/toTOC", toTOC);
// Update the table in the UI
int row = ui->tblChapters->rowCount();
ui->tblChapters->insertRow(row);
QTableWidgetItem * item = new QTableWidgetItem(title);
item->setCheckState(title.isEmpty()?Qt::Unchecked:Qt::Checked);
item->setData(Qt::UserRole, chapterFolder);
ui->tblChapters->setItem(row, 0, item);
// Finish
ui->txtPicFolder->clear();
ui->txtChapterTitle->clear();
ui->chkChapterTitle->setChecked(false);
ui->btnSelectPicFolder->setFocus();
setIsModifiedTab(true);
}
void removeChapter(Ui::MangaEditor *ui) {
// TODO: Confirm before delete
// Get the Selected line
QList<QTableWidgetItem*> selected = ui->tblChapters->selectedItems();
if (selected.isEmpty()) return;
QTableWidgetItem *item = selected.first();
int row = item->row();
// Delete the folder from Temporary path
QString chapterFolder = chaptersPath + DS + item->data(Qt::UserRole).toString();
QDir d(chapterFolder);
d.removeRecursively();
// Remove Information from content.ini
QSettings s(settingsPath, QSettings::IniFormat);
QStringList titles = s.value("Chapters/title", "").toString().split("::");
QStringList folders = s.value("Chapters/folders", "").toString().split("::");
QStringList toTOC = s.value("Chapters/toTOC", "").toString().split("::");
titles.removeAt(row);
folders.removeAt(row);
toTOC.removeAt(row);
s.setValue("Chapters/title", titles.join("::"));
s.setValue("Chapters/folders" , folders.join("::"));
s.setValue("Chapters/toTOC", toTOC.join("::"));
// Update the table in the UI
ui->tblChapters->removeRow(row);
// Finish
ui->tblChapters->selectRow(row-1);
ui->tblChapters->setFocus();
setIsModifiedTab(true);
}
void viewChapterImages(Ui::MangaEditor *ui) {
QList<QTableWidgetItem*> selected = ui->tblChapters->selectedItems();
if (selected.isEmpty()) return;
QTableWidgetItem *item = selected.first();
QString chapterFolder = chaptersPath + DS + item->data(Qt::UserRole).toString();
ImageViewer dlg(chapterFolder, q_ptr);
q_ptr->connect(&dlg, &ImageViewer::imageRotated, [=](){ setIsModifiedTab(true); });
dlg.setWindowTitle(item->data(Qt::DisplayRole).toString());
dlg.exec();
}
void updateChapterInformation(Ui::MangaEditor *ui, int row, int col=0) {
// Remove Informatzion from content.ini
QSettings s(settingsPath, QSettings::IniFormat);
QStringList titles = s.value("Chapters/title", "").toString().split("::");
QStringList folders = s.value("Chapters/folders", "").toString().split("::");
QStringList toTOC = s.value("Chapters/toTOC", "").toString().split("::");
titles.replace(row, ui->tblChapters->item(row, col)->text());
folders.replace(row, ui->tblChapters->item(row, col)->data(Qt::UserRole).toString());
toTOC.replace(row, ui->tblChapters->item(row, col)->checkState()==Qt::Checked?"1":"0");
s.setValue("Chapters/title", titles.join("::"));
s.setValue("Chapters/folders", folders.join("::"));
s.setValue("Chapters/toTOC", toTOC.join("::"));
setIsModifiedTab(true);
}
void chapterOrderUp(Ui::MangaEditor *ui) {
QList<QTableWidgetItem*> items = ui->tblChapters->selectedItems();
if (items.isEmpty() || ui->tblChapters->rowCount() == 1) return;
QTableWidgetItem *item = items.first();
if (item->row() == 0) return;
int row = item->row();
QTableWidgetItem *item_down = new QTableWidgetItem(* ui->tblChapters->item(row, 0));
QTableWidgetItem *item_up = new QTableWidgetItem(* ui->tblChapters->item(row-1, 0));
ui->tblChapters->setItem(row, 0, item_up);
ui->tblChapters->setItem(row-1, 0, item_down);
ui->tblChapters->selectRow(row-1);
}
void chapterOrderDown(Ui::MangaEditor *ui) {
QList<QTableWidgetItem*> items = ui->tblChapters->selectedItems();
if (items.isEmpty() || ui->tblChapters->rowCount() == 1) return;
QTableWidgetItem *item = items.first();
if (item->row() == ui->tblChapters->rowCount()-1) return;
int row = item->row();
QTableWidgetItem *item_up = new QTableWidgetItem(* ui->tblChapters->item(row, 0));
QTableWidgetItem *item_down = new QTableWidgetItem(* ui->tblChapters->item(row+1, 0));
ui->tblChapters->setItem(row, 0, item_down);
ui->tblChapters->setItem(row+1, 0, item_up);
ui->tblChapters->selectRow(row+1);
}
MangaEditor * const q_ptr;
QString tmpPath;
QString chaptersPath;
QString settingsPath;
QString coverPath;
bool tabModified;
QString projectFile;
QStringList excludedWidgets;
QStatusBar *statusbar;
QProgressBar *progressbar;
};
MangaEditor::MangaEditor(QWidget *parent) :
QWidget(parent),
ui(new Ui::MangaEditor),
d_ptr(new MangaEditorPrivate(this))
{
d_ptr->initMangaEditor(ui);
}
MangaEditor::MangaEditor(const QString& filename, QWidget *parent) :
QWidget(parent),
ui(new Ui::MangaEditor),
d_ptr(new MangaEditorPrivate(this))
{
d_ptr->initMangaEditor(ui, filename);
}
MangaEditor::~MangaEditor() {
d_ptr->removeTemporaryFolder();
delete d_ptr;
delete ui;
}
void MangaEditor::saveProject(const QString& filename) {
setEnabled(false);
d_ptr->statusbar->showMessage(MangaEditor::tr("Saving File: ") + filename + "...");
ProjArchive pa(filename, ProjArchive::OutputMode);
pa.setProgressBar(d_ptr->progressbar);
if (pa.isValid()) {
pa.save(d_ptr->tmpPath);
d_ptr->statusbar->showMessage(MangaEditor::tr("File saved successfully!!"), 5000);
}
else
d_ptr->statusbar->showMessage(MangaEditor::tr("Error saving the file!!!"));
setEnabled(true);
}
void MangaEditor::setProjectFile(const QString& s) {
if (d_ptr->projectFile != s)
d_ptr->projectFile = s;
}
QString MangaEditor::projectFile() const {
return d_ptr->projectFile;
}
void MangaEditor::setTabModified(bool b) {
if (d_ptr->tabModified != b)
d_ptr->setIsModifiedTab(b);
}
bool MangaEditor::tabModified() const {
return d_ptr->tabModified;
}
QString MangaEditor::tempPath() const {
return d_ptr->tmpPath;
}
bool MangaEditor::analyzeChapterPictures() {
QSettings s(d_ptr->settingsPath, QSettings::IniFormat);
QStringList chaptersFolders = s.value("Chapters/folders", "").toString().split("::");
QStringList dpPictures;
if (chaptersFolders.isEmpty() || (chaptersFolders.size()==1 && chaptersFolders.first()=="")) {
// TODO: Error no chapters added to this project.
}
else {
for (const QString& cf : chaptersFolders) {
QString cPath = d_ptr->chaptersPath + DS + cf;
QDir d(cPath);
QStringList files = d.entryList(QDir::NoFilter, QDir::Name|QDir::LocaleAware);
for (const QString& f : files) {
QImageReader reader(cPath + DS + f);
QSize imgS = reader.size();
if (imgS.width() > imgS.height()) {
// Detected as double page image
dpPictures << cPath+DS+f;
}
}
}
}
if (dpPictures.isEmpty()) {
// No double page pictures were detected
QMessageBox msg(QMessageBox::Information, tr("Pictures Analyzer"),
tr("No double page pictures were detected! Do you want to continue and generate the output file?"),
QMessageBox::Yes|QMessageBox::No, window());
msg.setWindowModality(Qt::WindowModal);
if (msg.exec() != QMessageBox::Yes) return false;
}
else {
// Open dialog to confirm double page images treatment
PicAnalyzeResult dlg(dpPictures, ui->cboDoublePage->currentIndex(), ui->chkLR->isChecked(), window());
if (dlg.exec() == QDialog::Rejected) return false;
if (dlg.modified()) d_ptr->setIsModifiedTab(true);
}
// Continue and generate the desired file
return true;
}