Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkEventAdapter.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "QmitkEventAdapter.h"
18 #include <mitkInteractionConst.h>
19 #include <mitkWheelEvent.h>
20 
21 #include <QPoint>
22 #include <QCursor>
23 
24 mitk::MouseEvent
25 QmitkEventAdapter::AdaptMouseEvent(mitk::BaseRenderer* sender, QMouseEvent* mouseEvent)
26 {
27  mitk::Point2D p;
28  p[0] = mouseEvent->x();
29  p[1] = mouseEvent->y();
30 
31  int modifiers = mouseEvent->modifiers();
32  int state = 0;
33 
34  switch (mouseEvent->type())
35  {
36  case QEvent::MouseButtonRelease:
37  state |= mouseEvent->button();
38  break;
39  case QEvent::MouseMove:
40  state |= mouseEvent->buttons();
41  break;
42  default:
43  break;
44  }
45 
46  if (modifiers & Qt::ShiftModifier)
47  state |= mitk::BS_ShiftButton;
48  if (modifiers & Qt::ControlModifier)
49  state |= mitk::BS_ControlButton;
50  if (modifiers & Qt::AltModifier)
51  state |= mitk::BS_AltButton;
52  if (modifiers & Qt::MetaModifier)
53  state |= mitk::BS_MetaButton;
54  if (modifiers & Qt::KeypadModifier)
55  state |= mitk::BS_Keypad;
56 
57  mitk::MouseEvent mitkEvent(sender, mouseEvent->type(), mouseEvent->button(),
58  state, mitk::Key_none, p);
59 
60  return mitkEvent;
61 }
62 
63 mitk::WheelEvent
64 QmitkEventAdapter::AdaptWheelEvent(mitk::BaseRenderer* sender, QWheelEvent* wheelEvent)
65 {
66  mitk::Point2D p;
67  p[0] = wheelEvent->x();
68  p[1] = wheelEvent->y();
69 
70  int modifiers = wheelEvent->modifiers();
71  int state = 0;
72 
73  state = wheelEvent->buttons();
74 
75  if (modifiers & Qt::ShiftModifier)
76  state |= mitk::BS_ShiftButton;
77  if (modifiers & Qt::ControlModifier)
78  state |= mitk::BS_ControlButton;
79  if (modifiers & Qt::AltModifier)
80  state |= mitk::BS_AltButton;
81  if (modifiers & Qt::MetaModifier)
82  state |= mitk::BS_MetaButton;
83  if (modifiers & Qt::KeypadModifier)
84  state |= mitk::BS_Keypad;
85 
86  mitk::WheelEvent mitkEvent(sender, wheelEvent->type(), wheelEvent->buttons(),
87  state, mitk::Key_none, p, wheelEvent->delta());
88 
89  return mitkEvent;
90 }
91 
92 
93 mitk::KeyEvent
94 QmitkEventAdapter::AdaptKeyEvent(mitk::BaseRenderer* sender, QKeyEvent* keyEvent, const QPoint& cp)
95 {
96  int key = keyEvent->key();
97 
98  // Those keycodes changed in Qt 4
99  if (key >= 0x01000000 && key <= 0x01000060)
100  key -= (0x01000000 - 0x1000);
101  else if(key >= 0x01001120 && key <= 0x01001262)
102  key -= 0x01000000;
103 
104  mitk::Point2D p;
105  p[0] = cp.x();
106  p[1] = cp.y();
107 
108  int modifiers = keyEvent->modifiers();
109  int state = 0;
110  if (modifiers & Qt::ShiftModifier)
111  state |= mitk::BS_ShiftButton;
112  if (modifiers & Qt::ControlModifier)
113  state |= mitk::BS_ControlButton;
114  if (modifiers & Qt::AltModifier)
115  state |= mitk::BS_AltButton;
116  if (modifiers & Qt::MetaModifier)
117  state |= mitk::BS_MetaButton;
118  //if (modifiers & Qt::KeypadModifier)
119  // state |= mitk::BS_Keypad;
120 
121  mitk::KeyEvent mke(sender, keyEvent->type(), mitk::BS_NoButton, state, key, keyEvent->text().toStdString(), p);
122 
123  return mke;
124 }
Organizes the rendering process.
static mitk::WheelEvent AdaptWheelEvent(mitk::BaseRenderer *sender, QWheelEvent *wheelEvent)
Constants for most interaction classes, due to the generic StateMachines.
static mitk::MouseEvent AdaptMouseEvent(mitk::BaseRenderer *sender, QMouseEvent *mouseEvent)
static mitk::KeyEvent AdaptKeyEvent(mitk::BaseRenderer *sender, QKeyEvent *keyEvent, const QPoint &point)