1 /*
2     SPDX-FileCopyrightText: 2005 Enrico Ros <eros.kde@email.it>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #ifndef _OKULAR_ANNOTATIONTOOLS_H_
8 #define _OKULAR_ANNOTATIONTOOLS_H_
9 
10 #include <QLinkedList>
11 #include <QPainter>
12 #include <QPen>
13 #include <QRect>
14 #include <qdom.h>
15 
16 #include "core/area.h"
17 
18 class QMouseEvent;
19 class QTabletEvent;
20 class PageViewItem;
21 namespace Okular
22 {
23 class Annotation;
24 class Page;
25 }
26 
27 /**
28  * @short Engine: filter events to distill Annotations.
29  */
30 class AnnotatorEngine
31 {
32 public:
33     explicit AnnotatorEngine(const QDomElement &engineElement);
34     virtual ~AnnotatorEngine();
35 
36     AnnotatorEngine(const AnnotatorEngine &) = delete;
37     AnnotatorEngine &operator=(const AnnotatorEngine &) = delete;
38 
39     // enum definitions
40     enum EventType { Press, Move, Release };
41     enum Button { None, Left, Right };
42     /** To tell the annotator engine about modifier keys and other special wishes */
43     struct Modifiers {
44         bool constrainRatioAndAngle; ///< Whether the engine shall snap to certain angles, if supported.
45     };
46 
47     // perform operations
48     virtual QRect event(EventType type, Button button, Modifiers modifiers, double nX, double nY, double xScale, double yScale, const Okular::Page *page) = 0;
49     virtual void paint(QPainter *painter, double xScale, double yScale, const QRect &clipRect) = 0;
50     virtual QList<Okular::Annotation *> end() = 0;
51 
52     // query creation state
53     // PageViewItem * editingItem() const { return m_lockedItem; }
creationCompleted()54     bool creationCompleted() const
55     {
56         return m_creationCompleted;
57     }
58 
setItem(PageViewItem * item)59     void setItem(PageViewItem *item)
60     {
61         m_item = item;
62     }
63 
64     static void decodeEvent(const QMouseEvent *mouseEvent, EventType *eventType, Button *button);
65     static void decodeEvent(const QTabletEvent *tabletEvent, EventType *eventType, Button *button);
66 
67     virtual QCursor cursor() const;
68 
69 protected:
item()70     PageViewItem *item()
71     {
72         return m_item;
73     }
74 
75     // common engine attributes (the element includes annotation desc)
76     QDomElement m_engineElement;
77     QDomElement m_annotElement;
78     QColor m_engineColor;
79     // other vars (remove this!)
80     bool m_creationCompleted;
81 
82 private:
83     PageViewItem *m_item;
84 };
85 
86 class SmoothPath
87 {
88 public:
89     SmoothPath(const QLinkedList<Okular::NormalizedPoint> &points, const QPen &pen, qreal opacity = 1.0, QPainter::CompositionMode compositionMode = QPainter::CompositionMode_SourceOver);
90     void paint(QPainter *painter, double xScale, double yScale) const;
91 
92 private:
93     const QLinkedList<Okular::NormalizedPoint> points;
94     const QPen pen;
95     const qreal opacity;
96     const QPainter::CompositionMode compositionMode;
97 };
98 
99 /** @short SmoothPathEngine */
100 class SmoothPathEngine : public AnnotatorEngine
101 {
102 public:
103     explicit SmoothPathEngine(const QDomElement &engineElement);
104 
105     QRect event(EventType type, Button button, Modifiers modifiers, double nX, double nY, double xScale, double yScale, const Okular::Page * /*page*/) override;
106 
107     void paint(QPainter *painter, double xScale, double yScale, const QRect & /*clipRect*/) override;
108 
109     // These are two alternative ways to get the resulting path. Don't call them both!
110     QList<Okular::Annotation *> end() override;
111     SmoothPath endSmoothPath();
112 
113 private:
114     // data
115     QLinkedList<Okular::NormalizedPoint> points;
116     Okular::NormalizedRect totalRect;
117     Okular::NormalizedPoint lastPoint;
118     QPainter::CompositionMode compositionMode;
119 };
120 
121 #endif
122 
123 /* kate: replace-tabs on; indent-width 4; */
124