File indexing completed on 2024-06-16 04:50:37

0001 /*
0002     SPDX-FileCopyrightText: 2009 Stephen Kelly <steveire@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "collection.h"
0010 #include <QAbstractItemView>
0011 
0012 namespace Akonadi
0013 {
0014 class DragDropManager
0015 {
0016 public:
0017     explicit DragDropManager(QAbstractItemView *view);
0018 
0019     /**
0020      * @returns True if the drop described in @p event is allowed.
0021      */
0022     bool dropAllowed(QDragMoveEvent *event) const;
0023 
0024     /**
0025      * Process an attempted drop event.
0026      *
0027      * Attempts to show a popup menu with possible actions for @p event.
0028      *
0029      * @returns True if the event should be further processed, and false otherwise.
0030      */
0031     bool processDropEvent(QDropEvent *event, bool &menuCanceled, bool dropOnItem = true);
0032 
0033     /**
0034      * Starts a drag if possible and sets the appropriate supported actions to allow moves.
0035      *
0036      * Also sets the pixmap for the drag to something appropriately small, overriding the Qt
0037      * behaviour of creating a painting of all selected rows when dragging.
0038      */
0039     void startDrag(Qt::DropActions supportedActions);
0040 
0041     /**
0042      * Sets whether to @p show the drop action menu on drop operation.
0043      */
0044     void setShowDropActionMenu(bool show);
0045 
0046     /**
0047      * Returns whether the drop action menu is shown on drop operation.
0048      */
0049     [[nodiscard]] bool showDropActionMenu() const;
0050 
0051     [[nodiscard]] bool isManualSortingActive() const;
0052 
0053     /**
0054      * Set true if we automatic sorting
0055      */
0056     void setManualSortingActive(bool active);
0057 
0058 private:
0059     Collection currentDropTarget(QDropEvent *event) const;
0060 
0061     bool hasAncestor(const QModelIndex &index, Collection::Id parentId) const;
0062     bool mShowDropActionMenu = true;
0063     bool mIsManualSortingActive = false;
0064     QAbstractItemView *const m_view;
0065 };
0066 
0067 }