3 #include <QtConcurrent>
8 #include <QDesktopWidget>
10 #include <QApplication>
11 #include <QDesktopServices>
12 #include <QDockWidget>
15 #include "boost/bind.hpp"
16 #include "boost/function.hpp"
52 this->createActions();
57 if (!mActions.count(uid))
58 CX_LOG_ERROR() << QString(
"Could not find action %1 in MainWindowActions object").arg(uid);
62 void MainWindowActions::createActions()
64 this->createAction(
"GotoDocumentation",
"Web Documentation",
65 QIcon(
":/icons/open_icon_library/applications-internet.png"),
67 &MainWindowActions::onGotoDocumentation);
69 this->createAction(
"StartLogConsole",
"Start Log Console",
71 QKeySequence(
"Ctrl+D"),
"Open Log Console as external application",
72 &MainWindowActions::onStartLogConsole);
74 this->createAction(
"ShootScreen",
"Shoot Screen",
75 QIcon(
":/icons/screenshot-screen.png"),
76 QKeySequence(
"Ctrl+f"),
"Save a screenshot to the patient folder.",
77 &MainWindowActions::shootScreen);
79 this->createAction(
"ShootWindow",
"Shoot Window",
80 QIcon(
":/icons/screenshot-window.png"),
81 QKeySequence(
"Ctrl+Shift+f"),
"Save an image of the application to the patient folder.",
82 &MainWindowActions::shootWindow);
84 mRecordFullscreenStreamingAction = this->createAction(
"RecordFullscreen",
"Record Fullscreen video with VLC (needs to be at least 7 sec to work)",
86 QKeySequence(
"F8"),
"Record a video of the full screen.",
87 &MainWindowActions::recordFullscreen);
89 this->updateRecordFullscreenActionSlot();
91 mShowPointPickerAction = this->createAction(
"ShowPointPicker",
"Point Picker",
92 QIcon(
":/icons/point_picker.png"),
93 QKeySequence(
""),
"Activate the 3D Point Picker Probe",
94 &MainWindowActions::togglePointPickerActionSlot);
95 mShowPointPickerAction->setCheckable(
true);
97 if (mServices->view()->getGroup(0))
99 this->updatePointPickerActionSlot();
101 mStartStreamingAction = this->createAction(
"StartStreaming",
"Start Streaming",
102 QIcon(
":/icons/open_icon_library/.png"),
103 QKeySequence(
"Ctrl+V"),
"",
104 &MainWindowActions::toggleStreamingSlot);
105 connect(mServices->video().get(), &
VideoService::connected,
this, &MainWindowActions::updateStreamingActionSlot);
106 this->updateStreamingActionSlot();
108 this->createAction(
"CenterToImageCenter",
"Center Image",
109 QIcon(
":/icons/center_image.png"),
111 &MainWindowActions::centerToImageCenterSlot);
113 this->createAction(
"CenterToTooltip",
"Center Tool",
114 QIcon(
":/icons/center_tool.png"),
115 QKeySequence(
""),
"",
116 &MainWindowActions::centerToTooltipSlot);
118 this->createPatientActions();
119 this->createTrackingActions();
122 void MainWindowActions::createTrackingActions()
133 mTrackingToolsAction = this->createAction(
"TrackingTools",
"Start tracking",
134 QIcon(), QKeySequence(
"Ctrl+T"),
"",
135 &MainWindowActions::toggleTrackingSlot);
138 this->updateTrackingActionSlot();
141 void MainWindowActions::createPatientActions()
143 this->createAction(
"NewPatient",
"New Patient",
144 QIcon(
":/icons/open_icon_library/document-new-8.png"),
145 QKeySequence(
"Ctrl+N"),
146 "Create a new patient file",
147 &MainWindowActions::newPatientSlot);
149 this->createAction(
"SaveFile",
"Save Patient",
150 QIcon(
":/icons/open_icon_library/document-save-5.png"),
151 QKeySequence(
"Ctrl+S"),
153 &MainWindowActions::savePatientFileSlot);
155 this->createAction(
"LoadFile",
"Load Patient",
156 QIcon(
":/icons/open_icon_library/document-open-7.png"),
157 QKeySequence(
"Ctrl+L"),
159 &MainWindowActions::loadPatientFileSlot);
161 this->createAction(
"LoadFileCopy",
"Load from Patient template",
162 QIcon(
":/icons/open_icon_library/document-open-7.png"),
164 "Create a new patient based on a template",
165 &MainWindowActions::loadPatientFileCopySlot);
167 this->createAction(
"ClearPatient",
"Clear Patient",
170 "Clear the current patient from the application",
171 &MainWindowActions::clearPatientSlot);
173 this->createAction(
"ExportPatient",
"Export Patient",
176 "Export patient data to a folder",
177 &MainWindowActions::exportDataSlot);
180 this->createAction(
"AddFilesForImport",
"Add files for import",
181 QIcon(
":/icons/open_icon_library/document-import-2.png"),
182 QKeySequence(
"Ctrl+I"),
183 "Add files to be imported",
184 [=](){this->importDataSlot(
"AddMoreFilesButtonClickedAction");});
186 this->createAction(
"ImportSelectedData",
"Import selected data",
189 "Import all selected data files",
190 [=](){this->importDataSlot(
"ImportButtonClickedAction");});
192 this->createAction(
"AddFilesForImportWithDialog",
"Add files for import (Dialog)",
195 "Add files to be imported",
196 [=](){this->importDataSlot(
"AddFilesForImportWithDialogAction");});
200 QAction* MainWindowActions::createAction(QString uid, QString text, QIcon icon,
201 QKeySequence shortcut, QString help,
204 QAction* retval =
new QAction(icon, text,
this);
205 retval->setObjectName(uid);
206 retval->setShortcut(shortcut);
207 retval->setStatusTip(help);
208 connect(retval, &QAction::triggered,
this, triggerSlot);
209 mActions[uid] = retval;
215 QString timestampFormatFolderFriendly()
217 return QString(
"yyyy-MM-dd_hh-mm");
221 QWidget* MainWindowActions::parentWidget()
223 return dynamic_cast<QWidget*
>(this->parent());
227 void MainWindowActions::newPatientSlot()
229 QString choosenDir = this->selectNewPatientFolder();
230 if(choosenDir.isEmpty())
234 int patientNumber =
settings()->
value(
"globalPatientNumber").toInt();
237 mServices->session()->load(choosenDir);
240 QString MainWindowActions::selectNewPatientFolder()
242 QString patientDatafolder = this->getExistingSessionFolder();
244 QString timestamp = QDateTime::currentDateTime().toString(timestampFormatFolderFriendly());
245 QString filename = QString(
"%1_%2_%3.cx3")
248 .arg(
settings()->value(
"globalPatientNumber").toString());
250 QString choosenDir = patientDatafolder +
"/" + filename;
252 QFileDialog dialog(this->parentWidget(), tr(
"Select directory to save patient in"), patientDatafolder +
"/");
253 dialog.setOption(QFileDialog::DontUseNativeDialog,
true);
254 dialog.setOption(QFileDialog::ShowDirsOnly,
true);
255 dialog.selectFile(filename);
258 choosenDir = dialog.selectedFiles().front();
260 if (!choosenDir.endsWith(
".cx3"))
261 choosenDir += QString(
".cx3");
266 QString MainWindowActions::getExistingSessionFolder()
268 return profile()->getSessionRootFolder();
271 void MainWindowActions::clearPatientSlot()
273 mServices->session()->clear();
276 void MainWindowActions::savePatientFileSlot()
278 if (mServices->patient()->getActivePatientFolder().isEmpty())
280 reportWarning(
"No patient selected, select or create patient before saving!");
281 this->newPatientSlot();
285 mServices->session()->save();
288 void MainWindowActions::loadPatientFileSlot()
290 QString patientDatafolder = this->getExistingSessionFolder();
293 QString folder = QFileDialog::getExistingDirectory(this->parentWidget(),
"Select patient", patientDatafolder, QFileDialog::ShowDirsOnly);
294 if (folder.isEmpty())
297 mServices->session()->load(folder);
300 void MainWindowActions::loadPatientFileCopySlot()
302 QString patientDatafolder =
profile()->getPatientTemplatePath();
305 QString folder = QFileDialog::getExistingDirectory(this->parentWidget(),
"Select template patient to copy", patientDatafolder, QFileDialog::ShowDirsOnly);
306 if (folder.isEmpty())
309 QString newFolder = this->selectNewPatientFolder();
310 if (newFolder.isEmpty())
315 CX_LOG_WARNING() <<
"MainWindowActions::loadPatientFileCopySlot(): Cannot copy patient folder: " << folder;
319 mServices->session()->load(newFolder);
322 void MainWindowActions::exportDataSlot()
324 this->savePatientFileSlot();
326 ExportDataDialog* wizard =
new ExportDataDialog(mServices->patient(), this->parentWidget());
330 void MainWindowActions::importDataSlot(QString actionText)
332 this->savePatientFileSlot();
334 QDockWidget* importDockWidget = findMainWindowChildWithObjectName<QDockWidget*>(
"import_widgetDockWidget");
335 if(!importDockWidget)
337 CX_LOG_ERROR() <<
"Cannot find DockWidget for ImportWidget";
341 importDockWidget->show();
342 importDockWidget->raise();
344 QWidget* widget = findMainWindowChildWithObjectName<QWidget*>(
"import_widget");
351 bool actionFound =
false;
352 QList<QAction*> actions = widget->actions();
353 foreach(QAction* action, actions)
355 if(action->text().contains(actionText))
362 CX_LOG_ERROR() <<
"MainWindowActions::importDataSlot, action not found: " << actionText;
365 void MainWindowActions::shootScreen()
367 mScreenShotWriter->grabAllScreensToFile();
370 void MainWindowActions::shootWindow()
375 while (mServices->view()->getLayoutWidget(index))
376 this->shootOneLayout(index++);
379 void MainWindowActions::shootOneLayout(
int index)
381 QWidget* widget = mServices->view()->getLayoutWidget(index);
382 ViewCollectionWidget* vcWidget =
dynamic_cast<ViewCollectionWidget*
>(widget);
384 ViewCollectionImageWriter grabber(vcWidget);
386 mScreenShotWriter->save(pm, QString(
"_layout%1").arg(index));
389 void MainWindowActions::recordFullscreen()
391 QString path = mServices->patient()->generateFilePath(
"Screenshots",
"mp4");
393 if(
vlc()->isRecording())
399 void MainWindowActions::updateRecordFullscreenActionSlot()
401 mRecordFullscreenStreamingAction->setCheckable(
true);
402 mRecordFullscreenStreamingAction->blockSignals(
true);
403 mRecordFullscreenStreamingAction->setChecked(
vlc()->isRecording());
404 mRecordFullscreenStreamingAction->blockSignals(
false);
406 if(
vlc()->isRecording())
408 mRecordFullscreenStreamingAction->setIcon(QIcon(
":/icons/Video-icon_green.png"));
412 mRecordFullscreenStreamingAction->setIcon(QIcon(
":/icons/Video-icon_gray.png"));
417 void MainWindowActions::onStartLogConsole()
421 mLocalVideoServerProcess.reset(
new ProcessWrapper(QString(
"LogConsole")));
422 mLocalVideoServerProcess->launchWithRelativePath(fullname, QStringList());
425 void MainWindowActions::toggleStreamingSlot()
427 if (mServices->video()->isConnected())
428 mServices->video()->closeConnection();
430 mServices->video()->openConnection();
433 void MainWindowActions::updateStreamingActionSlot()
435 if (mServices->video()->isConnected())
437 mStartStreamingAction->setIcon(QIcon(
":/icons/streaming_green.png"));
438 mStartStreamingAction->setText(
"Stop Streaming");
442 mStartStreamingAction->setIcon(QIcon(
":/icons/streaming_red.png"));
443 mStartStreamingAction->setText(
"Start Streaming");
447 void MainWindowActions::centerToImageCenterSlot()
449 mServices->view()->centerToImageCenterInActiveViewGroup();
452 void MainWindowActions::centerToTooltipSlot()
455 nav->centerToTooltip();
458 void MainWindowActions::togglePointPickerActionSlot()
461 ViewGroupData::Options options = data->getOptions();
462 options.mShowPointPickerProbe = !options.mShowPointPickerProbe;
463 data->setOptions(options);
465 void MainWindowActions::updatePointPickerActionSlot()
467 if (!mServices->view()->getGroup(0))
469 bool show = mServices->view()->getGroup(0)->getOptions().mShowPointPickerProbe;
470 mShowPointPickerAction->setChecked(show);
473 void MainWindowActions::updateTrackingActionSlot()
477 mTrackingToolsAction->setIcon(QIcon(
":/icons/polaris-green.png"));
478 mTrackingToolsAction->setText(
"Stop Tracking");
482 mTrackingToolsAction->setIcon(QIcon(
":/icons/polaris-red.png"));
483 mTrackingToolsAction->setText(
"Start Tracking");
487 void MainWindowActions::configureSlot()
492 void MainWindowActions::toggleTrackingSlot()
500 void MainWindowActions::onGotoDocumentation()
503 QDesktopServices::openUrl(QUrl(url, QUrl::TolerantMode));