File indexing completed on 2025-01-19 03:57:33

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2012-07-13
0007  * Description : Qt categorized item view for showfoto items
0008  *
0009  * SPDX-FileCopyrightText: 2013 by Mohamed_Anwer <m_dot_anwer at gmx dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #ifndef SHOW_FOTO_CATEGORIZED_VIEW_H
0016 #define SHOW_FOTO_CATEGORIZED_VIEW_H
0017 
0018 // Local includes
0019 
0020 #include "itemviewcategorized.h"
0021 #include "showfotoitemmodel.h"
0022 #include "showfotofiltermodel.h"
0023 #include "showfotothumbnailmodel.h"
0024 #include "showfotoiteminfo.h"
0025 #include "itemdelegateoverlay.h"
0026 
0027 namespace ShowFoto
0028 {
0029 
0030 class ShowfotoDelegate;
0031 
0032 class ShowfotoCategorizedView : public ItemViewCategorized
0033 {
0034 public:
0035 
0036     Q_OBJECT
0037 
0038 public:
0039 
0040     explicit ShowfotoCategorizedView(QWidget* const parent = nullptr);
0041     ~ShowfotoCategorizedView() override;
0042 
0043     void setModels(ShowfotoItemModel* model, ShowfotoSortFilterModel* filterModel);
0044 
0045     ShowfotoItemModel*          showfotoItemModel()                     const;
0046     ShowfotoSortFilterModel*    showfotoSortFilterModel()               const;
0047 
0048     QItemSelectionModel*        getSelectionModel()                     const;
0049 
0050     /// Returns any ShowfotoFilterModel in chain. May not be sourceModel()
0051     ShowfotoFilterModel*        showfotoFilterModel()                   const;
0052 
0053     /// Returns 0 if the ShowfotoItemModel is not an ShowfotoThumbnailModel
0054     ShowfotoThumbnailModel*     showfotoThumbnailModel()                const;
0055 
0056     ShowfotoDelegate*           delegate()                              const;
0057 
0058     ShowfotoItemInfo            currentInfo()                           const;
0059     QUrl                        currentUrl()                            const;
0060 
0061     QList<ShowfotoItemInfo>     selectedShowfotoItemInfos()             const;
0062     QList<ShowfotoItemInfo>     selectedShowfotoItemInfosCurrentFirst() const;
0063     QList<QUrl>                 selectedUrls()                          const;
0064 
0065     QList<ShowfotoItemInfo>     showfotoItemInfos()                     const;
0066     QList<QUrl>                 urls()                                  const;
0067 
0068     /**
0069      * Selects the index as current and scrolls to it
0070      */
0071     void toIndex(const QUrl& url);
0072 
0073     /**
0074      * Returns the n-th info after the given one.
0075      * Specifically, return the previous info for nth = -1
0076      * and the next info for n = 1.
0077      * Returns a null info if either startingPoint or the nth info are
0078      * not contained in the model
0079      */
0080     ShowfotoItemInfo nextInOrder(const ShowfotoItemInfo& startingPoint, int nth);
0081 
0082     ShowfotoItemInfo previousInfo(const ShowfotoItemInfo& info);
0083     ShowfotoItemInfo nextInfo(const ShowfotoItemInfo& info);
0084 
0085     /**
0086      * Add and remove an overlay. It will as well be removed automatically when destroyed.
0087      * Unless you pass a different delegate, the current delegate will be used.
0088      */
0089     void addOverlay(ItemDelegateOverlay* overlay, ShowfotoDelegate* delegate = nullptr);
0090     void removeOverlay(ItemDelegateOverlay* overlay);
0091 
0092     // TODO: Implement This
0093 /*
0094     void addSelectionOverlay(ShowfotoDelegate* delegate = 0);
0095 */
0096     ThumbnailSize thumbnailSize() const;
0097 
0098     virtual void setThumbnailSize(const ThumbnailSize& size);
0099 
0100 public Q_SLOTS:
0101 
0102     void setThumbnailSize(int size);
0103 
0104     /**
0105      * Scroll the view to the given item when it becomes available
0106      */
0107     void setCurrentWhenAvailable(qlonglong ShowfotoItemId);
0108 
0109     /**
0110      * Set as current item the item identified by its file url
0111      */
0112     void setCurrentUrl(const QUrl& url);
0113 
0114     /**
0115      * Set as current item the item identified by the ShowfotoItemInfo
0116      */
0117     void setCurrentInfo(const ShowfotoItemInfo& info);
0118 
0119     /**
0120      * Set selected items identified by their file urls
0121      */
0122     void setSelectedUrls(const QList<QUrl>& urlList);
0123 
0124     /**
0125      * Set selected items
0126      */
0127     void setSelectedShowfotoItemInfos(const QList<ShowfotoItemInfo>& infos);
0128 
0129     /**
0130      * Does something to gain attention for info, but not changing current selection
0131      */
0132     void hintAt(const ShowfotoItemInfo& info);
0133 
0134 Q_SIGNALS:
0135 
0136     void currentChanged(const ShowfotoItemInfo& info);
0137 
0138     /**
0139      * Emitted when new items are selected. The parameter includes only the newly selected infos,
0140      * there may be other already selected infos.
0141      */
0142     void selected(const QList<ShowfotoItemInfo>& newSelectedInfos);
0143 
0144     /**
0145      * Emitted when items are deselected. There may be other selected infos left.
0146      * This signal is not emitted when the model is reset; then only selectionCleared is emitted.
0147      */
0148     void deselected(const QList<ShowfotoItemInfo>& nowDeselectedInfos);
0149 
0150     /**
0151      * Emitted when the given ShowfotoItemInfo is activated. Info is never null.
0152      */
0153     void showfotoItemInfoActivated(const ShowfotoItemInfo& info);
0154 
0155     /**
0156      * Emitted when a new model is set.
0157      */
0158     void modelChanged();
0159 
0160 protected:
0161 
0162     /// reimplemented from parent class
0163     QSortFilterProxyModel*       filterModel()                                                                       const override;
0164     AbstractItemDragDropHandler* dragDropHandler()                                                                   const override;
0165     QModelIndex                  nextIndexHint(const QModelIndex& indexToAnchor, const QItemSelectionRange& removed) const override;
0166 
0167     void setItemDelegate(ShowfotoDelegate* delegate);
0168     void indexActivated(const QModelIndex& index, Qt::KeyboardModifiers modifiers)                                         override;
0169     void currentChanged(const QModelIndex& index, const QModelIndex& previous)                                             override;
0170     void paintEvent(QPaintEvent* e)                                                                                        override;
0171     void selectionChanged(const QItemSelection&, const QItemSelection&)                                                    override;
0172     void updateGeometries()                                                                                                override;
0173 
0174     /// Reimplement these in a subclass
0175     virtual void activated(const ShowfotoItemInfo& info, Qt::KeyboardModifiers modifiers);
0176     virtual void showContextMenuOnInfo(QContextMenuEvent* event, const ShowfotoItemInfo& info);
0177     void showContextMenuOnIndex(QContextMenuEvent* event, const QModelIndex& index) override;
0178 
0179 private Q_SLOTS:
0180 
0181     void slotFileChanged(const QString& filePath);
0182     void slotDelayedEnter();
0183 
0184 private:
0185 
0186     void scrollToStoredItem();
0187 
0188 private:
0189 
0190     // Disable
0191     ShowfotoCategorizedView(const ShowfotoCategorizedView&)            = delete;
0192     ShowfotoCategorizedView& operator=(const ShowfotoCategorizedView&) = delete;
0193 
0194 private:
0195 
0196     class Private;
0197     Private* const d;
0198 };
0199 
0200 } // namespace Showfoto
0201 
0202 #endif // SHOW_FOTO_CATEGORIZED_VIEW_H