NorMIT-nav  22.09
An IGT application
cx2DZoomHandler.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cx2DZoomHandler.h"
13 #include "cxViewGroup.h"
14 #include "cxLogger.h"
15 #include "cxUtilHelpers.h"
16 #include "cxSyncedValue.h"
17 
18 namespace cx
19 {
20 
22 {
23  this->set(SyncedValue::create(1.0));
24 }
25 
27 {
28  mGroupData = group;
29  this->set(group->getGlobal2DZoom());
30 }
31 
33 {
34  return mZoom2D->get().toDouble();
35 }
36 
37 void Zoom2DHandler::setFactor(double factor)
38 {
39  factor = constrainValue(factor, 0.2, 10.0);
40  mZoom2D->set(factor);
41 }
42 
43 void Zoom2DHandler::set(SyncedValuePtr value)
44 {
45  if (mZoom2D)
46  disconnect(mZoom2D.get(), SIGNAL(changed()), this, SIGNAL(zoomChanged()));
47  mZoom2D = value;
48  if (mZoom2D)
49  connect(mZoom2D.get(), SIGNAL(changed()), this, SIGNAL(zoomChanged()));
50 
51  emit zoomChanged();
52 }
53 
54 void Zoom2DHandler::addActionsToMenu(QMenu* contextMenu)
55 {
56  this->addConnectivityAction("global", "Global 2D Zoom",
57  "Zoom in all 2D views are synchronized", contextMenu);
58  this->addConnectivityAction("group", "Group 2D Zoom",
59  "Zoom for all 2D views in a view group with this option set\n"
60  "will be synchronized. ", contextMenu);
61  this->addConnectivityAction("local", "Disconnected 2D Zoom",
62  "2D zoom in this view will be decoupled from other 2D views", contextMenu);
63  contextMenu->addSeparator();
64 }
65 
66 void Zoom2DHandler::addConnectivityAction(QString type, QString text, QString toolTip, QMenu* contextMenu)
67 {
68  QAction* action = new QAction(text, contextMenu);
69  action->setCheckable(true);
70  action->setData(type);
71  action->setChecked(this->getConnectivityType()==type);
72  action->setToolTip(toolTip);
73  connect(action, SIGNAL(triggered()), this, SLOT(zoom2DActionSlot()));
74  contextMenu->addAction(action);
75 }
76 
80 void Zoom2DHandler::zoom2DActionSlot()
81 {
82  QAction* theAction = static_cast<QAction*>(sender());
83  if(!theAction)
84  return;
85 
86  QString action = theAction->data().toString();
87  this->setConnectivityFromType(action);
88 }
89 
90 QString Zoom2DHandler::getConnectivityType()
91 {
92  if (!mGroupData)
93  return "local";
94  if (mGroupData->getGroup2DZoom() == mZoom2D)
95  return "group";
96  if (mGroupData->getGlobal2DZoom() == mZoom2D)
97  return "global";
98  return "local";
99 }
100 
101 void Zoom2DHandler::setConnectivityFromType(QString type)
102 {
103  if (!mGroupData)
104  type = "local";
105 
106  if (type=="global")
107  {
108  this->set(mGroupData->getGlobal2DZoom());
109  }
110  else if (type=="group")
111  {
112  this->set(mGroupData->getGroup2DZoom());
113  }
114  else if (type=="local")
115  {
116  this->set(SyncedValue::create(this->getFactor()));
117  }
118  else
119  {
120  reportWarning(QString("No zoom connectivity found for type [%1].").arg(type));
121  }
122 }
123 
124 
125 
126 
127 } // namespace cx
128 
129 
cxLogger.h
cxSyncedValue.h
cx::ViewGroupDataPtr
boost::shared_ptr< class ViewGroupData > ViewGroupDataPtr
Definition: cxViewGroup.h:29
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cxUtilHelpers.h
cx::Zoom2DHandler::Zoom2DHandler
Zoom2DHandler()
Definition: cx2DZoomHandler.cpp:21
cxViewGroup.h
cx::Zoom2DHandler::addActionsToMenu
void addActionsToMenu(QMenu *contextMenu)
Definition: cx2DZoomHandler.cpp:54
cx2DZoomHandler.h
cx::constrainValue
double constrainValue(double val, double min, double max)
Definition: cxUtilHelpers.cpp:28
cx::SyncedValue::create
static SyncedValuePtr create(QVariant val=QVariant())
Definition: cxSyncedValue.cpp:21
cx::SyncedValuePtr
boost::shared_ptr< class SyncedValue > SyncedValuePtr
Definition: cxViewGroup.h:30
cx::Zoom2DHandler::setFactor
void setFactor(double factor)
Definition: cx2DZoomHandler.cpp:37
cx::Zoom2DHandler::getFactor
double getFactor()
Definition: cx2DZoomHandler.cpp:32
cx::reportWarning
void reportWarning(QString msg)
Definition: cxLogger.cpp:70
cx::Zoom2DHandler::setGroupData
void setGroupData(ViewGroupDataPtr group)
Definition: cx2DZoomHandler.cpp:26
cx::Zoom2DHandler::zoomChanged
void zoomChanged()