Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkDefaultDropTargetListener.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 
19 #include <QDebug>
20 #include <QDropEvent>
21 #include <QMimeData>
22 #include <QStringList>
23 #include <QUrl>
24 
25 #include "internal/org_mitk_gui_qt_application_Activator.h"
26 
28 #include <berryIPreferences.h>
29 #include <berryPlatformUI.h>
30 
31 #include <mitkWorkbenchUtil.h>
32 
33 class QmitkDefaultDropTargetListenerPrivate
34 {
35 public:
36 
37  berry::IPreferences::Pointer GetPreferences() const
38  {
39  berry::IPreferencesService* prefService = mitk::PluginActivator::GetInstance()->GetPreferencesService();
40  if (prefService)
41  {
42  return prefService->GetSystemPreferences()->Node("/General");
43  }
44  return berry::IPreferences::Pointer(nullptr);
45  }
46 
47  bool GetOpenEditor() const
48  {
49  berry::IPreferences::Pointer prefs = GetPreferences();
50  if(prefs.IsNotNull())
51  {
52  return prefs->GetBool("OpenEditor", true);
53  }
54  return true;
55  }
56 };
57 
59  : berry::IDropTargetListener(), d(new QmitkDefaultDropTargetListenerPrivate())
60 {
61 }
62 
64 {
65 }
66 
67 berry::IDropTargetListener::Events::Types QmitkDefaultDropTargetListener::GetDropTargetEventTypes() const
68 {
69  return Events::DROP;
70 }
71 
73 {
74  qDebug() << event->mimeData()->formats();
75  qDebug() << event->mimeData()->text();
76 
77  QList<QUrl> fileNames = event->mimeData()->urls();
78  if (fileNames.empty())
79  return;
80 
81  QStringList fileNames2;
82  foreach(QUrl url, fileNames)
83  {
84  fileNames2.push_back(url.toLocalFile());
85  }
86 
88  berry::PlatformUI::GetWorkbench()->GetActiveWorkbenchWindow(),
89  d->GetOpenEditor());
90 
91  event->accept();
92 }
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()
void DropEvent(QDropEvent *event) override
Events::Types GetDropTargetEventTypes() const override
berry::SmartPointer< Self > Pointer