viewport_mouse_event.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef VIEWPORT_MOUSE_EVENT_H
31 #define VIEWPORT_MOUSE_EVENT_H
32 
33 #include <QMouseEvent>
34 #include <QWheelEvent>
35 
36 namespace Ogre
37 {
38 class Viewport;
39 }
40 
41 namespace rviz
42 {
43 class RenderPanel;
44 
46 {
47 public:
49  {
50  }
51 
53  ViewportMouseEvent(RenderPanel* p, Ogre::Viewport* vp, QMouseEvent* e, int lx, int ly)
54  : panel(p)
55  , viewport(vp)
56  , type(e->type())
57 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
58  , x(e->position().x())
59  , y(e->position().y())
60 #else
61  , x(e->x())
62  , y(e->y())
63 #endif
64  , wheel_delta(0)
65  , acting_button(e->button())
66  , buttons_down(e->buttons())
67  , modifiers(e->modifiers())
68  , last_x(lx)
69  , last_y(ly)
70  {
71  }
72 
73  // Qt has a separate QWheelEvent for mousewheel events which is not
74  // a subclass of QMouseEvent, but has a lot of overlap with it.
75 
77  ViewportMouseEvent(RenderPanel* p, Ogre::Viewport* vp, QWheelEvent* e, int lx, int ly)
78  : panel(p)
79  , viewport(vp)
80  , type(e->type())
81 #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
82  , x(e->position().x())
83  , y(e->position().y())
84 #else
85  , x(e->x())
86  , y(e->y())
87 #endif
88  , wheel_delta(e->angleDelta().y())
89  , acting_button(Qt::NoButton)
90  , buttons_down(e->buttons())
91  , modifiers(e->modifiers())
92  , last_x(lx)
93  , last_y(ly)
94  {
95  }
96 
97  // Convenience functions for getting the state of the buttons and
98  // modifiers at the time of the event. For the button which caused
99  // a press or release event, use acting_button.
100  bool left()
101  {
102  return buttons_down & Qt::LeftButton;
103  }
104  bool middle()
105  {
106  return buttons_down & Qt::MiddleButton;
107  }
108  bool right()
109  {
110  return buttons_down & Qt::RightButton;
111  }
112 
113  bool shift()
114  {
115  return modifiers & Qt::ShiftModifier;
116  }
117  bool control()
118  {
119  return modifiers & Qt::ControlModifier;
120  }
121  bool alt()
122  {
123  return modifiers & Qt::AltModifier;
124  }
125 
126  // Convenience functions to tell if the event is a mouse-down or
127  // mouse-up event and which button caused it.
128  bool leftUp()
129  {
130  return type == QEvent::MouseButtonRelease && acting_button == Qt::LeftButton;
131  }
132  bool middleUp()
133  {
134  return type == QEvent::MouseButtonRelease && acting_button == Qt::MiddleButton;
135  }
136  bool rightUp()
137  {
138  return type == QEvent::MouseButtonRelease && acting_button == Qt::RightButton;
139  }
140 
141  bool leftDown()
142  {
143  return type == QEvent::MouseButtonPress && acting_button == Qt::LeftButton;
144  }
145  bool middleDown()
146  {
147  return type == QEvent::MouseButtonPress && acting_button == Qt::MiddleButton;
148  }
149  bool rightDown()
150  {
151  return type == QEvent::MouseButtonPress && acting_button == Qt::RightButton;
152  }
153 
155  Ogre::Viewport* viewport;
156  QEvent::Type type;
157  int x;
158  int y;
160  Qt::MouseButton
161  acting_button; // The button which caused the event. Can be Qt::NoButton (move or wheel events).
162  Qt::MouseButtons buttons_down;
163  Qt::KeyboardModifiers modifiers;
164  int last_x;
165  int last_y;
166 };
167 
168 } // namespace rviz
169 
170 #endif // VIEWPORT_MOUSE_EVENT_H
rviz::ViewportMouseEvent::middleUp
bool middleUp()
Definition: viewport_mouse_event.h:132
rviz::ViewportMouseEvent::leftDown
bool leftDown()
Definition: viewport_mouse_event.h:141
Ogre
Definition: axes_display.h:35
rviz::ViewportMouseEvent::rightUp
bool rightUp()
Definition: viewport_mouse_event.h:136
rviz::ViewportMouseEvent
Definition: viewport_mouse_event.h:45
rviz::ViewportMouseEvent::x
int x
Definition: viewport_mouse_event.h:157
rviz::ViewportMouseEvent::ViewportMouseEvent
ViewportMouseEvent(RenderPanel *p, Ogre::Viewport *vp, QWheelEvent *e, int lx, int ly)
Definition: viewport_mouse_event.h:77
rviz::ViewportMouseEvent::left
bool left()
Definition: viewport_mouse_event.h:100
rviz::ViewportMouseEvent::right
bool right()
Definition: viewport_mouse_event.h:108
rviz::ViewportMouseEvent::viewport
Ogre::Viewport * viewport
Definition: viewport_mouse_event.h:155
rviz::ViewportMouseEvent::buttons_down
Qt::MouseButtons buttons_down
Definition: viewport_mouse_event.h:162
rviz
Definition: add_display_dialog.cpp:54
rviz::ViewportMouseEvent::middle
bool middle()
Definition: viewport_mouse_event.h:104
rviz::ViewportMouseEvent::y
int y
Definition: viewport_mouse_event.h:158
rviz::ViewportMouseEvent::panel
RenderPanel * panel
Definition: viewport_mouse_event.h:154
rviz::ViewportMouseEvent::type
QEvent::Type type
Definition: viewport_mouse_event.h:156
rviz::ViewportMouseEvent::control
bool control()
Definition: viewport_mouse_event.h:117
rviz::ViewportMouseEvent::wheel_delta
int wheel_delta
Definition: viewport_mouse_event.h:159
rviz::ViewportMouseEvent::shift
bool shift()
Definition: viewport_mouse_event.h:113
rviz::ViewportMouseEvent::leftUp
bool leftUp()
Definition: viewport_mouse_event.h:128
rviz::ViewportMouseEvent::middleDown
bool middleDown()
Definition: viewport_mouse_event.h:145
rviz::ViewportMouseEvent::rightDown
bool rightDown()
Definition: viewport_mouse_event.h:149
rviz::ViewportMouseEvent::alt
bool alt()
Definition: viewport_mouse_event.h:121
rviz::ViewportMouseEvent::last_y
int last_y
Definition: viewport_mouse_event.h:165
rviz::ViewportMouseEvent::ViewportMouseEvent
ViewportMouseEvent(RenderPanel *p, Ogre::Viewport *vp, QMouseEvent *e, int lx, int ly)
Definition: viewport_mouse_event.h:53
rviz::ViewportMouseEvent::last_x
int last_x
Definition: viewport_mouse_event.h:164
rviz::RenderPanel
Definition: render_panel.h:74
rviz::ViewportMouseEvent::acting_button
Qt::MouseButton acting_button
Definition: viewport_mouse_event.h:161
rviz::ViewportMouseEvent::modifiers
Qt::KeyboardModifiers modifiers
Definition: viewport_mouse_event.h:163
rviz::ViewportMouseEvent::ViewportMouseEvent
ViewportMouseEvent()
Definition: viewport_mouse_event.h:48


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Aug 2 2024 08:43:10