mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
Reader: add support for horizontal mouse wheel
Without this commit the horizontal wheel on a two-wheel mouse acts the same as the vertical wheel in YACReader. horizontalScroller is used analogously to verticalScroller in Viewer::scrollTo(). So I made the horizontal wheel work analogously to the vertical wheel except for moving to the next or previous page.
This commit is contained in:
parent
15277d00b7
commit
8820c8769b
@ -634,9 +634,30 @@ void Viewer::keyPressEvent(QKeyEvent *event)
|
|||||||
QAbstractScrollArea::keyPressEvent(event);
|
QAbstractScrollArea::keyPressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void animateScroll(QPropertyAnimation &scroller, const QScrollBar &scrollBar, int delta)
|
||||||
|
{
|
||||||
|
int deltaNotFinished = 0;
|
||||||
|
if (scroller.state() == QAbstractAnimation::Running) {
|
||||||
|
deltaNotFinished = scroller.startValue().toInt() - scroller.endValue().toInt();
|
||||||
|
scroller.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
const int currentPos = scrollBar.sliderPosition();
|
||||||
|
scroller.setDuration(250);
|
||||||
|
scroller.setStartValue(currentPos);
|
||||||
|
scroller.setEndValue(currentPos - delta - deltaNotFinished);
|
||||||
|
|
||||||
|
scroller.start();
|
||||||
|
}
|
||||||
|
|
||||||
void Viewer::wheelEvent(QWheelEvent *event)
|
void Viewer::wheelEvent(QWheelEvent *event)
|
||||||
{
|
{
|
||||||
if (render->hasLoadedComic()) {
|
if (render->hasLoadedComic()) {
|
||||||
|
if (event->orientation() == Qt::Horizontal) {
|
||||||
|
animateScroll(*horizontalScroller, *horizontalScrollBar(), event->delta());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ((event->delta() < 0) && (verticalScrollBar()->sliderPosition() == verticalScrollBar()->maximum())) {
|
if ((event->delta() < 0) && (verticalScrollBar()->sliderPosition() == verticalScrollBar()->maximum())) {
|
||||||
if (wheelStop) {
|
if (wheelStop) {
|
||||||
if (getMovement(event) == Forward) {
|
if (getMovement(event) == Forward) {
|
||||||
@ -663,20 +684,7 @@ void Viewer::wheelEvent(QWheelEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int deltaNotFinished = 0;
|
animateScroll(*verticalScroller, *verticalScrollBar(), event->delta());
|
||||||
if (verticalScroller->state() == QAbstractAnimation::Running) {
|
|
||||||
deltaNotFinished = verticalScroller->startValue().toInt() - verticalScroller->endValue().toInt();
|
|
||||||
verticalScroller->stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
int currentPos = verticalScrollBar()->sliderPosition();
|
|
||||||
verticalScroller->setDuration(250);
|
|
||||||
verticalScroller->setStartValue(currentPos);
|
|
||||||
verticalScroller->setEndValue(currentPos - event->delta() - deltaNotFinished);
|
|
||||||
|
|
||||||
verticalScroller->start();
|
|
||||||
|
|
||||||
//QAbstractScrollArea::wheelEvent(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user