File indexing completed on 2025-01-05 03:51:14
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-04-22 0007 * Description : Qt model-view for items 0008 * 0009 * SPDX-FileCopyrightText: 2009-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0010 * SPDX-FileCopyrightText: 2017 by Simon Frei <freisim93 at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #ifndef DIGIKAM_ITEM_CATEGORIZED_VIEW_H 0017 #define DIGIKAM_ITEM_CATEGORIZED_VIEW_H 0018 0019 // Local includes 0020 0021 #include "iteminfo.h" 0022 #include "itemviewcategorized.h" 0023 #include "thumbnailsize.h" 0024 #include "iccsettingscontainer.h" 0025 0026 namespace Digikam 0027 { 0028 0029 class Album; 0030 class ItemAlbumModel; 0031 class ItemAlbumFilterModel; 0032 class ItemModel; 0033 class ItemFilterModel; 0034 class ImageSortFilterModel; 0035 class ItemDelegate; 0036 class ItemDelegateOverlay; 0037 class ItemThumbnailModel; 0038 0039 class ItemCategorizedView : public ItemViewCategorized 0040 { 0041 Q_OBJECT 0042 0043 public: 0044 0045 explicit ItemCategorizedView(QWidget* const parent = nullptr); 0046 ~ItemCategorizedView() override; 0047 0048 void setModels(ItemModel* model, ImageSortFilterModel* filterModel); 0049 0050 ItemModel* imageModel() const; 0051 ImageSortFilterModel* imageSortFilterModel() const; 0052 0053 QItemSelectionModel* getSelectionModel() const; 0054 0055 /// Returns any ItemFilterMode in chain. May not be sourceModel() 0056 ItemFilterModel* imageFilterModel() const; 0057 0058 /// Returns 0 if the ItemModel is not an ItemThumbnailModel 0059 ItemThumbnailModel* imageThumbnailModel() const; 0060 0061 /// Returns 0 if the ItemModel is not an ItemAlbumModel 0062 ItemAlbumModel* imageAlbumModel() const; 0063 ItemAlbumFilterModel* imageAlbumFilterModel() const; 0064 0065 ItemDelegate* delegate() const; 0066 0067 Album* currentAlbum() const; 0068 ItemInfo currentInfo() const; 0069 QUrl currentUrl() const; 0070 0071 ItemInfoList allItemInfos() const; 0072 QList<QUrl> allUrls() const; 0073 ItemInfoList selectedItemInfos() const; 0074 ItemInfoList selectedItemInfosCurrentFirst() const; 0075 0076 /** Selects the index as current and scrolls to it. 0077 */ 0078 void toIndex(const QUrl& url); 0079 0080 /** Returns the n-th info after the given one. 0081 * Specifically, return the previous info for nth = -1 0082 * and the next info for n = 1. 0083 * Returns a null info if either startingPoint or the nth info are 0084 * not contained in the model. 0085 */ 0086 ItemInfo nextInOrder(const ItemInfo& startingPoint, int nth); 0087 0088 ItemInfo previousInfo(const ItemInfo& info) 0089 { 0090 return nextInOrder(info, -1); 0091 } 0092 0093 ItemInfo nextInfo(const ItemInfo& info) 0094 { 0095 return nextInOrder(info, 1); 0096 } 0097 0098 QModelIndex indexForInfo(const ItemInfo& info) const; 0099 0100 ThumbnailSize thumbnailSize() const; 0101 0102 virtual void setThumbnailSize(const ThumbnailSize& size); 0103 0104 /** If the model is categorized by an album, returns the album of the category 0105 * that contains the position. 0106 * If this is not applicable, return the current album. May return 0. 0107 */ 0108 Album* albumAt(const QPoint& pos) const; 0109 0110 /// Add and remove an overlay. It will as well be removed automatically when destroyed. 0111 /// Unless you pass a different delegate, the current delegate will be used. 0112 void addOverlay(ItemDelegateOverlay* overlay, ItemDelegate* delegate = nullptr); 0113 0114 void removeOverlay(ItemDelegateOverlay* overlay); 0115 0116 void addSelectionOverlay(ItemDelegate* delegate = nullptr); 0117 0118 public Q_SLOTS: 0119 0120 void openAlbum(const QList<Album*>& album); 0121 0122 void setThumbnailSize(int size); 0123 0124 /** Scroll the view to the given item when it becomes available. 0125 */ 0126 void setCurrentWhenAvailable(qlonglong imageId); 0127 0128 /** Set as current item when it becomes available, the item identified by its file url. 0129 */ 0130 void setCurrentUrlWhenAvailable(const QUrl& url); 0131 0132 /** Set as current item the item identified by its file url. 0133 */ 0134 void setCurrentUrl(const QUrl& url); 0135 0136 /** Set as current item the item identified by the imageinfo. 0137 */ 0138 void setCurrentInfo(const ItemInfo& info); 0139 0140 /** Set selected items identified by their file urls. 0141 */ 0142 void setSelectedUrls(const QList<QUrl>& urlList); 0143 0144 /** Set selected items. 0145 */ 0146 void setSelectedItemInfos(const QList<ItemInfo>& infos); 0147 0148 /** Does something to gain attention for info, but not changing current selection. 0149 */ 0150 void hintAt(const ItemInfo& info); 0151 0152 Q_SIGNALS: 0153 0154 void currentChanged(const ItemInfo& info); 0155 0156 /// Emitted when new items are selected. The parameter includes only the newly selected infos, 0157 /// there may be other already selected infos. 0158 void selected(const QList<ItemInfo>& newSelectedInfos); 0159 0160 /// Emitted when items are deselected. There may be other selected infos left. 0161 /// This signal is not emitted when the model is reset; then only selectionCleared is emitted. 0162 void deselected(const QList<ItemInfo>& nowDeselectedInfos); 0163 0164 /// Emitted when the given image is activated. Info is never null. 0165 void imageActivated(const ItemInfo& info); 0166 0167 /// Emitted when a new model is set 0168 void modelChanged(); 0169 0170 protected Q_SLOTS: 0171 0172 void slotItemInfosAdded(); 0173 void slotCurrentUrlTimer(); 0174 0175 protected: 0176 0177 /// install default ItemAlbumModel and filter model, ready for use 0178 void installDefaultModels(); 0179 0180 // reimplemented from parent class 0181 0182 QSortFilterProxyModel* filterModel() const override; 0183 AbstractItemDragDropHandler* dragDropHandler() const override; 0184 QModelIndex nextIndexHint(const QModelIndex& indexToAnchor, 0185 const QItemSelectionRange& removed) const override; 0186 0187 void setItemDelegate(ItemDelegate* delegate); 0188 void indexActivated(const QModelIndex& index, Qt::KeyboardModifiers modifiers) override; 0189 void currentChanged(const QModelIndex& index, const QModelIndex& previous) override; 0190 void selectionChanged(const QItemSelection&, const QItemSelection&) override; 0191 void updateGeometries() override; 0192 0193 /// Reimplement these in a subclass 0194 virtual void activated(const ItemInfo& info, Qt::KeyboardModifiers modifiers); 0195 virtual void showContextMenuOnInfo(QContextMenuEvent* event, const ItemInfo& info); 0196 void showContextMenuOnIndex(QContextMenuEvent* event, const QModelIndex& index) override; 0197 0198 ItemInfo imageInfo(const QModelIndex& index) const; 0199 ItemInfoList imageInfos(const QList<QModelIndex>& indexes) const; 0200 0201 private Q_SLOTS: 0202 0203 void slotIccSettingsChanged(const ICCSettingsContainer&, const ICCSettingsContainer&); 0204 void slotFileChanged(const QString& filePath); 0205 void slotDelayedEnter(); 0206 0207 private: 0208 0209 void scrollToStoredItem(); 0210 0211 private: 0212 0213 class Private; 0214 Private* const d; 0215 }; 0216 0217 } // namespace Digikam 0218 0219 #endif // DIGIKAM_ITEM_CATEGORIZED_VIEW_H