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 
44 class RenderPanel;
45 
47 {
48  public:
50 
52  ViewportMouseEvent(RenderPanel* p, Ogre::Viewport* vp, QMouseEvent* e, int lx, int ly)
53  : panel( p )
54  , viewport( vp )
55  , type( e->type() )
56  , x( e->x() )
57  , y( e->y() )
58  , wheel_delta( 0 )
59  , acting_button( e->button() )
60  , buttons_down( e->buttons() )
61  , modifiers( e->modifiers() )
62  , last_x( lx )
63  , last_y( ly )
64  {
65  }
66 
67  // Qt has a separate QWheelEvent for mousewheel events which is not
68  // a subclass of QMouseEvent, but has a lot of overlap with it.
69 
71  ViewportMouseEvent(RenderPanel* p, Ogre::Viewport* vp, QWheelEvent* e, int lx, int ly)
72  : panel( p )
73  , viewport( vp )
74  , type( e->type() )
75  , x( e->x() )
76  , y( e->y() )
77  , wheel_delta( e->delta() )
78  , acting_button( Qt::NoButton )
79  , buttons_down( e->buttons() )
80  , modifiers( e->modifiers() )
81  , last_x( lx )
82  , last_y( ly )
83  {
84  }
85 
86  // Convenience functions for getting the state of the buttons and
87  // modifiers at the time of the event. For the button which caused
88  // a press or release event, use acting_button.
89  bool left() { return buttons_down & Qt::LeftButton; }
90  bool middle() { return buttons_down & Qt::MidButton; }
91  bool right() { return buttons_down & Qt::RightButton; }
92 
93  bool shift() { return modifiers & Qt::ShiftModifier; }
94  bool control() { return modifiers & Qt::ControlModifier; }
95  bool alt() { return modifiers & Qt::AltModifier; }
96 
97  // Convenience functions to tell if the event is a mouse-down or
98  // mouse-up event and which button caused it.
99  bool leftUp() { return type == QEvent::MouseButtonRelease && acting_button == Qt::LeftButton; }
100  bool middleUp() { return type == QEvent::MouseButtonRelease && acting_button == Qt::MidButton; }
101  bool rightUp() { return type == QEvent::MouseButtonRelease && acting_button == Qt::RightButton; }
102 
103  bool leftDown() { return type == QEvent::MouseButtonPress && acting_button == Qt::LeftButton; }
104  bool middleDown() { return type == QEvent::MouseButtonPress && acting_button == Qt::MidButton; }
105  bool rightDown() { return type == QEvent::MouseButtonPress && acting_button == Qt::RightButton; }
106 
108  Ogre::Viewport* viewport;
109  QEvent::Type type;
110  int x;
111  int y;
113  Qt::MouseButton acting_button; // The button which caused the event. Can be Qt::NoButton (move or wheel events).
114  Qt::MouseButtons buttons_down;
115  Qt::KeyboardModifiers modifiers;
116  int last_x;
117  int last_y;
118 };
119 
120 } // namespace rviz
121 
122 #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)
TFSIMD_FORCE_INLINE const tfScalar & y() const
TFSIMD_FORCE_INLINE const tfScalar & x() const


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat Apr 27 2019 02:33:42