File indexing completed on 2024-05-26 05:14:42

0001 /*
0002     SPDX-FileCopyrightText: 2006-2007 Volker Krause <vkrause@kde.org>
0003     SPDX-FileCopyrightText: 2008 Stephen Kelly <steveire@gmail.com>
0004     SPDX-FileCopyrightText: 2009 Kevin Ottens <ervin@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #pragma once
0010 
0011 #include "akonadiwidgets_export.h"
0012 
0013 #include <QListView>
0014 
0015 #include <memory>
0016 
0017 class KXMLGUIClient;
0018 class QDragMoveEvent;
0019 
0020 namespace Akonadi
0021 {
0022 class Collection;
0023 class Item;
0024 class EntityListViewPrivate;
0025 
0026 /**
0027  * @short A view to show an item/collection list provided by an EntityTreeModel.
0028  *
0029  * When a KXmlGuiWindow is passed to the constructor, the XMLGUI
0030  * defined context menu @c akonadi_collectionview_contextmenu or
0031  * @c akonadi_itemview_contextmenu is used if available.
0032  *
0033  * Example:
0034  *
0035  * @code
0036  *
0037  * using namespace Akonadi;
0038  *
0039  * class MyWindow : public KXmlGuiWindow
0040  * {
0041  *   public:
0042  *    MyWindow()
0043  *      : KXmlGuiWindow()
0044  *    {
0045  *      EntityListView *view = new EntityListView( this, this );
0046  *      setCentralWidget( view );
0047  *
0048  *      EntityTreeModel *model = new EntityTreeModel( ... );
0049  *
0050  *      KDescendantsProxyModel *flatModel = new KDescendantsProxyModel( this );
0051  *      flatModel->setSourceModel( model );
0052  *
0053  *      view->setModel( flatModel );
0054  *    }
0055  * }
0056  *
0057  * @endcode
0058  *
0059  * @author Volker Krause <vkrause@kde.org>
0060  * @author Stephen Kelly <steveire@gmail.com>
0061  * @since 4.4
0062  */
0063 class AKONADIWIDGETS_EXPORT EntityListView : public QListView
0064 {
0065     Q_OBJECT
0066 
0067 public:
0068     /**
0069      * Creates a new favorite collections view.
0070      *
0071      * @param parent The parent widget.
0072      */
0073     explicit EntityListView(QWidget *parent = nullptr);
0074 
0075     /**
0076      * Creates a new favorite collections view.
0077      *
0078      * @param xmlGuiClient The KXMLGUIClient the view is used in.
0079      *                     This is needed for the XMLGUI based context menu.
0080      *                     Passing 0 is ok and will disable the builtin context menu.
0081      * @param parent The parent widget.
0082      */
0083     explicit EntityListView(KXMLGUIClient *xmlGuiClient, QWidget *parent = nullptr);
0084 
0085     /**
0086      * Destroys the favorite collections view.
0087      */
0088     ~EntityListView() override;
0089 
0090     /**
0091      * Sets the XML GUI client which the view is used in.
0092      *
0093      * This is needed if you want to use the built-in context menu.
0094      *
0095      * @param xmlGuiClient The KXMLGUIClient the view is used in.
0096      */
0097     void setXmlGuiClient(KXMLGUIClient *xmlGuiClient);
0098 
0099     /**
0100      * Return the XML GUI client which the view is used in.
0101      * @since 4.12
0102      */
0103     KXMLGUIClient *xmlGuiClient() const;
0104 
0105     /**
0106      * @reimp
0107      * @param model the model to set
0108      */
0109     void setModel(QAbstractItemModel *model) override;
0110 
0111     /**
0112      * Sets whether the drop action menu is @p enabled and will
0113      * be shown on drop operation.
0114      * @param enabled enables drop action menu if set as @c true
0115      * @since 4.7
0116      */
0117     void setDropActionMenuEnabled(bool enabled);
0118 
0119     /**
0120      * Returns whether the drop action menu is enabled and will
0121      * be shown on drop operation.
0122      *
0123      * @since 4.7
0124      */
0125     [[nodiscard]] bool isDropActionMenuEnabled() const;
0126 
0127 Q_SIGNALS:
0128     /**
0129      * This signal is emitted whenever the user has clicked
0130      * a collection in the view.
0131      *
0132      * @param collection The clicked collection.
0133      */
0134     void clicked(const Akonadi::Collection &collection);
0135 
0136     /**
0137      * This signal is emitted whenever the user has clicked
0138      * an item in the view.
0139      *
0140      * @param item The clicked item.
0141      */
0142     void clicked(const Akonadi::Item &item);
0143 
0144     /**
0145      * This signal is emitted whenever the user has double clicked
0146      * a collection in the view.
0147      *
0148      * @param collection The double clicked collection.
0149      */
0150     void doubleClicked(const Akonadi::Collection &collection);
0151 
0152     /**
0153      * This signal is emitted whenever the user has double clicked
0154      * an item in the view.
0155      *
0156      * @param item The double clicked item.
0157      */
0158     void doubleClicked(const Akonadi::Item &item);
0159 
0160     /**
0161      * This signal is emitted whenever the current collection
0162      * in the view has changed.
0163      *
0164      * @param collection The new current collection.
0165      */
0166     void currentChanged(const Akonadi::Collection &collection);
0167 
0168     /**
0169      * This signal is emitted whenever the current item
0170      * in the view has changed.
0171      *
0172      * @param item The new current item.
0173      */
0174     void currentChanged(const Akonadi::Item &item);
0175 
0176 protected:
0177     using QListView::currentChanged;
0178 #ifndef QT_NO_DRAGANDDROP
0179     void startDrag(Qt::DropActions supportedActions) override;
0180     void dropEvent(QDropEvent *event) override;
0181     void dragMoveEvent(QDragMoveEvent *event) override;
0182 #endif
0183 
0184 #ifndef QT_NO_CONTEXTMENU
0185     void contextMenuEvent(QContextMenuEvent *event) override;
0186 #endif
0187 
0188 private:
0189     /// @cond PRIVATE
0190     std::unique_ptr<EntityListViewPrivate> const d;
0191     /// @endcond
0192 };
0193 
0194 }