CustusX  15.3.4-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxGeneralTab.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 "cxGeneralTab.h"
34 
35 #include <QLabel>
36 #include <QToolButton>
37 #include <QGridLayout>
38 #include <QFileDialog>
39 #include "cxSettings.h"
40 #include "cxStateService.h"
41 #include "cxVLCRecorder.h"
42 #include "cxHelperWidgets.h"
43 #include <QAction>
44 #include <QInputDialog>
45 #include "cxProfile.h"
46 #include "cxLogicManager.h"
47 
48 namespace cx
49 {
50 
51 GeneralTab::GeneralTab(VisualizationServicePtr visualizationService, PatientModelServicePtr patientModelService, QWidget *parent) :
52  PreferenceTab(parent), mVLCPath(""),
53  mVisualizationService(visualizationService),
54  mPatientModelService(patientModelService)
55 {
56  mPatientDataFolderComboBox = NULL;
57  mVLCPathComboBox = NULL;
58  mToolConfigFolderComboBox = NULL;
59 // mChooseApplicationComboBox = NULL;
60 }
61 
63 {
64  mGlobalPatientDataFolder = settings()->value("globalPatientDataFolder").toString();
65  mVLCPath = settings()->value("vlcPath").toString();
66  if(!QFile::exists(mVLCPath))
67  this->searchForVLC();
68 
69 // connect(stateService().get(), &StateService::applicationStateChanged, this, &GeneralTab::applicationStateChangedSlot);
70 
71  // patientDataFolder
72  QLabel* patientDataFolderLabel = new QLabel(tr("Patient data folder:"));
73  mPatientDataFolderComboBox = new QComboBox;
74  mPatientDataFolderComboBox->addItem( mGlobalPatientDataFolder);
75  QAction* browsePatientFolderAction = new QAction(QIcon(":/icons/open.png"), tr("B&rowse..."), this);
76  connect(browsePatientFolderAction, SIGNAL(triggered()), this, SLOT(browsePatientDataFolderSlot()));
77  QToolButton* browsePatientFolderButton = new QToolButton(this);
78  browsePatientFolderButton->setDefaultAction(browsePatientFolderAction);
79 
80  // VLC
81  QLabel* vlcPathLabel = new QLabel(tr("VLC path:"));
82  mVLCPathComboBox = new QComboBox();
83  mVLCPathComboBox->addItem( mVLCPath);
84  QAction* browseVLCPathAction = new QAction(QIcon(":/icons/open.png"), tr("Browse for VLC..."), this);
85  connect(browseVLCPathAction, SIGNAL(triggered()), this, SLOT(browseVLCPathSlot()));
86  QToolButton* browseVLCPathButton = new QToolButton(this);
87  browseVLCPathButton->setDefaultAction(browseVLCPathAction);
88 
89  // Choose application name
90 
91  StringPropertyPtr profileSelector = this->getProfileSelector();
92 
93 // QLabel* chooseApplicationLabel = new QLabel(tr("Choose application:"));
94 // mChooseApplicationComboBox = new QComboBox();
95 // setApplicationComboBox();
96 // connect(mChooseApplicationComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(currentApplicationChangedSlot(int)));
97 // this->applicationStateChangedSlot();
98 
99  bool filterToolPositions = settings()->value("TrackingPositionFilter/enabled").value<bool>();
100  mFilterToolPositions = BoolProperty::initialize("Tool smoothing", "",
101  "Smooth the tool tracking positions using a low-pass filter.",
102  filterToolPositions);
103 
104  QToolButton* addProfileButton = this->createAddProfileButton();
105 
106  // Layout
107  QGridLayout *mainLayout = new QGridLayout;
108  mainLayout->addWidget(patientDataFolderLabel, 0, 0);
109  mainLayout->addWidget(mPatientDataFolderComboBox, 0, 1);
110  mainLayout->addWidget(browsePatientFolderButton, 0, 2);
111 
112 // mainLayout->addWidget(chooseApplicationLabel, 1, 0);
113 // mainLayout->addWidget(mChooseApplicationComboBox, 1, 1);
114  createDataWidget(mVisualizationService, mPatientModelService, this, profileSelector, mainLayout, 1);
115  mainLayout->addWidget(addProfileButton, 1, 2);
116 
117  mainLayout->addWidget(vlcPathLabel, 2, 0);
118  mainLayout->addWidget(mVLCPathComboBox, 2, 1);
119  mainLayout->addWidget(browseVLCPathButton, 2, 2);
120 
121  createDataWidget(mVisualizationService, mPatientModelService, this, mFilterToolPositions, mainLayout, 3);
122 // mainLayout->addWidget(createDataWidget(this, mFilterToolPositions ));
123 
124  mTopLayout->addLayout(mainLayout);
125 }
126 
128 {}
129 
130 QToolButton* GeneralTab::createAddProfileButton()
131 {
132  QString tip = "Create a new profile based on the current";
133  QAction* action = new QAction(QIcon(":/icons/preset_save.png"), "Add", this);
134  action->setStatusTip(tip);
135  action->setWhatsThis(tip);
136  action->setToolTip(tip);
137  connect(action, &QAction::triggered, this, &GeneralTab::onAddProfile);
138 
139  QToolButton* button = new QToolButton();
140  button->setDefaultAction(action);
141  return button;
142 }
143 
144 void GeneralTab::onAddProfile()
145 {
146  QString current = ProfileManager::getInstance()->activeProfile()->getUid();
147  QStringList profiles = ProfileManager::getInstance()->getProfiles();
148  QString name;
149  for(int i=0; ; ++i)
150  {
151  name = QString("%1(%2)").arg(current).arg(i);
152  if (!profiles.contains(name, Qt::CaseInsensitive))
153  break;
154  }
155 
156  bool ok = true;
157  QString text = QInputDialog::getText(this, "Select profile name",
158  "Name", QLineEdit::Normal, name, &ok);
159  if (!ok || text.isEmpty())
160  return;
161 
162  this->selectProfile(text);
163 }
164 
165 void GeneralTab::browsePatientDataFolderSlot()
166 {
167  mGlobalPatientDataFolder = QFileDialog::getExistingDirectory(this,
168  tr("Find Patient Data Folder"),
169  mGlobalPatientDataFolder,
170  QFileDialog::ShowDirsOnly);
171  if( !mGlobalPatientDataFolder.isEmpty() ) {
172  mPatientDataFolderComboBox->addItem( mGlobalPatientDataFolder );
173  mPatientDataFolderComboBox->setCurrentIndex( mPatientDataFolderComboBox->currentIndex() + 1 );
174  }
175 }
176 
177 void GeneralTab::browseVLCPathSlot()
178 {
179  mVLCPath = QFileDialog::getOpenFileName(this, tr("Find VLC executable"));
180 
181  if(!mVLCPath.isEmpty())
182  {
183  mVLCPathComboBox->addItem( mVLCPath );
184  mVLCPathComboBox->setCurrentIndex( mVLCPathComboBox->currentIndex() + 1 );
185  }
186 }
187 
188 StringPropertyPtr GeneralTab::getProfileSelector()
189 {
190  if (!mSelector)
191  {
192  ProfileManager* manager = ProfileManager::getInstance();
193  QString defaultValue = profile()->getUid();
194  mSelector = StringProperty::initialize("profile", "Profile",
195  "Choose profile, containing settings and configuration",
196  defaultValue, manager->getProfiles(), QDomNode());
197 
198  connect(mSelector.get(), &StringProperty::valueWasSet, this, &GeneralTab::onProfileSelected);
199  connect(manager, &ProfileManager::activeProfileChanged, this, &GeneralTab::onProfileChanged);
200  }
201 
202  return mSelector;
203 }
204 
205 void GeneralTab::onProfileChanged()
206 {
207  mSelector->setValueRange(ProfileManager::getInstance()->getProfiles());
208  mSelector->setValue(profile()->getUid());
209 }
210 
211 void GeneralTab::onProfileSelected()
212 {
213  this->selectProfile(mSelector->getValue());
214 }
215 
216 void GeneralTab::selectProfile(QString uid)
217 {
218  this->rejectDialog();
220 }
221 
222 void GeneralTab::rejectDialog()
223 {
224  QObject* item = this;
225  while (item)
226  {
227  QDialog* dialog = dynamic_cast<QDialog*>(item);
228  if (dialog)
229  {
230  dialog->reject();
231  break;
232  }
233  item = item->parent();
234  }
235 }
236 
237 void GeneralTab::searchForVLC(QStringList searchPaths)
238 {
239  vlc()->findVLCApplication(searchPaths);
240  if(vlc()->hasVLCApplication())
241  mVLCPath = vlc()->getVLCPath();
242 }
243 
245 {
246  settings()->setValue("globalPatientDataFolder", mGlobalPatientDataFolder);
247  settings()->setValue("vlcPath", mVLCPath);
248  settings()->setValue("TrackingPositionFilter/enabled", mFilterToolPositions->getValue());
249  settings()->sync();
250 
251  emit savedParameters();
252 }
253 
254 } /* namespace cx */
GeneralTab(VisualizationServicePtr visualizationService, PatientModelServicePtr patientModelService, QWidget *parent=0)
cxResource_EXPORT ProfilePtr profile()
Definition: cxProfile.cpp:142
void activeProfileChanged()
static BoolPropertyPtr initialize(const QString &uid, QString name, QString help, bool value, QDomNode root=QDomNode())
ProfilePtr activeProfile()
Definition: cxProfile.cpp:267
QVBoxLayout * mTopLayout
QWidget * createDataWidget(VisualizationServicePtr visualizationService, PatientModelServicePtr patientModelService, QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: cxSettings.cpp:99
virtual ~GeneralTab()
QStringList getProfiles()
Definition: cxProfile.cpp:238
void setValue(const QString &key, const QVariant &value)
Definition: cxSettings.cpp:91
boost::shared_ptr< class StringProperty > StringPropertyPtr
void findVLCApplication(QStringList suggestedVLCLocations=QStringList())
boost::shared_ptr< class VisualizationService > VisualizationServicePtr
Definition: cxRegServices.h:43
static ProfileManager * getInstance()
returns the only instance of this class
Definition: cxProfile.cpp:149
static LogicManager * getInstance()
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
void saveParametersSlot()
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:42
void restartWithNewProfile(QString uid)
static StringPropertyPtr initialize(const QString &uid, QString name, QString help, QString value, QStringList range, QDomNode root=QDomNode())
QString getVLCPath()
VLCRecorder * vlc()
Shortcut for accessing the vlc recorder.