2021-05-24 07:25:56 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2005 Enrico Ros <eros.kde@email.it>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2006-11-01 15:23:11 +00:00
|
|
|
|
|
|
|
#ifndef _OKULAR_ANNOTATIONTOOLS_H_
|
|
|
|
#define _OKULAR_ANNOTATIONTOOLS_H_
|
|
|
|
|
2020-07-08 11:54:37 +00:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QPen>
|
|
|
|
#include <QRect>
|
2006-11-01 15:23:11 +00:00
|
|
|
#include <qdom.h>
|
|
|
|
|
|
|
|
#include "core/area.h"
|
|
|
|
|
2010-08-18 19:14:54 +00:00
|
|
|
class QMouseEvent;
|
2012-10-15 18:11:47 +00:00
|
|
|
class QTabletEvent;
|
2006-11-01 15:23:11 +00:00
|
|
|
class PageViewItem;
|
|
|
|
namespace Okular
|
|
|
|
{
|
2007-03-18 17:14:36 +00:00
|
|
|
class Annotation;
|
2006-11-01 15:23:11 +00:00
|
|
|
class Page;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-08-12 18:07:15 +00:00
|
|
|
* @short Engine: filter events to distill Annotations.
|
2006-11-01 15:23:11 +00:00
|
|
|
*/
|
|
|
|
class AnnotatorEngine
|
|
|
|
{
|
|
|
|
public:
|
2018-09-01 08:25:57 +00:00
|
|
|
explicit AnnotatorEngine(const QDomElement &engineElement);
|
2006-11-01 15:23:11 +00:00
|
|
|
virtual ~AnnotatorEngine();
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2020-02-21 15:11:42 +00:00
|
|
|
AnnotatorEngine(const AnnotatorEngine &) = delete;
|
|
|
|
AnnotatorEngine &operator=(const AnnotatorEngine &) = delete;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-01 15:23:11 +00:00
|
|
|
// enum definitions
|
|
|
|
enum EventType { Press, Move, Release };
|
|
|
|
enum Button { None, Left, Right };
|
2020-07-16 22:32:42 +00:00
|
|
|
/** To tell the annotator engine about modifier keys and other special wishes */
|
2020-07-10 22:44:57 +00:00
|
|
|
struct Modifiers {
|
2023-06-16 14:26:27 +00:00
|
|
|
bool constrainRatioAndAngle = false; ///< Whether the engine shall snap to certain angles, if supported.
|
2020-07-10 22:44:57 +00:00
|
|
|
};
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-01 15:23:11 +00:00
|
|
|
// perform operations
|
2020-07-10 22:44:57 +00:00
|
|
|
virtual QRect event(EventType type, Button button, Modifiers modifiers, double nX, double nY, double xScale, double yScale, const Okular::Page *page) = 0;
|
2006-11-01 15:23:11 +00:00
|
|
|
virtual void paint(QPainter *painter, double xScale, double yScale, const QRect &clipRect) = 0;
|
|
|
|
virtual QList<Okular::Annotation *> end() = 0;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-01 15:23:11 +00:00
|
|
|
// query creation state
|
|
|
|
// PageViewItem * editingItem() const { return m_lockedItem; }
|
|
|
|
bool creationCompleted() const
|
|
|
|
{
|
|
|
|
return m_creationCompleted;
|
|
|
|
}
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-01 15:23:11 +00:00
|
|
|
void setItem(PageViewItem *item)
|
|
|
|
{
|
|
|
|
m_item = item;
|
|
|
|
}
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2020-07-16 22:32:42 +00:00
|
|
|
static void decodeEvent(const QMouseEvent *mouseEvent, EventType *eventType, Button *button);
|
|
|
|
static void decodeEvent(const QTabletEvent *tabletEvent, EventType *eventType, Button *button);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2013-07-30 21:36:55 +00:00
|
|
|
virtual QCursor cursor() const;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-01 15:23:11 +00:00
|
|
|
protected:
|
|
|
|
PageViewItem *item()
|
|
|
|
{
|
|
|
|
return m_item;
|
|
|
|
}
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-01 15:23:11 +00:00
|
|
|
// common engine attributes (the element includes annotation desc)
|
|
|
|
QDomElement m_engineElement;
|
|
|
|
QDomElement m_annotElement;
|
|
|
|
QColor m_engineColor;
|
|
|
|
// other vars (remove this!)
|
|
|
|
bool m_creationCompleted;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2006-11-01 15:23:11 +00:00
|
|
|
private:
|
|
|
|
PageViewItem *m_item;
|
|
|
|
};
|
|
|
|
|
2012-06-07 13:48:53 +00:00
|
|
|
class SmoothPath
|
|
|
|
{
|
|
|
|
public:
|
2022-03-19 00:00:01 +00:00
|
|
|
SmoothPath(const QList<Okular::NormalizedPoint> &points, const QPen &pen, qreal opacity = 1.0, QPainter::CompositionMode compositionMode = QPainter::CompositionMode_SourceOver);
|
2012-06-07 13:48:53 +00:00
|
|
|
void paint(QPainter *painter, double xScale, double yScale) const;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2012-06-07 13:48:53 +00:00
|
|
|
private:
|
2022-03-19 00:00:01 +00:00
|
|
|
const QList<Okular::NormalizedPoint> points;
|
2012-06-07 13:48:53 +00:00
|
|
|
const QPen pen;
|
2015-08-22 14:00:04 +00:00
|
|
|
const qreal opacity;
|
2015-08-10 11:05:12 +00:00
|
|
|
const QPainter::CompositionMode compositionMode;
|
2012-06-07 13:48:53 +00:00
|
|
|
};
|
|
|
|
|
2006-11-01 15:23:11 +00:00
|
|
|
/** @short SmoothPathEngine */
|
|
|
|
class SmoothPathEngine : public AnnotatorEngine
|
|
|
|
{
|
|
|
|
public:
|
2018-09-01 08:25:57 +00:00
|
|
|
explicit SmoothPathEngine(const QDomElement &engineElement);
|
2006-11-01 15:23:11 +00:00
|
|
|
|
2020-07-10 22:44:57 +00:00
|
|
|
QRect event(EventType type, Button button, Modifiers modifiers, double nX, double nY, double xScale, double yScale, const Okular::Page * /*page*/) override;
|
2006-11-01 15:23:11 +00:00
|
|
|
|
2017-03-02 19:39:24 +00:00
|
|
|
void paint(QPainter *painter, double xScale, double yScale, const QRect & /*clipRect*/) override;
|
2006-11-01 15:23:11 +00:00
|
|
|
|
2012-06-07 13:48:53 +00:00
|
|
|
// These are two alternative ways to get the resulting path. Don't call them both!
|
2017-03-02 19:39:24 +00:00
|
|
|
QList<Okular::Annotation *> end() override;
|
2012-06-07 13:48:53 +00:00
|
|
|
SmoothPath endSmoothPath();
|
2006-11-01 15:23:11 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// data
|
2022-03-19 00:00:01 +00:00
|
|
|
QList<Okular::NormalizedPoint> points;
|
2006-11-01 15:23:11 +00:00
|
|
|
Okular::NormalizedRect totalRect;
|
|
|
|
Okular::NormalizedPoint lastPoint;
|
2015-08-10 11:05:12 +00:00
|
|
|
QPainter::CompositionMode compositionMode;
|
2006-11-01 15:23:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2012-10-15 18:21:43 +00:00
|
|
|
|
|
|
|
/* kate: replace-tabs on; indent-width 4; */
|