CustusX  15.3.3-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cx2DZoomHandler.h"
34 #include "cxViewGroup.h"
35 #include "cxLogger.h"
36 #include "cxUtilHelpers.h"
37 #include "cxSyncedValue.h"
38 
39 namespace cx
40 {
41 
43 {
44  this->set(SyncedValue::create(1.0));
45 }
46 
48 {
49  mGroupData = group;
50  this->set(group->getGlobal2DZoom());
51 }
52 
54 {
55  return mZoom2D->get().toDouble();
56 }
57 
58 void Zoom2DHandler::setFactor(double factor)
59 {
60  factor = constrainValue(factor, 0.2, 10.0);
61  mZoom2D->set(factor);
62 }
63 
64 void Zoom2DHandler::set(SyncedValuePtr value)
65 {
66  if (mZoom2D)
67  disconnect(mZoom2D.get(), SIGNAL(changed()), this, SIGNAL(zoomChanged()));
68  mZoom2D = value;
69  if (mZoom2D)
70  connect(mZoom2D.get(), SIGNAL(changed()), this, SIGNAL(zoomChanged()));
71 
72  emit zoomChanged();
73 }
74 
75 void Zoom2DHandler::addActionsToMenu(QMenu* contextMenu)
76 {
77  this->addConnectivityAction("global", "Global 2D Zoom", contextMenu);
78  this->addConnectivityAction("group", "Group 2D Zoom", contextMenu);
79  this->addConnectivityAction("local", "Disconnected 2D Zoom", contextMenu);
80  contextMenu->addSeparator();
81 }
82 
83 void Zoom2DHandler::addConnectivityAction(QString type, QString text, QMenu* contextMenu)
84 {
85  QAction* action = new QAction(text, contextMenu);
86  action->setCheckable(true);
87  action->setData(type);
88  action->setChecked(this->getConnectivityType()==type);
89  connect(action, SIGNAL(triggered()), this, SLOT(zoom2DActionSlot()));
90  contextMenu->addAction(action);
91 }
92 
96 void Zoom2DHandler::zoom2DActionSlot()
97 {
98  QAction* theAction = static_cast<QAction*>(sender());
99  if(!theAction)
100  return;
101 
102  QString action = theAction->data().toString();
103  this->setConnectivityFromType(action);
104 }
105 
106 QString Zoom2DHandler::getConnectivityType()
107 {
108  if (!mGroupData)
109  return "local";
110  if (mGroupData->getGroup2DZoom() == mZoom2D)
111  return "group";
112  if (mGroupData->getGlobal2DZoom() == mZoom2D)
113  return "global";
114  return "local";
115 }
116 
117 void Zoom2DHandler::setConnectivityFromType(QString type)
118 {
119  if (!mGroupData)
120  type = "local";
121 
122  if (type=="global")
123  {
124  this->set(mGroupData->getGlobal2DZoom());
125  }
126  else if (type=="group")
127  {
128  this->set(mGroupData->getGroup2DZoom());
129  }
130  else if (type=="local")
131  {
132  this->set(SyncedValue::create(this->getFactor()));
133  }
134  else
135  {
136  reportWarning(QString("No zoom connectivity found for type [%1].").arg(type));
137  }
138 }
139 
140 
141 
142 
143 } // namespace cx
144 
145 
boost::shared_ptr< class ViewGroupData > ViewGroupDataPtr
Definition: cxViewGroup.h:50
void setFactor(double factor)
void addActionsToMenu(QMenu *contextMenu)
void reportWarning(QString msg)
Definition: cxLogger.cpp:91
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:51