diff --git a/YACReaderLibrary/images.qrc b/YACReaderLibrary/images.qrc
index 4fa88ed4..56e90257 100644
--- a/YACReaderLibrary/images.qrc
+++ b/YACReaderLibrary/images.qrc
@@ -43,6 +43,7 @@
../images/flow4.png
../images/flow5.png
../images/glowLine.png
+ ../images/loadCustomCover.svg
../images/hiddenCovers.png
../images/icon-new.svg
../images/iconLibrary.png
diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp
index 48ef18ef..5ed2f4fc 100644
--- a/YACReaderLibrary/library_window.cpp
+++ b/YACReaderLibrary/library_window.cpp
@@ -1,6 +1,7 @@
#include "library_window.h"
#include "yacreader_global.h"
+#include "yacreader_global_gui.h"
#include
#include
@@ -2313,12 +2314,7 @@ void LibraryWindow::setFolderCover()
void LibraryWindow::setCustomFolderCover(Folder folder)
{
- QString supportedImageFormatsString;
- for (const QByteArray &format : QImageReader::supportedImageFormats()) {
- supportedImageFormatsString += QString("*.%1 ").arg(QString(format));
- }
-
- QString customCoverPath = QFileDialog::getOpenFileName(this, tr("Select custom cover"), QDir::homePath(), tr("Images (%1)").arg(supportedImageFormatsString));
+ auto customCoverPath = YACReader::imageFileLoader(this);
if (!customCoverPath.isEmpty()) {
QImage cover(customCoverPath);
if (cover.isNull()) {
diff --git a/YACReaderLibrary/properties_dialog.cpp b/YACReaderLibrary/properties_dialog.cpp
index d9aefb40..d0eea83a 100644
--- a/YACReaderLibrary/properties_dialog.cpp
+++ b/YACReaderLibrary/properties_dialog.cpp
@@ -1,5 +1,8 @@
#include "properties_dialog.h"
+#include "yacreader_global_gui.h"
+
+#include "cover_utils.h"
#include "data_base_management.h"
#include "initial_comic_info_extractor.h"
#include "yacreader_field_edit.h"
@@ -102,15 +105,23 @@ void PropertiesDialog::createCoverBox()
showPreviousCoverPageButton = new QToolButton();
showPreviousCoverPageButton->setIcon(QIcon(":/images/previousCoverPage.png"));
+ showPreviousCoverPageButton->setToolTip(tr("Load previous page as cover"));
showPreviousCoverPageButton->setStyleSheet("QToolButton {border:none;}");
showNextCoverPageButton = new QToolButton();
showNextCoverPageButton->setIcon(QIcon(":/images/nextCoverPage.png"));
+ showNextCoverPageButton->setToolTip(tr("Load next page as cover"));
showNextCoverPageButton->setStyleSheet("QToolButton {border:none;}");
resetCoverButton = new QToolButton();
resetCoverButton->setIcon(QIcon(":/images/resetCover.svg"));
+ resetCoverButton->setToolTip(tr("Reset cover to the default image"));
resetCoverButton->setStyleSheet("QToolButton {border:none;}");
+ loadCustomCoverImageButton = new QToolButton();
+ loadCustomCoverImageButton->setIcon(QIcon(":/images/loadCustomCover.svg"));
+ loadCustomCoverImageButton->setToolTip(tr("Load custom cover image"));
+ loadCustomCoverImageButton->setStyleSheet("QToolButton {border:none;}");
+
coverPageNumberLabel = new QLabel("-");
coverPageNumberLabel->setStyleSheet("QLabel {color: white; font-weight:bold; font-size:14px;}");
@@ -122,6 +133,8 @@ void PropertiesDialog::createCoverBox()
layout->addWidget(showNextCoverPageButton, 0, Qt::AlignVCenter);
layout->addSpacing(5);
layout->addWidget(resetCoverButton, 0, Qt::AlignVCenter);
+ layout->addSpacing(5);
+ layout->addWidget(loadCustomCoverImageButton, 0, Qt::AlignVCenter);
coverPageEdit->setStyleSheet("QLineEdit {border:none;}");
layout->setSpacing(0);
@@ -139,6 +152,7 @@ void PropertiesDialog::createCoverBox()
connect(showPreviousCoverPageButton, &QAbstractButton::clicked, this, &PropertiesDialog::loadPreviousCover);
connect(showNextCoverPageButton, &QAbstractButton::clicked, this, &PropertiesDialog::loadNextCover);
connect(resetCoverButton, &QAbstractButton::clicked, this, &PropertiesDialog::resetCover);
+ connect(loadCustomCoverImageButton, &QAbstractButton::clicked, this, &PropertiesDialog::loadCustomCoverImage);
}
void PropertiesDialog::createGeneralInfoBox()
@@ -441,6 +455,8 @@ QImage blurred(const QImage &image, const QRect &rect, int radius, bool alphaOnl
void PropertiesDialog::loadComic(ComicDB &comic)
{
+ customCover = QImage();
+
if (!comic.info.series.isNull())
series->setText(comic.info.series.toString());
if (!comic.info.title.isNull())
@@ -583,9 +599,13 @@ void PropertiesDialog::updateButtons()
void PropertiesDialog::setComics(QList comics)
{
- updated = false;
sequentialEditing = false;
+ updated = false;
+ currentComicIndex = 0;
+ coverChanged = false;
+ customCover = QImage();
+
this->comics = comics;
ComicDB comic = comics[0];
@@ -702,9 +722,12 @@ void PropertiesDialog::setComics(QList comics)
void PropertiesDialog::setComicsForSequentialEditing(int currentComicIndex, QList comics)
{
- updated = false;
sequentialEditing = true;
+ updated = false;
+ coverChanged = false;
+ customCover = QImage();
+
this->comics = comics;
this->currentComicIndex = currentComicIndex;
@@ -789,7 +812,11 @@ void PropertiesDialog::save()
if (sequentialEditing)
if (coverChanged) {
- itr->info.coverPage = coverPageNumberLabel->text().toInt();
+ if (customCover.isNull()) {
+ itr->info.coverPage = coverPageNumberLabel->text().toInt();
+ } else {
+ itr->info.coverPage = QVariant();
+ }
edited = true;
}
@@ -957,15 +984,22 @@ void PropertiesDialog::save()
if (sequentialEditing) {
if (coverChanged) {
auto coverPath = LibraryPaths::coverPath(basePath, comics[currentComicIndex].info.hash);
- InitialComicInfoExtractor ie(basePath + comics[currentComicIndex].path, coverPath, comics[currentComicIndex].info.coverPage.toInt());
- ie.extract();
- if (ie.getOriginalCoverSize().second > 0) {
- comics[currentComicIndex].info.originalCoverSize = QString("%1x%2").arg(ie.getOriginalCoverSize().first).arg(ie.getOriginalCoverSize().second);
- comics[currentComicIndex].info.coverSizeRatio = static_cast(ie.getOriginalCoverSize().first) / ie.getOriginalCoverSize().second;
+ if (customCover.isNull()) {
+ InitialComicInfoExtractor ie(basePath + comics[currentComicIndex].path, coverPath, comics[currentComicIndex].info.coverPage.toInt());
+ ie.extract();
+
+ if (ie.getOriginalCoverSize().second > 0) {
+ comics[currentComicIndex].info.originalCoverSize = QString("%1x%2").arg(ie.getOriginalCoverSize().first).arg(ie.getOriginalCoverSize().second);
+ comics[currentComicIndex].info.coverSizeRatio = static_cast(ie.getOriginalCoverSize().first) / ie.getOriginalCoverSize().second;
+ }
+
+ emit coverChangedSignal(comics[currentComicIndex]);
+ } else {
+
+ YACReader::saveCover(coverPath, customCover);
+ emit coverChangedSignal(comics[currentComicIndex]);
}
-
- emit coverChangedSignal(comics[currentComicIndex]);
}
}
}
@@ -1125,11 +1159,32 @@ void PropertiesDialog::loadPreviousCover()
void PropertiesDialog::resetCover()
{
setCoverPage(1);
- coverChanged = 1 != comics[currentComicIndex].info.coverPage.toInt();
+ coverChanged = true; // it could be that the cover is a custom cover, so we need to always update it
+}
+
+void PropertiesDialog::loadCustomCoverImage()
+{
+ auto path = YACReader::imageFileLoader(this);
+
+ if (path.isEmpty()) {
+ return;
+ }
+
+ customCover = QImage(path);
+ coverChanged = true;
+
+ if (customCover.isNull()) {
+ QMessageBox::warning(this, tr("Invalid cover"), tr("The image is invalid."));
+ return;
+ }
+
+ setCover(QPixmap::fromImage(customCover));
}
void PropertiesDialog::setCoverPage(int pageNumber)
{
+ customCover = QImage();
+
updateCoverPageNumberLabel(pageNumber);
InitialComicInfoExtractor ie(basePath + comics[currentComicIndex].path, "", pageNumber);
ie.extract();
diff --git a/YACReaderLibrary/properties_dialog.h b/YACReaderLibrary/properties_dialog.h
index cd3acf1e..8d95f08d 100644
--- a/YACReaderLibrary/properties_dialog.h
+++ b/YACReaderLibrary/properties_dialog.h
@@ -118,6 +118,7 @@ private:
QLabel *coverPageNumberLabel;
QToolButton *resetCoverButton;
+ QToolButton *loadCustomCoverImageButton;
void createTabBar();
void createCoverBox();
@@ -144,6 +145,8 @@ private:
bool updated;
QString originalCoverSize;
+ QImage customCover;
+
public:
PropertiesDialog(QWidget *parent = nullptr);
QString databasePath;
@@ -171,6 +174,7 @@ public slots:
void loadNextCover();
void loadPreviousCover();
void resetCover();
+ void loadCustomCoverImage();
void setCoverPage(int pageNumber);
bool close();
diff --git a/common/comic_db.cpp b/common/comic_db.cpp
index 1d1c3dc1..3b57650b 100644
--- a/common/comic_db.cpp
+++ b/common/comic_db.cpp
@@ -404,12 +404,7 @@ ComicInfo &ComicInfo::operator=(const ComicInfo &comicInfo)
QPixmap ComicInfo::getCover(const QString &basePath)
{
- if (cover.isNull()) {
- cover.load(YACReader::LibraryPaths::coverPath(basePath, hash));
- }
- QPixmap c;
- c.convertFromImage(cover);
- return c;
+ return QPixmap(YACReader::LibraryPaths::coverPath(basePath, hash));
}
QStringList ComicInfo::getWriters()
diff --git a/common/comic_db.h b/common/comic_db.h
index 6c6dac09..18e1f0b7 100644
--- a/common/comic_db.h
+++ b/common/comic_db.h
@@ -84,7 +84,7 @@ public:
QVariant comicVineID; // string
- QImage cover;
+ // QImage cover;
QVariant lastTimeOpened; // integer/date
QVariant coverSizeRatio; // h/w
@@ -189,8 +189,6 @@ public:
Q_PROPERTY(QVariant comicVineID MEMBER comicVineID CONSTANT)
- Q_PROPERTY(QImage cover MEMBER cover CONSTANT)
-
Q_PROPERTY(QVariant lastTimeOpened MEMBER lastTimeOpened CONSTANT)
Q_PROPERTY(QVariant coverSizeRatio MEMBER coverSizeRatio CONSTANT)
diff --git a/common/yacreader_global_gui.cpp b/common/yacreader_global_gui.cpp
index e9589490..a196ab1c 100644
--- a/common/yacreader_global_gui.cpp
+++ b/common/yacreader_global_gui.cpp
@@ -2,6 +2,8 @@
#include
#include
+#include
+#include
using namespace YACReader;
@@ -99,3 +101,13 @@ QPixmap YACReader::hdpiPixmap(const QString &file, QSize size)
{
return QIcon(file).pixmap(size);
}
+
+QString YACReader::imageFileLoader(QWidget *parent)
+{
+ QString supportedImageFormatsString;
+ for (const QByteArray &format : QImageReader::supportedImageFormats()) {
+ supportedImageFormatsString += QString("*.%1 ").arg(QString(format));
+ }
+
+ return QFileDialog::getOpenFileName(parent, QObject::tr("Select custom cover"), QDir::homePath(), QObject::tr("Images (%1)").arg(supportedImageFormatsString));
+}
diff --git a/common/yacreader_global_gui.h b/common/yacreader_global_gui.h
index 0b61d42f..c4758204 100644
--- a/common/yacreader_global_gui.h
+++ b/common/yacreader_global_gui.h
@@ -112,6 +112,6 @@ QString addExtensionToIconPath(const QString &path);
QString addExtensionToIconPathInToolbar(const QString &path);
QAction *actionWithCustomIcon(const QIcon &icon, QAction *action);
QPixmap hdpiPixmap(const QString &file, QSize size);
-
+QString imageFileLoader(QWidget *parent);
}
#endif
diff --git a/images/loadCustomCover.svg b/images/loadCustomCover.svg
new file mode 100644
index 00000000..08ff06b1
Binary files /dev/null and b/images/loadCustomCover.svg differ