Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

Version counting is based on semantic versioning (Major.Feature.Patch)

## 9.16.4

### YACReaderLibrary
* Fix migration from pre-9.14 libraries.

## 9.16.3

### YACReader
Expand Down
3 changes: 3 additions & 0 deletions YACReader/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ class Configuration : public QObject

MouseMode getMouseMode() { return static_cast<MouseMode>(settings->value(MOUSE_MODE, MouseMode::Normal).toInt()); }
void setMouseMode(MouseMode mouseMode) { settings->setValue(MOUSE_MODE, static_cast<int>(mouseMode)); }

bool getPinchToZoomEnabled() { return settings->value(PINCH_TO_ZOOM_ENABLED, true).toBool(); }
void setPinchToZoomEnabled(bool b) { settings->setValue(PINCH_TO_ZOOM_ENABLED, b); }
};

}
Expand Down
11 changes: 11 additions & 0 deletions YACReader/options_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,20 @@ OptionsDialog::OptionsDialog(QWidget *parent)

mouseModeBox->setLayout(mouseModeLayout);

auto zoomModeBox = new QGroupBox(tr("Zoom mode"));
auto zoomModeLayout = new QVBoxLayout();
pinchToZoomEnabled = new QCheckBox(tr("Enable pinch-to-zoom trackpad gesture"));
zoomModeLayout->addWidget(pinchToZoomEnabled);
zoomModeBox->setLayout(zoomModeLayout);

layoutGeneral->addWidget(pathBox);
layoutGeneral->addWidget(displayBox);
layoutGeneral->addWidget(slideSizeBox);
// layoutGeneral->addWidget(fitBox);
layoutGeneral->addWidget(colorBox);
layoutGeneral->addWidget(scrollBox);
layoutGeneral->addWidget(mouseModeBox);
layoutGeneral->addWidget(zoomModeBox);
layoutGeneral->addWidget(shortcutsBox);
layoutGeneral->addStretch();

Expand Down Expand Up @@ -281,6 +288,8 @@ void OptionsDialog::saveOptions()
}
Configuration::getConfiguration().setMouseMode(mouseMode);

Configuration::getConfiguration().setPinchToZoomEnabled(pinchToZoomEnabled->isChecked());

YACReaderOptionsDialog::saveOptions();
}

Expand Down Expand Up @@ -344,6 +353,8 @@ void OptionsDialog::restoreOptions(QSettings *settings)
hotAreasMouseModeRadioButton->setChecked(true);
break;
}

pinchToZoomEnabled->setChecked(Configuration::getConfiguration().getPinchToZoomEnabled());
}

void OptionsDialog::updateColor(const QColor &color)
Expand Down
2 changes: 2 additions & 0 deletions YACReader/options_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class OptionsDialog : public YACReaderOptionsDialog
QRadioButton *leftRightNavigationMouseModeRadioButton;
QRadioButton *hotAreasMouseModeRadioButton;

QCheckBox *pinchToZoomEnabled;

public slots:
void saveOptions() override;
void restoreOptions(QSettings *settings) override;
Expand Down
85 changes: 85 additions & 0 deletions YACReader/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <QFile>
#include <QKeyEvent>
#include <QPinchGesture>

#include <QsLog.h>

Expand All @@ -38,8 +39,23 @@ Viewer::Viewer(QWidget *parent)
shouldOpenPrevious(false),
magnifyingGlassShown(false),
restoreMagnifyingGlass(false),
pinchStartZoom(100),
pinchAnchorNormX(0.5),
pinchAnchorNormY(0.5),
pinchZoomHud(nullptr),
mouseHandler(std::make_unique<YACReader::MouseHandler>(this))
{
grabGesture(Qt::PinchGesture);

pinchZoomHud = new QLabel(this);
pinchZoomHud->setAlignment(Qt::AlignCenter);
pinchZoomHud->setAttribute(Qt::WA_TransparentForMouseEvents);
pinchZoomHud->setTextFormat(Qt::RichText);
pinchZoomHud->setStyleSheet(
"background-color: rgba(0, 0, 0, 153); border-radius: 3px;");
pinchZoomHud->setFixedSize(100, 60);
pinchZoomHud->hide();

translator = new YACReaderTranslator(this);
translator->hide();
translatorAnimation = new QPropertyAnimation(translator, "pos");
Expand Down Expand Up @@ -1092,6 +1108,75 @@ void Viewer::mouseMoveEvent(QMouseEvent *event)
mouseHandler->mouseMoveEvent(event);
}

bool Viewer::event(QEvent *event)
{
if (event->type() == QEvent::Gesture) {
return gestureEvent(static_cast<QGestureEvent *>(event));
}
return QScrollArea::event(event);
}

void Viewer::positionPinchZoomHud()
{
const int margin = 16;
pinchZoomHud->move(width() - pinchZoomHud->width() - margin,
height() - pinchZoomHud->height() - margin);
pinchZoomHud->raise();
}

