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