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()
124 this->createAction(
"ConfigureTools",
"Tool configuration",
125 QIcon(), QKeySequence(),
"",
126 &MainWindowActions::configureSlot);
129 this->createAction(
"InitializeTools",
"Initialize",
130 QIcon(), QKeySequence(),
"",
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");});
194 QAction* MainWindowActions::createAction(QString uid, QString text, QIcon icon,
195 QKeySequence shortcut, QString help,
198 QAction* retval =
new QAction(icon, text,
this);
199 retval->setObjectName(uid);
200 retval->setShortcut(shortcut);
201 retval->setStatusTip(help);
202 connect(retval, &QAction::triggered,
this, triggerSlot);
203 mActions[uid] = retval;
209 QString timestampFormatFolderFriendly()
211 return QString(
"yyyy-MM-dd_hh-mm");
215 QWidget* MainWindowActions::parentWidget()
217 return dynamic_cast<QWidget*
>(this->parent());
221 void MainWindowActions::newPatientSlot()
223 QString choosenDir = this->selectNewPatientFolder();
224 if(choosenDir.isEmpty())
228 int patientNumber =
settings()->
value(
"globalPatientNumber").toInt();
231 mServices->session()->load(choosenDir);
234 QString MainWindowActions::selectNewPatientFolder()
236 QString patientDatafolder = this->getExistingSessionFolder();
238 QString timestamp = QDateTime::currentDateTime().toString(timestampFormatFolderFriendly());
239 QString filename = QString(
"%1_%2_%3.cx3")
244 QString choosenDir = patientDatafolder +
"/" + filename;
246 QFileDialog dialog(this->parentWidget(), tr(
"Select directory to save patient in"), patientDatafolder +
"/");
247 dialog.setOption(QFileDialog::DontUseNativeDialog,
true);
248 dialog.setOption(QFileDialog::ShowDirsOnly,
true);
249 dialog.selectFile(filename);
252 choosenDir = dialog.selectedFiles().front();
254 if (!choosenDir.endsWith(
".cx3"))
255 choosenDir += QString(
".cx3");
260 QString MainWindowActions::getExistingSessionFolder()
262 return profile()->getSessionRootFolder();
265 void MainWindowActions::clearPatientSlot()
267 mServices->session()->clear();
270 void MainWindowActions::savePatientFileSlot()
272 if (mServices->patient()->getActivePatientFolder().isEmpty())
274 reportWarning(
"No patient selected, select or create patient before saving!");
275 this->newPatientSlot();
279 mServices->session()->save();
282 void MainWindowActions::loadPatientFileSlot()
284 QString patientDatafolder = this->getExistingSessionFolder();
287 QString folder = QFileDialog::getExistingDirectory(this->parentWidget(),
"Select patient", patientDatafolder, QFileDialog::ShowDirsOnly);
288 if (folder.isEmpty())
291 mServices->session()->load(folder);
294 void MainWindowActions::loadPatientFileCopySlot()
296 QString patientDatafolder =
profile()->getPatientTemplatePath();
299 QString folder = QFileDialog::getExistingDirectory(this->parentWidget(),
"Select template patient to copy", patientDatafolder, QFileDialog::ShowDirsOnly);
300 if (folder.isEmpty())
303 QString newFolder = this->selectNewPatientFolder();
304 if (newFolder.isEmpty())
309 CX_LOG_WARNING() <<
"MainWindowActions::loadPatientFileCopySlot(): Cannot copy patient folder: " << folder;
313 mServices->session()->load(newFolder);
316 void MainWindowActions::exportDataSlot()
318 this->savePatientFileSlot();
324 void MainWindowActions::importDataSlot(QString actionText)
326 this->savePatientFileSlot();
328 QDockWidget* importDockWidget = findMainWindowChildWithObjectName<QDockWidget*>(
"import_widgetDockWidget");
329 if(!importDockWidget)
331 CX_LOG_ERROR() <<
"Cannot find DockWidget for ImportWidget";
335 importDockWidget->show();
336 importDockWidget->raise();
338 QWidget* widget = findMainWindowChildWithObjectName<QWidget*>(
"import_widget");
345 bool actionFound =
false;
346 QList<QAction*> actions = widget->actions();
347 foreach(QAction* action, actions)
349 if(action->text().contains(actionText))
356 CX_LOG_ERROR() <<
"MainWindowActions::importDataSlot, action not found: " << actionText;
359 void MainWindowActions::shootScreen()
361 mScreenShotWriter->grabAllScreensToFile();
364 void MainWindowActions::shootWindow()
369 while (mServices->view()->getLayoutWidget(index))
370 this->shootOneLayout(index++);
373 void MainWindowActions::shootOneLayout(
int index)
375 QWidget* widget = mServices->view()->getLayoutWidget(index);
380 mScreenShotWriter->save(pm, QString(
"_layout%1").arg(index));
383 void MainWindowActions::recordFullscreen()
385 QString path = mServices->patient()->generateFilePath(
"Screenshots",
"mp4");
387 if(
vlc()->isRecording())
393 void MainWindowActions::updateRecordFullscreenActionSlot()
395 mRecordFullscreenStreamingAction->setCheckable(
true);
396 mRecordFullscreenStreamingAction->blockSignals(
true);
397 mRecordFullscreenStreamingAction->setChecked(
vlc()->isRecording());
398 mRecordFullscreenStreamingAction->blockSignals(
false);
400 if(
vlc()->isRecording())
402 mRecordFullscreenStreamingAction->setIcon(QIcon(
":/icons/Video-icon_green.png"));
406 mRecordFullscreenStreamingAction->setIcon(QIcon(
":/icons/Video-icon_gray.png"));
411 void MainWindowActions::onStartLogConsole()
415 mLocalVideoServerProcess.reset(
new ProcessWrapper(QString(
"LogConsole")));
416 mLocalVideoServerProcess->launchWithRelativePath(fullname, QStringList());
419 void MainWindowActions::toggleStreamingSlot()
421 if (mServices->video()->isConnected())
422 mServices->video()->closeConnection();
424 mServices->video()->openConnection();
427 void MainWindowActions::updateStreamingActionSlot()
429 if (mServices->video()->isConnected())
431 mStartStreamingAction->setIcon(QIcon(
":/icons/streaming_green.png"));
432 mStartStreamingAction->setText(
"Stop Streaming");
436 mStartStreamingAction->setIcon(QIcon(
":/icons/streaming_red.png"));
437 mStartStreamingAction->setText(
"Start Streaming");
441 void MainWindowActions::centerToImageCenterSlot()
443 mServices->view()->centerToImageCenterInActiveViewGroup();
446 void MainWindowActions::centerToTooltipSlot()
449 nav->centerToTooltip();
452 void MainWindowActions::togglePointPickerActionSlot()
457 data->setOptions(options);
459 void MainWindowActions::updatePointPickerActionSlot()
461 if (!mServices->view()->getGroup(0))
463 bool show = mServices->view()->getGroup(0)->getOptions().mShowPointPickerProbe;
464 mShowPointPickerAction->setChecked(show);
467 void MainWindowActions::updateTrackingActionSlot()
471 mTrackingToolsAction->setIcon(QIcon(
":/icons/polaris-green.png"));
472 mTrackingToolsAction->setText(
"Stop Tracking");
476 mTrackingToolsAction->setIcon(QIcon(
":/icons/polaris-red.png"));
477 mTrackingToolsAction->setText(
"Start Tracking");
481 void MainWindowActions::configureSlot()
486 void MainWindowActions::toggleTrackingSlot()
494 void MainWindowActions::onGotoDocumentation()
497 QDesktopServices::openUrl(QUrl(url, QUrl::TolerantMode));
cxResource_EXPORT ProfilePtr profile()
boost::shared_ptr< class ViewGroupData > ViewGroupDataPtr
boost::shared_ptr< class VisServices > VisServicesPtr
std::string toString(T const &value)
converts any type to a string
static QString getWebsiteUserDocumentationURL()
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
void startRecording(QString saveFile)
bool copyRecursively(QString sourceDir, QString destinationDir, bool overWriteDirectory)
void setValue(const QString &key, const QVariant &value)
static QImage vtkImageData2QImage(vtkImageDataPtr input)
void reportWarning(QString msg)
MainWindowActions(VisServicesPtr services, QWidget *parent)
virtual void setState(const Tool::State val)=0
Settings * settings()
Shortcut for accessing the settings instance.
QAction * getAction(QString uid)
static QString findExecutableInStandardLocations(QString filename)
look for an exe in the same folder as the executable or bundle.
boost::shared_ptr< class Navigation > NavigationPtr
bool mShowPointPickerProbe
VLCRecorder * vlc()
Shortcut for accessing the vlc recorder.
Namespace for all CustusX production code.