Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkMouseModeSwitcher.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 "QmitkMouseModeSwitcher.h"
18 #include <QActionGroup>
19 
21  : QToolBar(parent),
22  m_ActionGroup(new QActionGroup(this)),
23  m_MouseModeSwitcher(NULL),
24  m_ObserverTag(0),
25  m_InObservationReaction(false)
26 {
27  QToolBar::setOrientation(Qt::Vertical);
28  QToolBar::setIconSize(QSize(17, 17));
29  m_ActionGroup->setExclusive(true); // only one selectable
30 
31  addButton(mitk::MouseModeSwitcher::MousePointer, tr("Pointer"), QIcon(":/Qmitk/mm_pointer.png"), true); // toggle ON
32  addButton(mitk::MouseModeSwitcher::Scroll, tr("Scroll"), QIcon(":/Qmitk/mm_scroll.png"));
33  addButton(mitk::MouseModeSwitcher::LevelWindow, tr("Level/Window"), QIcon(":/Qmitk/mm_contrast.png"));
34  addButton(mitk::MouseModeSwitcher::Zoom, tr("Zoom"), QIcon(":/Qmitk/mm_zoom.png"));
35  addButton(mitk::MouseModeSwitcher::Pan, tr("Pan"), QIcon(":/Qmitk/mm_pan.png"));
36 }
37 
38 void QmitkMouseModeSwitcher::addButton(MouseMode id, const QString &toolName, const QIcon &icon, bool on)
39 {
40  QAction *action = new QAction(icon, toolName, this);
41  action->setCheckable(true);
42  action->setActionGroup(m_ActionGroup);
43  action->setChecked(on);
44  action->setData(id);
45  connect(action, SIGNAL(triggered()), this, SLOT(modeSelectedByUser()));
46  QToolBar::addAction(action);
47 }
48 
50 {
52  {
53  m_MouseModeSwitcher->RemoveObserver(m_ObserverTag);
54  }
55 }
56 
58 {
59  // goodbye / welcome ceremonies
61  {
62  m_MouseModeSwitcher->RemoveObserver(m_ObserverTag);
63  }
64 
65  m_MouseModeSwitcher = mms;
66 
68  {
71  command->SetCallbackFunction(this, &QmitkMouseModeSwitcher::OnMouseModeChanged);
72  m_ObserverTag = m_MouseModeSwitcher->AddObserver(mitk::MouseModeSwitcher::MouseModeChangedEvent(), command);
73  }
74 }
75 
77 {
79  return; // this was NOT actually by the user but by ourselves
80 
81  QAction *action = dynamic_cast<QAction *>(sender());
82 
83  if (action)
84  {
85  MouseMode id = static_cast<MouseMode>(action->data().toInt());
86  // qDebug() << "Mouse mode '" << qPrintable(action->text()) << "' selected, trigger mode id " << id;
87 
89  {
90  m_MouseModeSwitcher->SetInteractionScheme(mitk::MouseModeSwitcher::InteractionScheme::PACS);
92  }
93  emit MouseModeSelected(id);
94  }
95 }
96 
97 void QmitkMouseModeSwitcher::OnMouseModeChanged(const itk::EventObject &)
98 {
100 
101  // push button graphically
102  assert(m_MouseModeSwitcher);
103 
105 
106  foreach (QAction *action, m_ActionGroup->actions())
107  {
108  if (action->data().toInt() == activeMode)
109  {
110  action->setChecked(true);
111  }
112  }
113 
114  m_InObservationReaction = false;
115 }
itk::SmartPointer< Self > Pointer
void SetInteractionScheme(InteractionScheme)
Setter for interaction scheme.
QmitkMouseModeSwitcher(QWidget *parent=0)
void MouseModeSelected(mitk::MouseModeSwitcher::MouseMode id)
Mode activated.
void OnMouseModeChanged(const itk::EventObject &)
void setMouseModeSwitcher(mitk::MouseModeSwitcher *)
Connect to non-GUI class.
mitk::MouseModeSwitcher * m_MouseModeSwitcher
MouseMode GetCurrentMouseMode() const
Returns the current mouse mode.
void addButton(MouseMode id, const QString &toolName, const QIcon &icon, bool on=false)
void SelectMouseMode(MouseMode mode)
Setter for mouse mode.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.