diff --git a/qimgv/gui/customwidgets/thumbnailview.cpp b/qimgv/gui/customwidgets/thumbnailview.cpp index 8110fa4a..a468e2dd 100644 --- a/qimgv/gui/customwidgets/thumbnailview.cpp +++ b/qimgv/gui/customwidgets/thumbnailview.cpp @@ -24,6 +24,7 @@ ThumbnailView::ThumbnailView(ThumbnailViewOrientation orient, QWidget *parent) setRenderHint(QPainter::Antialiasing, false); setRenderHint(QPainter::SmoothPixmapTransform, false); + lastTouchpadScroll.start(); connect(&loadTimer, &QTimer::timeout, this, &ThumbnailView::loadVisibleThumbnails); loadTimer.setInterval(static_cast(LOAD_DELAY)); @@ -457,20 +458,20 @@ void ThumbnailView::fitSceneToContents() { //################### scrolling ###################### void ThumbnailView::wheelEvent(QWheelEvent *event) { event->accept(); - // alright, i officially gave up on fixing libinput scrolling - // let's just hope it gets done in Qt while I am still alive int pixelDelta = event->pixelDelta().y(); int angleDelta = event->angleDelta().ry(); + bool isWheel = angleDelta && !(angleDelta % 120) && lastTouchpadScroll.elapsed() > 100; + if(!isWheel) + lastTouchpadScroll.restart(); + if(!settings->enableSmoothScroll()) { if(pixelDelta) scrollPrecise(pixelDelta); else if(angleDelta) scrollPrecise(angleDelta); } else { - if(pixelDelta) + if(!isWheel && pixelDelta) scrollPrecise(pixelDelta); - else if(abs(angleDelta) < SMOOTH_SCROLL_THRESHOLD) - scrollPrecise(angleDelta); else if(angleDelta) scrollSmooth(angleDelta, SCROLL_MULTIPLIER, SCROLL_ACCELERATION, true); } diff --git a/qimgv/gui/customwidgets/thumbnailview.h b/qimgv/gui/customwidgets/thumbnailview.h index 8d75e30c..d3e9a77b 100644 --- a/qimgv/gui/customwidgets/thumbnailview.h +++ b/qimgv/gui/customwidgets/thumbnailview.h @@ -81,10 +81,6 @@ public slots: QTimer loadTimer; bool blockThumbnailLoading; - // let's say mouse wheel scroll always sends angleDelta = 120 - // then we can treat anything smaller as a touchpad scroll - // TODO: tune this value - const int SMOOTH_SCROLL_THRESHOLD = 120; int mDrawScrollbarIndicator, lastScrollFrameTime; QList mSelection; @@ -97,6 +93,7 @@ public slots: void createScrollTimeLine(); QElapsedTimer scrollFrameTimer; std::function centerOn; + QElapsedTimer lastTouchpadScroll; protected: QGraphicsScene scene; diff --git a/qimgv/gui/customwidgets/thumbnailwidget.cpp b/qimgv/gui/customwidgets/thumbnailwidget.cpp index 292621ea..b689de22 100644 --- a/qimgv/gui/customwidgets/thumbnailwidget.cpp +++ b/qimgv/gui/customwidgets/thumbnailwidget.cpp @@ -16,7 +16,9 @@ ThumbnailWidget::ThumbnailWidget(QGraphicsItem *parent) : thumbStyle(THUMB_SIMPLE) { setAttribute(Qt::WA_OpaquePaintEvent, true); - //setCacheMode(QGraphicsItem::DeviceCoordinateCache); breaks hidpi fractional scaling + float dpr = qApp->devicePixelRatio(); + if(trunc(dpr) == dpr) // don't enable for fractional scaling + setCacheMode(QGraphicsItem::DeviceCoordinateCache); setAcceptHoverEvents(true); font.setBold(false); QFontMetrics fm(font);