Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
QmitkResidualViewWidget.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 
18 #include <iostream>
19 #include <QToolTip>
20 
21 
23  : QGraphicsView(parent)
24 {
25 
26 
27 }
28 
29 
30 QmitkResidualViewWidget::QmitkResidualViewWidget(QGraphicsScene *scene, QWidget *parent)
31  : QGraphicsView(scene, parent)
32 {
33 
34 }
35 
36 
37 void QmitkResidualViewWidget::mousePressEvent(QMouseEvent* event) {
38  // Panning
39  m_LastPanPoint = event->pos();
40  setCursor(Qt::ClosedHandCursor);
41 
42 
43 
44  QGraphicsItem *item = this->itemAt(event->pos());
45  if(item == m_ResidualPixmapItem)
46  {
47  QPointF sceneCoord(mapToScene(event->pos()));
48  QPointF imageCoord(item->mapFromParent(sceneCoord));
49 
50  int volume = (int)imageCoord.y();
51  int slice = (int)imageCoord.x();
52 
53  emit pointSelected(slice, volume);
54 
55  }
56 }
57 
58 
60  setCursor(Qt::OpenHandCursor);
61  m_LastPanPoint = QPoint();
62 }
63 
65 {
66  if(!m_LastPanPoint.isNull()) {
67  QPointF delta = mapToScene(m_LastPanPoint) - mapToScene(event->pos());
68  m_LastPanPoint = event->pos();
70  }
71 }
72 
73 void QmitkResidualViewWidget::wheelEvent(QWheelEvent *event)
74 {
75 
76  // Position of the mouse in scene coordinates
77  QPointF before(mapToScene(event->pos()));
78 
79  QPointF screenCenter = m_CurrentCenterPoint;
80 
81  double factor = 1.15;
82  if(event->delta() > 0)
83  {
84  scale(factor, factor);
85  }
86  else
87  {
88  scale(1.0 / factor, 1.0 / factor);
89  }
90 
91  //Get the position after scaling, in scene coords
92  QPointF after(mapToScene(event->pos()));
93 
94  //Get the offset of how the screen moved
95  QPointF offset = before - after;
96 
97  //Adjust to the new center for correct zooming
98  QPointF newCenter = screenCenter + offset;
99  SetCenter(newCenter);
100 
101 }
102 
103 
112 void QmitkResidualViewWidget::SetCenter(const QPointF& center) {
113 
114  QRectF visibleArea = mapToScene(rect()).boundingRect();
115  QRectF sceneBounds = sceneRect();
116 
117  double boundX = visibleArea.width() / 2.0 ;
118  double boundY = visibleArea.height() / 2.0;
119  double boundWidth = sceneBounds.width() -2.0 * boundX;
120  double boundHeight = sceneBounds.height() - 2.0 * boundY;
121 
122  //The max boundary that the centerPoint can be to
123  QRectF bounds(boundX, boundY, boundWidth, boundHeight);
124 
125  if(bounds.contains(center))
126  {
127  m_CurrentCenterPoint = center;
128  }
129  else
130  {
131  //We need to clamp or use the center of the screen
132  if(visibleArea.contains(sceneBounds))
133  {
134  //Use the center of scene ie. we can see the whole scene
135  m_CurrentCenterPoint = sceneBounds.center();
136  }
137  else{
138 
139  m_CurrentCenterPoint = center;
140 
141  //We need to clamp the center. The centerPoint is too large
142  if(center.x() > bounds.x() + bounds.width())
143  {
144  m_CurrentCenterPoint.setX(bounds.x() + bounds.width());
145  }
146  else if(center.x() < bounds.x()) {
147  m_CurrentCenterPoint.setX(bounds.x());
148  }
149 
150  if(center.y() > bounds.y() + bounds.height())
151  {
152  m_CurrentCenterPoint.setY(bounds.y() + bounds.height());
153  }
154  else if(center.y() < bounds.y())
155  {
156  m_CurrentCenterPoint.setY(bounds.y());
157  }
158 
159  }
160  }
161 
162  // Update the scrollbars
163  centerOn(m_CurrentCenterPoint);
164 }
165 
166 
167 
168 
169 
170 
QGraphicsPixmapItem * m_ResidualPixmapItem
void pointSelected(int slice, int volume)
void mouseMoveEvent(QMouseEvent *event) override
void wheelEvent(QWheelEvent *event) override
static Vector3D offset
void mouseReleaseEvent(QMouseEvent *event) override
QmitkResidualViewWidget(QWidget *parent=nullptr)
void mousePressEvent(QMouseEvent *event) override
void SetCenter(const QPointF &centerPoint)