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