viewport_mouse_event.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #ifndef VIEWPORT_MOUSE_EVENT_H
00031 #define VIEWPORT_MOUSE_EVENT_H
00032 
00033 #include <QMouseEvent>
00034 #include <QWheelEvent>
00035 
00036 namespace Ogre
00037 {
00038 class Viewport;
00039 }
00040 
00041 namespace rviz
00042 {
00043 
00044 class RenderPanel;
00045 
00046 class ViewportMouseEvent
00047 {
00048  public:
00049   ViewportMouseEvent() {}
00050 
00052   ViewportMouseEvent(RenderPanel* p, Ogre::Viewport* vp, QMouseEvent* e, int lx, int ly)
00053   : panel( p )
00054   , viewport( vp )
00055   , type( e->type() )
00056   , x( e->x() )
00057   , y( e->y() )
00058   , wheel_delta( 0 )
00059   , acting_button( e->button() )
00060   , buttons_down( e->buttons() )
00061   , modifiers( e->modifiers() )
00062   , last_x( lx )
00063   , last_y( ly )
00064   {
00065   }
00066 
00067   // Qt has a separate QWheelEvent for mousewheel events which is not
00068   // a subclass of QMouseEvent, but has a lot of overlap with it.
00069 
00071   ViewportMouseEvent(RenderPanel* p, Ogre::Viewport* vp, QWheelEvent* e, int lx, int ly)
00072   : panel( p )
00073   , viewport( vp )
00074   , type( e->type() )
00075   , x( e->x() )
00076   , y( e->y() )
00077   , wheel_delta( e->delta() )
00078   , acting_button( Qt::NoButton )
00079   , buttons_down( e->buttons() )
00080   , modifiers( e->modifiers() )
00081   , last_x( lx )
00082   , last_y( ly )
00083   {
00084   }
00085 
00086   // Convenience functions for getting the state of the buttons and
00087   // modifiers at the time of the event.  For the button which caused
00088   // a press or release event, use acting_button.
00089   bool left() { return buttons_down & Qt::LeftButton; }
00090   bool middle() { return buttons_down & Qt::MidButton; }
00091   bool right() { return buttons_down & Qt::RightButton; }
00092 
00093   bool shift() { return modifiers & Qt::ShiftModifier; }
00094   bool control() { return modifiers & Qt::ControlModifier; }
00095   bool alt() { return modifiers & Qt::AltModifier; }
00096 
00097   // Convenience functions to tell if the event is a mouse-down or
00098   // mouse-up event and which button caused it.
00099   bool leftUp() { return type == QEvent::MouseButtonRelease && acting_button == Qt::LeftButton; }
00100   bool middleUp() { return type == QEvent::MouseButtonRelease && acting_button == Qt::MidButton; }
00101   bool rightUp() { return type == QEvent::MouseButtonRelease && acting_button == Qt::RightButton; }
00102 
00103   bool leftDown() { return type == QEvent::MouseButtonPress && acting_button == Qt::LeftButton; }
00104   bool middleDown() { return type == QEvent::MouseButtonPress && acting_button == Qt::MidButton; }
00105   bool rightDown() { return type == QEvent::MouseButtonPress && acting_button == Qt::RightButton; }
00106 
00107   RenderPanel* panel;
00108   Ogre::Viewport* viewport;
00109   QEvent::Type type;
00110   int x;
00111   int y;
00112   int wheel_delta;
00113   Qt::MouseButton acting_button; // The button which caused the event.  Can be Qt::NoButton (move or wheel events).
00114   Qt::MouseButtons buttons_down;
00115   Qt::KeyboardModifiers modifiers;
00116   int last_x;
00117   int last_y;
00118 };
00119 
00120 } // namespace rviz
00121 
00122 #endif // VIEWPORT_MOUSE_EVENT_H


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Thu Jun 6 2019 18:02:16