bool Viewer::gestureEvent(QGestureEvent *event)
{
if (QGesture *g = event->gesture(Qt::PinchGesture)) {
auto *pinch = static_cast<QPinchGesture *>(g);
if (!Configuration::getConfiguration().getPinchToZoomEnabled()) {
pinchZoomHud->hide();
event->ignore(pinch);
return QScrollArea::event(event);
}
if (!render->hasLoadedComic()) {
event->accept(pinch);
return true;
}
if (pinch->state() == Qt::GestureStarted) {
pinchStartZoom = zoom;
const QPoint cursorViewport = viewport()->mapFromGlobal(QCursor::pos());
pinchAnchorViewport = cursorViewport;
if (content->width() > 0 && content->height() > 0) {
const QPoint cursorInContent = content->mapFrom(viewport(), cursorViewport);
pinchAnchorNormX = std::clamp(double(cursorInContent.x()) / content->width(), 0.0, 1.0);
pinchAnchorNormY = std::clamp(double(cursorInContent.y()) / content->height(), 0.0, 1.0);
} else {
pinchAnchorNormX = 0.5;
pinchAnchorNormY = 0.5;
}
}
int newZoom = std::clamp<int>(std::lround(pinchStartZoom * pinch->totalScaleFactor()), 30, 500);
if (newZoom != zoom) {
zoom = newZoom;
updateContentSize();

const int alignX = std::max(0, (viewport()->width() - content->width()) / 2);
const int alignY = std::max(0, (viewport()->height() - content->height()) / 2);
const int targetH = std::lround(pinchAnchorNormX * content->width()) + alignX - pinchAnchorViewport.x();
const int targetV = std::lround(pinchAnchorNormY * content->height()) + alignY - pinchAnchorViewport.y();
horizontalScrollBar()->setValue(targetH);
verticalScrollBar()->setValue(targetV);

pinchZoomHud->setText(QStringLiteral("<span style=\"color:white; font-size:12px;\">%1%</span>").arg(zoom));
positionPinchZoomHud();
pinchZoomHud->show();

emit zoomUpdated(zoom);
}
if (pinch->state() == Qt::GestureFinished || pinch->state() == Qt::GestureCanceled) {
pinchZoomHud->hide();
}
event->accept(pinch);
return true;
}
return QScrollArea::event(event);
}

