Commit 35de8e5a authored by Albert Astals Cid's avatar Albert Astals Cid

Merge remote-tracking branch 'origin/release/20.08'

parents 19c2fbc1 cac97208
Pipeline #27111 passed with stage
in 16 minutes and 57 seconds
......@@ -34,7 +34,7 @@ AnnotatorEngine::AnnotatorEngine(const QDomElement &engineElement)
m_annotElement = annElement;
}
void AnnotatorEngine::decodeEvent(const QMouseEvent *mouseEvent, EventType *eventType, Button *button)
void AnnotatorEngine::decodeEvent(const QMouseEvent *mouseEvent, EventType *eventType, Button *button, Modifiers *modifiers)
{
*eventType = AnnotatorEngine::Press;
if (mouseEvent->type() == QEvent::MouseMove)
......@@ -48,9 +48,11 @@ void AnnotatorEngine::decodeEvent(const QMouseEvent *mouseEvent, EventType *even
*button = AnnotatorEngine::Left;
else if (buttonState == Qt::RightButton)
*button = AnnotatorEngine::Right;
modifiers->shift = mouseEvent->modifiers() & Qt::ShiftModifier;
}
void AnnotatorEngine::decodeEvent(const QTabletEvent *tabletEvent, EventType *eventType, Button *button)
void AnnotatorEngine::decodeEvent(const QTabletEvent *tabletEvent, EventType *eventType, Button *button, Modifiers *modifiers)
{
switch (tabletEvent->type()) {
case QEvent::TabletPress:
......@@ -73,6 +75,8 @@ void AnnotatorEngine::decodeEvent(const QTabletEvent *tabletEvent, EventType *ev
Q_ASSERT(false);
break;
}
modifiers->shift = tabletEvent->modifiers() & Qt::ShiftModifier;
}
AnnotatorEngine::~AnnotatorEngine()
......@@ -102,7 +106,7 @@ SmoothPathEngine::SmoothPathEngine(const QDomElement &engineElement)
compositionMode = QPainter::CompositionMode_Clear;
}
QRect SmoothPathEngine::event(EventType type, Button button, double nX, double nY, double xScale, double yScale, const Okular::Page * /*page*/)
QRect SmoothPathEngine::event(EventType type, Button button, Modifiers /*modifiers*/, double nX, double nY, double xScale, double yScale, const Okular::Page * /*page*/)
{
// only proceed if pressing left button
if (button != Left)
......
......@@ -42,9 +42,12 @@ public:
// enum definitions
enum EventType { Press, Move, Release };
enum Button { None, Left, Right };
struct Modifiers {
bool shift;
};
// perform operations
virtual QRect event(EventType type, Button button, double nX, double nY, double xScale, double yScale, const Okular::Page *page) = 0;
virtual QRect event(EventType type, Button button, Modifiers modifiers, double nX, double nY, double xScale, double yScale, const Okular::Page *page) = 0;
virtual void paint(QPainter *painter, double xScale, double yScale, const QRect &clipRect) = 0;
virtual QList<Okular::Annotation *> end() = 0;
......@@ -60,8 +63,8 @@ public:
m_item = item;
}
static void decodeEvent(const QMouseEvent *mouseEvent, EventType *eventType, Button *button);
static void decodeEvent(const QTabletEvent *tabletEvent, EventType *eventType, Button *button);
static void decodeEvent(const QMouseEvent *mouseEvent, EventType *eventType, Button *button, Modifiers *modifiers);
static void decodeEvent(const QTabletEvent *tabletEvent, EventType *eventType, Button *button, Modifiers *modifiers);
virtual QCursor cursor() const;
......@@ -101,7 +104,7 @@ class SmoothPathEngine : public AnnotatorEngine
public:
explicit SmoothPathEngine(const QDomElement &engineElement);
QRect event(EventType type, Button button, double nX, double nY, double xScale, double yScale, const Okular::Page * /*page*/) override;
QRect event(EventType type, Button button, Modifiers modifiers, double nX, double nY, double xScale, double yScale, const Okular::Page * /*page*/) override;
void paint(QPainter *painter, double xScale, double yScale, const QRect & /*clipRect*/) override;
......
......@@ -74,7 +74,7 @@ public:
pixmap = GuiUtils::loadStamp(hoverIconName, size);
}
QRect event(EventType type, Button button, double nX, double nY, double xScale, double yScale, const Okular::Page *page) override
QRect event(EventType type, Button button, Modifiers modifiers, double nX, double nY, double xScale, double yScale, const Okular::Page *page) override
{
xscale = xScale;
yscale = yScale;
......@@ -99,6 +99,12 @@ public:
} else
return QRect();
// shift button: enforce 1:1 form factor (e.g. circle or square)
if (modifiers.shift) {
double side = qMin(qAbs(nX - startpoint.x) * xScale, qAbs(nY - startpoint.y) * yScale);
nX = qBound(startpoint.x - side / xScale, nX, startpoint.x + side / xScale);
nY = qBound(startpoint.y - side / yScale, nY, startpoint.y + side / yScale);
}
// update variables and extents (zoom invariant rect)
point.x = nX;
point.y = nY;
......@@ -325,13 +331,32 @@ public:
numofpoints = -1;
}
QRect event(EventType type, Button button, double nX, double nY, double xScale, double yScale, const Okular::Page * /*page*/) override
static Okular::NormalizedPoint constrainAngle(const Okular::NormalizedPoint &p1, double x, double y, double xScale, double yScale, double angleIncrement)
{
// given the normalized point (x, y), return the closest point such that the line segment from p1 forms an angle
// with the horizontal axis which is an integer multiple of angleIncrement on a reference area of size xScale x yScale
double dist = sqrt(p1.distanceSqr(x, y, xScale, yScale));
double angle = atan2((y - p1.y) * yScale, (x - p1.x) * xScale);
double constrainedAngle = round(angle / angleIncrement) * angleIncrement;
double offset = dist * sin(angle - constrainedAngle);
x += offset * sin(constrainedAngle) / xScale;
y -= offset * cos(constrainedAngle) / yScale;
return Okular::NormalizedPoint(x, y);
}
QRect event(EventType type, Button button, Modifiers modifiers, double nX, double nY, double xScale, double yScale, const Okular::Page * /*page*/) override
{
// only proceed if pressing left button
// if ( button != Left )
// return rect;
// start operation
// shift button: constrain to 15° steps
if (modifiers.shift && !points.isEmpty()) {
const Okular::NormalizedPoint constrainedPoint = constrainAngle(points.constLast(), nX, nY, xScale, yScale, M_PI / 12.);
nX = constrainedPoint.x;
nY = constrainedPoint.y;
}
// process button press
if (type == Press) {
newPoint.x = nX;
newPoint.y = nY;
......@@ -471,7 +496,7 @@ public:
// parse engine specific attributes
}
QRect event(EventType type, Button button, double nX, double nY, double xScale, double yScale, const Okular::Page * /*page*/) override
QRect event(EventType type, Button button, Modifiers /*modifiers*/, double nX, double nY, double xScale, double yScale, const Okular::Page * /*page*/) override
{
// only proceed if pressing left button
if (button != Left)
......@@ -728,7 +753,7 @@ QCursor PageViewAnnotator::cursor() const
return m_engine->cursor();
}
QRect PageViewAnnotator::performRouteMouseOrTabletEvent(const AnnotatorEngine::EventType eventType, const AnnotatorEngine::Button button, const QPointF pos, PageViewItem *item)
QRect PageViewAnnotator::performRouteMouseOrTabletEvent(const AnnotatorEngine::EventType eventType, const AnnotatorEngine::Button button, const AnnotatorEngine::Modifiers modifiers, const QPointF pos, PageViewItem *item)
{
// creationCompleted is intended to be set by event(), handled subsequently by end(), and cleared within end().
// If it's set here, we recursed for some reason (e.g., stacked event loop).
......@@ -765,7 +790,7 @@ QRect PageViewAnnotator::performRouteMouseOrTabletEvent(const AnnotatorEngine::E
QRect modifiedRect;
// 2. use engine to perform operations
const QRect paintRect = m_engine->event(eventType, button, nX, nY, itemRect.width(), itemRect.height(), m_lockedItem->page());
const QRect paintRect = m_engine->event(eventType, button, modifiers, nX, nY, itemRect.width(), itemRect.height(), m_lockedItem->page());
// 3. update absolute extents rect and send paint event(s)
if (paintRect.isValid()) {
......@@ -812,11 +837,12 @@ QRect PageViewAnnotator::routeMouseEvent(QMouseEvent *e, PageViewItem *item)
{
AnnotatorEngine::EventType eventType;
AnnotatorEngine::Button button;
AnnotatorEngine::Modifiers modifiers;
// figure out the event type and button
AnnotatorEngine::decodeEvent(e, &eventType, &button);
AnnotatorEngine::decodeEvent(e, &eventType, &button, &modifiers);
return performRouteMouseOrTabletEvent(eventType, button, e->localPos(), item);
return performRouteMouseOrTabletEvent(eventType, button, modifiers, e->localPos(), item);
}
QRect PageViewAnnotator::routeTabletEvent(QTabletEvent *e, PageViewItem *item, const QPoint localOriginInGlobal)
......@@ -830,13 +856,14 @@ QRect PageViewAnnotator::routeTabletEvent(QTabletEvent *e, PageViewItem *item, c
AnnotatorEngine::EventType eventType;
AnnotatorEngine::Button button;
AnnotatorEngine::Modifiers modifiers;
// figure out the event type and button
AnnotatorEngine::decodeEvent(e, &eventType, &button);
AnnotatorEngine::decodeEvent(e, &eventType, &button, &modifiers);
const QPointF globalPosF = e->globalPosF();
const QPointF localPosF = globalPosF - localOriginInGlobal;
return performRouteMouseOrTabletEvent(eventType, button, localPosF, item);
return performRouteMouseOrTabletEvent(eventType, button, modifiers, localPosF, item);
}
bool PageViewAnnotator::routeKeyEvent(QKeyEvent *event)
......
......@@ -76,7 +76,7 @@ public:
QRect routeMouseEvent(QMouseEvent *event, PageViewItem *item);
QRect routeTabletEvent(QTabletEvent *event, PageViewItem *item, const QPoint localOriginInGlobal);
QRect performRouteMouseOrTabletEvent(const AnnotatorEngine::EventType eventType, const AnnotatorEngine::Button button, const QPointF pos, PageViewItem *item);
QRect performRouteMouseOrTabletEvent(const AnnotatorEngine::EventType eventType, const AnnotatorEngine::Button button, const AnnotatorEngine::Modifiers modifiers, const QPointF pos, PageViewItem *item);
bool routeKeyEvent(QKeyEvent *event);
bool routePaints(const QRect wantedRect) const;
void routePaint(QPainter *painter, const QRect paintRect);
......
......@@ -1234,9 +1234,10 @@ QRect PresentationWidget::routeMouseDrawingEvent(QMouseEvent *e)
AnnotatorEngine::EventType eventType;
AnnotatorEngine::Button button;
AnnotatorEngine::Modifiers modifiers;
// figure out the event type and button
AnnotatorEngine::decodeEvent(e, &eventType, &button);
AnnotatorEngine::decodeEvent(e, &eventType, &button, &modifiers);
static bool hasclicked = false;
if (eventType == AnnotatorEngine::Press)
......@@ -1252,7 +1253,7 @@ QRect PresentationWidget::routeMouseDrawingEvent(QMouseEvent *e)
// Fake a move to the last border pos
nX = qBound(0., nX, 1.);
nY = qBound(0., nY, 1.);
m_drawingEngine->event(AnnotatorEngine::Move, button, nX, nY, geom.width(), geom.height(), page);
m_drawingEngine->event(AnnotatorEngine::Move, button, modifiers, nX, nY, geom.width(), geom.height(), page);
// Fake a release in the following lines
eventType = AnnotatorEngine::Release;
......@@ -1273,7 +1274,7 @@ QRect PresentationWidget::routeMouseDrawingEvent(QMouseEvent *e)
}
if (hasclicked && isInside) {
ret = m_drawingEngine->event(eventType, button, nX, nY, geom.width(), geom.height(), page);
ret = m_drawingEngine->event(eventType, button, modifiers, nX, nY, geom.width(), geom.height(), page);
}
if (eventType == AnnotatorEngine::Release) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment