mirror of
https://github.com/YACReader/yacreader
synced 2025-05-25 09:50:33 -04:00
Add support for loading custom comic images
This commit is contained in:
parent
0457c08fca
commit
508ff6d547
@ -43,6 +43,7 @@
|
||||
<file>../images/flow4.png</file>
|
||||
<file>../images/flow5.png</file>
|
||||
<file>../images/glowLine.png</file>
|
||||
<file>../images/loadCustomCover.svg</file>
|
||||
<file>../images/hiddenCovers.png</file>
|
||||
<file>../images/icon-new.svg</file>
|
||||
<file>../images/iconLibrary.png</file>
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "library_window.h"
|
||||
|
||||
#include "yacreader_global.h"
|
||||
#include "yacreader_global_gui.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QSplitter>
|
||||
@ -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()) {
|
||||
|
@ -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<ComicDB> 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<ComicDB> comics)
|
||||
|
||||
void PropertiesDialog::setComicsForSequentialEditing(int currentComicIndex, QList<ComicDB> 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<float>(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<float>(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();
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <QtCore>
|
||||
#include <QAction>
|
||||
#include <QImageReader>
|
||||
#include <QFileDialog>
|
||||
|
||||
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));
|
||||
}
|
||||
|
@ -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
|
||||
|
BIN
images/loadCustomCover.svg
Normal file
BIN
images/loadCustomCover.svg
Normal file
Binary file not shown.
After Width: | Height: | Size: 292 B |
Loading…
Reference in New Issue
Block a user