mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
new class for controlling high res touchpads
This commit is contained in:
parent
976935b86d
commit
d7a99ec639
@ -101,6 +101,7 @@ HEADERS += $$PWD/../common/comic.h \
|
||||
$$PWD/yacreader_local_client.h \
|
||||
$$PWD/../common/http_worker.h \
|
||||
$$PWD/../common/exit_check.h \
|
||||
$$PWD/../common/scroll_management.h
|
||||
|
||||
SOURCES += $$PWD/../common/comic.cpp \
|
||||
$$PWD/configuration.cpp \
|
||||
@ -135,6 +136,7 @@ SOURCES += $$PWD/../common/comic.cpp \
|
||||
$$PWD/../common/http_worker.cpp \
|
||||
$$PWD/../common/yacreader_global.cpp \
|
||||
$$PWD/../common/exit_check.cpp \
|
||||
$$PWD/../common/scroll_management.cpp
|
||||
|
||||
include($$PWD/../custom_widgets/custom_widgets_yacreader.pri)
|
||||
include($$PWD/../compressed_archive/wrapper.pri)
|
||||
|
@ -478,11 +478,14 @@ void Viewer::wheelEvent(QWheelEvent * event)
|
||||
if((event->delta()<0)&&(verticalScrollBar()->sliderPosition()==verticalScrollBar()->maximum()))
|
||||
{
|
||||
if(wheelStop)
|
||||
{
|
||||
if(getMovement(event) == Forward)
|
||||
{
|
||||
next();
|
||||
verticalScroller->stop();
|
||||
event->accept();
|
||||
wheelStop = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
@ -493,11 +496,14 @@ void Viewer::wheelEvent(QWheelEvent * event)
|
||||
if((event->delta()>0)&&(verticalScrollBar()->sliderPosition()==verticalScrollBar()->minimum()))
|
||||
{
|
||||
if(wheelStop)
|
||||
{
|
||||
if(getMovement(event) == Backward)
|
||||
{
|
||||
prev();
|
||||
verticalScroller->stop();
|
||||
event->accept();
|
||||
wheelStop = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
@ -16,6 +16,8 @@
|
||||
#include <QPropertyAnimation>
|
||||
#include <QSettings>
|
||||
|
||||
#include "scroll_management.h"
|
||||
|
||||
class ComicDB;
|
||||
class Comic;
|
||||
class MagnifyingGlass;
|
||||
@ -29,7 +31,7 @@ class Bookmarks;
|
||||
class PageLabelWidget;
|
||||
class NotificationsLabelWidget;
|
||||
|
||||
class Viewer : public QScrollArea
|
||||
class Viewer : public QScrollArea, public ScrollManagement
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -131,7 +131,8 @@ HEADERS += comic_flow.h \
|
||||
empty_label_widget.h \
|
||||
empty_container_info.h \
|
||||
empty_special_list.h \
|
||||
empty_reading_list_widget.h
|
||||
empty_reading_list_widget.h \
|
||||
../common/scroll_management.h
|
||||
|
||||
|
||||
SOURCES += comic_flow.cpp \
|
||||
@ -191,7 +192,8 @@ SOURCES += comic_flow.cpp \
|
||||
empty_label_widget.cpp \
|
||||
empty_container_info.cpp \
|
||||
empty_special_list.cpp \
|
||||
empty_reading_list_widget.cpp
|
||||
empty_reading_list_widget.cpp \
|
||||
../common/scroll_management.cpp
|
||||
|
||||
|
||||
include(./server/server.pri)
|
||||
|
61
common/scroll_management.cpp
Normal file
61
common/scroll_management.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
#include "scroll_management.h"
|
||||
|
||||
ScrollManagement::ScrollManagement()
|
||||
{
|
||||
wheelTimer = new QTime();
|
||||
wheelTimer->start();
|
||||
wheelAccumulator = 0;
|
||||
}
|
||||
|
||||
ScrollManagement::Movement ScrollManagement::getMovement(QWheelEvent *event)
|
||||
{
|
||||
/*QLOG_DEBUG() << "WheelEvent angle delta : " << event->angleDelta();
|
||||
QLOG_DEBUG() << "WheelEvent pixel delta : " << event->pixelDelta();*/
|
||||
|
||||
int tooFast = 1;
|
||||
int timeThrottle = 16;
|
||||
int minimumMove = 70;
|
||||
|
||||
//avoid any events overflood
|
||||
if((wheelTimer->elapsed() < tooFast)){
|
||||
event->setAccepted(true);
|
||||
return None;
|
||||
}
|
||||
|
||||
// Accumulate the delta
|
||||
if(event->delta()<0 != wheelAccumulator<0 ) //different sign means change in direction
|
||||
wheelAccumulator = 0;
|
||||
|
||||
wheelAccumulator += event->delta();
|
||||
|
||||
//Do not process events too fast
|
||||
if((wheelTimer->elapsed() < timeThrottle)){
|
||||
event->setAccepted(true);
|
||||
return None;
|
||||
}
|
||||
|
||||
//small intervals are ignored until with have enough acumulated delta
|
||||
if((wheelAccumulator < minimumMove) && (wheelAccumulator > -minimumMove)){
|
||||
event->setAccepted(true);
|
||||
return None;
|
||||
}
|
||||
|
||||
Movement m;
|
||||
if(wheelAccumulator<0)
|
||||
m = Forward;
|
||||
else
|
||||
m = Backward;
|
||||
|
||||
event->accept();
|
||||
//Clean up
|
||||
wheelAccumulator = 0;
|
||||
wheelTimer->restart();
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
ScrollManagement::~ScrollManagement()
|
||||
{
|
||||
|
||||
}
|
||||
|
25
common/scroll_management.h
Normal file
25
common/scroll_management.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef SCROLLMANAGAMENT_H
|
||||
#define SCROLLMANAGAMENT_H
|
||||
|
||||
#include <QTime>
|
||||
#include <QWheelEvent>
|
||||
|
||||
class ScrollManagement
|
||||
{
|
||||
public:
|
||||
enum Movement{
|
||||
None,
|
||||
Forward,
|
||||
Backward
|
||||
};
|
||||
|
||||
ScrollManagement();
|
||||
ScrollManagement::Movement getMovement(QWheelEvent * event);
|
||||
~ScrollManagement();
|
||||
|
||||
private:
|
||||
QTime * wheelTimer;
|
||||
int wheelAccumulator;
|
||||
};
|
||||
|
||||
#endif // SCROLLMANAGAMENT_H
|
@ -247,11 +247,6 @@ YACReaderFlowGL::YACReaderFlowGL(QWidget *parent,struct Preset p)
|
||||
setFormat(f);
|
||||
|
||||
timerId = startTimer(updateInterval);
|
||||
|
||||
wheelTimer = new QTime();
|
||||
wheelTimer->start();
|
||||
wheelAccumulator = 0;
|
||||
|
||||
}
|
||||
|
||||
void YACReaderFlowGL::timerEvent(QTimerEvent * event)
|
||||
@ -1049,51 +1044,19 @@ void YACReaderFlowGL::render()
|
||||
#include "QsLog.h"
|
||||
void YACReaderFlowGL::wheelEvent(QWheelEvent * event)
|
||||
{
|
||||
/*QLOG_DEBUG() << "WheelEvent angle delta : " << event->angleDelta();
|
||||
QLOG_DEBUG() << "WheelEvent pixel delta : " << event->pixelDelta();*/
|
||||
|
||||
/*if(event->delta()<0)
|
||||
Movement m = getMovement(event);
|
||||
switch (m) {
|
||||
case None:
|
||||
return;
|
||||
case Forward:
|
||||
showNext();
|
||||
else
|
||||
break;
|
||||
case Backward:
|
||||
showPrevious();
|
||||
event->accept();*/
|
||||
|
||||
int tooFast = 1;
|
||||
int timeThrottle = 16;
|
||||
int minimumMove = 70;
|
||||
|
||||
//avoid any events overflood
|
||||
if((wheelTimer->elapsed() < tooFast)){
|
||||
event->setAccepted(true);
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Accumulate the delta
|
||||
if(event->delta()<0 != wheelAccumulator<0 ) //different sign means change in direction
|
||||
wheelAccumulator = 0;
|
||||
|
||||
wheelAccumulator += event->delta();
|
||||
|
||||
//Do not process events too fast
|
||||
if((wheelTimer->elapsed() < timeThrottle)){
|
||||
event->setAccepted(true);
|
||||
return;
|
||||
}
|
||||
|
||||
//small intervals are ignored until with have enough acumulated delta
|
||||
if((wheelAccumulator < minimumMove) && (wheelAccumulator > -minimumMove)){
|
||||
event->setAccepted(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if(wheelAccumulator<0)
|
||||
showNext();
|
||||
else
|
||||
showPrevious();
|
||||
event->accept();
|
||||
//Clean up
|
||||
wheelAccumulator = 0;
|
||||
wheelTimer->restart();
|
||||
}
|
||||
|
||||
void YACReaderFlowGL::keyPressEvent(QKeyEvent *event)
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "pictureflow.h" //TODO mover los tipos de flow de sitio
|
||||
#include "scroll_management.h"
|
||||
|
||||
class ImageLoaderGL;
|
||||
class QGLContext;
|
||||
@ -104,7 +105,7 @@ extern struct Preset presetYACReaderFlowOverlappedStripeConfig;
|
||||
extern struct Preset pressetYACReaderFlowUpConfig;
|
||||
extern struct Preset pressetYACReaderFlowDownConfig;
|
||||
|
||||
class YACReaderFlowGL : public QOpenGLWidget
|
||||
class YACReaderFlowGL : public QOpenGLWidget, public ScrollManagement
|
||||
{
|
||||
Q_OBJECT
|
||||
protected:
|
||||
@ -176,9 +177,6 @@ protected:
|
||||
void startAnimationTimer();
|
||||
void stopAnimationTimer();
|
||||
|
||||
QTime * wheelTimer;
|
||||
int wheelAccumulator;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user