File indexing completed on 2024-04-28 15:51:39
0001 /* 0002 SPDX-FileCopyrightText: 2005 Enrico Ros <eros.kde@email.it> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef _OKULAR_ANNOTATIONTOOLS_H_ 0008 #define _OKULAR_ANNOTATIONTOOLS_H_ 0009 0010 #include <QPainter> 0011 #include <QPen> 0012 #include <QRect> 0013 #include <qdom.h> 0014 0015 #include "core/area.h" 0016 0017 class QMouseEvent; 0018 class QTabletEvent; 0019 class PageViewItem; 0020 namespace Okular 0021 { 0022 class Annotation; 0023 class Page; 0024 } 0025 0026 /** 0027 * @short Engine: filter events to distill Annotations. 0028 */ 0029 class AnnotatorEngine 0030 { 0031 public: 0032 explicit AnnotatorEngine(const QDomElement &engineElement); 0033 virtual ~AnnotatorEngine(); 0034 0035 AnnotatorEngine(const AnnotatorEngine &) = delete; 0036 AnnotatorEngine &operator=(const AnnotatorEngine &) = delete; 0037 0038 // enum definitions 0039 enum EventType { Press, Move, Release }; 0040 enum Button { None, Left, Right }; 0041 /** To tell the annotator engine about modifier keys and other special wishes */ 0042 struct Modifiers { 0043 bool constrainRatioAndAngle = false; ///< Whether the engine shall snap to certain angles, if supported. 0044 }; 0045 0046 // perform operations 0047 virtual QRect event(EventType type, Button button, Modifiers modifiers, double nX, double nY, double xScale, double yScale, const Okular::Page *page) = 0; 0048 virtual void paint(QPainter *painter, double xScale, double yScale, const QRect &clipRect) = 0; 0049 virtual QList<Okular::Annotation *> end() = 0; 0050 0051 // query creation state 0052 // PageViewItem * editingItem() const { return m_lockedItem; } 0053 bool creationCompleted() const 0054 { 0055 return m_creationCompleted; 0056 } 0057 0058 void setItem(PageViewItem *item) 0059 { 0060 m_item = item; 0061 } 0062 0063 static void decodeEvent(const QMouseEvent *mouseEvent, EventType *eventType, Button *button); 0064 static void decodeEvent(const QTabletEvent *tabletEvent, EventType *eventType, Button *button); 0065 0066 virtual QCursor cursor() const; 0067 0068 protected: 0069 PageViewItem *item() 0070 { 0071 return m_item; 0072 } 0073 0074 // common engine attributes (the element includes annotation desc) 0075 QDomElement m_engineElement; 0076 QDomElement m_annotElement; 0077 QColor m_engineColor; 0078 // other vars (remove this!) 0079 bool m_creationCompleted; 0080 0081 private: 0082 PageViewItem *m_item; 0083 }; 0084 0085 class SmoothPath 0086 { 0087 public: 0088 SmoothPath(const QList<Okular::NormalizedPoint> &points, const QPen &pen, qreal opacity = 1.0, QPainter::CompositionMode compositionMode = QPainter::CompositionMode_SourceOver); 0089 void paint(QPainter *painter, double xScale, double yScale) const; 0090 0091 private: 0092 const QList<Okular::NormalizedPoint> points; 0093 const QPen pen; 0094 const qreal opacity; 0095 const QPainter::CompositionMode compositionMode; 0096 }; 0097 0098 /** @short SmoothPathEngine */ 0099 class SmoothPathEngine : public AnnotatorEngine 0100 { 0101 public: 0102 explicit SmoothPathEngine(const QDomElement &engineElement); 0103 0104 QRect event(EventType type, Button button, Modifiers modifiers, double nX, double nY, double xScale, double yScale, const Okular::Page * /*page*/) override; 0105 0106 void paint(QPainter *painter, double xScale, double yScale, const QRect & /*clipRect*/) override; 0107 0108 // These are two alternative ways to get the resulting path. Don't call them both! 0109 QList<Okular::Annotation *> end() override; 0110 SmoothPath endSmoothPath(); 0111 0112 private: 0113 // data 0114 QList<Okular::NormalizedPoint> points; 0115 Okular::NormalizedRect totalRect; 0116 Okular::NormalizedPoint lastPoint; 0117 QPainter::CompositionMode compositionMode; 0118 }; 0119 0120 #endif 0121 0122 /* kate: replace-tabs on; indent-width 4; */