mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -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/flow4.png</file>
|
||||||
<file>../images/flow5.png</file>
|
<file>../images/flow5.png</file>
|
||||||
<file>../images/glowLine.png</file>
|
<file>../images/glowLine.png</file>
|
||||||
|
<file>../images/loadCustomCover.svg</file>
|
||||||
<file>../images/hiddenCovers.png</file>
|
<file>../images/hiddenCovers.png</file>
|
||||||
<file>../images/icon-new.svg</file>
|
<file>../images/icon-new.svg</file>
|
||||||
<file>../images/iconLibrary.png</file>
|
<file>../images/iconLibrary.png</file>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "library_window.h"
|
#include "library_window.h"
|
||||||
|
|
||||||
#include "yacreader_global.h"
|
#include "yacreader_global.h"
|
||||||
|
#include "yacreader_global_gui.h"
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
@ -2313,12 +2314,7 @@ void LibraryWindow::setFolderCover()
|
|||||||
|
|
||||||
void LibraryWindow::setCustomFolderCover(Folder folder)
|
void LibraryWindow::setCustomFolderCover(Folder folder)
|
||||||
{
|
{
|
||||||
QString supportedImageFormatsString;
|
auto customCoverPath = YACReader::imageFileLoader(this);
|
||||||
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));
|
|
||||||
if (!customCoverPath.isEmpty()) {
|
if (!customCoverPath.isEmpty()) {
|
||||||
QImage cover(customCoverPath);
|
QImage cover(customCoverPath);
|
||||||
if (cover.isNull()) {
|
if (cover.isNull()) {
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
#include "properties_dialog.h"
|
#include "properties_dialog.h"
|
||||||
|
|
||||||
|
#include "yacreader_global_gui.h"
|
||||||
|
|
||||||
|
#include "cover_utils.h"
|
||||||
#include "data_base_management.h"
|
#include "data_base_management.h"
|
||||||
#include "initial_comic_info_extractor.h"
|
#include "initial_comic_info_extractor.h"
|
||||||
#include "yacreader_field_edit.h"
|
#include "yacreader_field_edit.h"
|
||||||
@ -102,15 +105,23 @@ void PropertiesDialog::createCoverBox()
|
|||||||
|
|
||||||
showPreviousCoverPageButton = new QToolButton();
|
showPreviousCoverPageButton = new QToolButton();
|
||||||
showPreviousCoverPageButton->setIcon(QIcon(":/images/previousCoverPage.png"));
|
showPreviousCoverPageButton->setIcon(QIcon(":/images/previousCoverPage.png"));
|
||||||
|
showPreviousCoverPageButton->setToolTip(tr("Load previous page as cover"));
|
||||||
showPreviousCoverPageButton->setStyleSheet("QToolButton {border:none;}");
|
showPreviousCoverPageButton->setStyleSheet("QToolButton {border:none;}");
|
||||||
showNextCoverPageButton = new QToolButton();
|
showNextCoverPageButton = new QToolButton();
|
||||||
showNextCoverPageButton->setIcon(QIcon(":/images/nextCoverPage.png"));
|
showNextCoverPageButton->setIcon(QIcon(":/images/nextCoverPage.png"));
|
||||||
|
showNextCoverPageButton->setToolTip(tr("Load next page as cover"));
|
||||||
showNextCoverPageButton->setStyleSheet("QToolButton {border:none;}");
|
showNextCoverPageButton->setStyleSheet("QToolButton {border:none;}");
|
||||||
|
|
||||||
resetCoverButton = new QToolButton();
|
resetCoverButton = new QToolButton();
|
||||||
resetCoverButton->setIcon(QIcon(":/images/resetCover.svg"));
|
resetCoverButton->setIcon(QIcon(":/images/resetCover.svg"));
|
||||||
|
resetCoverButton->setToolTip(tr("Reset cover to the default image"));
|
||||||
resetCoverButton->setStyleSheet("QToolButton {border:none;}");
|
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 = new QLabel("-");
|
||||||
|
|
||||||
coverPageNumberLabel->setStyleSheet("QLabel {color: white; font-weight:bold; font-size:14px;}");
|
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->addWidget(showNextCoverPageButton, 0, Qt::AlignVCenter);
|
||||||
layout->addSpacing(5);
|
layout->addSpacing(5);
|
||||||
layout->addWidget(resetCoverButton, 0, Qt::AlignVCenter);
|
layout->addWidget(resetCoverButton, 0, Qt::AlignVCenter);
|
||||||
|
layout->addSpacing(5);
|
||||||
|
layout->addWidget(loadCustomCoverImageButton, 0, Qt::AlignVCenter);
|
||||||
|
|
||||||
coverPageEdit->setStyleSheet("QLineEdit {border:none;}");
|
coverPageEdit->setStyleSheet("QLineEdit {border:none;}");
|
||||||
layout->setSpacing(0);
|
layout->setSpacing(0);
|
||||||
@ -139,6 +152,7 @@ void PropertiesDialog::createCoverBox()
|
|||||||
connect(showPreviousCoverPageButton, &QAbstractButton::clicked, this, &PropertiesDialog::loadPreviousCover);
|
connect(showPreviousCoverPageButton, &QAbstractButton::clicked, this, &PropertiesDialog::loadPreviousCover);
|
||||||
connect(showNextCoverPageButton, &QAbstractButton::clicked, this, &PropertiesDialog::loadNextCover);
|
connect(showNextCoverPageButton, &QAbstractButton::clicked, this, &PropertiesDialog::loadNextCover);
|
||||||
connect(resetCoverButton, &QAbstractButton::clicked, this, &PropertiesDialog::resetCover);
|
connect(resetCoverButton, &QAbstractButton::clicked, this, &PropertiesDialog::resetCover);
|
||||||
|
connect(loadCustomCoverImageButton, &QAbstractButton::clicked, this, &PropertiesDialog::loadCustomCoverImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropertiesDialog::createGeneralInfoBox()
|
void PropertiesDialog::createGeneralInfoBox()
|
||||||
@ -441,6 +455,8 @@ QImage blurred(const QImage &image, const QRect &rect, int radius, bool alphaOnl
|
|||||||
|
|
||||||
void PropertiesDialog::loadComic(ComicDB &comic)
|
void PropertiesDialog::loadComic(ComicDB &comic)
|
||||||
{
|
{
|
||||||
|
customCover = QImage();
|
||||||
|
|
||||||
if (!comic.info.series.isNull())
|
if (!comic.info.series.isNull())
|
||||||
series->setText(comic.info.series.toString());
|
series->setText(comic.info.series.toString());
|
||||||
if (!comic.info.title.isNull())
|
if (!comic.info.title.isNull())
|
||||||
@ -583,9 +599,13 @@ void PropertiesDialog::updateButtons()
|
|||||||
|
|
||||||
void PropertiesDialog::setComics(QList<ComicDB> comics)
|
void PropertiesDialog::setComics(QList<ComicDB> comics)
|
||||||
{
|
{
|
||||||
updated = false;
|
|
||||||
sequentialEditing = false;
|
sequentialEditing = false;
|
||||||
|
|
||||||
|
updated = false;
|
||||||
|
currentComicIndex = 0;
|
||||||
|
coverChanged = false;
|
||||||
|
customCover = QImage();
|
||||||
|
|
||||||
this->comics = comics;
|
this->comics = comics;
|
||||||
|
|
||||||
ComicDB comic = comics[0];
|
ComicDB comic = comics[0];
|
||||||
@ -702,9 +722,12 @@ void PropertiesDialog::setComics(QList<ComicDB> comics)
|
|||||||
|
|
||||||
void PropertiesDialog::setComicsForSequentialEditing(int currentComicIndex, QList<ComicDB> comics)
|
void PropertiesDialog::setComicsForSequentialEditing(int currentComicIndex, QList<ComicDB> comics)
|
||||||
{
|
{
|
||||||
updated = false;
|
|
||||||
sequentialEditing = true;
|
sequentialEditing = true;
|
||||||
|
|
||||||
|
updated = false;
|
||||||
|
coverChanged = false;
|
||||||
|
customCover = QImage();
|
||||||
|
|
||||||
this->comics = comics;
|
this->comics = comics;
|
||||||
this->currentComicIndex = currentComicIndex;
|
this->currentComicIndex = currentComicIndex;
|
||||||
|
|
||||||
@ -789,7 +812,11 @@ void PropertiesDialog::save()
|
|||||||
|
|
||||||
if (sequentialEditing)
|
if (sequentialEditing)
|
||||||
if (coverChanged) {
|
if (coverChanged) {
|
||||||
itr->info.coverPage = coverPageNumberLabel->text().toInt();
|
if (customCover.isNull()) {
|
||||||
|
itr->info.coverPage = coverPageNumberLabel->text().toInt();
|
||||||
|
} else {
|
||||||
|
itr->info.coverPage = QVariant();
|
||||||
|
}
|
||||||
edited = true;
|
edited = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -957,15 +984,22 @@ void PropertiesDialog::save()
|
|||||||
if (sequentialEditing) {
|
if (sequentialEditing) {
|
||||||
if (coverChanged) {
|
if (coverChanged) {
|
||||||
auto coverPath = LibraryPaths::coverPath(basePath, comics[currentComicIndex].info.hash);
|
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) {
|
if (customCover.isNull()) {
|
||||||
comics[currentComicIndex].info.originalCoverSize = QString("%1x%2").arg(ie.getOriginalCoverSize().first).arg(ie.getOriginalCoverSize().second);
|
InitialComicInfoExtractor ie(basePath + comics[currentComicIndex].path, coverPath, comics[currentComicIndex].info.coverPage.toInt());
|
||||||
comics[currentComicIndex].info.coverSizeRatio = static_cast<float>(ie.getOriginalCoverSize().first) / ie.getOriginalCoverSize().second;
|
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()
|
void PropertiesDialog::resetCover()
|
||||||
{
|
{
|
||||||
setCoverPage(1);
|
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)
|
void PropertiesDialog::setCoverPage(int pageNumber)
|
||||||
{
|
{
|
||||||
|
customCover = QImage();
|
||||||
|
|
||||||
updateCoverPageNumberLabel(pageNumber);
|
updateCoverPageNumberLabel(pageNumber);
|
||||||
InitialComicInfoExtractor ie(basePath + comics[currentComicIndex].path, "", pageNumber);
|
InitialComicInfoExtractor ie(basePath + comics[currentComicIndex].path, "", pageNumber);
|
||||||
ie.extract();
|
ie.extract();
|
||||||
|
@ -118,6 +118,7 @@ private:
|
|||||||
QLabel *coverPageNumberLabel;
|
QLabel *coverPageNumberLabel;
|
||||||
|
|
||||||
QToolButton *resetCoverButton;
|
QToolButton *resetCoverButton;
|
||||||
|
QToolButton *loadCustomCoverImageButton;
|
||||||
|
|
||||||
void createTabBar();
|
void createTabBar();
|
||||||
void createCoverBox();
|
void createCoverBox();
|
||||||
@ -144,6 +145,8 @@ private:
|
|||||||
bool updated;
|
bool updated;
|
||||||
QString originalCoverSize;
|
QString originalCoverSize;
|
||||||
|
|
||||||
|
QImage customCover;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PropertiesDialog(QWidget *parent = nullptr);
|
PropertiesDialog(QWidget *parent = nullptr);
|
||||||
QString databasePath;
|
QString databasePath;
|
||||||
@ -171,6 +174,7 @@ public slots:
|
|||||||
void loadNextCover();
|
void loadNextCover();
|
||||||
void loadPreviousCover();
|
void loadPreviousCover();
|
||||||
void resetCover();
|
void resetCover();
|
||||||
|
void loadCustomCoverImage();
|
||||||
void setCoverPage(int pageNumber);
|
void setCoverPage(int pageNumber);
|
||||||
bool close();
|
bool close();
|
||||||
|
|
||||||
|
@ -404,12 +404,7 @@ ComicInfo &ComicInfo::operator=(const ComicInfo &comicInfo)
|
|||||||
|
|
||||||
QPixmap ComicInfo::getCover(const QString &basePath)
|
QPixmap ComicInfo::getCover(const QString &basePath)
|
||||||
{
|
{
|
||||||
if (cover.isNull()) {
|
return QPixmap(YACReader::LibraryPaths::coverPath(basePath, hash));
|
||||||
cover.load(YACReader::LibraryPaths::coverPath(basePath, hash));
|
|
||||||
}
|
|
||||||
QPixmap c;
|
|
||||||
c.convertFromImage(cover);
|
|
||||||
return c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList ComicInfo::getWriters()
|
QStringList ComicInfo::getWriters()
|
||||||
|
@ -84,7 +84,7 @@ public:
|
|||||||
|
|
||||||
QVariant comicVineID; // string
|
QVariant comicVineID; // string
|
||||||
|
|
||||||
QImage cover;
|
// QImage cover;
|
||||||
|
|
||||||
QVariant lastTimeOpened; // integer/date
|
QVariant lastTimeOpened; // integer/date
|
||||||
QVariant coverSizeRatio; // h/w
|
QVariant coverSizeRatio; // h/w
|
||||||
@ -189,8 +189,6 @@ public:
|
|||||||
|
|
||||||
Q_PROPERTY(QVariant comicVineID MEMBER comicVineID CONSTANT)
|
Q_PROPERTY(QVariant comicVineID MEMBER comicVineID CONSTANT)
|
||||||
|
|
||||||
Q_PROPERTY(QImage cover MEMBER cover CONSTANT)
|
|
||||||
|
|
||||||
Q_PROPERTY(QVariant lastTimeOpened MEMBER lastTimeOpened CONSTANT)
|
Q_PROPERTY(QVariant lastTimeOpened MEMBER lastTimeOpened CONSTANT)
|
||||||
|
|
||||||
Q_PROPERTY(QVariant coverSizeRatio MEMBER coverSizeRatio CONSTANT)
|
Q_PROPERTY(QVariant coverSizeRatio MEMBER coverSizeRatio CONSTANT)
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
#include <QImageReader>
|
||||||
|
#include <QFileDialog>
|
||||||
|
|
||||||
using namespace YACReader;
|
using namespace YACReader;
|
||||||
|
|
||||||
@ -99,3 +101,13 @@ QPixmap YACReader::hdpiPixmap(const QString &file, QSize size)
|
|||||||
{
|
{
|
||||||
return QIcon(file).pixmap(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);
|
QString addExtensionToIconPathInToolbar(const QString &path);
|
||||||
QAction *actionWithCustomIcon(const QIcon &icon, QAction *action);
|
QAction *actionWithCustomIcon(const QIcon &icon, QAction *action);
|
||||||
QPixmap hdpiPixmap(const QString &file, QSize size);
|
QPixmap hdpiPixmap(const QString &file, QSize size);
|
||||||
|
QString imageFileLoader(QWidget *parent);
|
||||||
}
|
}
|
||||||
#endif
|
#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