Compare commits

...

8 Commits

Author SHA1 Message Date
Zack Mak
30370b1da3 Merge branch 'work/hires_wheel_page_scroll_rework' into 'master'
Fixed Page Scroll Using Hires Scroll Wheel

See merge request graphics/okular!658
2024-06-24 22:47:06 +00:00
Pratham Gandhi
e5900f9a4f created global qobject 2024-06-24 10:39:38 +05:30
l10n daemon script
b0ba4a343d GIT_SILENT Sync po/docbooks with svn 2024-06-23 01:24:01 +00:00
l10n daemon script
10e622c356 GIT_SILENT Sync po/docbooks with svn 2024-06-22 01:28:12 +00:00
Zack Mak
10b0e0cfd9 Merge branch okular:master into work/hires_wheel_page_scroll_rework 2024-05-02 16:49:00 +00:00
Zack Mak
fefcd396a7 Group page scroll into a single function
Renamed wheelAccumulatedDelta to pageScrollDelta
Use QTimer instead of timestamp for scroll idle timeout
2024-05-03 00:46:21 +08:00
Zack Mak
4a6d28ddb8 Merge branch 'master' of https://invent.kde.org/graphics/okular into work/hires_wheel_page_scroll_rework 2024-05-02 21:39:21 +08:00
Zack Mak
785bdb7c05 Fixed Page Scroll Using Hires Scroll Wheel
This change fixes the issue of page scroll in non-continuous mode using
high resolution scroll wheel of a mouse. In the original code, the page
scroll is hardly triggered due to small delta values reported by the
mouse wheel. The modified code added a handle to accumulate the small
delta values to make sure page scroll will be triggered.

BUG: #443404
2022-09-23 23:08:34 +08:00
8 changed files with 127 additions and 34 deletions

View File

@ -487,6 +487,7 @@ if (TARGET Qt6::Qml)
core/script/js_util.cpp
core/script/js_event.cpp
core/script/js_ocg.cpp
core/script/js_global.cpp
)
target_link_libraries(okularcore PRIVATE Qt6::Qml)
endif()

View File

@ -20,6 +20,7 @@
#include "js_event_p.h"
#include "js_field_p.h"
#include "js_fullscreen_p.h"
#include "js_global_p.h"
#include "js_ocg_p.h"
#include "js_spell_p.h"
#include "js_util_p.h"
@ -71,6 +72,7 @@ void ExecutorJSPrivate::initTypes()
m_interpreter.globalObject().setProperty(QStringLiteral("display"), m_interpreter.newQObject(new JSDisplay));
m_interpreter.globalObject().setProperty(QStringLiteral("spell"), m_interpreter.newQObject(new JSSpell));
m_interpreter.globalObject().setProperty(QStringLiteral("util"), m_interpreter.newQObject(new JSUtil));
m_interpreter.globalObject().setProperty(QStringLiteral("global"), m_interpreter.newQObject(new JSGlobal));
}
ExecutorJS::ExecutorJS(DocumentPrivate *doc)

16
core/script/js_global.cpp Normal file
View File

