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 struct ViewportMouseEvent
00047 {
00048   ViewportMouseEvent() {}
00049 
00051   ViewportMouseEvent(RenderPanel* p, Ogre::Viewport* vp, QMouseEvent* e, int lx, int ly)
00052   : panel( p )
00053   , viewport( vp )
00054   , type( e->type() )
00055   , x( e->x() )
00056   , y( e->y() )
00057   , wheel_delta( 0 )
00058   , acting_button( e->button() )
00059   , buttons_down( e->buttons() )
00060   , modifiers( e->modifiers() )
00061   , last_x( lx )
00062   , last_y( ly )
00063   {
00064   }
00065 
00066   // Qt has a separate QWheelEvent for mousewheel events which is not
00067   // a subclass of QMouseEvent, but has a lot of overlap with it.
00068 
00070   ViewportMouseEvent(RenderPanel* p, Ogre::Viewport* vp, QWheelEvent* e, int lx, int ly)
00071   : panel( p )
00072   , viewport( vp )
00073   , type( e->type() )
00074   , x( e->x() )
00075   , y( e->y() )
00076   , wheel_delta( e->delta() )
00077   , acting_button( Qt::NoButton )
00078   , buttons_down( e->buttons() )
00079   , modifiers( e->modifiers() )
00080   , last_x( lx )
00081   , last_y( ly )
00082   {
00083   }
00084 
00085   // Convenience functions for getting the state of the buttons and
00086   // modifiers at the time of the event.  For the button which caused
00087   // a press or release event, use acting_button.
00088   bool left() { return buttons_down & Qt::LeftButton; }
00089   bool middle() { return buttons_down & Qt::MidButton; }
00090   bool right() { return buttons_down & Qt::RightButton; }
00091 
00092   bool shift() { return modifiers & Qt::ShiftModifier; }
00093   bool control() { return modifiers & Qt::ControlModifier; }
00094   bool alt() { return modifiers & Qt::AltModifier; }
00095 
00096   // Convenience functions to tell if the event is a mouse-down or
00097   // mouse-up event and which button caused it.
00098   bool leftUp() { return type == QEvent::MouseButtonRelease && acting_button == Qt::LeftButton; }
00099   bool middleUp() { return type == QEvent::MouseButtonRelease && acting_button == Qt::MidButton; }
00100   bool rightUp() { return type == QEvent::MouseButtonRelease && acting_button == Qt::RightButton; }
00101 
00102   bool leftDown() { return type == QEvent::MouseButtonPress && acting_button == Qt::LeftButton; }
00103   bool middleDown() { return type == QEvent::MouseButtonPress && acting_button == Qt::MidButton; }
00104   bool rightDown() { return type == QEvent::MouseButtonPress && acting_button == Qt::RightButton; }
00105 
00106   RenderPanel* panel;
00107   Ogre::Viewport* viewport;
00108   QEvent::Type type;
00109   int x;
00110   int y;
00111   int wheel_delta;
00112   Qt::MouseButton acting_button; // The button which caused the event.  Can be Qt::NoButton (move or wheel events).
00113   Qt::MouseButtons buttons_down;
00114   Qt::KeyboardModifiers modifiers;
00115   int last_x;
00116   int last_y;
00117 };
00118 
00119 } // namespace rviz
00120 
00121 #endif // VIEWPORT_MOUSE_EVENT_H


rviz
Author(s): Dave Hershberger, Josh Faust
autogenerated on Mon Jan 6 2014 11:54:33