Image Component Library (ICL)
|
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.LGPL ** 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 <ICLUtils/CompatMacros.h> 00034 #include <ICLUtils/Point.h> 00035 #include <ICLUtils/Point32f.h> 00036 #include <ICLCore/Img.h> 00037 #include <QtCore/Qt> 00038 #include <vector> 00039 00040 namespace icl{ 00041 namespace qt{ 00042 00044 class ICLWidget; 00047 00048 enum MouseEventType { 00049 MouseMoveEvent = 0, 00050 MouseDragEvent = 1, 00051 MousePressEvent = 2, 00052 MouseReleaseEvent = 3, 00053 MouseEnterEvent = 4, 00054 MouseLeaveEvent = 5, 00055 MouseWheelEvent = 6, 00056 MAX_MOUSE_EVENT = MouseWheelEvent 00057 }; 00058 00060 00062 enum MouseButton{ 00063 LeftMouseButton = 0, 00064 MiddleMouseButton = 1, 00065 RightMouseButton = 2, 00066 MAX_MOUSE_BUTTON = RightMouseButton 00067 }; 00068 00069 enum KeyboardModifier{ 00070 NoModifier = Qt::NoModifier, 00071 ShiftModifier = Qt::ShiftModifier, 00072 ControlModifier = Qt::ControlModifier, 00073 AltModifier = Qt::AltModifier, 00074 MetaModifier = Qt::MetaModifier, 00075 KeypadModifier = Qt::KeypadModifier, 00076 GroupSwitchModifier = Qt::GroupSwitchModifier 00077 }; 00078 00080 00086 class ICLQt_API MouseEvent{ 00088 utils::Point m_widgetPos; 00089 00091 utils::Point m_imagePos; 00092 00094 utils::Point32f m_imagePos32f; 00095 00097 utils::Point32f m_relImagePos; 00098 00100 utils::Point m_wheelDelta; 00101 00103 bool m_downMask[3]; 00104 00106 std::vector<double> m_color; 00107 00109 ICLWidget *m_widget; 00110 00112 MouseEventType m_type; 00113 00115 int m_keyboardModifiers; 00116 00117 public: 00118 00120 MouseEvent(const utils::Point &widgetPos, 00121 const utils::Point &imagePos, 00122 const utils::Point32f &imagePos32f, 00123 const utils::Point32f &relImagePos, 00124 const bool downMask[3], 00125 const std::vector<double> &color, 00126 const utils::Point &wheelDelta, 00127 MouseEventType type, 00128 ICLWidget *widget); 00129 00130 00132 MouseEvent(); 00133 00135 inline int getWidgetX() const { return m_widgetPos.x; } 00136 00138 inline int getWidgetY() const { return m_widgetPos.y; } 00139 00141 inline const utils::Point &getWidgetPos() const { return m_widgetPos; } 00142 00144 inline int getX() const { return m_imagePos.x; } 00145 00147 inline int getY() const { return m_imagePos.y; } 00148 00150 inline const utils::Point &getPos() const { return m_imagePos; } 00151 00153 inline float getX32f() const { return m_imagePos32f.x; } 00154 00156 inline float getY32f() const { return m_imagePos32f.y; } 00157 00159 inline const utils::Point32f &getPos32f() const { return m_imagePos32f; } 00160 00162 00170 inline const utils::Point &getWheelDelta() const { return m_wheelDelta; } 00171 00173 inline float getRelX() const { return m_relImagePos.x; } 00174 00176 inline float getRelY() const { return m_relImagePos.y; } 00177 00179 inline const utils::Point32f getRelPos() const { return m_relImagePos; } 00180 00182 inline const std::vector<double> &getColor() const { return m_color; } 00183 00185 inline bool hitImage() const { return m_color.size(); } 00186 00188 inline std::vector<bool> getDownMask() const { return std::vector<bool>(m_downMask,m_downMask+3); } 00189 00191 inline bool isLeft() const { return m_downMask[LeftMouseButton]; } 00192 00194 inline bool isMiddle() const { return m_downMask[MiddleMouseButton]; } 00195 00197 inline bool isRight() const { return m_downMask[RightMouseButton]; } 00198 00200 inline bool isLeftOnly() const { return (isLeft() && !isMiddle() & !isRight()); } 00201 00203 inline bool isMiddleOnly() const { return (!isLeft() && isMiddle() && !isRight()); } 00204 00206 inline bool isRightOnly() const { return (!isLeft() && !isMiddle() && isRight()); } 00207 00209 inline const MouseEventType getType() const { return m_type; } 00210 00212 inline bool isMoveEvent() const { return m_type == MouseMoveEvent; } 00213 00215 inline bool isDragEvent() const { return m_type == MouseDragEvent; } 00216 00218 inline bool isPressEvent() const { return m_type == MousePressEvent; } 00219 00221 inline bool isReleaseEvent() const { return m_type == MouseReleaseEvent; } 00222 00224 inline bool isEnterEvent() const { return m_type == MouseEnterEvent; } 00225 00227 inline bool isLeaveEvent() const { return m_type == MouseLeaveEvent; } 00228 00230 inline bool isWheelEvent() const { return m_type == MouseWheelEvent; } 00231 00233 inline ICLWidget *getWidget() const { return m_widget; } 00234 00236 00242 inline int getKeyboardModifiers() const { return m_keyboardModifiers; } 00243 00245 inline bool isModifierActive(KeyboardModifier m) const { return m & m_keyboardModifiers; } 00246 00248 00250 inline MouseEvent remapEvent(const utils::Point32f &imagePos) const { 00251 qt::MouseEvent cpy = *this; 00252 cpy.m_imagePos32f = imagePos; 00253 cpy.m_imagePos = imagePos; 00254 return cpy; 00255 } 00256 }; 00257 } // namespace qt 00258 } 00259