Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkDnDFrameWidget.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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include <QmitkDnDFrameWidget.h>
18 
20 #include <berryIPreferences.h>
21 #include <berryPlatformUI.h>
22 
23 #include "internal/QmitkCommonActivator.h"
24 
25 #include <mitkWorkbenchUtil.h>
26 
27 #include <QDragEnterEvent>
28 #include <QMimeData>
29 
30 class QmitkDnDFrameWidgetPrivate
31 {
32 public:
33 
34  berry::IPreferences::Pointer GetPreferences() const
35  {
36  berry::IPreferencesService* prefService = QmitkCommonActivator::GetInstance()->GetPreferencesService();
37  if (prefService)
38  {
39  return prefService->GetSystemPreferences()->Node("/General");
40  }
41  return berry::IPreferences::Pointer(nullptr);
42  }
43 
44  bool GetOpenEditor() const
45  {
46  berry::IPreferences::Pointer prefs = GetPreferences();
47  if(prefs.IsNotNull())
48  {
49  return prefs->GetBool("OpenEditor", true);
50  }
51  return true;
52  }
53 
54 };
55 
57 : QWidget(parent), d(new QmitkDnDFrameWidgetPrivate())
58 {
59  setAcceptDrops(true);
60 }
61 
63 {
64 }
65 
66 void QmitkDnDFrameWidget::dragEnterEvent( QDragEnterEvent *event )
67 { // accept drags
68  event->acceptProposedAction();
69 }
70 
71 void QmitkDnDFrameWidget::dropEvent( QDropEvent * event )
72 { //open dragged files
73 
74  QList<QUrl> fileNames = event->mimeData()->urls();
75  if (fileNames.empty())
76  return;
77 
78  QStringList fileNames2;
79  foreach(QUrl url, fileNames)
80  {
81  fileNames2.push_back(url.toLocalFile());
82  }
83 
85  berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow(),
86  d->GetOpenEditor());
87 
88  event->accept();
89 }
virtual SmartPointer< IPreferences > GetSystemPreferences()=0
Implements transparent reference counting.
static void LoadFiles(const QStringList &fileNames, berry::IWorkbenchWindow::Pointer wnd, bool openEditor=true)
static IWorkbench * GetWorkbench()
QmitkDnDFrameWidget(QWidget *parent)
berry::SmartPointer< Self > Pointer