Fraxinus  17.12
An IGT application
cxCameraStyleInteractor.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 
34 
35 
36 #include <QAction>
37 #include "cxLogger.h"
38 #include "cxView.h"
39 #include "cxLogger.h"
40 #include "cxViewGroupData.h"
41 
42 namespace cx
43 {
44 
46  mCameraStyleGroup(NULL)
47 {
48 }
49 
51 {
52  if (mGroup)
53  disconnect(mGroup.get(), &ViewGroupData::optionsChanged, this, &CameraStyleInteractor::updateActionGroup);
54  mGroup = vg;
55  if (mGroup)
56  connect(mGroup.get(), &ViewGroupData::optionsChanged, this, &CameraStyleInteractor::updateActionGroup);
57  this->updateActionGroup();
58 }
59 
61 {
62  if (mCameraStyleGroup)
63  return mCameraStyleGroup;
64 
65  mCameraStyleGroup = new QActionGroup(this);
66  mCameraStyleGroup->setExclusive(true);
67 
68  this->addInteractorStyleAction("Normal Camera", mCameraStyleGroup,
70  QIcon(":/icons/camera-n.png"),
71  "Set 3D interaction to the normal camera-oriented style.");
72  this->addInteractorStyleAction("Tool", mCameraStyleGroup,
74  QIcon(":/icons/camera-t.png"),
75  "Camera following tool.");
76  this->addInteractorStyleAction("Angled Tool", mCameraStyleGroup,
78  QIcon(":/icons/camera-at.png"),
79  "Camera following tool (Placed at an angle of 20 degrees).");
80  this->addInteractorStyleAction("Unicam", mCameraStyleGroup,
82  QIcon(":/icons/camera-u.png"),
83  "Set 3D interaction to a single-button style, useful for touch screens.");
84  return mCameraStyleGroup;
85 }
86 
87 void CameraStyleInteractor::addInteractorStyleAction(QString caption, QActionGroup* group, QString uid, QIcon icon,
88  QString helptext)
89 {
90  QAction* action = new QAction(caption, group);
91  action->setIcon(icon);
92  action->setCheckable(true);
93  action->setData(uid);
94  action->setToolTip(helptext);
95  action->setWhatsThis(helptext);
96  connect(action, SIGNAL(triggered(bool)), this, SLOT(setInteractionStyleActionSlot()));
97 }
98 
99 void CameraStyleInteractor::updateActionGroup()
100 {
101  QString currentStyle;
102  if (mGroup)
103  currentStyle = enum2string(mGroup->getOptions().mCameraStyle.getStyle());
104 
105  if(mCameraStyleGroup)
106  {
107  QList<QAction*> actions = mCameraStyleGroup->actions();
108  for (int i=0; i<actions.size(); ++i)
109  {
110  actions[i]->setEnabled(mGroup!=0);
111  bool check = actions[i]->data().toString() == currentStyle;
112  if(actions[i]->isChecked() != check)
113  actions[i]->setChecked(check);
114  }
115  }
116 }
117 
118 void CameraStyleInteractor::setInteractionStyleActionSlot()
119 {
120  QAction* theAction = static_cast<QAction*>(sender());
121  if(!theAction)
122  return;
123 
124  QString uid = theAction->data().toString();
125  CAMERA_STYLE_TYPE newStyle = string2enum<cx::CAMERA_STYLE_TYPE>(uid);
126  if (newStyle==cstCOUNT)
127  return;
128 
129  if (mGroup)
130  {
131  ViewGroupData::Options options = mGroup->getOptions();
132  options.mCameraStyle = CameraStyleData(newStyle);
133  mGroup->setOptions(options);
134  }
135 }
136 
137 
138 
139 }//namespace cx
boost::shared_ptr< class ViewGroupData > ViewGroupDataPtr
Definition: cxViewGroup.h:50
void connectCameraStyle(ViewGroupDataPtr vg)
cstTOOL_STYLE
Definition: cxViewService.h:55
cstDEFAULT_STYLE
Definition: cxViewService.h:55
QActionGroup * getInteractorStyleActionGroup()
cstANGLED_TOOL_STYLE
Definition: cxViewService.h:55
cstUNICAM_STYLE
Definition: cxViewService.h:55
QString enum2string(const ENUM &val)
Namespace for all CustusX production code.