Medical Imaging Interaction Toolkit  2018.4.99-3e3f1a6e
Medical Imaging Interaction Toolkit
QmitkExtWorkbenchWindowAdvisor.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
15 
16 #include <QMenu>
17 #include <QMenuBar>
18 #include <QMainWindow>
19 #include <QStatusBar>
20 #include <QString>
21 #include <QFile>
22 #include <QRegExp>
23 #include <QTextStream>
24 #include <QSettings>
25 
26 #include <ctkPluginException.h>
27 #include <service/event/ctkEventAdmin.h>
28 
29 #include <berryPlatform.h>
30 #include <berryPlatformUI.h>
32 #include <berryIWorkbenchWindow.h>
33 #include <berryIWorkbenchPage.h>
37 #include <berryIProduct.h>
39 #include <berryQtPreferences.h>
40 #include <berryQtStyleManager.h>
41 #include <berryWorkbenchPlugin.h>
42 
43 #include <internal/berryQtShowViewAction.h>
44 #include <internal/berryQtOpenPerspectiveAction.h>
45 
46 #include <QmitkFileOpenAction.h>
47 #include <QmitkFileSaveAction.h>
49 #include <QmitkFileExitAction.h>
51 #include <QmitkUndoAction.h>
52 #include <QmitkRedoAction.h>
54 #include <QmitkStatusBar.h>
55 #include <QmitkProgressBar.h>
57 #include <QmitkPreferencesDialog.h>
61 
62 #include <itkConfigure.h>
63 #include <vtkConfigure.h>
64 #include <mitkVersion.h>
68 #include <mitkWorkbenchUtil.h>
69 #include <vtkVersionMacros.h>
70 
71 // UGLYYY
72 #include "internal/QmitkExtWorkbenchWindowAdvisorHack.h"
73 #include "internal/QmitkCommonExtPlugin.h"
74 #include "mitkUndoController.h"
76 #include <QToolBar>
77 #include <QToolButton>
78 #include <QMessageBox>
79 #include <QMouseEvent>
80 #include <QLabel>
81 #include <QmitkAboutDialog.h>
82 
83 QmitkExtWorkbenchWindowAdvisorHack* QmitkExtWorkbenchWindowAdvisorHack::undohack =
84  new QmitkExtWorkbenchWindowAdvisorHack();
85 
86 QString QmitkExtWorkbenchWindowAdvisor::QT_SETTINGS_FILENAME = "QtSettings.ini";
87 
89 
90 class PartListenerForTitle: public berry::IPartListener
91 {
92 public:
93 
94  PartListenerForTitle(QmitkExtWorkbenchWindowAdvisor* wa)
95  : windowAdvisor(wa)
96  {
97  }
98 
99  Events::Types GetPartEventTypes() const override
100  {
103  }
104 
106  {
107  if (ref.Cast<berry::IEditorReference> ())
108  {
109  windowAdvisor->UpdateTitle(false);
110  }
111  }
112 
114  {
115  if (ref.Cast<berry::IEditorReference> ())
116  {
117  windowAdvisor->UpdateTitle(false);
118  }
119  }
120 
121  void PartClosed(const berry::IWorkbenchPartReference::Pointer& /*ref*/) override
122  {
123  windowAdvisor->UpdateTitle(false);
124  }
125 
126  void PartHidden(const berry::IWorkbenchPartReference::Pointer& ref) override
127  {
128  if (!windowAdvisor->lastActiveEditor.Expired() &&
129  ref->GetPart(false) == windowAdvisor->lastActiveEditor.Lock())
130  {
131  windowAdvisor->UpdateTitle(true);
132  }
133  }
134 
135  void PartVisible(const berry::IWorkbenchPartReference::Pointer& ref) override
136  {
137  if (!windowAdvisor->lastActiveEditor.Expired() &&
138  ref->GetPart(false) == windowAdvisor->lastActiveEditor.Lock())
139  {
140  windowAdvisor->UpdateTitle(false);
141  }
142  }
143 
144 private:
145  QmitkExtWorkbenchWindowAdvisor* windowAdvisor;
146 };
147 
148 class PartListenerForViewNavigator: public berry::IPartListener
149 {
150 public:
151 
152  PartListenerForViewNavigator(QAction* act)
153  : viewNavigatorAction(act)
154  {
155  }
156 
157  Events::Types GetPartEventTypes() const override
158  {
161  }
162 
163  void PartOpened(const berry::IWorkbenchPartReference::Pointer& ref) override
164  {
165  if (ref->GetId()=="org.mitk.views.viewnavigatorview")
166  {
167  viewNavigatorAction->setChecked(true);
168  }
169  }
170 
171  void PartClosed(const berry::IWorkbenchPartReference::Pointer& ref) override
172  {
173  if (ref->GetId()=="org.mitk.views.viewnavigatorview")
174  {
175  viewNavigatorAction->setChecked(false);
176  }
177  }
178 
179  void PartVisible(const berry::IWorkbenchPartReference::Pointer& ref) override
180  {
181  if (ref->GetId()=="org.mitk.views.viewnavigatorview")
182  {
183  viewNavigatorAction->setChecked(true);
184  }
185  }
186 
187  void PartHidden(const berry::IWorkbenchPartReference::Pointer& ref) override
188  {
189  if (ref->GetId()=="org.mitk.views.viewnavigatorview")
190  {
191  viewNavigatorAction->setChecked(false);
192  }
193  }
194 
195 private:
196  QAction* viewNavigatorAction;
197 };
198 
199 class PartListenerForImageNavigator: public berry::IPartListener
200 {
201 public:
202 
203  PartListenerForImageNavigator(QAction* act)
204  : imageNavigatorAction(act)
205  {
206  }
207 
208  Events::Types GetPartEventTypes() const override
209  {
212  }
213 
214  void PartOpened(const berry::IWorkbenchPartReference::Pointer& ref) override
215  {
216  if (ref->GetId()=="org.mitk.views.imagenavigator")
217  {
218  imageNavigatorAction->setChecked(true);
219  }
220  }
221 
222  void PartClosed(const berry::IWorkbenchPartReference::Pointer& ref) override
223  {
224  if (ref->GetId()=="org.mitk.views.imagenavigator")
225  {
226  imageNavigatorAction->setChecked(false);
227  }
228  }
229 
230  void PartVisible(const berry::IWorkbenchPartReference::Pointer& ref) override
231  {
232  if (ref->GetId()=="org.mitk.views.imagenavigator")
233  {
234  imageNavigatorAction->setChecked(true);
235  }
236  }
237 
238  void PartHidden(const berry::IWorkbenchPartReference::Pointer& ref) override
239  {
240  if (ref->GetId()=="org.mitk.views.imagenavigator")
241  {
242  imageNavigatorAction->setChecked(false);
243  }
244  }
245 
246 private:
247  QAction* imageNavigatorAction;
248 };
249 
250 class PerspectiveListenerForTitle: public berry::IPerspectiveListener
251 {
252 public:
253 
254  PerspectiveListenerForTitle(QmitkExtWorkbenchWindowAdvisor* wa)
255  : windowAdvisor(wa)
256  , perspectivesClosed(false)
257  {
258  }
259 
260  Events::Types GetPerspectiveEventTypes() const override
261  {
263  {
264  return Events::ACTIVATED | Events::SAVED_AS | Events::DEACTIVATED;
265  }
266  else
267  {
268  return Events::ACTIVATED | Events::SAVED_AS | Events::DEACTIVATED
270  }
271  }
272 
273  void PerspectiveActivated(const berry::IWorkbenchPage::Pointer& /*page*/,
274  const berry::IPerspectiveDescriptor::Pointer& /*perspective*/) override
275  {
276  windowAdvisor->UpdateTitle(false);
277  }
278 
279  void PerspectiveSavedAs(const berry::IWorkbenchPage::Pointer& /*page*/,
280  const berry::IPerspectiveDescriptor::Pointer& /*oldPerspective*/,
281  const berry::IPerspectiveDescriptor::Pointer& /*newPerspective*/) override
282  {
283  windowAdvisor->UpdateTitle(false);
284  }
285 
286  void PerspectiveDeactivated(const berry::IWorkbenchPage::Pointer& /*page*/,
287  const berry::IPerspectiveDescriptor::Pointer& /*perspective*/) override
288  {
289  windowAdvisor->UpdateTitle(false);
290  }
291 
292  void PerspectiveOpened(const berry::IWorkbenchPage::Pointer& /*page*/,
293  const berry::IPerspectiveDescriptor::Pointer& /*perspective*/) override
294  {
295  if (perspectivesClosed)
296  {
297  QListIterator<QAction*> i(windowAdvisor->viewActions);
298  while (i.hasNext())
299  {
300  i.next()->setEnabled(true);
301  }
302 
303  //GetViewRegistry()->Find("org.mitk.views.imagenavigator");
304  if(windowAdvisor->GetWindowConfigurer()->GetWindow()->GetWorkbench()->GetEditorRegistry()->FindEditor("org.mitk.editors.dicomeditor"))
305  {
306  windowAdvisor->openDicomEditorAction->setEnabled(true);
307  }
308  if (windowAdvisor->GetWindowConfigurer()->GetWindow()->GetWorkbench()->GetEditorRegistry()->FindEditor("org.mitk.editors.stdmultiwidget"))
309  {
310  windowAdvisor->openStdMultiWidgetEditorAction->setEnabled(true);
311  }
312  if (windowAdvisor->GetWindowConfigurer()->GetWindow()->GetWorkbench()->GetEditorRegistry()->FindEditor("org.mitk.editors.mxnmultiwidget"))
313  {
314  windowAdvisor->openMxNMultiWidgetEditorAction->setEnabled(true);
315  }
316 
317  windowAdvisor->fileSaveProjectAction->setEnabled(true);
318  windowAdvisor->closeProjectAction->setEnabled(true);
319  windowAdvisor->undoAction->setEnabled(true);
320  windowAdvisor->redoAction->setEnabled(true);
321  windowAdvisor->imageNavigatorAction->setEnabled(true);
322  windowAdvisor->viewNavigatorAction->setEnabled(true);
323  windowAdvisor->resetPerspAction->setEnabled(true);
324  if( windowAdvisor->GetShowClosePerspectiveMenuItem() )
325  {
326  windowAdvisor->closePerspAction->setEnabled(true);
327  }
328  }
329 
330  perspectivesClosed = false;
331  }
332 
333  void PerspectiveClosed(const berry::IWorkbenchPage::Pointer& /*page*/,
334  const berry::IPerspectiveDescriptor::Pointer& /*perspective*/) override
335  {
336  berry::IWorkbenchWindow::Pointer wnd = windowAdvisor->GetWindowConfigurer()->GetWindow();
337  bool allClosed = true;
338  if (wnd->GetActivePage())
339  {
340  QList<berry::IPerspectiveDescriptor::Pointer> perspectives(wnd->GetActivePage()->GetOpenPerspectives());
341  allClosed = perspectives.empty();
342  }
343 
344  if (allClosed)
345  {
346  perspectivesClosed = true;
347 
348  QListIterator<QAction*> i(windowAdvisor->viewActions);
349  while (i.hasNext())
350  {
351  i.next()->setEnabled(false);
352  }
353 
354  if(windowAdvisor->GetWindowConfigurer()->GetWindow()->GetWorkbench()->GetEditorRegistry()->FindEditor("org.mitk.editors.dicomeditor"))
355  {
356  windowAdvisor->openDicomEditorAction->setEnabled(false);
357  }
358  if (windowAdvisor->GetWindowConfigurer()->GetWindow()->GetWorkbench()->GetEditorRegistry()->FindEditor("org.mitk.editors.stdmultiwidget"))
359  {
360  windowAdvisor->openStdMultiWidgetEditorAction->setEnabled(false);
361  }
362  if (windowAdvisor->GetWindowConfigurer()->GetWindow()->GetWorkbench()->GetEditorRegistry()->FindEditor("org.mitk.editors.mxnmultiwidget"))
363  {
364  windowAdvisor->openMxNMultiWidgetEditorAction->setEnabled(false);
365  }
366 
367  windowAdvisor->fileSaveProjectAction->setEnabled(false);
368  windowAdvisor->closeProjectAction->setEnabled(false);
369  windowAdvisor->undoAction->setEnabled(false);
370  windowAdvisor->redoAction->setEnabled(false);
371  windowAdvisor->imageNavigatorAction->setEnabled(false);
372  windowAdvisor->viewNavigatorAction->setEnabled(false);
373  windowAdvisor->resetPerspAction->setEnabled(false);
374  if( windowAdvisor->GetShowClosePerspectiveMenuItem() )
375  {
376  windowAdvisor->closePerspAction->setEnabled(false);
377  }
378  }
379  }
380 
381 private:
382  QmitkExtWorkbenchWindowAdvisor* windowAdvisor;
383  bool perspectivesClosed;
384 };
385 
386 class PerspectiveListenerForMenu: public berry::IPerspectiveListener
387 {
388 public:
389 
390  PerspectiveListenerForMenu(QmitkExtWorkbenchWindowAdvisor* wa)
391  : windowAdvisor(wa)
392  {
393  }
394 
395  Events::Types GetPerspectiveEventTypes() const override
396  {
398  }
399 
400  void PerspectiveActivated(const berry::IWorkbenchPage::Pointer& /*page*/,
402  {
403  QAction* action = windowAdvisor->mapPerspIdToAction[perspective->GetId()];
404  if (action)
405  {
406  action->setChecked(true);
407  }
408  }
409 
410  void PerspectiveDeactivated(const berry::IWorkbenchPage::Pointer& /*page*/,
411  const berry::IPerspectiveDescriptor::Pointer& perspective) override
412  {
413  QAction* action = windowAdvisor->mapPerspIdToAction[perspective->GetId()];
414  if (action)
415  {
416  action->setChecked(false);
417  }
418  }
419 
420 private:
421  QmitkExtWorkbenchWindowAdvisor* windowAdvisor;
422 };
423 
426  : berry::WorkbenchWindowAdvisor(configurer)
427  , lastInput(nullptr)
428  , wbAdvisor(wbAdvisor)
429  , showViewToolbar(true)
430  , showPerspectiveToolbar(false)
431  , showVersionInfo(true)
432  , showMitkVersionInfo(true)
433  , showViewMenuItem(true)
434  , showNewWindowMenuItem(false)
435  , showClosePerspectiveMenuItem(true)
436  , viewNavigatorFound(false)
437  , showMemoryIndicator(true)
438  , dropTargetListener(new QmitkDefaultDropTargetListener)
439 {
440  productName = QCoreApplication::applicationName();
441  viewExcludeList.push_back("org.mitk.views.viewnavigatorview");
442 }
443 
445 {
446 }
447 
449 {
451  {
452  berry::ActionBarAdvisor::Pointer actionBarAdvisor(new QmitkExtActionBarAdvisor(configurer));
453  return actionBarAdvisor;
454  }
455  else
456  {
458  }
459 }
460 
462 {
463  QWidget* parentWidget = static_cast<QWidget*>(parent);
464  auto label = new QLabel(parentWidget);
465  label->setText("<b>No perspectives are open. Open a perspective in the <i>Window->Open Perspective</i> menu.</b>");
466  label->setContentsMargins(10,10,10,10);
467  label->setAlignment(Qt::AlignTop);
468  label->setEnabled(false);
469  parentWidget->layout()->addWidget(label);
470  return label;
471 }
472 
474 {
475  showClosePerspectiveMenuItem = show;
476 }
477 
479 {
480  return showClosePerspectiveMenuItem;
481 }
482 
484 {
485  showMemoryIndicator = show;
486 }
487 
489 {
490  return showMemoryIndicator;
491 }
492 
494 {
495  showNewWindowMenuItem = show;
496 }
497 
499 {
500  showViewToolbar = show;
501 }
502 
504 {
505  showViewMenuItem = show;
506 }
507 
509 {
510  showPerspectiveToolbar = show;
511 }
512 
514 {
515  showVersionInfo = show;
516 }
517 
519 {
520  showMitkVersionInfo = show;
521 }
522 
524 {
525  productName = product;
526 }
527 
529 {
530  windowIcon = wndIcon;
531 }
532 
534 {
535  // very bad hack...
536  berry::IWorkbenchWindow::Pointer window = this->GetWindowConfigurer()->GetWindow();
537  QMainWindow* mainWindow = qobject_cast<QMainWindow*> (window->GetShell()->GetControl());
538 
539  if (!windowIcon.isEmpty())
540  {
541  mainWindow->setWindowIcon(QIcon(windowIcon));
542  }
543  mainWindow->setContextMenuPolicy(Qt::PreventContextMenu);
544 
545  // Load icon theme
546  QIcon::setThemeSearchPaths(QStringList() << QStringLiteral(":/org_mitk_icons/icons/"));
547  QIcon::setThemeName(QStringLiteral("awesome"));
548 
549  // ==== Application menu ============================
550 
551  QMenuBar* menuBar = mainWindow->menuBar();
552  menuBar->setContextMenuPolicy(Qt::PreventContextMenu);
553 
554 #ifdef __APPLE__
555  menuBar->setNativeMenuBar(true);
556 #else
557  menuBar->setNativeMenuBar(false);
558 #endif
559 
560  auto basePath = QStringLiteral(":/org_mitk_icons/icons/awesome/scalable/actions/");
561 
562  auto fileOpenAction = new QmitkFileOpenAction(berry::QtStyleManager::ThemeIcon(basePath + "document-open.svg"), window);
563  fileOpenAction->setShortcut(QKeySequence::Open);
564  auto fileSaveAction = new QmitkFileSaveAction(berry::QtStyleManager::ThemeIcon(basePath + "document-save.svg"), window);
565  fileSaveAction->setShortcut(QKeySequence::Save);
566  fileSaveProjectAction = new QmitkExtFileSaveProjectAction(window);
567  fileSaveProjectAction->setIcon(berry::QtStyleManager::ThemeIcon(basePath + "document-save.svg"));
568  closeProjectAction = new QmitkCloseProjectAction(window);
569  closeProjectAction->setIcon(berry::QtStyleManager::ThemeIcon(basePath + "edit-delete.svg"));
570 
571  auto perspGroup = new QActionGroup(menuBar);
572  std::map<QString, berry::IViewDescriptor::Pointer> VDMap;
573 
574  // sort elements (converting vector to map...)
575  QList<berry::IViewDescriptor::Pointer>::const_iterator iter;
576 
577  berry::IViewRegistry* viewRegistry =
579  const QList<berry::IViewDescriptor::Pointer> viewDescriptors = viewRegistry->GetViews();
580 
581  bool skip = false;
582  for (iter = viewDescriptors.begin(); iter != viewDescriptors.end(); ++iter)
583  {
584  // if viewExcludeList is set, it contains the id-strings of view, which
585  // should not appear as an menu-entry in the menu
586  if (viewExcludeList.size() > 0)
587  {
588  for (int i=0; i<viewExcludeList.size(); i++)
589  {
590  if (viewExcludeList.at(i) == (*iter)->GetId())
591  {
592  skip = true;
593  break;
594  }
595  }
596  if (skip)
597  {
598  skip = false;
599  continue;
600  }
601  }
602 
603  if ((*iter)->GetId() == "org.blueberry.ui.internal.introview")
604  continue;
605  if ((*iter)->GetId() == "org.mitk.views.imagenavigator")
606  continue;
607  if ((*iter)->GetId() == "org.mitk.views.viewnavigatorview")
608  continue;
609 
610  std::pair<QString, berry::IViewDescriptor::Pointer> p((*iter)->GetLabel(), (*iter));
611  VDMap.insert(p);
612  }
613 
614  std::map<QString, berry::IViewDescriptor::Pointer>::const_iterator MapIter;
615  for (MapIter = VDMap.begin(); MapIter != VDMap.end(); ++MapIter)
616  {
617  berry::QtShowViewAction* viewAction = new berry::QtShowViewAction(window, (*MapIter).second);
618  viewActions.push_back(viewAction);
619  }
620 
622  {
623  QMenu* fileMenu = menuBar->addMenu("&File");
624  fileMenu->setObjectName("FileMenu");
625  fileMenu->addAction(fileOpenAction);
626  fileMenu->addAction(fileSaveAction);
627  fileMenu->addAction(fileSaveProjectAction);
628  fileMenu->addAction(closeProjectAction);
629  fileMenu->addSeparator();
630 
631  QAction* fileExitAction = new QmitkFileExitAction(window);
632  fileExitAction->setIcon(berry::QtStyleManager::ThemeIcon(basePath + "system-log-out.svg"));
633  fileExitAction->setShortcut(QKeySequence::Quit);
634  fileExitAction->setObjectName("QmitkFileExitAction");
635  fileMenu->addAction(fileExitAction);
636 
637  // another bad hack to get an edit/undo menu...
638  QMenu* editMenu = menuBar->addMenu("&Edit");
639  undoAction = editMenu->addAction(berry::QtStyleManager::ThemeIcon(basePath + "edit-undo.svg"),
640  "&Undo",
641  QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onUndo()),
642  QKeySequence("CTRL+Z"));
643  undoAction->setToolTip("Undo the last action (not supported by all modules)");
644  redoAction = editMenu->addAction(berry::QtStyleManager::ThemeIcon(basePath + "edit-redo.svg"),
645  "&Redo",
646  QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onRedo()),
647  QKeySequence("CTRL+Y"));
648  redoAction->setToolTip("execute the last action that was undone again (not supported by all modules)");
649 
650  // ==== Window Menu ==========================
651  QMenu* windowMenu = menuBar->addMenu("Window");
652  if (showNewWindowMenuItem)
653  {
654  windowMenu->addAction("&New Window", QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onNewWindow()));
655  windowMenu->addSeparator();
656  }
657 
658  QMenu* perspMenu = windowMenu->addMenu("&Open Perspective");
659 
660  QMenu* viewMenu = nullptr;
661  if (showViewMenuItem)
662  {
663  viewMenu = windowMenu->addMenu("Show &View");
664  viewMenu->setObjectName("Show View");
665  }
666  windowMenu->addSeparator();
667  resetPerspAction = windowMenu->addAction("&Reset Perspective",
668  QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onResetPerspective()));
669 
670  if(showClosePerspectiveMenuItem)
671  closePerspAction = windowMenu->addAction("&Close Perspective", QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onClosePerspective()));
672 
673  windowMenu->addSeparator();
674  windowMenu->addAction("&Preferences...",
675  QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onEditPreferences()),
676  QKeySequence("CTRL+P"));
677 
678  // fill perspective menu
679  berry::IPerspectiveRegistry* perspRegistry =
680  window->GetWorkbench()->GetPerspectiveRegistry();
681 
682  QList<berry::IPerspectiveDescriptor::Pointer> perspectives(
683  perspRegistry->GetPerspectives());
684 
685  skip = false;
686  for (QList<berry::IPerspectiveDescriptor::Pointer>::iterator perspIt =
687  perspectives.begin(); perspIt != perspectives.end(); ++perspIt)
688  {
689  // if perspectiveExcludeList is set, it contains the id-strings of perspectives, which
690  // should not appear as an menu-entry in the perspective menu
691  if (perspectiveExcludeList.size() > 0)
692  {
693  for (int i=0; i<perspectiveExcludeList.size(); i++)
694  {
695  if (perspectiveExcludeList.at(i) == (*perspIt)->GetId())
696  {
697  skip = true;
698  break;
699  }
700  }
701  if (skip)
702  {
703  skip = false;
704  continue;
705  }
706  }
707 
708  QAction* perspAction = new berry::QtOpenPerspectiveAction(window, *perspIt, perspGroup);
709  mapPerspIdToAction.insert((*perspIt)->GetId(), perspAction);
710  }
711  perspMenu->addActions(perspGroup->actions());
712 
713  if (showViewMenuItem)
714  {
715  for (auto viewAction : viewActions)
716  {
717  viewMenu->addAction(viewAction);
718  }
719  }
720 
721  // ===== Help menu ====================================
722  QMenu* helpMenu = menuBar->addMenu("&Help");
723  helpMenu->addAction("&Welcome",this, SLOT(onIntro()));
724  helpMenu->addAction("&Open Help Perspective", this, SLOT(onHelpOpenHelpPerspective()));
725  helpMenu->addAction("&Context Help",this, SLOT(onHelp()), QKeySequence("F1"));
726  helpMenu->addAction("&About",this, SLOT(onAbout()));
727  // =====================================================
728  }
729  else
730  {
731  undoAction = new QmitkUndoAction(berry::QtStyleManager::ThemeIcon(basePath + "edit-undo.svg"), nullptr);
732  undoAction->setShortcut(QKeySequence::Undo);
733  redoAction = new QmitkRedoAction(berry::QtStyleManager::ThemeIcon(basePath + "edit-redo.svg"), nullptr);
734  redoAction->setShortcut(QKeySequence::Redo);
735  }
736 
737  // toolbar for showing file open, undo, redo and other main actions
738  auto mainActionsToolBar = new QToolBar;
739  mainActionsToolBar->setObjectName("mainActionsToolBar");
740  mainActionsToolBar->setContextMenuPolicy(Qt::PreventContextMenu);
741 #ifdef __APPLE__
742  mainActionsToolBar->setToolButtonStyle ( Qt::ToolButtonTextUnderIcon );
743 #else
744  mainActionsToolBar->setToolButtonStyle ( Qt::ToolButtonTextBesideIcon );
745 #endif
746 
747  basePath = QStringLiteral(":/org.mitk.gui.qt.ext/");
748  imageNavigatorAction = new QAction(berry::QtStyleManager::ThemeIcon(basePath + "image_navigator.svg"), "&Image Navigator", nullptr);
749  bool imageNavigatorViewFound = window->GetWorkbench()->GetViewRegistry()->Find("org.mitk.views.imagenavigator");
750 
751  if (this->GetWindowConfigurer()->GetWindow()->GetWorkbench()->GetEditorRegistry()->FindEditor("org.mitk.editors.dicomeditor"))
752  {
753  openDicomEditorAction = new QmitkOpenDicomEditorAction(berry::QtStyleManager::ThemeIcon(basePath + "dicom.svg"), window);
754  }
755  if (this->GetWindowConfigurer()->GetWindow()->GetWorkbench()->GetEditorRegistry()->FindEditor("org.mitk.editors.stdmultiwidget"))
756  {
757  openStdMultiWidgetEditorAction = new QmitkOpenStdMultiWidgetEditorAction(QIcon(":/org.mitk.gui.qt.ext/Editor.png"), window);
758  }
759  if (this->GetWindowConfigurer()->GetWindow()->GetWorkbench()->GetEditorRegistry()->FindEditor("org.mitk.editors.mxnmultiwidget"))
760  {
761  openMxNMultiWidgetEditorAction = new QmitkOpenMxNMultiWidgetEditorAction(QIcon(":/org.mitk.gui.qt.ext/Editor.png"), window);
762  }
763 
764  if (imageNavigatorViewFound)
765  {
766  QObject::connect(imageNavigatorAction, SIGNAL(triggered(bool)), QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onImageNavigator()));
767  imageNavigatorAction->setCheckable(true);
768 
769  // add part listener for image navigator
770  imageNavigatorPartListener.reset(new PartListenerForImageNavigator(imageNavigatorAction));
771  window->GetPartService()->AddPartListener(imageNavigatorPartListener.data());
772  berry::IViewPart::Pointer imageNavigatorView = window->GetActivePage()->FindView("org.mitk.views.imagenavigator");
773  imageNavigatorAction->setChecked(false);
774  if (imageNavigatorView)
775  {
776  bool isImageNavigatorVisible = window->GetActivePage()->IsPartVisible(imageNavigatorView);
777  if (isImageNavigatorVisible)
778  imageNavigatorAction->setChecked(true);
779  }
780  imageNavigatorAction->setToolTip("Toggle image navigator for navigating through image");
781  }
782 
783  viewNavigatorAction = new QAction(berry::QtStyleManager::ThemeIcon(QStringLiteral(":/org.mitk.gui.qt.ext/view-manager.svg")),"&View Navigator", nullptr);
784  viewNavigatorFound = window->GetWorkbench()->GetViewRegistry()->Find("org.mitk.views.viewnavigatorview");
785  if (viewNavigatorFound)
786  {
787  QObject::connect(viewNavigatorAction, SIGNAL(triggered(bool)), QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onViewNavigator()));
788  viewNavigatorAction->setCheckable(true);
789 
790  // add part listener for view navigator
791  viewNavigatorPartListener.reset(new PartListenerForViewNavigator(viewNavigatorAction));
792  window->GetPartService()->AddPartListener(viewNavigatorPartListener.data());
793  berry::IViewPart::Pointer viewnavigatorview = window->GetActivePage()->FindView("org.mitk.views.viewnavigatorview");
794  viewNavigatorAction->setChecked(false);
795  if (viewnavigatorview)
796  {
797  bool isViewNavigatorVisible = window->GetActivePage()->IsPartVisible(viewnavigatorview);
798  if (isViewNavigatorVisible)
799  viewNavigatorAction->setChecked(true);
800  }
801  viewNavigatorAction->setToolTip("Toggle View Navigator");
802  }
803 
804  mainActionsToolBar->addAction(fileOpenAction);
805  mainActionsToolBar->addAction(fileSaveProjectAction);
806  mainActionsToolBar->addAction(closeProjectAction);
807  mainActionsToolBar->addAction(undoAction);
808  mainActionsToolBar->addAction(redoAction);
809  if(this->GetWindowConfigurer()->GetWindow()->GetWorkbench()->GetEditorRegistry()->FindEditor("org.mitk.editors.dicomeditor"))
810  {
811  mainActionsToolBar->addAction(openDicomEditorAction);
812  }
813  if (this->GetWindowConfigurer()->GetWindow()->GetWorkbench()->GetEditorRegistry()->FindEditor("org.mitk.editors.stdmultiwidget"))
814  {
815  mainActionsToolBar->addAction(openStdMultiWidgetEditorAction);
816  }
817  if (this->GetWindowConfigurer()->GetWindow()->GetWorkbench()->GetEditorRegistry()->FindEditor("org.mitk.editors.mxnmultiwidget"))
818  {
819  mainActionsToolBar->addAction(openMxNMultiWidgetEditorAction);
820  }
821 
822  if (imageNavigatorViewFound)
823  {
824  mainActionsToolBar->addAction(imageNavigatorAction);
825  }
826  if (viewNavigatorFound)
827  {
828  mainActionsToolBar->addAction(viewNavigatorAction);
829  }
830  mainWindow->addToolBar(mainActionsToolBar);
831 
832  // ==== Perspective Toolbar ==================================
833  auto qPerspectiveToolbar = new QToolBar;
834  qPerspectiveToolbar->setObjectName("perspectiveToolBar");
835 
836  if (showPerspectiveToolbar)
837  {
838  qPerspectiveToolbar->addActions(perspGroup->actions());
839  mainWindow->addToolBar(qPerspectiveToolbar);
840  }
841  else
842  delete qPerspectiveToolbar;
843 
844  if (showViewToolbar)
845  {
847  berry::IPreferences::Pointer stylePrefs = prefService->GetSystemPreferences()->Node(berry::QtPreferences::QT_STYLES_NODE);
848  bool showCategoryNames = stylePrefs->GetBool(berry::QtPreferences::QT_SHOW_TOOLBAR_CATEGORY_NAMES, true);
849 
850  // Order view descriptors by category
851 
852  QMultiMap<QString, berry::IViewDescriptor::Pointer> categoryViewDescriptorMap;
853 
854  for (auto labelViewDescriptorPair : VDMap)
855  {
856  auto viewDescriptor = labelViewDescriptorPair.second;
857  auto category = !viewDescriptor->GetCategoryPath().isEmpty()
858  ? viewDescriptor->GetCategoryPath().back()
859  : QString();
860 
861  categoryViewDescriptorMap.insert(category, viewDescriptor);
862  }
863 
864  // Create a separate toolbar for each category
865 
866  for (auto category : categoryViewDescriptorMap.uniqueKeys())
867  {
868  auto viewDescriptorsInCurrentCategory = categoryViewDescriptorMap.values(category);
869 
870  if (!viewDescriptorsInCurrentCategory.isEmpty())
871  {
872  auto toolbar = new QToolBar;
873  toolbar->setObjectName(category + " View Toolbar");
874  mainWindow->addToolBar(toolbar);
875 
876  if (showCategoryNames && !category.isEmpty())
877  {
878  auto categoryButton = new QToolButton;
879  categoryButton->setToolButtonStyle(Qt::ToolButtonTextOnly);
880  categoryButton->setText(category);
881  categoryButton->setStyleSheet("background: transparent; margin: 0; padding: 0;");
882  toolbar->addWidget(categoryButton);
883 
884  connect(categoryButton, &QToolButton::clicked, [toolbar]()
885  {
886  for (QWidget* widget : toolbar->findChildren<QWidget*>())
887  {
888  if (QStringLiteral("qt_toolbar_ext_button") == widget->objectName() && widget->isVisible())
889  {
890  QMouseEvent pressEvent(QEvent::MouseButtonPress, QPointF(0.0f, 0.0f), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
891  QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPointF(0.0f, 0.0f), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
892  QApplication::sendEvent(widget, &pressEvent);
893  QApplication::sendEvent(widget, &releaseEvent);
894  }
895  }
896  });
897  }
898 
899  for (auto viewDescriptor : viewDescriptorsInCurrentCategory)
900  {
901  auto viewAction = new berry::QtShowViewAction(window, viewDescriptor);
902  toolbar->addAction(viewAction);
903  }
904  }
905  }
906  }
907 
908  QSettings settings(GetQSettingsFile(), QSettings::IniFormat);
909  mainWindow->restoreState(settings.value("ToolbarPosition").toByteArray());
910 
911  auto qStatusBar = new QStatusBar();
912 
913  //creating a QmitkStatusBar for Output on the QStatusBar and connecting it with the MainStatusBar
914  auto statusBar = new QmitkStatusBar(qStatusBar);
915  //disabling the SizeGrip in the lower right corner
916  statusBar->SetSizeGripEnabled(false);
917 
918  auto progBar = new QmitkProgressBar();
919 
920  qStatusBar->addPermanentWidget(progBar, 0);
921  progBar->hide();
922  // progBar->AddStepsToDo(2);
923  // progBar->Progress(1);
924 
925  mainWindow->setStatusBar(qStatusBar);
926 
927  if (showMemoryIndicator)
928  {
929  auto memoryIndicator = new QmitkMemoryUsageIndicatorView();
930  qStatusBar->addPermanentWidget(memoryIndicator, 0);
931  }
932 }
933 
935 {
937 
938  // show the shortcut bar and progress indicator, which are hidden by
939  // default
940  //configurer->SetShowPerspectiveBar(true);
941  //configurer->SetShowFastViewBars(true);
942  //configurer->SetShowProgressIndicator(true);
943 
944  // // add the drag and drop support for the editor area
945  // configurer.addEditorAreaTransfer(EditorInputTransfer.getInstance());
946  // configurer.addEditorAreaTransfer(ResourceTransfer.getInstance());
947  // configurer.addEditorAreaTransfer(FileTransfer.getInstance());
948  // configurer.addEditorAreaTransfer(MarkerTransfer.getInstance());
949  // configurer.configureEditorAreaDropListener(new EditorAreaDropAdapter(
950  // configurer.getWindow()));
951 
952  this->HookTitleUpdateListeners(configurer);
953 
954  menuPerspectiveListener.reset(new PerspectiveListenerForMenu(this));
955  configurer->GetWindow()->AddPerspectiveListener(menuPerspectiveListener.data());
956 
957  configurer->AddEditorAreaTransfer(QStringList("text/uri-list"));
958  configurer->ConfigureEditorAreaDropListener(dropTargetListener.data());
959 }
960 
962 {
964  // Force Rendering Window Creation on startup.
966 
967  ctkPluginContext* context = QmitkCommonExtPlugin::getContext();
968  ctkServiceReference serviceRef = context->getServiceReference<mitk::IDataStorageService>();
969  if (serviceRef)
970  {
971  mitk::IDataStorageService *dsService = context->getService<mitk::IDataStorageService>(serviceRef);
972  if (dsService)
973  {
976  mitk::WorkbenchUtil::OpenEditor(configurer->GetWindow()->GetActivePage(),dsInput);
977  }
978  }
979 }
980 
982 {
983  QmitkExtWorkbenchWindowAdvisorHack::undohack->onIntro();
984 }
985 
987 {
988  QmitkExtWorkbenchWindowAdvisorHack::undohack->onHelp();
989 }
990 
992 {
993  QmitkExtWorkbenchWindowAdvisorHack::undohack->onHelpOpenHelpPerspective();
994 }
995 
997 {
998  QmitkExtWorkbenchWindowAdvisorHack::undohack->onAbout();
999 }
1000 
1001 //--------------------------------------------------------------------------------
1002 // Ugly hack from here on. Feel free to delete when command framework
1003 // and undo buttons are done.
1004 //--------------------------------------------------------------------------------
1005 
1006 QmitkExtWorkbenchWindowAdvisorHack::QmitkExtWorkbenchWindowAdvisorHack()
1007  : QObject()
1008 {
1009 }
1010 
1011 QmitkExtWorkbenchWindowAdvisorHack::~QmitkExtWorkbenchWindowAdvisorHack()
1012 {
1013 }
1014 
1015 void QmitkExtWorkbenchWindowAdvisorHack::onUndo()
1016 {
1018  if (model)
1019  {
1020  if (mitk::VerboseLimitedLinearUndo* verboseundo = dynamic_cast<mitk::VerboseLimitedLinearUndo*>( model ))
1021  {
1022  mitk::VerboseLimitedLinearUndo::StackDescription descriptions = verboseundo->GetUndoDescriptions();
1023  if (descriptions.size() >= 1)
1024  {
1025  MITK_INFO << "Undo " << descriptions.front().second;
1026  }
1027  }
1028  model->Undo();
1029  }
1030  else
1031  {
1032  MITK_ERROR << "No undo model instantiated";
1033  }
1034 }
1035 
1036 void QmitkExtWorkbenchWindowAdvisorHack::onRedo()
1037 {
1039  if (model)
1040  {
1041  if (mitk::VerboseLimitedLinearUndo* verboseundo = dynamic_cast<mitk::VerboseLimitedLinearUndo*>( model ))
1042  {
1043  mitk::VerboseLimitedLinearUndo::StackDescription descriptions = verboseundo->GetRedoDescriptions();
1044  if (descriptions.size() >= 1)
1045  {
1046  MITK_INFO << "Redo " << descriptions.front().second;
1047  }
1048  }
1049  model->Redo();
1050  }
1051  else
1052  {
1053  MITK_ERROR << "No undo model instantiated";
1054  }
1055 }
1056 
1057 // safe calls to the complete chain
1058 // berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow()->GetActivePage()->FindView("org.mitk.views.imagenavigator");
1059 // to cover for all possible cases of closed pages etc.
1060 static void SafeHandleNavigatorView(QString view_query_name)
1061 {
1063  if( wbench == nullptr )
1064  return;
1065 
1067  if( wbench_window.IsNull() )
1068  return;
1069 
1070  berry::IWorkbenchPage::Pointer wbench_page = wbench_window->GetActivePage();
1071  if( wbench_page.IsNull() )
1072  return;
1073 
1074  auto wbench_view = wbench_page->FindView( view_query_name );
1075 
1076  if( wbench_view.IsNotNull() )
1077  {
1078  bool isViewVisible = wbench_page->IsPartVisible( wbench_view );
1079  if( isViewVisible )
1080  {
1081  wbench_page->HideView( wbench_view );
1082  return;
1083  }
1084 
1085  }
1086 
1087  wbench_page->ShowView( view_query_name );
1088 }
1089 
1090 void QmitkExtWorkbenchWindowAdvisorHack::onImageNavigator()
1091 {
1092  // show/hide ImageNavigatorView
1093  SafeHandleNavigatorView("org.mitk.views.imagenavigator");
1094 }
1095 
1096 void QmitkExtWorkbenchWindowAdvisorHack::onViewNavigator()
1097 {
1098  // show/hide viewnavigatorView
1099  SafeHandleNavigatorView("org.mitk.views.viewnavigatorview");
1100 }
1101 
1102 void QmitkExtWorkbenchWindowAdvisorHack::onEditPreferences()
1103 {
1104  QmitkPreferencesDialog _PreferencesDialog(QApplication::activeWindow());
1105  _PreferencesDialog.exec();
1106 }
1107 
1108 void QmitkExtWorkbenchWindowAdvisorHack::onQuit()
1109 {
1111 }
1112 
1113 void QmitkExtWorkbenchWindowAdvisorHack::onResetPerspective()
1114 {
1115  berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow()->GetActivePage()->ResetPerspective();
1116 }
1117 
1118 void QmitkExtWorkbenchWindowAdvisorHack::onClosePerspective()
1119 {
1122  page->ClosePerspective(page->GetPerspective(), true, true);
1123 }
1124 
1125 void QmitkExtWorkbenchWindowAdvisorHack::onNewWindow()
1126 {
1128 }
1129 
1130 void QmitkExtWorkbenchWindowAdvisorHack::onIntro()
1131 {
1132  bool hasIntro =
1134  if (!hasIntro)
1135  {
1136  QRegExp reg("(.*)<title>(\\n)*");
1137  QRegExp reg2("(\\n)*</title>(.*)");
1138  QFile file(":/org.mitk.gui.qt.ext/index.html");
1139  file.open(QIODevice::ReadOnly | QIODevice::Text); //text file only for reading
1140 
1141  QString text = QString(file.readAll());
1142 
1143  file.close();
1144 
1145  QString title = text;
1146  title.replace(reg, "");
1147  title.replace(reg2, "");
1148 
1149  std::cout << title.toStdString() << std::endl;
1150 
1151  QMessageBox::information(nullptr, title,
1152  text, "Close");
1153  }
1154  else
1155  {
1157  berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow(), false);
1158  }
1159 }
1160 
1161 void QmitkExtWorkbenchWindowAdvisorHack::onHelp()
1162 {
1163  ctkPluginContext* context = QmitkCommonExtPlugin::getContext();
1164  if (context == nullptr)
1165  {
1166  MITK_WARN << "Plugin context not set, unable to open context help";
1167  return;
1168  }
1169 
1170  // Check if the org.blueberry.ui.qt.help plug-in is installed and started
1171  QList<QSharedPointer<ctkPlugin> > plugins = context->getPlugins();
1172  foreach(QSharedPointer<ctkPlugin> p, plugins)
1173  {
1174  if (p->getSymbolicName() == "org.blueberry.ui.qt.help")
1175  {
1176  if (p->getState() != ctkPlugin::ACTIVE)
1177  {
1178  // try to activate the plug-in explicitly
1179  try
1180  {
1181  p->start(ctkPlugin::START_TRANSIENT);
1182  }
1183  catch (const ctkPluginException& pe)
1184  {
1185  MITK_ERROR << "Activating org.blueberry.ui.qt.help failed: " << pe.what();
1186  return;
1187  }
1188  }
1189  }
1190  }
1191 
1192  ctkServiceReference eventAdminRef = context->getServiceReference<ctkEventAdmin>();
1193  ctkEventAdmin* eventAdmin = nullptr;
1194  if (eventAdminRef)
1195  {
1196  eventAdmin = context->getService<ctkEventAdmin>(eventAdminRef);
1197  }
1198  if (eventAdmin == nullptr)
1199  {
1200  MITK_WARN << "ctkEventAdmin service not found. Unable to open context help";
1201  }
1202  else
1203  {
1204  ctkEvent ev("org/blueberry/ui/help/CONTEXTHELP_REQUESTED");
1205  eventAdmin->postEvent(ev);
1206  }
1207 }
1208 
1209 void QmitkExtWorkbenchWindowAdvisorHack::onHelpOpenHelpPerspective()
1210 {
1211  berry::PlatformUI::GetWorkbench()->ShowPerspective("org.blueberry.perspectives.help",
1212  berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow());
1213 }
1214 
1215 void QmitkExtWorkbenchWindowAdvisorHack::onAbout()
1216 {
1217  auto aboutDialog = new QmitkAboutDialog(QApplication::activeWindow(),nullptr);
1218  aboutDialog->open();
1219 }
1220 
1221 void QmitkExtWorkbenchWindowAdvisor::HookTitleUpdateListeners(berry::IWorkbenchWindowConfigurer::Pointer configurer)
1222 {
1223  // hook up the listeners to update the window title
1224  titlePartListener.reset(new PartListenerForTitle(this));
1225  titlePerspectiveListener.reset(new PerspectiveListenerForTitle(this));
1226  editorPropertyListener.reset(new berry::PropertyChangeIntAdapter<
1228  &QmitkExtWorkbenchWindowAdvisor::PropertyChange));
1229 
1230  // configurer.getWindow().addPageListener(new IPageListener() {
1231  // public void pageActivated(IWorkbenchPage page) {
1232  // updateTitle(false);
1233  // }
1234  //
1235  // public void pageClosed(IWorkbenchPage page) {
1236  // updateTitle(false);
1237  // }
1238  //
1239  // public void pageOpened(IWorkbenchPage page) {
1240  // // do nothing
1241  // }
1242  // });
1243 
1244  configurer->GetWindow()->AddPerspectiveListener(titlePerspectiveListener.data());
1245  configurer->GetWindow()->GetPartService()->AddPartListener(titlePartListener.data());
1246 }
1247 
1248 QString QmitkExtWorkbenchWindowAdvisor::ComputeTitle()
1249 {
1251  berry::IWorkbenchPage::Pointer currentPage = configurer->GetWindow()->GetActivePage();
1252  berry::IEditorPart::Pointer activeEditor;
1253  if (currentPage)
1254  {
1255  activeEditor = lastActiveEditor.Lock();
1256  }
1257 
1258  QString title;
1260  if (product.IsNotNull())
1261  {
1262  title = product->GetName();
1263  }
1264  if (title.isEmpty())
1265  {
1266  // instead of the product name, we use a custom variable for now
1267  title = productName;
1268  }
1269 
1270  if(showMitkVersionInfo)
1271  {
1272  QString mitkVersionInfo = MITK_REVISION_DESC;
1273 
1274  if(mitkVersionInfo.isEmpty())
1275  mitkVersionInfo = MITK_VERSION_STRING;
1276 
1277  title += " " + mitkVersionInfo;
1278  }
1279 
1280  if (showVersionInfo)
1281  {
1282  // add version informatioin
1283  QString versions = QString(" (ITK %1.%2.%3 | VTK %4.%5.%6 | Qt %7)")
1284  .arg(ITK_VERSION_MAJOR).arg(ITK_VERSION_MINOR).arg(ITK_VERSION_PATCH)
1285  .arg(VTK_MAJOR_VERSION).arg(VTK_MINOR_VERSION).arg(VTK_BUILD_VERSION)
1286  .arg(QT_VERSION_STR);
1287 
1288  title += versions;
1289  }
1290 
1291  if (currentPage)
1292  {
1293  if (activeEditor)
1294  {
1295  lastEditorTitle = activeEditor->GetTitleToolTip();
1296  if (!lastEditorTitle.isEmpty())
1297  title = lastEditorTitle + " - " + title;
1298  }
1299  berry::IPerspectiveDescriptor::Pointer persp = currentPage->GetPerspective();
1300  QString label = "";
1301  if (persp)
1302  {
1303  label = persp->GetLabel();
1304  }
1305  berry::IAdaptable* input = currentPage->GetInput();
1306  if (input && input != wbAdvisor->GetDefaultPageInput())
1307  {
1308  label = currentPage->GetLabel();
1309  }
1310  if (!label.isEmpty())
1311  {
1312  title = label + " - " + title;
1313  }
1314  }
1315 
1316  title += " (Not for use in diagnosis or treatment of patients)";
1317 
1318  return title;
1319 }
1320 
1321 void QmitkExtWorkbenchWindowAdvisor::RecomputeTitle()
1322 {
1324  QString oldTitle = configurer->GetTitle();
1325  QString newTitle = ComputeTitle();
1326  if (newTitle != oldTitle)
1327  {
1328  configurer->SetTitle(newTitle);
1329  }
1330 }
1331 
1332 void QmitkExtWorkbenchWindowAdvisor::UpdateTitle(bool editorHidden)
1333 {
1335  berry::IWorkbenchWindow::Pointer window = configurer->GetWindow();
1336  berry::IEditorPart::Pointer activeEditor;
1337  berry::IWorkbenchPage::Pointer currentPage = window->GetActivePage();
1339  berry::IAdaptable* input = nullptr;
1340 
1341  if (currentPage)
1342  {
1343  activeEditor = currentPage->GetActiveEditor();
1344  persp = currentPage->GetPerspective();
1345  input = currentPage->GetInput();
1346  }
1347 
1348  if (editorHidden)
1349  {
1350  activeEditor = nullptr;
1351  }
1352 
1353  // Nothing to do if the editor hasn't changed
1354  if (activeEditor == lastActiveEditor.Lock() && currentPage == lastActivePage.Lock()
1355  && persp == lastPerspective.Lock() && input == lastInput)
1356  {
1357  return;
1358  }
1359 
1360  if (!lastActiveEditor.Expired())
1361  {
1362  lastActiveEditor.Lock()->RemovePropertyListener(editorPropertyListener.data());
1363  }
1364 
1365  lastActiveEditor = activeEditor;
1366  lastActivePage = currentPage;
1367  lastPerspective = persp;
1368  lastInput = input;
1369 
1370  if (activeEditor)
1371  {
1372  activeEditor->AddPropertyListener(editorPropertyListener.data());
1373  }
1374 
1375  RecomputeTitle();
1376 }
1377 
1378 void QmitkExtWorkbenchWindowAdvisor::PropertyChange(const berry::Object::Pointer& /*source*/, int propId)
1379 {
1381  {
1382  if (!lastActiveEditor.Expired())
1383  {
1384  QString newTitle = lastActiveEditor.Lock()->GetPartName();
1385  if (lastEditorTitle != newTitle)
1386  {
1387  RecomputeTitle();
1388  }
1389  }
1390  }
1391 }
1392 
1394 {
1395  this->perspectiveExcludeList = v;
1396 }
1397 
1399 {
1400  return this->perspectiveExcludeList;
1401 }
1402 
1404 {
1405  this->viewExcludeList = v;
1406 }
1407 
1409 {
1410  return this->viewExcludeList;
1411 }
1412 
1414 {
1415  berry::IWorkbenchWindow::Pointer window = this->GetWindowConfigurer()->GetWindow();
1416  QMainWindow* mainWindow = static_cast<QMainWindow*> (window->GetShell()->GetControl());
1417 
1418  QSettings settings(GetQSettingsFile(), QSettings::IniFormat);
1419  settings.setValue("ToolbarPosition", mainWindow->saveState());
1420 }
1421 
1422 QString QmitkExtWorkbenchWindowAdvisor::GetQSettingsFile() const
1423 {
1424  QFileInfo settingsInfo = QmitkCommonExtPlugin::getContext()->getDataFile(QT_SETTINGS_FILENAME);
1425  return settingsInfo.canonicalFilePath();
1426 }
QWidget * CreateEmptyWindowContents(QWidget *parent) override
virtual void PartHidden(const IWorkbenchPartReference::Pointer &)
#define MITK_VERSION_STRING
Definition: mitkVersion.h:9
virtual bool Redo()=0
#define MITK_INFO
Definition: mitkLogMacros.h:18
#define MITK_ERROR
Definition: mitkLogMacros.h:20
berry::SmartPointer< berry::ActionBarAdvisor > CreateActionBarAdvisor(berry::SmartPointer< berry::IActionBarConfigurer > configurer) override
SmartPointer< Other > Cast() const
QmitkExtWorkbenchWindowAdvisor(berry::WorkbenchAdvisor *wbAdvisor, berry::IWorkbenchWindowConfigurer::Pointer configurer)
virtual IDataStorageReference::Pointer GetDataStorage() const =0
static QIcon ThemeIcon(const QByteArray &originalSVG)
virtual SmartPointer< ActionBarAdvisor > CreateActionBarAdvisor(SmartPointer< IActionBarConfigurer > configurer)
virtual IIntroManager * GetIntroManager() const =0
virtual QList< IPerspectiveDescriptor::Pointer > GetPerspectives()=0
static bool USE_EXPERIMENTAL_COMMAND_CONTRIBUTIONS
QT-Toolkit/GUI dependent class that provides the QT&#39;s ProgressBar.
static WorkbenchPlugin * GetDefault()
virtual bool Close()=0
An editor input based on a mitk::DataStorage.
SmartPointer< ObjectType > Lock() const
virtual void PartActivated(const IWorkbenchPartReference::Pointer &)
virtual IIntroPart::Pointer ShowIntro(IWorkbenchWindow::Pointer preferredWindow, bool standby)=0
SmartPointer< IWorkbenchWindowConfigurer > GetWindowConfigurer()
void SetPerspectiveExcludeList(const QList< QString > &v)
virtual bool HasIntro() const =0
#define MITK_WARN
Definition: mitkLogMacros.h:19
virtual QList< IViewDescriptor::Pointer > GetViews() const =0
IPreferencesService * GetPreferencesService() const
QT-Toolkit/GUI dependent class that provides to send a Message to the QT&#39;s StatusBar.
virtual IWorkbenchWindow::Pointer OpenWorkbenchWindow(const QString &perspectiveId, IAdaptable *input)=0
virtual bool Undo()=0
static IWorkbench * GetWorkbench()
static const QString QT_STYLES_NODE
virtual IWorkbenchWindow::Pointer GetActiveWorkbenchWindow() const =0
virtual IAdaptable * GetDefaultPageInput()
#define MITK_REVISION_DESC
Definition: mitkVersion.h:13
The custom viewer plugin implements simple viewer functionality presented in a customized look and feel It was developed to demonstrate extensibility and customizability of the blueberry application framework As an example for the GUI customization capabilities provided by the BlueBerry application the custom viewer plugin was developed It features simple viewer functionality presented in a customized look and feel The custom viewer consists of two i e a viewer perspective and a DICOM perspective As part of the viewer perspective
static SmartPointer< IProduct > GetProduct()
superclass for all UndoModels
Definition: mitkUndoModel.h:32
A limited linear undo model providing GUI elements with stack status information. ...
virtual void PartClosed(const IWorkbenchPartReference::Pointer &)
virtual void PartVisible(const IWorkbenchPartReference::Pointer &)
The custom viewer plugin implements simple viewer functionality presented in a customized look and feel It was developed to demonstrate extensibility and customizability of the blueberry application framework As an example for the GUI customization capabilities provided by the BlueBerry application the custom viewer plugin was developed It features simple viewer functionality presented in a customized look and feel The custom viewer consists of two perspectives
virtual void PartBroughtToTop(const IWorkbenchPartReference::Pointer &)
static const QString QT_SHOW_TOOLBAR_CATEGORY_NAMES
static UndoModel * GetCurrentUndoModel()
gives access to the currently used UndoModel Introduced to access special functions of more specific ...
virtual IViewRegistry * GetViewRegistry() const =0
static berry::IEditorPart::Pointer OpenEditor(berry::IWorkbenchPage::Pointer page, berry::IEditorInput::Pointer input, const QString &editorId, bool activate=false)
virtual Events::Types GetPartEventTypes() const =0
std::vector< StackDescriptionItem > StackDescription
virtual SmartPointer< IWorkbenchPage > ShowPerspective(const QString &perspectiveId, IWorkbenchWindow::Pointer window)=0
void SetViewExcludeList(const QList< QString > &v)
static void SafeHandleNavigatorView(QString view_query_name)