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  , x(e->x())
58  , y(e->y())
59  , wheel_delta(0)
60  , acting_button(e->button())
61  , buttons_down(e->buttons())
62  , modifiers(e->modifiers())
63  , last_x(lx)
64  , last_y(ly)
65  {
66  }
67 
68  // Qt has a separate QWheelEvent for mousewheel events which is not
69  // a subclass of QMouseEvent, but has a lot of overlap with it.
70 
72  ViewportMouseEvent(RenderPanel* p, Ogre::Viewport* vp, QWheelEvent* e, int lx, int ly)
73  : panel(p)
74  , viewport(vp)
75  , type(e->type())
76  , x(e->x())
77  , y(e->y())
78  , wheel_delta(e->delta())
79  , acting_button(Qt::NoButton)
80  , buttons_down(e->buttons())
81  , modifiers(e->modifiers())
82  , last_x(lx)
83  , last_y(ly)
84  {
85  }
86 
87  // Convenience functions for getting the state of the buttons and
88  // modifiers at the time of the event. For the button which caused
89  // a press or release event, use acting_button.
90  bool left()
91  {
92  return buttons_down & Qt::LeftButton;
93  }
94  bool middle()
95  {
96  return buttons_down & Qt::MidButton;
97  }
98  bool right()
99  {
100  return buttons_down & Qt::RightButton;
101  }
102 
103  bool shift()
104  {
105  return modifiers & Qt::ShiftModifier;
106  }
107  bool control()
108  {
109  return modifiers & Qt::ControlModifier;
110  }
111  bool alt()
112  {
113  return modifiers & Qt::AltModifier;
114  }
115 
116  // Convenience functions to tell if the event is a mouse-down or
117  // mouse-up event and which button caused it.
118  bool leftUp()
119  {
120  return type == QEvent::MouseButtonRelease && acting_button == Qt::LeftButton;
121  }
122  bool middleUp()
123  {
124  return type == QEvent::MouseButtonRelease && acting_button == Qt::MidButton;
125  }
126  bool rightUp()
127  {
128  return type == QEvent::MouseButtonRelease && acting_button == Qt::RightButton;
129  }
130 
131  bool leftDown()
132  {
133  return type == QEvent::MouseButtonPress && acting_button == Qt::LeftButton;
134  }
135  bool middleDown()
136  {
137  return type == QEvent::MouseButtonPress && acting_button == Qt::MidButton;
138  }
139  bool rightDown()
140  {
141  return type == QEvent::MouseButtonPress && acting_button == Qt::RightButton;
142  }
143 
145  Ogre::Viewport* viewport;
146  QEvent::Type type;
147  int x;
148  int y;
150  Qt::MouseButton
151  acting_button; // The button which caused the event. Can be Qt::NoButton (move or wheel events).
152  Qt::MouseButtons buttons_down;
153  Qt::KeyboardModifiers modifiers;
154  int last_x;
155  int last_y;
156 };
157 
158 } // namespace rviz
159 
160 #endif // VIEWPORT_MOUSE_EVENT_H
Qt::KeyboardModifiers modifiers
ViewportMouseEvent(RenderPanel *p, Ogre::Viewport *vp, QWheelEvent *e, int lx, int ly)
ViewportMouseEvent(RenderPanel *p, Ogre::Viewport *vp, QMouseEvent *e, int lx, int ly)


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Mon Aug 15 2022 02:05:17