1 /* ============================================================
2 * Falkon - Qt web browser
3 * Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 * ============================================================ */
18 #pragma once
19 
20 #include <QWheelEvent>
21 #include <QObject>
22 
23 /**
24  * @brief The class exposing WheelEvent to QML
25  */
26 class QmlWheelEvent : public QObject
27 {
28     Q_OBJECT
29     /**
30      * @brief the distance that the wheel is rotated, in eighths of a degree
31      */
32     Q_PROPERTY(QPoint angleDelta READ angleDelta CONSTANT)
33     /**
34      * @brief mouse state at the time of event
35      */
36     Q_PROPERTY(int buttons READ buttons CONSTANT)
37     /**
38      * @brief global position of mouse cursor at the time of event
39      */
40     Q_PROPERTY(QPoint globalPos READ globalPos CONSTANT)
41     /**
42      * @brief global position of mouse cursor at the time of event
43      */
44     Q_PROPERTY(QPointF globalPosF READ globalPosF CONSTANT)
45     /**
46      * @brief global x position of mouse cursor at the time of event
47      */
48     Q_PROPERTY(int globalX READ globalX CONSTANT)
49     /**
50      * @brief global y position of mouse cursor at the time of event
51      */
52     Q_PROPERTY(int globalY READ globalY CONSTANT)
53     /**
54      * @brief checks if the delta values delivered with the event are inverted
55      */
56     Q_PROPERTY(bool inverted READ inverted CONSTANT)
57     /**
58      * @brief scrolling phase of this wheel event
59      */
60     Q_PROPERTY(int phase READ phase CONSTANT)
61     /**
62      * @brief scrolling distance in pixels on screen
63      */
64     Q_PROPERTY(QPoint pixelDelta READ pixelDelta CONSTANT)
65     /**
66      * @brief position of mouse cursor at the time of event
67      */
68     Q_PROPERTY(QPoint pos READ pos CONSTANT)
69     /**
70      * @brief position of mouse cursor at the time of event
71      */
72     Q_PROPERTY(QPointF posF READ posF CONSTANT)
73     /**
74      * @brief source of the event
75      */
76     Q_PROPERTY(int source READ source CONSTANT)
77     /**
78      * @brief x position of mouse cursor at the time of event
79      */
80     Q_PROPERTY(int x READ x CONSTANT)
81     /**
82      * @brief y position of mouse cursor at the time of event
83      */
84     Q_PROPERTY(int y READ y CONSTANT)
85 public:
86     explicit QmlWheelEvent(QWheelEvent *wheelEvent = nullptr, QObject *parent = nullptr);
87     QPoint angleDelta() const;
88     int buttons() const;
89     QPoint globalPos() const;
90     QPointF globalPosF() const;
91     int globalX() const;
92     int globalY() const;
93     bool inverted() const;
94     int phase() const;
95     QPoint pixelDelta() const;
96     QPoint pos() const;
97     QPointF posF() const;
98     int source() const;
99     int x() const;
100     int y() const;
101 
102     void clear();
103 private:
104     QWheelEvent *m_wheelEvent = nullptr;
105 };
106