File indexing completed on 2025-03-09 03:58:42

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