void Viewer::updateZoomRatio(int ratio)
{
zoom = ratio;
Expand Down
10 changes: 10 additions & 0 deletions YACReader/viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <QPropertyAnimation>
#include <QParallelAnimationGroup>
#include <QSettings>
#include <QGestureEvent>

#include "scroll_management.h"
#include "mouse_handler.h"
Expand Down Expand Up @@ -166,6 +167,15 @@ public slots:
void wheelEventMouse(QWheelEvent *event);
void wheelEventTrackpad(QWheelEvent *event);
void mouseMoveEvent(QMouseEvent *event) override;
bool event(QEvent *event) override;
bool gestureEvent(QGestureEvent *event);
void positionPinchZoomHud();

int pinchStartZoom;
QPoint pinchAnchorViewport;
double pinchAnchorNormX;
double pinchAnchorNormY;
QLabel *pinchZoomHud;

int verticalScrollStep() const;
int horizontalScrollStep() const;
Expand Down
96 changes: 92 additions & 4 deletions YACReaderLibrary/db/data_base_management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,87 @@ bool DataBaseManagement::createComicInfoTable(QSqlDatabase &database, QString ta
return queryComicInfo.exec();
}

bool DataBaseManagement::createComicInfoTable9_14(QSqlDatabase &database, QString tableName)
{
QSqlQuery queryComicInfo(database);
queryComicInfo.prepare("CREATE TABLE " + tableName + " ("
"id INTEGER PRIMARY KEY,"
"title TEXT,"

"coverPage INTEGER DEFAULT 1,"
"numPages INTEGER,"

"number TEXT," // changed to text from INTEGER (9.13)
"isBis BOOLEAN,"
"count INTEGER,"

"volume TEXT,"
"storyArc TEXT,"
"arcNumber TEXT," // changed to text from INTEGER (9.13)
"arcCount INTEGER,"

"genere TEXT,"

"writer TEXT,"
"penciller TEXT,"
"inker TEXT,"
"colorist TEXT,"
"letterer TEXT,"
"coverArtist TEXT,"

"date TEXT," // publication date dd/mm/yyyy --> se mostrará en 3 campos diferentes
"publisher TEXT,"
"format TEXT,"
"color BOOLEAN,"
"ageRating TEXT,"

"synopsis TEXT,"
"characters TEXT,"
"notes TEXT,"

"hash TEXT UNIQUE NOT NULL,"
"edited BOOLEAN DEFAULT 0,"
"read BOOLEAN DEFAULT 0,"
// new 7.0 fields

"hasBeenOpened BOOLEAN DEFAULT 0,"
"rating REAL DEFAULT 0," // changed to REAL from INTEGER (9.13)
"currentPage INTEGER DEFAULT 1, "
"bookmark1 INTEGER DEFAULT -1, "
"bookmark2 INTEGER DEFAULT -1, "
"bookmark3 INTEGER DEFAULT -1, "
"brightness INTEGER DEFAULT -1, "
"contrast INTEGER DEFAULT -1, "
"gamma INTEGER DEFAULT -1, "
// new 7.1 fields
"comicVineID TEXT,"
// new 9.5 fields
"lastTimeOpened INTEGER,"
"coverSizeRatio REAL,"
"originalCoverSize STRING," // h/w
// new 9.8 fields
"manga BOOLEAN DEFAULT 0," // deprecated 9.13
// new 9.13 fields
"added INTEGER,"
"type INTEGER DEFAULT 0," // 0 = comic, 1 = manga, 2 = manga left to right, 3 = webcomic, 4 = 4koma
"editor TEXT,"
"imprint TEXT,"
"teams TEXT,"
"locations TEXT,"
"series TEXT,"
"alternateSeries TEXT,"
"alternateNumber TEXT,"
"alternateCount INTEGER,"
"languageISO TEXT,"
"seriesGroup TEXT,"
"mainCharacterOrTeam TEXT,"
"review TEXT,"
"tags TEXT"
")");

return queryComicInfo.exec();
}

bool DataBaseManagement::createV8Tables(QSqlDatabase &database)
{
bool success = true;
Expand Down Expand Up @@ -901,6 +982,9 @@ bool DataBaseManagement::updateToCurrentVersion(const QString &libraryPath)
{
QSqlDatabase db = loadDatabaseFromFile(libraryDatabasePath);
if (db.isValid() && db.isOpen()) {

QSqlQuery pragmaFKOFF("PRAGMA foreign_keys = OFF", db);

if (!db.transaction()) {
QLOG_ERROR() << "Failed to start transaction for database update";
returnValue = false;
Expand Down Expand Up @@ -1066,25 +1150,26 @@ bool DataBaseManagement::updateToCurrentVersion(const QString &libraryPath)
{
bool pre9_14_successfulMigration = true;

QSqlQuery pragmaFKOFF(db);
pragmaFKOFF.prepare("PRAGMA foreign_keys=OFF");
pre9_14_successfulMigration = pre9_14_successfulMigration && pragmaFKOFF.exec();

pre9_14_successfulMigration = pre9_14_successfulMigration && createComicInfoTable(db, "comic_info_migration");
pre9_14_successfulMigration = pre9_14_successfulMigration && createComicInfoTable9_14(db, "comic_info_migration");

QSqlQuery copyComicInfoToComicInfoMigration(db);
copyComicInfoToComicInfoMigration.prepare("INSERT INTO comic_info_migration SELECT * FROM comic_info");

pre9_14_successfulMigration = pre9_14_successfulMigration && copyComicInfoToComicInfoMigration.exec();

QSqlQuery dropComicInfo(db);
dropComicInfo.prepare("DROP TABLE comic_info");
pre9_14_successfulMigration = pre9_14_successfulMigration && dropComicInfo.exec();

QLOG_ERROR() << "Migration failed1:" << dropComicInfo.lastError().text();

QSqlQuery renameComicInfoMigrationToComicInfo(db);
renameComicInfoMigrationToComicInfo.prepare("ALTER TABLE comic_info_migration RENAME TO comic_info");
pre9_14_successfulMigration = pre9_14_successfulMigration && renameComicInfoMigrationToComicInfo.exec();

QSqlQuery pragmaFKON1("PRAGMA foreign_keys=ON", db);
QLOG_ERROR() << "Migration failed2:" << renameComicInfoMigrationToComicInfo.lastError().text();

returnValue = returnValue && pre9_14_successfulMigration;
}
Expand Down Expand Up @@ -1125,7 +1210,10 @@ bool DataBaseManagement::updateToCurrentVersion(const QString &libraryPath)
} else {
db.rollback();
}

QSqlQuery pragmaFKON("PRAGMA foreign_keys = ON", db);
}

connectionName = db.connectionName();
}

Expand Down
1 change: 1 addition & 0 deletions YACReaderLibrary/db/data_base_management.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class DataBaseManagement : public QObject
static QSqlDatabase loadDatabaseFromFile(QString path);
static bool createTables(QSqlDatabase &database);
static bool createComicInfoTable(QSqlDatabase &database, QString tableName);
static bool createComicInfoTable9_14(QSqlDatabase &database, QString tableName);
static bool createV8Tables(QSqlDatabase &database);

static void exportComicsInfo(QString source, QString dest);
Expand Down
2 changes: 1 addition & 1 deletion common/yacreader_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class QLibrary;

#define VERSION "9.16.3"
#define VERSION "9.16.4"

// Used to check if the database needs to be updated, the version is stored in the database.
// This value is only incremented when the database structure changes.
Expand Down
1 change: 1 addition & 0 deletions common/yacreader_global_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#define USE_SINGLE_SCROLL_STEP_TO_TURN_PAGE "USE_SINGLE_SCROLL_STEP_TO_TURN_PAGE"
#define DISABLE_SCROLL_ANIMATION "DISABLE_SCROLL_ANIMATION"
#define MOUSE_MODE "MOUSE_MODE"
#define PINCH_TO_ZOOM_ENABLED "PINCH_TO_ZOOM_ENABLED"

#define FLOW_TYPE_GL "FLOW_TYPE_GL"
#define Y_POSITION "Y_POSITION"
Expand Down