• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kde-runtime API Reference
  • KDE Home
  • Contact Us
 

QtExtraComponents

  • sources
  • kde-4.12
  • kde-runtime
  • plasma
  • declarativeimports
  • qtextracomponents
mouseeventlistener.h
Go to the documentation of this file.
1 /*
2  Copyright 2011 Marco Martin <notmart@gmail.com>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef MOUSEEVENTLISTENER_H
21 #define MOUSEEVENTLISTENER_H
22 
23 #include <QDeclarativeItem>
24 
25 class KDeclarativeMouseEvent : public QObject
26 {
27  Q_OBJECT
28  Q_PROPERTY(int x READ x)
29  Q_PROPERTY(int y READ y)
30  Q_PROPERTY(int screenX READ screenX)
31  Q_PROPERTY(int screenY READ screenY)
32  Q_PROPERTY(int button READ button)
33  Q_PROPERTY(Qt::MouseButtons buttons READ buttons)
34  Q_PROPERTY(Qt::KeyboardModifiers modifiers READ modifiers)
35 
36 public:
37  KDeclarativeMouseEvent(int x, int y, int screenX, int screenY,
38  Qt::MouseButton button,
39  Qt::MouseButtons buttons,
40  Qt::KeyboardModifiers modifiers)
41  : m_x(x),
42  m_y(y),
43  m_screenX(screenX),
44  m_screenY(screenY),
45  m_button(button),
46  m_buttons(buttons),
47  m_modifiers(modifiers)
48  {}
49 
50  int x() const { return m_x; }
51  int y() const { return m_y; }
52  int screenX() const { return m_screenX; }
53  int screenY() const { return m_screenY; }
54  int button() const { return m_button; }
55  Qt::MouseButtons buttons() const { return m_buttons; }
56  Qt::KeyboardModifiers modifiers() const { return m_modifiers; }
57 
58  // only for internal usage
59  void setX(int x) { m_x = x; }
60  void setY(int y) { m_y = y; }
61 
62 private:
63  int m_x;
64  int m_y;
65  int m_screenX;
66  int m_screenY;
67  Qt::MouseButton m_button;
68  Qt::MouseButtons m_buttons;
69  Qt::KeyboardModifiers m_modifiers;
70 };
71 
72 class KDeclarativeWheelEvent : public QObject
73 {
74  Q_OBJECT
75  Q_PROPERTY(int x READ x CONSTANT)
76  Q_PROPERTY(int y READ y CONSTANT)
77  Q_PROPERTY(int screenX READ screenX CONSTANT)
78  Q_PROPERTY(int screenY READ screenY CONSTANT)
79  Q_PROPERTY(int delta READ delta CONSTANT)
80  Q_PROPERTY(Qt::MouseButtons buttons READ buttons CONSTANT)
81  Q_PROPERTY(Qt::KeyboardModifiers modifiers READ modifiers CONSTANT)
82  Q_PROPERTY(Qt::Orientation orientation READ orientation CONSTANT)
83 
84 public:
85  KDeclarativeWheelEvent(QPointF pos, QPoint screenPos, int delta,
86  Qt::MouseButtons buttons,
87  Qt::KeyboardModifiers modifiers,
88  Qt::Orientation orientation)
89  : m_x(pos.x()),
90  m_y(pos.y()),
91  m_screenX(screenPos.x()),
92  m_screenY(screenPos.y()),
93  m_delta(delta),
94  m_buttons(buttons),
95  m_modifiers(modifiers),
96  m_orientation(orientation)
97  {}
98 
99  int x() const { return m_x; }
100  int y() const { return m_y; }
101  int screenX() const { return m_screenX; }
102  int screenY() const { return m_screenY; }
103  int delta() const { return m_delta; }
104  Qt::MouseButtons buttons() const { return m_buttons; }
105  Qt::KeyboardModifiers modifiers() const { return m_modifiers; }
106  Qt::Orientation orientation() { return m_orientation; }
107 
108  // only for internal usage
109  void setX(int x) { m_x = x; }
110  void setY(int y) { m_y = y; }
111 
112 private:
113  int m_x;
114  int m_y;
115  int m_screenX;
116  int m_screenY;
117  int m_delta;
118  Qt::MouseButtons m_buttons;
119  Qt::KeyboardModifiers m_modifiers;
120  Qt::Orientation m_orientation;
121 };
122 
123 class MouseEventListener : public QDeclarativeItem
124 {
125  Q_OBJECT
130  Q_PROPERTY(bool hoverEnabled READ hoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged)
131 
132 
136  Q_PROPERTY(bool containsMouse READ containsMouse NOTIFY containsMouseChanged)
137 
138 public:
139  MouseEventListener(QDeclarativeItem *parent=0);
140  ~MouseEventListener();
141 
142  bool containsMouse() const;
143  void setHoverEnabled(bool enable);
144  bool hoverEnabled() const;
145 
146 protected:
147  void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
148  void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
149  void mousePressEvent(QGraphicsSceneMouseEvent *event);
150  void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
151  void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
152  void wheelEvent(QGraphicsSceneWheelEvent *event);
153  bool sceneEventFilter(QGraphicsItem *i, QEvent *e);
154 
155 Q_SIGNALS:
156  void pressed(KDeclarativeMouseEvent *mouse);
157  void positionChanged(KDeclarativeMouseEvent *mouse);
158  void released(KDeclarativeMouseEvent *mouse);
159  void clicked(KDeclarativeMouseEvent *mouse);
160  void pressAndHold(KDeclarativeMouseEvent *mouse);
161  void wheelMoved(KDeclarativeWheelEvent *wheel);
162  void containsMouseChanged(bool containsMouseChanged);
163  void hoverEnabledChanged(bool hoverEnabled);
164 
165 private Q_SLOTS:
166  void handlePressAndHold();
167 private:
168  bool m_pressed;
169  KDeclarativeMouseEvent* m_pressAndHoldEvent;
170  QPointF m_pressAndHoldPosition;
171  //Important: used only for comparison. If you will ever need to access this pointer, make it a QWeakPointer
172  QEvent *m_lastEvent;
173  QTimer *m_pressAndHoldTimer;
174  bool m_containsMouse;
175 };
176 
177 #endif
KDeclarativeWheelEvent::delta
int delta() const
Definition: mouseeventlistener.h:103
KDeclarativeWheelEvent::buttons
Qt::MouseButtons buttons() const
Definition: mouseeventlistener.h:104
MouseEventListener::mouseReleaseEvent
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Definition: mouseeventlistener.cpp:124
KDeclarativeMouseEvent::buttons
Qt::MouseButtons buttons() const
Definition: mouseeventlistener.h:55
MouseEventListener::containsMouse
bool containsMouse() const
KDeclarativeMouseEvent::x
int x() const
Definition: mouseeventlistener.h:50
MouseEventListener::released
void released(KDeclarativeMouseEvent *mouse)
KDeclarativeWheelEvent::screenX
int screenX() const
Definition: mouseeventlistener.h:101
KDeclarativeWheelEvent::screenY
int screenY() const
Definition: mouseeventlistener.h:102
MouseEventListener::wheelMoved
void wheelMoved(KDeclarativeWheelEvent *wheel)
KDeclarativeWheelEvent::orientation
Qt::Orientation orientation()
Definition: mouseeventlistener.h:106
MouseEventListener
Definition: mouseeventlistener.h:123
MouseEventListener::hoverLeaveEvent
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Definition: mouseeventlistener.cpp:77
MouseEventListener::hoverEnabledChanged
void hoverEnabledChanged(bool hoverEnabled)
MouseEventListener::setHoverEnabled
void setHoverEnabled(bool enable)
Definition: mouseeventlistener.cpp:54
MouseEventListener::clicked
void clicked(KDeclarativeMouseEvent *mouse)
QObject
KDeclarativeWheelEvent::y
int y() const
Definition: mouseeventlistener.h:100
MouseEventListener::mousePressEvent
void mousePressEvent(QGraphicsSceneMouseEvent *event)
Definition: mouseeventlistener.cpp:90
KDeclarativeMouseEvent::screenY
int screenY() const
Definition: mouseeventlistener.h:53
KDeclarativeMouseEvent::button
int button() const
Definition: mouseeventlistener.h:54
MouseEventListener::pressed
void pressed(KDeclarativeMouseEvent *mouse)
KDeclarativeMouseEvent::setY
void setY(int y)
Definition: mouseeventlistener.h:60
KDeclarativeWheelEvent::setX
void setX(int x)
Definition: mouseeventlistener.h:109
QDeclarativeItem
MouseEventListener::wheelEvent
void wheelEvent(QGraphicsSceneWheelEvent *event)
Definition: mouseeventlistener.cpp:141
MouseEventListener::containsMouseChanged
void containsMouseChanged(bool containsMouseChanged)
KDeclarativeMouseEvent::y
int y() const
Definition: mouseeventlistener.h:51
MouseEventListener::mouseMoveEvent
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
Definition: mouseeventlistener.cpp:113
KDeclarativeMouseEvent::setX
void setX(int x)
Definition: mouseeventlistener.h:59
KDeclarativeMouseEvent
Definition: mouseeventlistener.h:25
MouseEventListener::sceneEventFilter
bool sceneEventFilter(QGraphicsItem *i, QEvent *e)
Definition: mouseeventlistener.cpp:161
MouseEventListener::pressAndHold
void pressAndHold(KDeclarativeMouseEvent *mouse)
MouseEventListener::positionChanged
void positionChanged(KDeclarativeMouseEvent *mouse)
KDeclarativeWheelEvent::setY
void setY(int y)
Definition: mouseeventlistener.h:110
KDeclarativeMouseEvent::screenX
int screenX() const
Definition: mouseeventlistener.h:52
MouseEventListener::hoverEnterEvent
void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
Definition: mouseeventlistener.cpp:69
MouseEventListener::hoverEnabled
bool hoverEnabled() const
KDeclarativeWheelEvent::modifiers
Qt::KeyboardModifiers modifiers() const
Definition: mouseeventlistener.h:105
KDeclarativeWheelEvent
Definition: mouseeventlistener.h:72
KDeclarativeMouseEvent::modifiers
Qt::KeyboardModifiers modifiers() const
Definition: mouseeventlistener.h:56
KDeclarativeWheelEvent::x
int x() const
Definition: mouseeventlistener.h:99
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:02:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

QtExtraComponents

Skip menu "QtExtraComponents"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kde-runtime API Reference

Skip menu "kde-runtime API Reference"
  • KCMShell
  • KNotify
  • Plasma Runtime
  •     PlasmaCore
  •     DragAndDrop
  •     PlasmaComponents
  •     PlasmaExtraComponents
  •     QtExtraComponents

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal