3 #include <QtConcurrent> 8 #include <QDesktopWidget> 10 #include <QApplication> 11 #include <QDesktopServices> 13 #include "boost/bind.hpp" 14 #include "boost/function.hpp" 47 this->createActions();
52 if (!mActions.count(uid))
53 CX_LOG_ERROR() << QString(
"Could not find action %1 in MainWindowActions object").arg(uid);
57 void MainWindowActions::createActions()
59 this->createAction(
"GotoDocumentation",
"Web Documentation",
60 QIcon(
":/icons/open_icon_library/applications-internet.png"),
62 &MainWindowActions::onGotoDocumentation);
64 this->createAction(
"StartLogConsole",
"Start Log Console",
66 QKeySequence(
"Ctrl+D"),
"Open Log Console as external application",
67 &MainWindowActions::onStartLogConsole);
69 this->createAction(
"ShootScreen",
"Shoot Screen",
70 QIcon(
":/icons/screenshot-screen.png"),
71 QKeySequence(
"Ctrl+f"),
"Save a screenshot to the patient folder.",
72 &MainWindowActions::shootScreen);
74 this->createAction(
"ShootWindow",
"Shoot Window",
75 QIcon(
":/icons/screenshot-window.png"),
76 QKeySequence(
"Ctrl+Shift+f"),
"Save an image of the application to the patient folder.",
77 &MainWindowActions::shootWindow);
79 mRecordFullscreenStreamingAction = this->createAction(
"RecordFullscreen",
"Record Fullscreen",
81 QKeySequence(
"F8"),
"Record a video of the full screen.",
82 &MainWindowActions::recordFullscreen);
84 this->updateRecordFullscreenActionSlot();
86 mShowPointPickerAction = this->createAction(
"ShowPointPicker",
"Point Picker",
87 QIcon(
":/icons/point_picker.png"),
88 QKeySequence(
""),
"Activate the 3D Point Picker Probe",
89 &MainWindowActions::togglePointPickerActionSlot);
90 mShowPointPickerAction->setCheckable(
true);
92 if (mServices->view()->getGroup(0))
94 this->updatePointPickerActionSlot();
96 mStartStreamingAction = this->createAction(
"StartStreaming",
"Start Streaming",
97 QIcon(
":/icons/open_icon_library/.png"),
98 QKeySequence(
"Ctrl+V"),
"",
99 &MainWindowActions::toggleStreamingSlot);
100 connect(mServices->video().get(), &
VideoService::connected,
this, &MainWindowActions::updateStreamingActionSlot);
101 this->updateStreamingActionSlot();
103 this->createAction(
"CenterToImageCenter",
"Center Image",
104 QIcon(
":/icons/center_image.png"),
106 &MainWindowActions::centerToImageCenterSlot);
108 this->createAction(
"CenterToTooltip",
"Center Tool",
109 QIcon(
":/icons/center_tool.png"),
110 QKeySequence(
""),
"",
111 &MainWindowActions::centerToTooltipSlot);
113 this->createPatientActions();
114 this->createTrackingActions();
117 void MainWindowActions::createTrackingActions()
119 this->createAction(
"ConfigureTools",
"Tool configuration",
120 QIcon(), QKeySequence(),
"",
121 &MainWindowActions::configureSlot);
124 this->createAction(
"InitializeTools",
"Initialize",
125 QIcon(), QKeySequence(),
"",
128 mTrackingToolsAction = this->createAction(
"TrackingTools",
"Start tracking",
129 QIcon(), QKeySequence(
"Ctrl+T"),
"",
130 &MainWindowActions::toggleTrackingSlot);
133 this->updateTrackingActionSlot();
136 void MainWindowActions::createPatientActions()
138 this->createAction(
"NewPatient",
"New Patient",
139 QIcon(
":/icons/open_icon_library/document-new-8.png"),
140 QKeySequence(
"Ctrl+N"),
141 "Create a new patient file",
142 &MainWindowActions::newPatientSlot);
144 this->createAction(
"SaveFile",
"Save Patient",
145 QIcon(
":/icons/open_icon_library/document-save-5.png"),
146 QKeySequence(
"Ctrl+S"),
148 &MainWindowActions::savePatientFileSlot);
150 this->createAction(
"LoadFile",
"Load Patient",
151 QIcon(
":/icons/open_icon_library/document-open-7.png"),
152 QKeySequence(
"Ctrl+L"),
154 &MainWindowActions::loadPatientFileSlot);
156 this->createAction(
"LoadFileCopy",
"Load from Patient template",
157 QIcon(
":/icons/open_icon_library/document-open-7.png"),
159 "Create a new patient based on a template",
160 &MainWindowActions::loadPatientFileCopySlot);
162 this->createAction(
"ClearPatient",
"Clear Patient",
165 "Clear the current patient from the application",
166 &MainWindowActions::clearPatientSlot);
168 this->createAction(
"ExportPatient",
"Export Patient",
171 "Export patient data to a folder",
172 &MainWindowActions::exportDataSlot);
174 this->createAction(
"ImportData",
"Import data",
175 QIcon(
":/icons/open_icon_library/document-import-2.png"),
176 QKeySequence(
"Ctrl+I"),
178 &MainWindowActions::importDataSlot);
182 QAction* MainWindowActions::createAction(QString uid, QString text, QIcon icon,
183 QKeySequence shortcut, QString help,
186 QAction* retval =
new QAction(icon, text,
this);
187 retval->setObjectName(uid);
188 retval->setShortcut(shortcut);
189 retval->setStatusTip(help);
190 connect(retval, &QAction::triggered,
this, triggerSlot);
191 mActions[uid] = retval;
197 QString timestampFormatFolderFriendly()
199 return QString(
"yyyy-MM-dd_hh-mm");
203 QWidget* MainWindowActions::parentWidget()
205 return dynamic_cast<QWidget*
>(this->parent());
209 void MainWindowActions::newPatientSlot()
211 QString choosenDir = this->selectNewPatientFolder();
212 if(choosenDir.isEmpty())
216 int patientNumber =
settings()->
value(
"globalPatientNumber").toInt();
219 mServices->session()->load(choosenDir);
222 QString MainWindowActions::selectNewPatientFolder()
224 QString patientDatafolder = this->getExistingSessionFolder();
226 QString timestamp = QDateTime::currentDateTime().toString(timestampFormatFolderFriendly());
227 QString filename = QString(
"%1_%2_%3.cx3")
232 QString choosenDir = patientDatafolder +
"/" + filename;
234 QFileDialog dialog(this->parentWidget(), tr(
"Select directory to save patient in"), patientDatafolder +
"/");
235 dialog.setOption(QFileDialog::DontUseNativeDialog,
true);
236 dialog.setOption(QFileDialog::ShowDirsOnly,
true);
237 dialog.selectFile(filename);
240 choosenDir = dialog.selectedFiles().front();
242 if (!choosenDir.endsWith(
".cx3"))
243 choosenDir += QString(
".cx3");
248 QString MainWindowActions::getExistingSessionFolder()
250 return profile()->getSessionRootFolder();
253 void MainWindowActions::clearPatientSlot()
255 mServices->session()->clear();
258 void MainWindowActions::savePatientFileSlot()
260 if (mServices->patient()->getActivePatientFolder().isEmpty())
262 reportWarning(
"No patient selected, select or create patient before saving!");
263 this->newPatientSlot();
267 mServices->session()->save();
270 void MainWindowActions::loadPatientFileSlot()
272 QString patientDatafolder = this->getExistingSessionFolder();
275 QString folder = QFileDialog::getExistingDirectory(this->parentWidget(),
"Select patient", patientDatafolder, QFileDialog::ShowDirsOnly);
276 if (folder.isEmpty())
279 mServices->session()->load(folder);
282 void MainWindowActions::loadPatientFileCopySlot()
284 QString patientDatafolder =
profile()->getPatientTemplatePath();
287 QString folder = QFileDialog::getExistingDirectory(this->parentWidget(),
"Select template patient to copy", patientDatafolder, QFileDialog::ShowDirsOnly);
288 if (folder.isEmpty())
291 QString newFolder = this->selectNewPatientFolder();
292 if (newFolder.isEmpty())
297 CX_LOG_WARNING() <<
"MainWindowActions::loadPatientFileCopySlot(): Cannot copy patient folder: " << folder;
301 mServices->session()->load(newFolder);
304 void MainWindowActions::exportDataSlot()
306 this->savePatientFileSlot();
312 void MainWindowActions::importDataSlot()
314 this->savePatientFileSlot();
316 QString folder = mLastImportDataFolder;
317 if (folder.isEmpty())
318 folder =
profile()->getSessionRootFolder();
320 QStringList fileName = QFileDialog::getOpenFileNames(this->parentWidget(), QString(tr(
"Select data file(s) for import")),
321 folder, tr(
"Image/Mesh (*.mhd *.mha *.nii *.stl *.vtk *.vtp *.mnc *.png)"));
322 if (fileName.empty())
324 report(
"Import canceled");
328 mLastImportDataFolder = QFileInfo(fileName[0]).absolutePath();
330 for (
int i=0; i<fileName.size(); ++i)
337 void MainWindowActions::shootScreen()
339 mScreenShotWriter->grabAllScreensToFile();
342 void MainWindowActions::shootWindow()
347 while (mServices->view()->getLayoutWidget(index))
348 this->shootOneLayout(index++);
351 void MainWindowActions::shootOneLayout(
int index)
353 QWidget* widget = mServices->view()->getLayoutWidget(index);
358 mScreenShotWriter->save(pm, QString(
"_layout%1").arg(index));
361 void MainWindowActions::recordFullscreen()
363 QString path = mServices->patient()->generateFilePath(
"Screenshots",
"mp4");
365 if(
vlc()->isRecording())
371 void MainWindowActions::updateRecordFullscreenActionSlot()
373 mRecordFullscreenStreamingAction->setCheckable(
true);
374 mRecordFullscreenStreamingAction->blockSignals(
true);
375 mRecordFullscreenStreamingAction->setChecked(
vlc()->isRecording());
376 mRecordFullscreenStreamingAction->blockSignals(
false);
378 if(
vlc()->isRecording())
380 mRecordFullscreenStreamingAction->setIcon(QIcon(
":/icons/Video-icon_green.png"));
384 mRecordFullscreenStreamingAction->setIcon(QIcon(
":/icons/Video-icon_gray.png"));
389 void MainWindowActions::onStartLogConsole()
393 mLocalVideoServerProcess.reset(
new ProcessWrapper(QString(
"LogConsole")));
394 mLocalVideoServerProcess->launchWithRelativePath(fullname, QStringList());
397 void MainWindowActions::toggleStreamingSlot()
399 if (mServices->video()->isConnected())
400 mServices->video()->closeConnection();
402 mServices->video()->openConnection();
405 void MainWindowActions::updateStreamingActionSlot()
407 if (mServices->video()->isConnected())
409 mStartStreamingAction->setIcon(QIcon(
":/icons/streaming_green.png"));
410 mStartStreamingAction->setText(
"Stop Streaming");
414 mStartStreamingAction->setIcon(QIcon(
":/icons/streaming_red.png"));
415 mStartStreamingAction->setText(
"Start Streaming");
419 void MainWindowActions::centerToImageCenterSlot()
421 mServices->view()->centerToImageCenterInActiveViewGroup();
424 void MainWindowActions::centerToTooltipSlot()
427 nav->centerToTooltip();
430 void MainWindowActions::togglePointPickerActionSlot()
435 data->setOptions(options);
437 void MainWindowActions::updatePointPickerActionSlot()
439 if (!mServices->view()->getGroup(0))
441 bool show = mServices->view()->getGroup(0)->getOptions().mShowPointPickerProbe;
442 mShowPointPickerAction->setChecked(show);
445 void MainWindowActions::updateTrackingActionSlot()
449 mTrackingToolsAction->setIcon(QIcon(
":/icons/polaris-green.png"));
450 mTrackingToolsAction->setText(
"Stop Tracking");
454 mTrackingToolsAction->setIcon(QIcon(
":/icons/polaris-red.png"));
455 mTrackingToolsAction->setText(
"Start Tracking");
459 void MainWindowActions::configureSlot()
464 void MainWindowActions::toggleTrackingSlot()
472 void MainWindowActions::onGotoDocumentation()
475 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.