okular/part/annotationtools.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

123 lines
3.4 KiB
C
Raw Normal View History

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
*/
#ifndef _OKULAR_ANNOTATIONTOOLS_H_
#define _OKULAR_ANNOTATIONTOOLS_H_
2020-07-08 11:54:37 +00:00
#include <QPainter>
#include <QPen>
#include <QRect>
#include <qdom.h>
#include "core/area.h"
class QMouseEvent;
class QTabletEvent;
class PageViewItem;
namespace Okular
{
class Annotation;
class Page;
}
/**
* @short Engine: filter events to distill Annotations.
*/
class AnnotatorEngine
{
public:
2018-09-01 08:25:57 +00:00
explicit AnnotatorEngine(const QDomElement &engineElement);
virtual ~AnnotatorEngine();
2020-02-21 15:11:42 +00:00
AnnotatorEngine(const AnnotatorEngine &) = delete;
AnnotatorEngine &operator=(const AnnotatorEngine &) = delete;
// enum definitions
enum EventType { Press, Move, Release };
enum Button { None, Left, Right };
/** To tell the annotator engine about modifier keys and other special wishes */
struct Modifiers {
2023-06-16 14:26:27 +00:00
bool constrainRatioAndAngle = false; ///< Whether the engine shall snap to certain angles, if supported.
};
// perform operations
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;
// query creation state
// PageViewItem * editingItem() const { return m_lockedItem; }
bool creationCompleted() const
{
return m_creationCompleted;
}
void setItem(PageViewItem *item)
{
m_item = item;
}
static void decodeEvent(const QMouseEvent *mouseEvent, EventType *eventType, Button *button);
static void decodeEvent(const QTabletEvent *tabletEvent, EventType *eventType, Button *button);
virtual QCursor cursor() const;
protected:
PageViewItem *item()
{
return m_item;
}
// common engine attributes (the element includes annotation desc)
QDomElement m_engineElement;
QDomElement m_annotElement;
QColor m_engineColor;
// other vars (remove this!)
bool m_creationCompleted;
private:
PageViewItem *m_item;
};
class SmoothPath
{
public:
SmoothPath(const QList<Okular::NormalizedPoint> &points, const QPen &pen, qreal opacity = 1.0, QPainter::CompositionMode compositionMode = QPainter::CompositionMode_SourceOver);
void paint(QPainter *painter, double xScale, double yScale) const;
private:
const QList<Okular::NormalizedPoint> points;
const QPen pen;
const qreal opacity;
const QPainter::CompositionMode compositionMode;
};
/** @short SmoothPathEngine */
class SmoothPathEngine : public AnnotatorEngine
{
public:
2018-09-01 08:25:57 +00:00
explicit SmoothPathEngine(const QDomElement &engineElement);
QRect event(EventType type, Button button, Modifiers modifiers, double nX, double nY, double xScale, double yScale, const Okular::Page * /*page*/) override;
2017-03-02 19:39:24 +00:00
void paint(QPainter *painter, double xScale, double yScale, const QRect & /*clipRect*/) override;
// 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;
SmoothPath endSmoothPath();
private:
// data
QList<Okular::NormalizedPoint> points;
Okular::NormalizedRect totalRect;
Okular::NormalizedPoint lastPoint;
QPainter::CompositionMode compositionMode;
};
#endif
2012-10-15 18:21:43 +00:00
/* kate: replace-tabs on; indent-width 4; */