Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
MouseEvent.h
Go to the documentation of this file.
00001 /********************************************************************
00002 **                Image Component Library (ICL)                    **
00003 **                                                                 **
00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld          **
00005 **                         Neuroinformatics Group                  **
00006 ** Website: www.iclcv.org and                                      **
00007 **          http://opensource.cit-ec.de/projects/icl               **
00008 **                                                                 **
00009 ** File   : ICLQt/src/ICLQt/MouseEvent.h                           **
00010 ** Module : ICLQt                                                  **
00011 ** Authors: Christof Elbrechter                                    **
00012 **                                                                 **
00013 **                                                                 **
00014 ** GNU LESSER GENERAL PUBLIC LICENSE                               **
00015 ** This file may be used under the terms of the GNU Lesser General **
00016 ** Public License version 3.0 as published by the                  **
00017 **                                                                 **
00018 ** Free Software Foundation and appearing in the file LICENSE.GPL  **
00019 ** included in the packaging of this file.  Please review the      **
00020 ** following information to ensure the license requirements will   **
00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt                **
00022 **                                                                 **
00023 ** The development of this software was supported by the           **
00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology.    **
00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche       **
00026 ** Forschungsgemeinschaft (DFG) in the context of the German       **
00027 ** Excellence Initiative.                                          **
00028 **                                                                 **
00029 ********************************************************************/
00030 
00031 #pragma once
00032 
00033 #include <vector>
00034 #include <QtCore/Qt>
00035 #include <ICLCore/Img.h>
00036 #include <ICLUtils/Point.h>
00037 #include <ICLUtils/Point32f.h>
00038 
00039 namespace icl{
00040   namespace qt{
00041     
00043     class ICLWidget;
00046 
00047     enum MouseEventType { 
00048       MouseMoveEvent    = 0,                           
00049       MouseDragEvent    = 1,                           
00050       MousePressEvent   = 2,                           
00051       MouseReleaseEvent = 3,                           
00052       MouseEnterEvent   = 4,                           
00053       MouseLeaveEvent   = 5,                           
00054       MouseWheelEvent   = 6,                           
00055       MAX_MOUSE_EVENT   = MouseWheelEvent              
00056     };
00057   
00059 
00061     enum MouseButton{
00062       LeftMouseButton   = 0,                           
00063       MiddleMouseButton = 1,                           
00064       RightMouseButton  = 2,                           
00065       MAX_MOUSE_BUTTON  = RightMouseButton             
00066     };
00067   
00068     enum KeyboardModifier{
00069         NoModifier = Qt::NoModifier,                   
00070         ShiftModifier = Qt::ShiftModifier,             
00071         ControlModifier = Qt::ControlModifier,         
00072         AltModifier = Qt::AltModifier,                 
00073         MetaModifier = Qt::MetaModifier,               
00074         KeypadModifier = Qt::KeypadModifier,           
00075         GroupSwitchModifier = Qt::GroupSwitchModifier  
00076     };
00077   
00079 
00085     class MouseEvent{
00087       utils::Point m_widgetPos;
00088       
00090       utils::Point m_imagePos;
00091       
00093       utils::Point32f m_imagePos32f;
00094       
00096       utils::Point32f m_relImagePos;
00097       
00099       utils::Point m_wheelDelta;
00100      
00102       bool m_downMask[3];
00103       
00105       std::vector<double> m_color;
00106       
00108       ICLWidget *m_widget;
00109       
00111       MouseEventType m_type;
00112       
00114       int m_keyboardModifiers;
00115       
00116       public:
00117       
00119       MouseEvent(const utils::Point &widgetPos,
00120                  const utils::Point &imagePos,
00121                  const utils::Point32f &imagePos32f,
00122                  const utils::Point32f &relImagePos,
00123                  const bool downMask[3],
00124                  const std::vector<double> &color,
00125                  const utils::Point &wheelDelta,
00126                  MouseEventType type,
00127                ICLWidget *widget);
00128       
00129 
00131       MouseEvent();
00132           
00134       inline int getWidgetX() const { return m_widgetPos.x; }
00135   
00137       inline int getWidgetY() const { return m_widgetPos.y; }
00138   
00140       inline const utils::Point &getWidgetPos() const { return m_widgetPos; }
00141   
00143       inline int getX() const { return m_imagePos.x; }
00144   
00146       inline int getY() const { return m_imagePos.y; }
00147   
00149       inline const utils::Point &getPos() const { return m_imagePos; }
00150   
00152       inline float getX32f() const { return m_imagePos32f.x; }
00153   
00155       inline float getY32f() const { return m_imagePos32f.y; }
00156   
00158       inline const utils::Point32f &getPos32f() const { return m_imagePos32f; }
00159       
00161 
00169       inline const utils::Point &getWheelDelta() const { return m_wheelDelta; }
00170       
00172       inline float getRelX() const { return m_relImagePos.x; }
00173   
00175       inline float getRelY() const { return m_relImagePos.y; }
00176   
00178       inline const utils::Point32f getRelPos() const { return m_relImagePos; }
00179   
00181       inline const std::vector<double> &getColor() const { return m_color; }
00182       
00184       inline bool hitImage() const { return m_color.size(); }
00185       
00187       inline std::vector<bool> getDownMask() const { return std::vector<bool>(m_downMask,m_downMask+3); }
00188   
00190       inline bool isLeft() const { return m_downMask[LeftMouseButton]; }
00191   
00193       inline bool isMiddle() const { return m_downMask[MiddleMouseButton]; }
00194   
00196       inline bool isRight() const { return m_downMask[RightMouseButton]; }
00197   
00199       inline bool isLeftOnly() const { return (isLeft() && !isMiddle()) || (!isRight()); }
00200   
00202       inline bool isMiddleOnly() const { return (!isLeft() && isMiddle()) || (!isRight()); }
00203   
00205       inline bool isRightOnly() const { return (!isLeft() && !isMiddle()) || (isRight()); }
00206   
00208       inline const MouseEventType getType() const { return m_type; }
00209       
00211       inline bool isMoveEvent() const { return m_type == MouseMoveEvent; }
00212   
00214       inline bool isDragEvent() const { return m_type == MouseDragEvent; }
00215   
00217       inline bool isPressEvent() const { return m_type == MousePressEvent; }
00218   
00220       inline bool isReleaseEvent() const { return m_type == MouseReleaseEvent; }
00221   
00223       inline bool isEnterEvent() const { return m_type == MouseEnterEvent; }
00224   
00226       inline bool isLeaveEvent() const { return m_type == MouseLeaveEvent; }
00227       
00229       inline bool isWheelEvent() const { return m_type == MouseWheelEvent; }
00230       
00232       inline ICLWidget *getWidget() const { return m_widget; }
00233       
00235 
00241       inline int getKeyboardModifiers() const { return m_keyboardModifiers; }
00242       
00244       inline bool isModifierActive(KeyboardModifier m) const { return m & m_keyboardModifiers; }
00245 
00247 
00249       inline MouseEvent remapEvent(const utils::Point32f &imagePos) const {
00250         qt::MouseEvent cpy = *this;
00251         cpy.m_imagePos32f = imagePos;
00252         cpy.m_imagePos = imagePos;
00253         return cpy;
00254       }
00255     };
00256   } // namespace qt
00257 }
00258 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines