KoPointerEvent.h 6.92 KB
Newer Older
Thomas Zander's avatar
Thomas Zander committed
1
/* This file is part of the KDE project
2

Thomas Zander's avatar
Thomas Zander committed
3
   Copyright (C) 2006 Thorsten Zachmann <zachmann@kde.org>
C. Boemann's avatar
C. Boemann committed
4
   Copyright (C) 2006 C. Boemann Rasmussen <cbo@boemann.dk>
Thomas Zander's avatar
Thomas Zander committed
5
   Copyright (C) 2006-2007 Thomas Zander <zander@kde.org>
Boudewijn Rempt's avatar
Boudewijn Rempt committed
6
   Copyright (C) 2012 Boudewijn Rempt <boud@valdyas.org>
7

Thomas Zander's avatar
Thomas Zander committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

24 25
#ifndef KOPOINTEREVENT_H
#define KOPOINTEREVENT_H
Thomas Zander's avatar
Thomas Zander committed
26

27 28
#include <QTouchEvent>

29 30 31
class QTabletEvent;
class QMouseEvent;
class QWheelEvent;
32
class KoInputDeviceHandlerEvent;
33

34
#include "kritaflake_export.h"
Thomas Zander's avatar
Thomas Zander committed
35

36 37 38 39 40 41 42 43 44
struct KoTouchPoint
{
    QTouchEvent::TouchPoint touchPoint;
    // the point in document coordinates
    QPointF lastPoint;
    QPointF point;

};

Thomas Zander's avatar
Thomas Zander committed
45
/**
46 47
 * KoPointerEvent is a synthetic event that can be built from a mouse,
 * touch or tablet event. In addition to always providing tools with tablet
48
 * pressure characteristics, KoPointerEvent has both the original
49 50
 * (canvas based) position as well as the normalized position, that is,
 * the position of the event _in_ the document coordinates.
Thomas Zander's avatar
Thomas Zander committed
51
 */
