Fraxinus  18.10
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", contextMenu);
57  this->addConnectivityAction("group", "Group 2D Zoom", contextMenu);
58  this->addConnectivityAction("local", "Disconnected 2D Zoom", contextMenu);
59  contextMenu->addSeparator();
60 }
61 
62 void Zoom2DHandler::addConnectivityAction(QString type, QString text, QMenu* contextMenu)
63 {
64  QAction* action = new QAction(text, contextMenu);
65  action->setCheckable(true);
66  action->setData(type);
67  action->setChecked(this->getConnectivityType()==type);
68  connect(action, SIGNAL(triggered()), this, SLOT(zoom2DActionSlot()));
69  contextMenu->addAction(action);
70 }
71 
75 void Zoom2DHandler::zoom2DActionSlot()
76 {
77  QAction* theAction = static_cast<QAction*>(sender());
78  if(!theAction)
79  return;
80 
81  QString action = theAction->data().toString();
82  this->setConnectivityFromType(action);
83 }
84 
85 QString Zoom2DHandler::getConnectivityType()
86 {
87  if (!mGroupData)
88  return "local";
89  if (mGroupData->getGroup2DZoom() == mZoom2D)
90  return "group";
91  if (mGroupData->getGlobal2DZoom() == mZoom2D)
92  return "global";
93  return "local";
94 }
95 
96 void Zoom2DHandler::setConnectivityFromType(QString type)
97 {
98  if (!mGroupData)
99  type = "local";
100 
101  if (type=="global")
102  {
103  this->set(mGroupData->getGlobal2DZoom());
104  }
105  else if (type=="group")
106  {
107  this->set(mGroupData->getGroup2DZoom());
108  }
109  else if (type=="local")
110  {
111  this->set(SyncedValue::create(this->getFactor()));
112  }
113  else
114  {
115  reportWarning(QString("No zoom connectivity found for type [%1].").arg(type));
116  }
117 }
118 
119 
120 
121 
122 } // namespace cx
123 
124 
boost::shared_ptr< class ViewGroupData > ViewGroupDataPtr
Definition: cxViewGroup.h:29
void setFactor(double factor)
void addActionsToMenu(QMenu *contextMenu)
void reportWarning(QString msg)
Definition: cxLogger.cpp:70
double constrainValue(double val, double min, double max)
static SyncedValuePtr create(QVariant val=QVariant())
void setGroupData(ViewGroupDataPtr group)
boost::shared_ptr< class SyncedValue > SyncedValuePtr
Definition: cxViewGroup.h:30
Namespace for all CustusX production code.