File indexing completed on 2025-04-27 03:58:27

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2010-01-16
0007  * Description : Item view for listing items in a categorized fashion optionally
0008  *
0009  * SPDX-FileCopyrightText: 2007      by Rafael Fernández López <ereslibre at kde dot org>
0010  * SPDX-FileCopyrightText: 2009-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0011  * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0012  *
0013  * SPDX-License-Identifier: GPL-2.0-or-later
0014  *
0015  * ============================================================ */
0016 
0017 #ifndef DIGIKAM_DCATEGORIZED_VIEW_H
0018 #define DIGIKAM_DCATEGORIZED_VIEW_H
0019 
0020 // Qt includes
0021 
0022 #include <QListView>
0023 
0024 // Local includes
0025 
0026 #include "digikam_export.h"
0027 
0028 namespace Digikam
0029 {
0030 
0031 class DCategoryDrawer;
0032 
0033 /**
0034  * @short Item view for listing items
0035  *
0036  * DCategorizedView allows you to use it as it were a QListView.
0037  * Subclass DCategorizedSortFilterProxyModel to provide category information for items.
0038  */
0039 class DIGIKAM_EXPORT DCategorizedView : public QListView
0040 {
0041     Q_OBJECT
0042 
0043 public:
0044 
0045     explicit DCategorizedView(QWidget* const parent = nullptr);
0046     ~DCategorizedView() override;
0047 
0048     void setGridSize(const QSize& size);
0049 
0050     void setCategoryDrawer(DCategoryDrawer* categoryDrawer);
0051     DCategoryDrawer* categoryDrawer()                                                   const;
0052 
0053     /**
0054      * Switch on drawing of dragged items. Default: on.
0055      * While dragging over the view, dragged items will be drawn transparently
0056      * following the mouse cursor.
0057      *
0058      * @param drawDraggedItems if <code>true</code>, dragged items will be
0059      *                         drawn
0060      */
0061     void setDrawDraggedItems(bool drawDraggedItems);
0062 
0063     void        setModel(QAbstractItemModel* model)                                    override;
0064     QRect       visualRect(const QModelIndex& index)                            const  override;
0065     QModelIndex indexAt(const QPoint& point)                                    const  override;
0066 
0067     /**
0068      * This method will return all indexes whose visual rect intersects @p rect.
0069      * @param rect rectangle to test intersection with
0070      * @note Returns an empty list if the view is not categorized.
0071      */
0072     virtual QModelIndexList categorizedIndexesIn(const QRect& rect)                     const;
0073 
0074     /**
0075      * This method will return the visual rect of the header of the category
0076      * in which @p index is sorted.
0077      * @note Returns QRect() if the view is not categorized.
0078      */
0079     virtual QRect categoryVisualRect(const QModelIndex& index)                          const;
0080 
0081     /**
0082      * This method will return the first index of the category
0083      * in the region of which @p point is found.
0084      * @note Returns QModelIndex() if the view is not categorized.
0085      */
0086     virtual QModelIndex categoryAt(const QPoint& point)                                 const;
0087 
0088     /**
0089      * This method returns the range of indexes contained
0090      * in the category in which @p index is sorted.
0091      * @note Returns an empty range if the view is no categorized.
0092      */
0093     virtual QItemSelectionRange categoryRange(const QModelIndex& index)                 const;
0094 
0095 public Q_SLOTS:
0096 
0097     void reset()                                                                       override;
0098 
0099 protected:
0100 
0101     void paintEvent(QPaintEvent* event)                                                override;
0102 
0103     void resizeEvent(QResizeEvent* event)                                              override;
0104 
0105     void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags flags)    override;
0106 
0107     void mouseMoveEvent(QMouseEvent* event)                                            override;
0108 
0109     void mousePressEvent(QMouseEvent* event)                                           override;
0110 
0111     void mouseReleaseEvent(QMouseEvent* event)                                         override;
0112 
0113     void leaveEvent(QEvent* event)                                                     override;
0114 
0115     void startDrag(Qt::DropActions supportedActions)                                   override;
0116 
0117     void dragMoveEvent(QDragMoveEvent* event)                                          override;
0118 
0119     void dragLeaveEvent(QDragLeaveEvent* event)                                        override;
0120 
0121     void dropEvent(QDropEvent* event)                                                  override;
0122 
0123     QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
0124 
0125 protected Q_SLOTS:
0126 
0127     void rowsInserted(const QModelIndex& parent, int start, int end)                   override;
0128 
0129     virtual void rowsInsertedArtifficial(const QModelIndex& parent, int start, int end);
0130 
0131     virtual void rowsRemoved(const QModelIndex& parent, int start, int end);
0132 
0133     void updateGeometries()                                                            override;
0134 
0135     virtual void slotLayoutChanged();
0136 
0137     void currentChanged(const QModelIndex& current, const QModelIndex& previous)       override;
0138 
0139 private:
0140 
0141     class Private;
0142     Private* const d;
0143 };
0144 
0145 } // namespace Digikam
0146 
0147 #endif // DIGIKAM_DCATEGORIZED_VIEW_H