52
class KRITAFLAKE_EXPORT KoPointerEvent
Thomas Zander's avatar
Thomas Zander committed
53 54 55 56
{
public:
    /**
     * Constructor.
57
     *
Thomas Zander's avatar
Thomas Zander committed
58 59
     * @param event the mouse event that is the base of this event.
     * @param point the zoomed point in the normal coordinate system.
Thomas Zander's avatar
Thomas Zander committed
60
     */
Thomas Zander's avatar
Thomas Zander committed
61
    KoPointerEvent(QMouseEvent *event, const QPointF &point);
62 63 64

    /**
     * Constructor.
65
     *
Thomas Zander's avatar
Thomas Zander committed
66 67
     * @param event the tablet event that is the base of this event.
     * @param point the zoomed point in the normal coordinate system.
68
     */
Thomas Zander's avatar
Thomas Zander committed
69
    KoPointerEvent(QTabletEvent *event, const QPointF &point);
Thomas Zander's avatar
Thomas Zander committed
70

Sharaf Zaman's avatar
Sharaf Zaman committed
71 72
    KoPointerEvent(QTouchEvent* ev, const QPointF& pnt);

73
    KoPointerEvent(KoInputDeviceHandlerEvent *event, int x, int y, int z = 0, int rx = 0, int ry = 0, int rz = 0);
74

75 76
    KoPointerEvent(KoPointerEvent *event, const QPointF& point);

77 78
    KoPointerEvent(const KoPointerEvent &rhs);

Thomas Zander's avatar
Thomas Zander committed
79 80
    ~KoPointerEvent();

Thomas Zander's avatar
Thomas Zander committed
81 82
    /**
     * For classes that are handed this event, you can choose to accept (default) this event.
83
     * Acceptance signifies that you have handled this event and found it useful, the effect
Thomas Zander's avatar
Thomas Zander committed
84 85
     * of that will be that the event will not be handled to other event handlers.
     */
86 87 88
    inline void accept() {
        m_event->accept();
    }
89

Thomas Zander's avatar
Thomas Zander committed
90 91 92 93 94
    /**
     * For classes that are handed this event, you can choose to ignore this event.
     * Ignoring this event means you have not handled it and want to allow other event
     * handlers to try to handle it.
     */
95 96 97
    inline void ignore() {
        m_event->ignore();
    }
98

Thomas Zander's avatar
Thomas Zander committed
99
    /**
100 101
     * Returns the keyboard modifier flags that existed immediately before the event occurred.
     * See also QApplication::keyboardModifiers().
Thomas Zander's avatar
Thomas Zander committed
102
     */
103
    Qt::KeyboardModifiers modifiers() const;
Thomas Zander's avatar
Thomas Zander committed
104 105

    /// return if the event has been accepted.
106 107 108
    inline bool isAccepted() const {
        return m_event->isAccepted();
    }
109

Thomas Zander's avatar
Thomas Zander committed
110
    /// return if this event was spontaneous (see QMouseEvent::spontaneous())
111 112 113
    inline bool spontaneous() const {
        return m_event->spontaneous();
    }
Thomas Zander's avatar
Thomas Zander committed
114 115

    /// return button pressed (see QMouseEvent::button());
116
    Qt::MouseButton button() const;
117

Thomas Zander's avatar
Thomas Zander committed
118
    /// return buttons pressed (see QMouseEvent::buttons());
119
    Qt::MouseButtons buttons() const;
120

121
    /// Return the position screen coordinates
122
    QPoint globalPos() const;
123 124

    /// return the position in widget coordinates
125
    QPoint pos() const;
126

127 128 129
    /**
     * return the pressure (or a default value). The range is 0.0 - 1.0
     * and the default pressure (this is the pressure that will be given
130
     * when you use something like the mouse) is 1.0
131
     */
132
    qreal pressure() const;
133 134

    /// return the rotation (or a default value)
135
    qreal rotation() const;
136 137 138

    /**
     * return the tangential pressure  (or a default value)
139 140 141
     * This is typically given by a finger wheel on an airbrush tool. The range
     * is from -1.0 to 1.0. 0.0 indicates a neutral position. Current airbrushes can
     * only move in the positive direction from the neutral position. If the device
142 143
     * does not support tangential pressure, this value is always 0.0.
     */
144
    qreal tangentialPressure() const;
145

146 147 148 149
    /**
     * Return the x position in widget coordinates.
     * @see point
     */
150
    int x() const;
151

152
    /**
153 154 155
     * Returns the angle between the device (a pen, for example) and the
     * perpendicular in the direction of the x axis. Positive values are
     * towards the tablet's physical right. The angle is in the range -60
156 157
     * to +60 degrees. The default value is 0.
     */
158
    int xTilt() const;
159

160 161 162 163
    /**
     * Return the y position in widget coordinates.
     * @see point
     */
164
    int y() const;
165 166

    /**
167 168 169
     * Returns the angle between the device (a pen, for example) and the
     * perpendicular in the direction of the x axis. Positive values are
     * towards the tablet's physical right. The angle is in the range -60
170 171
     * to +60 degrees. The default value is 0.
     */
172
    int yTilt() const;
173 174

    /**
175 176
     * Returns the z position of the device. Typically this is represented
     * by a wheel on a 4D Mouse. If the device does not support a Z-axis,
177 178
     * this value is always zero. This is <em>not</em> the same as pressure.
     */
179
    int z() const;
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
    /**
     * Returns the rotation around the X-axis. If the device does not support
     * this, the value is always zero.
     */
    int rotationX() const;

    /**
     * Returns the rotation around the X-axis. If the device does not support
     * this, the value is always zero.
     */
    int rotationY() const;

    /**
     * Returns the rotation around the Z-axis. If the device does not support
     * this, the value is always zero.
     */
    int rotationZ() const;

Thomas Zander's avatar
Thomas Zander committed
198

Adrian Page's avatar
Adrian Page committed
199
    /// The point in document coordinates.
Jarosław Staniek's avatar
Jarosław Staniek committed
200
    const QPointF point;
201

202
    const QList<KoTouchPoint> touchPoints;
203 204 205 206 207
    /**
     * Returns if the event comes from a tablet
     */
    bool isTabletEvent();

Thomas Zander's avatar
Thomas Zander committed
208 209
protected:
    friend class KoToolProxy;
210
    friend class KisToolProxy;
Dmitry Kazakov's avatar
Dmitry Kazakov committed
211
    friend class KisScratchPadEventFilter;
Thomas Zander's avatar
Thomas Zander committed
212
    /// called by KoToolProxy to set which button was pressed.
Thomas Zander's avatar
Thomas Zander committed
213
    void setTabletButton(Qt::MouseButton button);
Thomas Zander's avatar
Thomas Zander committed
214
private:
215 216
    KoPointerEvent& operator=(const KoPointerEvent &rhs);

Thomas Zander's avatar
Thomas Zander committed
217
    // for the d-pointer police; we want to make accessors to the event inline, so this one stays here.
218
    QEvent *m_event;
Thomas Zander's avatar
Thomas Zander committed
219 220 221

    class Private;
    Private * const d;
Thomas Zander's avatar
Thomas Zander committed
222 223
};

Thomas Zander's avatar
Thomas Zander committed
224
#endif
Thomas Zander's avatar
Thomas Zander committed
225