mirror of https://github.com/JakubMelka/PDF4QT.git
Merge remote-tracking branch 'remotes/origin/branches/issue112'
This commit is contained in:
commit
277b40acc9
|
@ -24,7 +24,6 @@ jobs:
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
./vcpkg/buildtrees
|
|
||||||
./vcpkg/downloads
|
./vcpkg/downloads
|
||||||
./vcpkg/packages
|
./vcpkg/packages
|
||||||
key: ${{ runner.os }}-vcpkg-v2-${{ hashFiles('**/vcpkg.json') }}
|
key: ${{ runner.os }}-vcpkg-v2-${{ hashFiles('**/vcpkg.json') }}
|
||||||
|
|
|
@ -266,6 +266,8 @@ PDFDrawWidgetBase<BaseWidget>::PDFDrawWidgetBase(PDFWidget* widget, QWidget* par
|
||||||
{
|
{
|
||||||
this->setFocusPolicy(Qt::StrongFocus);
|
this->setFocusPolicy(Qt::StrongFocus);
|
||||||
this->setMouseTracking(true);
|
this->setMouseTracking(true);
|
||||||
|
|
||||||
|
QObject::connect(&m_autoScrollTimer, &QTimer::timeout, this, &PDFDrawWidgetBase::onAutoScrollTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename BaseWidget>
|
template<typename BaseWidget>
|
||||||
|
@ -308,6 +310,13 @@ void PDFDrawWidgetBase<BaseWidget>::performMouseOperation(QPoint currentMousePos
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case MouseOperation::AutoScroll:
|
||||||
|
{
|
||||||
|
m_lastMousePosition = currentMousePosition;
|
||||||
|
onAutoScrollTimeout();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
}
|
}
|
||||||
|
@ -407,6 +416,27 @@ void PDFDrawWidgetBase<BaseWidget>::mousePressEvent(QMouseEvent* event)
|
||||||
m_lastMousePosition = event->pos();
|
m_lastMousePosition = event->pos();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event->button() == Qt::MiddleButton)
|
||||||
|
{
|
||||||
|
if (m_mouseOperation == MouseOperation::AutoScroll)
|
||||||
|
{
|
||||||
|
m_mouseOperation = MouseOperation::None;
|
||||||
|
m_autoScrollTimer.stop();
|
||||||
|
m_autoScrollLastElapsedTimer.restart();
|
||||||
|
m_autoScrollOffset = QPointF(0.0, 0.0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_mouseOperation = MouseOperation::AutoScroll;
|
||||||
|
m_autoScrollMousePosition = event->pos();
|
||||||
|
m_autoScrollLastElapsedTimer.restart();
|
||||||
|
m_autoScrollOffset = QPointF(0.0, 0.0);
|
||||||
|
m_lastMousePosition = event->pos();
|
||||||
|
m_autoScrollTimer.setInterval(10);
|
||||||
|
m_autoScrollTimer.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
updateCursor();
|
updateCursor();
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
@ -440,13 +470,20 @@ void PDFDrawWidgetBase<BaseWidget>::mouseReleaseEvent(QMouseEvent* event)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MouseOperation::Translate:
|
case MouseOperation::Translate:
|
||||||
|
{
|
||||||
|
if (event->button() != Qt::MiddleButton)
|
||||||
{
|
{
|
||||||
m_mouseOperation = MouseOperation::None;
|
m_mouseOperation = MouseOperation::None;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case MouseOperation::AutoScroll:
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCursor();
|
updateCursor();
|
||||||
|
@ -496,6 +533,10 @@ void PDFDrawWidgetBase<BaseWidget>::updateCursor()
|
||||||
cursor = QCursor(Qt::ClosedHandCursor);
|
cursor = QCursor(Qt::ClosedHandCursor);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case MouseOperation::AutoScroll:
|
||||||
|
cursor = QCursor(Qt::SizeAllCursor);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
break;
|
break;
|
||||||
|
@ -512,6 +553,31 @@ void PDFDrawWidgetBase<BaseWidget>::updateCursor()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename BaseWidget>
|
||||||
|
void PDFDrawWidgetBase<BaseWidget>::onAutoScrollTimeout()
|
||||||
|
{
|
||||||
|
if (m_mouseOperation != MouseOperation::AutoScroll)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPointF offset = m_autoScrollMousePosition - m_lastMousePosition;
|
||||||
|
QPointF scrollOffset = m_autoScrollOffset;
|
||||||
|
|
||||||
|
qreal secondsElapsed = qreal(m_autoScrollLastElapsedTimer.nsecsElapsed()) * 0.000000001;
|
||||||
|
m_autoScrollLastElapsedTimer.restart();
|
||||||
|
scrollOffset += offset * secondsElapsed;
|
||||||
|
|
||||||
|
int scrollX = qFloor(scrollOffset.x());
|
||||||
|
int scrollY = qFloor(scrollOffset.y());
|
||||||
|
|
||||||
|
scrollOffset -= QPointF(scrollX, scrollY);
|
||||||
|
m_autoScrollOffset = scrollOffset;
|
||||||
|
|
||||||
|
PDFDrawWidgetProxy* proxy = m_widget->getDrawWidgetProxy();
|
||||||
|
proxy->scrollByPixels(QPoint(scrollX, scrollY));
|
||||||
|
}
|
||||||
|
|
||||||
template<typename BaseWidget>
|
template<typename BaseWidget>
|
||||||
void PDFDrawWidgetBase<BaseWidget>::wheelEvent(QWheelEvent* event)
|
void PDFDrawWidgetBase<BaseWidget>::wheelEvent(QWheelEvent* event)
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QElapsedTimer>
|
||||||
|
|
||||||
#ifdef PDF4QT_ENABLE_OPENGL
|
#ifdef PDF4QT_ENABLE_OPENGL
|
||||||
#include <QOpenGLWidget>
|
#include <QOpenGLWidget>
|
||||||
|
@ -161,6 +163,7 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateCursor();
|
void updateCursor();
|
||||||
|
void onAutoScrollTimeout();
|
||||||
|
|
||||||
template<typename Event, void(IDrawWidgetInputInterface::* Function)(QWidget*, Event*)>
|
template<typename Event, void(IDrawWidgetInputInterface::* Function)(QWidget*, Event*)>
|
||||||
bool processEvent(Event* event);
|
bool processEvent(Event* event);
|
||||||
|
@ -168,7 +171,8 @@ private:
|
||||||
enum class MouseOperation
|
enum class MouseOperation
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
Translate
|
Translate,
|
||||||
|
AutoScroll
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Performs the mouse operation (under the current mouse position)
|
/// Performs the mouse operation (under the current mouse position)
|
||||||
|
@ -177,7 +181,11 @@ private:
|
||||||
|
|
||||||
PDFWidget* m_widget;
|
PDFWidget* m_widget;
|
||||||
QPoint m_lastMousePosition;
|
QPoint m_lastMousePosition;
|
||||||
|
QPoint m_autoScrollMousePosition;
|
||||||
MouseOperation m_mouseOperation;
|
MouseOperation m_mouseOperation;
|
||||||
|
QTimer m_autoScrollTimer;
|
||||||
|
QPointF m_autoScrollOffset;
|
||||||
|
QElapsedTimer m_autoScrollLastElapsedTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PDFDrawWidget : public PDFDrawWidgetBase<QWidget>
|
class PDFDrawWidget : public PDFDrawWidgetBase<QWidget>
|
||||||
|
|
Loading…
Reference in New Issue