@ -0,0 +1,16 @@
/*
SPDX-FileCopyrightText: 2024 Pratham Gandhi <ppg.1382@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "js_global_p.h"
using namespace Okular;
JSGlobal::JSGlobal(QObject *parent)
: QObject(parent)
{
}
JSGlobal::~JSGlobal() = default;

25
core/script/js_global_p.h Normal file
View File

@ -0,0 +1,25 @@
/*
SPDX-FileCopyrightText: 2024 Pratham Gandhi <ppg.1382@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef OKULAR_SCRIPT_JS_GLOBAL_P_H
#define OKULAR_SCRIPT_JS_GLOBAL_P_H
#include <QObject>
namespace Okular
{
class JSGlobal : public QObject
{
Q_OBJECT
public:
explicit JSGlobal(QObject *parent = nullptr);
~JSGlobal() override;
};
}
#endif

View File

@ -217,6 +217,10 @@ public:
QPoint dragScrollVector;
QTimer dragScrollTimer;
// page scroll
int pageScrollDelta = 0;
QTimer pageScrollTimer;
// left click depress
QTimer leftClickTimer;
@ -422,6 +426,8 @@ PageView::PageView(QWidget *parent, Okular::Document *document)
connect(&d->dragScrollTimer, &QTimer::timeout, this, &PageView::slotDragScroll);
connect(&d->pageScrollTimer, &QTimer::timeout, this, &PageView::slotPageScroll);
d->leftClickTimer.setSingleShot(true);
connect(&d->leftClickTimer, &QTimer::timeout, this, &PageView::slotShowSizeAllCursor);
@ -2183,6 +2189,56 @@ void PageView::continuousZoomEnd()
updateCursor();
}
bool PageView::isPageScroll(int delta)
{
bool pageScroll = false;
int vScroll = verticalScrollBar()->value();
d->pageScrollDelta += delta;
if (d->pageScrollTimer.isActive()) {
d->pageScrollTimer.stop();
}
d->pageScrollTimer.setSingleShot(true);
d->pageScrollTimer.start(500);
if (d->pageScrollDelta <= -QWheelEvent::DefaultDeltasPerStep && vScroll == verticalScrollBar()->maximum()) {
// go to next page
if ((int)d->document->currentPage() < d->items.count() - 1) {
// more optimized than document->setNextPage and then move view to top
Okular::DocumentViewport newViewport = d->document->viewport();
newViewport.pageNumber += viewColumns();
if (newViewport.pageNumber >= (int)d->items.count()) {
newViewport.pageNumber = d->items.count() - 1;
}
newViewport.rePos.enabled = true;
newViewport.rePos.normalizedY = 0.0;
d->document->setViewport(newViewport);
d->scroller->scrollTo(QPoint(horizontalScrollBar()->value(), verticalScrollBar()->value()), 0); // sync scroller with scrollbar
d->pageScrollDelta = 0;
pageScroll = true;
}
} else if (d->pageScrollDelta >= QWheelEvent::DefaultDeltasPerStep && vScroll == verticalScrollBar()->minimum()) {
// go to prev page
if (d->document->currentPage() > 0) {
// more optimized than document->setPrevPage and then move view to bottom
Okular::DocumentViewport newViewport = d->document->viewport();
newViewport.pageNumber -= viewColumns();
if (newViewport.pageNumber < 0) {
newViewport.pageNumber = 0;
}
newViewport.rePos.enabled = true;
newViewport.rePos.normalizedY = 1.0;
d->document->setViewport(newViewport);
d->scroller->scrollTo(QPoint(horizontalScrollBar()->value(), verticalScrollBar()->value()), 0); // sync scroller with scrollbar
d->pageScrollDelta = 0;
pageScroll = true;
}
} else if ((d->pageScrollDelta < 0 && vScroll == verticalScrollBar()->maximum()) || (d->pageScrollDelta > 0 && vScroll == verticalScrollBar()->minimum())) {
pageScroll = true;
}
return pageScroll;
}
void PageView::mouseMoveEvent(QMouseEvent *e)
{
d->previousMouseMovePos = e->globalPosition();
@ -2313,6 +2369,8 @@ void PageView::mouseMoveEvent(QMouseEvent *e)
void PageView::mousePressEvent(QMouseEvent *e)
{
d->pageScrollDelta = 0;
// don't perform any mouse action when no document is shown
if (d->items.isEmpty()) {
return;
@ -2512,6 +2570,8 @@ void PageView::mousePressEvent(QMouseEvent *e)
void PageView::mouseReleaseEvent(QMouseEvent *e)
{
d->pageScrollDelta = 0;
// stop the drag scrolling
d->dragScrollTimer.stop();
@ -3159,6 +3219,8 @@ void PageView::guessTableDividers()
void PageView::mouseDoubleClickEvent(QMouseEvent *e)
{
d->pageScrollDelta = 0;
if (e->button() == Qt::LeftButton) {
const QPoint eventPos = contentAreaPoint(e->pos());
PageViewItem *pageItem = pickItemOnPoint(eventPos.x(), eventPos.y());
@ -3209,40 +3271,16 @@ void PageView::wheelEvent(QWheelEvent *e)
return;
}
int delta = e->angleDelta().y(), vScroll = verticalScrollBar()->value();
int delta = e->angleDelta().y();
e->accept();
if ((e->modifiers() & Qt::ControlModifier) == Qt::ControlModifier) {
continuousZoom(delta);
} else {
if (delta <= -QWheelEvent::DefaultDeltasPerStep && !getContinuousMode() && vScroll == verticalScrollBar()->maximum()) {
// go to next page
if ((int)d->document->currentPage() < d->items.count() - 1) {
// more optimized than document->setNextPage and then move view to top
Okular::DocumentViewport newViewport = d->document->viewport();
newViewport.pageNumber += viewColumns();
if (newViewport.pageNumber >= (int)d->items.count()) {
newViewport.pageNumber = d->items.count() - 1;
}
newViewport.rePos.enabled = true;
newViewport.rePos.normalizedY = 0.0;
d->document->setViewport(newViewport);
d->scroller->scrollTo(QPoint(horizontalScrollBar()->value(), verticalScrollBar()->value()), 0); // sync scroller with scrollbar
}
} else if (delta >= QWheelEvent::DefaultDeltasPerStep && !getContinuousMode() && vScroll == verticalScrollBar()->minimum()) {
// go to prev page
if (d->document->currentPage() > 0) {
// more optimized than document->setPrevPage and then move view to bottom
Okular::DocumentViewport newViewport = d->document->viewport();
newViewport.pageNumber -= viewColumns();
if (newViewport.pageNumber < 0) {
newViewport.pageNumber = 0;
}
newViewport.rePos.enabled = true;
newViewport.rePos.normalizedY = 1.0;
d->document->setViewport(newViewport);
d->scroller->scrollTo(QPoint(horizontalScrollBar()->value(), verticalScrollBar()->value()), 0); // sync scroller with scrollbar
}
} else {
bool skipScroll = false;
if (!getContinuousMode()) {
skipScroll = isPageScroll(delta);
}
if (!skipScroll) {
// When the shift key is held down, scroll ten times faster
int multiplier = e->modifiers() & Qt::ShiftModifier ? 10 : 1;
@ -3257,6 +3295,7 @@ void PageView::wheelEvent(QWheelEvent *e)
} else {
d->scroller->scrollTo(d->scroller->finalPosition() - e->angleDelta() * multiplier, 0);
}
d->pageScrollDelta = 0;
}
}
}
@ -4909,6 +4948,11 @@ void PageView::slotDragScroll()
updateSelection(p);
}
void PageView::slotPageScroll()
{
d->pageScrollDelta = 0;
}
void PageView::slotShowWelcome()
{
// show initial welcome text

View File

@ -242,6 +242,9 @@ private:
*/
bool getContinuousMode() const;
// Hangle page scrolling in non-continuous mode
bool isPageScroll(int delta);
// Zoom around the point given as zoomCenter
// zoomCenter is given in viewport coordinates
// newZoom is the intended new zoom level. A value of 0.0 means: Don't change the current zoom level.
@ -264,6 +267,8 @@ private Q_SLOTS:
void slotAutoScroll();
// activated by the dragScroll timer
void slotDragScroll();
// activated by the pageScroll timer
void slotPageScroll();
// show the welcome message
void slotShowWelcome();
// activated by left click timer

