digiKam
dragdropimplementations.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2011-01-02
7  * Description : Sample implementations for drag and drop handling
8  *
9  * Copyright (C) 2009-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_DRAG_DROP_IMPLEMENTATIONS_H
25 #define DIGIKAM_DRAG_DROP_IMPLEMENTATIONS_H
26 
27 // Qt includes
28 
29 #include <QAbstractItemView>
30 
31 // Local includes
32 
33 #include "digikam_export.h"
35 
36 namespace Digikam
37 {
38 
39 class DIGIKAM_EXPORT DragDropModelImplementation
40 {
41 public:
42 
49  virtual ~DragDropModelImplementation();
50 
56  Qt::DropActions supportedDropActions() const;
57  QStringList mimeTypes() const;
58  bool dropMimeData(const QMimeData*,
60  int,
61  int,
62  const QModelIndex&);
63  QMimeData* mimeData(const QModelIndexList& indexes) const;
64 
71  virtual Qt::ItemFlags dragDropFlags(const QModelIndex& index) const;
72 
80  Qt::ItemFlags dragDropFlagsV2(const QModelIndex& index) const;
81  virtual bool isDragEnabled(const QModelIndex& index) const;
82  virtual bool isDropEnabled(const QModelIndex& index) const;
83 
87  void setDragDropHandler(AbstractItemDragDropHandler* handler);
88  AbstractItemDragDropHandler* dragDropHandler() const;
89 
90 #define DECLARE_MODEL_DRAG_DROP_METHODS \
91  virtual Qt::DropActions supportedDropActions() const override \
92  { return DragDropModelImplementation::supportedDropActions(); } \
93  virtual QStringList mimeTypes() const override \
94  { return DragDropModelImplementation::mimeTypes(); } \
95  virtual bool dropMimeData(const QMimeData* d, Qt::DropAction a, \
96  int r, int c, const QModelIndex& p) override \
97  { return DragDropModelImplementation::dropMimeData(d, a, r, c, p); } \
98  virtual QMimeData* mimeData(const QModelIndexList& indexes) const override \
99  { return DragDropModelImplementation::mimeData(indexes); }
100 
101 protected:
102 
104 
105 private:
106 
107  Q_DISABLE_COPY(DragDropModelImplementation)
108 };
109 
110 // --------------------------------------------------------------------------------------------
111 
112 class DIGIKAM_EXPORT DragDropViewImplementation
113 {
114 public:
115 
117  virtual ~DragDropViewImplementation() = default;
118 
119  virtual void cut();
120  virtual void copy();
121  virtual void paste();
122 
123 protected:
124 
128  virtual QAbstractItemView* asView() = 0;
129 
135 
140  virtual QModelIndex mapIndexForDragDrop(const QModelIndex& index) const = 0;
141 
145  virtual QPixmap pixmapForDrag(const QList<QModelIndex>& indexes) const = 0;
146 
150  void dragEnterEvent(QDragEnterEvent* event);
151  void dragMoveEvent(QDragMoveEvent* e);
152  void dropEvent(QDropEvent* e);
153  void startDrag(Qt::DropActions supportedActions);
154 
155 #define DECLARE_VIEW_DRAG_DROP_METHODS(ParentViewClass) \
156  virtual QAbstractItemView* asView() override \
157  { return this; } \
158  void dragEnterEvent(QDragEnterEvent* e) override \
159  { DragDropViewImplementation::dragEnterEvent(e); } \
160  void dragMoveEvent(QDragMoveEvent* e) override \
161  { ParentViewClass::dragMoveEvent(e); \
162  DragDropViewImplementation::dragMoveEvent(e); } \
163  void dropEvent(QDropEvent* e) override \
164  { ParentViewClass::dropEvent(e); \
165  DragDropViewImplementation::dropEvent(e); } \
166  void startDrag(Qt::DropActions supportedActions) override \
167  { DragDropViewImplementation::startDrag(supportedActions); }
168 
169  void encodeIsCutSelection(QMimeData* mime, bool isCutSelection);
170  bool decodeIsCutSelection(const QMimeData* mimeData);
171 
172 private:
173 
174  Q_DISABLE_COPY(DragDropViewImplementation)
175 };
176 
177 } // namespace Digikam
178 
179 #endif // DIGIKAM_DRAG_DROP_IMPLEMENTATIONS_H
Definition: abstractitemdragdrophandler.h:42
Definition: dragdropimplementations.h:40
AbstractItemDragDropHandler * m_dragDropHandler
Definition: dragdropimplementations.h:103
Definition: dragdropimplementations.h:113
virtual QAbstractItemView * asView()=0
virtual QPixmap pixmapForDrag(const QList< QModelIndex > &indexes) const =0
virtual QModelIndex mapIndexForDragDrop(const QModelIndex &index) const =0
virtual AbstractItemDragDropHandler * dragDropHandler() const =0
virtual ~DragDropViewImplementation()=default
Definition: datefolderview.cpp:43
DropAction
Definition: itemdragdrop.cpp:60