Fix trackpad scrolling in YACReader

This commit is contained in:
Luis Ángel San Martín Rodríguez 2024-08-18 14:51:10 +02:00
parent ca1b057361
commit c5924e625b
3 changed files with 85 additions and 25 deletions

View File

@ -8,6 +8,7 @@ Version counting is based on semantic versioning (Major.Feature.Patch)
* Save magnifying glass size and zoom level.
* Add shortcut to reset the magnifying glass to its defaults (size and zoom), it is `slash` by default but it can be reasigned.
* Bump PDF render size.
* Fix trackpad scrolling, it makes using trackpads more reponsive and natural.
### YACReaderLibrary
* Fix headers in the table view getting stuck in a non moveable state.

View File

@ -660,21 +660,45 @@ void Viewer::animateScroll(QPropertyAnimation &scroller, const QScrollBar &scrol
void Viewer::wheelEvent(QWheelEvent *event)
{
if (render->hasLoadedComic()) {
auto delta = event->angleDelta();
if (!render->hasLoadedComic()) {
return;
}
if (delta.x() != 0) {
animateScroll(*horizontalScroller, *horizontalScrollBar(), delta.x());
if (!event->pixelDelta().isNull()) {
wheelEventTrackpad(event);
} else {
wheelEventMouse(event);
}
}
void Viewer::wheelEventMouse(QWheelEvent *event)
{
auto delta = event->angleDelta();
if (delta.x() != 0) {
animateScroll(*horizontalScroller, *horizontalScrollBar(), delta.x());
return;
}
auto turnPageOnScroll = !Configuration::getConfiguration().getDoNotTurnPageOnScroll();
auto getUseSingleScrollStepToTurnPage = Configuration::getConfiguration().getUseSingleScrollStepToTurnPage();
if ((delta.y() < 0) && (verticalScrollBar()->sliderPosition() == verticalScrollBar()->maximum()) && turnPageOnScroll) {
if (wheelStop || getUseSingleScrollStepToTurnPage || verticalScrollBar()->maximum() == verticalScrollBar()->minimum()) {
if (getMovement(event) == Forward) {
next();
verticalScroller->stop();
event->accept();
wheelStop = false;
}
return;
}
auto turnPageOnScroll = !Configuration::getConfiguration().getDoNotTurnPageOnScroll();
auto getUseSingleScrollStepToTurnPage = Configuration::getConfiguration().getUseSingleScrollStepToTurnPage();
if ((delta.y() < 0) && (verticalScrollBar()->sliderPosition() == verticalScrollBar()->maximum()) && turnPageOnScroll) {
} else
wheelStop = true;
} else {
if ((delta.y() > 0) && (verticalScrollBar()->sliderPosition() == verticalScrollBar()->minimum()) && turnPageOnScroll) {
if (wheelStop || getUseSingleScrollStepToTurnPage || verticalScrollBar()->maximum() == verticalScrollBar()->minimum()) {
if (getMovement(event) == Forward) {
next();
if (getMovement(event) == Backward) {
prev();
verticalScroller->stop();
event->accept();
wheelStop = false;
@ -682,22 +706,55 @@ void Viewer::wheelEvent(QWheelEvent *event)
return;
} else
wheelStop = true;
}
}
animateScroll(*verticalScroller, *verticalScrollBar(), delta.y());
}
void Viewer::wheelEventTrackpad(QWheelEvent *event)
{
auto delta = event->pixelDelta();
// Apply delta to horizontal scrollbar
if (delta.x() != 0) {
int newHorizontalValue = horizontalScrollBar()->value() - delta.x();
horizontalScrollBar()->setValue(newHorizontalValue);
}
// Apply delta to vertical scrollbar
if (delta.y() != 0) {
int newVerticalValue = verticalScrollBar()->value() - delta.y();
verticalScrollBar()->setValue(newVerticalValue);
}
auto turnPageOnScroll = !Configuration::getConfiguration().getDoNotTurnPageOnScroll();
auto getUseSingleScrollStepToTurnPage = Configuration::getConfiguration().getUseSingleScrollStepToTurnPage();
if ((delta.y() < 0) && (verticalScrollBar()->sliderPosition() == verticalScrollBar()->maximum()) && turnPageOnScroll) {
if (wheelStop || getUseSingleScrollStepToTurnPage || verticalScrollBar()->maximum() == verticalScrollBar()->minimum()) {
if (getMovement(event) == Forward) {
next();
event->accept();
wheelStop = false;
}
return;
} else {
if ((delta.y() > 0) && (verticalScrollBar()->sliderPosition() == verticalScrollBar()->minimum()) && turnPageOnScroll) {
if (wheelStop || getUseSingleScrollStepToTurnPage || verticalScrollBar()->maximum() == verticalScrollBar()->minimum()) {
if (getMovement(event) == Backward) {
prev();
verticalScroller->stop();
event->accept();
wheelStop = false;
}
return;
} else
wheelStop = true;
wheelStop = true;
}
} else {
if ((delta.y() > 0) && (verticalScrollBar()->sliderPosition() == verticalScrollBar()->minimum()) && turnPageOnScroll) {
if (wheelStop || getUseSingleScrollStepToTurnPage || verticalScrollBar()->maximum() == verticalScrollBar()->minimum()) {
if (getMovement(event) == Backward) {
prev();
event->accept();
wheelStop = false;
}
return;
} else {
wheelStop = true;
}
}
animateScroll(*verticalScroller, *verticalScrollBar(), delta.y());
}
}

View File

@ -165,6 +165,8 @@ private:
//! Event handlers:
void resizeEvent(QResizeEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
void wheelEventMouse(QWheelEvent *event);
void wheelEventTrackpad(QWheelEvent *event);
void mouseMoveEvent(QMouseEvent *event) override;
int verticalScrollStep() const;