1/*
2 Copyright (c) 2009 Stephen Kelly <steveire@gmail.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#ifndef AKONADI_DRAGDROPMANAGER_P_H
21#define AKONADI_DRAGDROPMANAGER_P_H
22
23#include <QAbstractItemView>
24
25#include "akonadi/collection.h"
26
27namespace Akonadi
28{
29
30class DragDropManager
31{
32public:
33 explicit DragDropManager(QAbstractItemView *view);
34
35 /**
36 * @returns True if the drop described in @p event is allowed.
37 */
38 bool dropAllowed(QDragMoveEvent *event) const;
39
40 /**
41 * Process an attempted drop event.
42 *
43 * Attempts to show a popup menu with possible actions for @p event.
44 *
45 * @returns True if the event should be further processed, and false otherwise.
46 */
47 bool processDropEvent(QDropEvent *event, bool &menuCanceled, bool dropOnItem = true);
48
49 /**
50 * Starts a drag if possible and sets the appropriate supported actions to allow moves.
51 *
52 * Also sets the pixmap for hte drag to something appropriately small, overriding the Qt
53 * behaviour of creating a painting of all selected rows when dragging.
54 */
55 void startDrag(Qt::DropActions supportedActions);
56
57 /**
58 * Sets whether to @p show the drop action menu on drop operation.
59 */
60 void setShowDropActionMenu(bool show);
61
62 /**
63 * Returns whether the drop action menu is shown on drop operation.
64 */
65 bool showDropActionMenu() const;
66
67 bool isManualSortingActive() const;
68
69 /**
70 * Set true if we automatic sorting
71 */
72 void setManualSortingActive(bool active);
73
74private:
75 Collection currentDropTarget(QDropEvent *event) const;
76
77 bool hasAncestor(const QModelIndex &index, Collection::Id parentId) const;
78 bool mShowDropActionMenu;
79 bool mIsManualSortingActive;
80 QAbstractItemView *m_view;
81};
82
83}
84
85#endif
86