View File

@ -21,7 +21,7 @@ msgstr ""
"Project-Id-Version: kdegraphics-kde4\n"
"Report-Msgid-Bugs-To: https://bugs.kde.org\n"
"POT-Creation-Date: 2024-06-20 00:38+0000\n"
"PO-Revision-Date: 2024-03-22 16:14+0300\n"
"PO-Revision-Date: 2024-06-22 13:04+0300\n"
"Last-Translator: Emir SARI <emir_sari@icloud.com>\n"
"Language-Team: Turkish <kde-l10n-tr@kde.org>\n"
"Language: tr\n"
@ -29,7 +29,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Generator: Lokalize 24.02.1\n"
"X-Generator: Lokalize 24.07.70\n"
#, kde-format
msgctxt "NAME OF TRANSLATORS"
@ -4768,7 +4768,7 @@ msgstr "Küçük görselleri sayfa ile eşzamanla"
#: part/part.cpp:3126
#, kde-format
msgid "Add Bookmark"
msgstr "Yer İmi Ekle"
msgstr "Yer İmi Koy"
#: part/part.cpp:3148
#, kde-format

View File

@ -2887,7 +2887,7 @@ msgstr "启用图像抗锯齿"
#, kde-format
msgctxt "@option:check Config dialog, performance page"
msgid "Enable text hinting"
msgstr "启用字微调"
msgstr "启用字体轮廓微调"
#: part/dlgperformance.cpp:77
#, kde-format