File indexing completed on 2025-01-19 03:55:42
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2008-05-21 0007 * Description : widget to display a list of items 0008 * 0009 * SPDX-FileCopyrightText: 2006-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2008-2010 by Andi Clemens <andi dot clemens at googlemail dot com> 0011 * SPDX-FileCopyrightText: 2009-2010 by Luka Renko <lure at kubuntu dot org> 0012 * 0013 * SPDX-License-Identifier: GPL-2.0-or-later 0014 * 0015 * ============================================================ */ 0016 0017 #ifndef DIGIKAM_DITEMS_LIST_H 0018 #define DIGIKAM_DITEMS_LIST_H 0019 0020 // Qt includes 0021 0022 #include <QBoxLayout> 0023 #include <QPushButton> 0024 #include <QStringList> 0025 #include <QTreeWidget> 0026 #include <QWidget> 0027 #include <QXmlStreamWriter> 0028 #include <QXmlStreamReader> 0029 #include <QIcon> 0030 #include <QUrl> 0031 0032 // Local includes 0033 0034 #include "loadingdescription.h" 0035 #include "digikam_export.h" 0036 #include "dinfointerface.h" 0037 0038 namespace Digikam 0039 { 0040 0041 class DItemsList; 0042 class DItemsListView; 0043 0044 /** 0045 * Type of static fonction used to customize sort items in list. 0046 * Sort items call this method in DItemsListViewItem::operator<. 0047 * To setup this method, uses DItemList::setIsLessThanHandler(). 0048 */ 0049 typedef bool (*DItemsListIsLessThanHandler)(const QTreeWidgetItem* current, const QTreeWidgetItem& other); 0050 0051 class DIGIKAM_EXPORT DItemsListViewItem : public QTreeWidgetItem 0052 { 0053 0054 public: 0055 0056 enum State 0057 { 0058 Waiting, 0059 Success, 0060 Failed 0061 }; 0062 0063 public: 0064 0065 explicit DItemsListViewItem(DItemsListView* const view, const QUrl& url); 0066 ~DItemsListViewItem() override; 0067 0068 bool hasValidThumbnail() const; 0069 0070 void setUrl(const QUrl& url); 0071 QUrl url() const; 0072 0073 void setComments(const QString& comments); 0074 QString comments() const; 0075 0076 void setTags(const QStringList& tags); 0077 QStringList tags() const; 0078 0079 void setRating(int rating); 0080 int rating() const; 0081 0082 void setThumb(const QPixmap& pix, bool hasThumb=true); 0083 void setProgressAnimation(const QPixmap& pix); 0084 0085 void setProcessedIcon(const QIcon& icon); 0086 void setState(State state); 0087 State state() const; 0088 0089 void updateInformation(); 0090 0091 void setIsLessThanHandler(DItemsListIsLessThanHandler fncptr); 0092 0093 /** 0094 * Implement this, if you have special item widgets, e.g. an edit line 0095 * they will be set automatically when adding items, changing order, etc. 0096 */ 0097 virtual void updateItemWidgets() {}; 0098 0099 protected: 0100 0101 DItemsListView* view() const; 0102 0103 private: 0104 0105 void setPixmap(const QPixmap& pix); 0106 bool operator<(const QTreeWidgetItem& other) const override; 0107 0108 private: 0109 0110 class Private; 0111 Private* const d; 0112 0113 private: 0114 0115 Q_DISABLE_COPY(DItemsListViewItem) 0116 }; 0117 0118 // ------------------------------------------------------------------------- 0119 0120 class DIGIKAM_EXPORT DItemsListView : public QTreeWidget 0121 { 0122 Q_OBJECT 0123 0124 public: 0125 0126 enum ColumnType 0127 { 0128 Thumbnail = 0, 0129 Filename, 0130 User1, 0131 User2, 0132 User3, 0133 User4, 0134 User5, 0135 User6 0136 }; 0137 0138 public: 0139 0140 explicit DItemsListView(DItemsList* const parent); 0141 ~DItemsListView() override; 0142 0143 void setColumnLabel(ColumnType column, const QString& label); 0144 void setColumnEnabled(ColumnType column, bool enable); 0145 void setColumn(ColumnType column, const QString& label, bool enable); 0146 0147 DItemsListViewItem* findItem(const QUrl& url); 0148 QModelIndex indexFromItem(DItemsListViewItem* item, 0149 int column = 0) const; 0150 0151 DItemsListViewItem* getCurrentItem() const; 0152 0153 DInfoInterface* iface() const; 0154 DItemsListIsLessThanHandler isLessThanHandler() const; 0155 0156 Q_SIGNALS: 0157 0158 void signalAddedDropedItems(const QList<QUrl>&); 0159 void signalItemClicked(QTreeWidgetItem*); 0160 void signalContextMenuRequested(); 0161 0162 private Q_SLOTS: 0163 0164 void slotItemClicked(QTreeWidgetItem* item, int column); 0165 0166 public: 0167 0168 void enableDragAndDrop(const bool enable = true); 0169 0170 private: 0171 0172 void dragEnterEvent(QDragEnterEvent* e) override; 0173 void dragMoveEvent(QDragMoveEvent* e) override; 0174 void dropEvent(QDropEvent* e) override; 0175 void contextMenuEvent(QContextMenuEvent* e) override; 0176 0177 void drawRow(QPainter* p, 0178 const QStyleOptionViewItem& opt, 0179 const QModelIndex& index) const override; 0180 0181 private: 0182 0183 QTreeWidgetItem* m_itemDraged; 0184 }; 0185 0186 // ------------------------------------------------------------------------- 0187 0188 class DIGIKAM_EXPORT DItemsList : public QWidget 0189 { 0190 Q_OBJECT 0191 0192 public: 0193 0194 enum ControlButtonPlacement 0195 { 0196 NoControlButtons = 0, 0197 ControlButtonsLeft, 0198 ControlButtonsRight, 0199 ControlButtonsAbove, 0200 ControlButtonsBelow 0201 }; 0202 0203 enum ControlButton 0204 { 0205 Add = 0x1, 0206 Remove = 0x2, 0207 MoveUp = 0x4, 0208 MoveDown = 0x8, 0209 Clear = 0x10, 0210 Load = 0x20, 0211 Save = 0x40 0212 }; 0213 Q_DECLARE_FLAGS(ControlButtons, ControlButton) 0214 0215 public: 0216 0217 explicit DItemsList(QWidget* const parent); 0218 ~DItemsList() override; 0219 0220 void setAllowRAW(bool allow); 0221 void setAllowDuplicate(bool allow); 0222 0223 void loadImagesFromCurrentSelection(); 0224 0225 /** 0226 * A function to load all the images from the album if no image has been selected by user. 0227 */ 0228 void loadImagesFromCurrentAlbum(); 0229 0230 /** 0231 * a function to check whether an image has been selected or not. 0232 */ 0233 bool checkSelection(); 0234 0235 void setIconSize(int size); 0236 int iconSize() const; 0237 0238 DItemsListView* listView() const; 0239 0240 void processing(const QUrl& url); 0241 void processed(const QUrl& url, bool success); 0242 void cancelProcess(); 0243 void clearProcessedStatus(); 0244 0245 void setControlButtons(ControlButtons buttonMask); 0246 0247 /** 0248 * Plug the control buttons near to the list, following 'placement' position. 0249 * Return the instance of the layout supporting the control buttons, if any. 0250 * This method must be calls after to use appendControlButtonsWidget(). 0251 */ 0252 QBoxLayout* setControlButtonsPlacement(ControlButtonPlacement placement); 0253 0254 /** 0255 * Append a extra widget to the end of Control Button layout (as a progress bar for exemple). 0256 * This method must be call before setControlButtonsPlacement(). 0257 * Ownership of the widget is not transferred to the DItemList. 0258 */ 0259 void appendControlButtonsWidget(QWidget* const widget); 0260 0261 void enableControlButtons(bool enable = true); 0262 void enableDragAndDrop(const bool enable = true); 0263 0264 void updateThumbnail(const QUrl& url); 0265 0266 virtual QList<QUrl> imageUrls(bool onlyUnprocessed = false) const; 0267 virtual void removeItemByUrl(const QUrl& url); 0268 0269 void setCurrentUrl(const QUrl& url); 0270 QUrl getCurrentUrl() const; 0271 0272 void setIface(DInfoInterface* const iface); 0273 DInfoInterface* iface() const; 0274 0275 ///@{ 0276 /** 0277 * Methods to handle function pointer used to customize sort items in list. 0278 * See DItemsListIsLessThanHandler type for details. 0279 */ 0280 void setIsLessThanHandler(DItemsListIsLessThanHandler fncptr); 0281 DItemsListIsLessThanHandler isLessThanHandler() const; 0282 ///@} 0283 0284 Q_SIGNALS: 0285 0286 void signalAddItems(const QList<QUrl>&); 0287 void signalMoveUpItem(); 0288 void signalMoveDownItem(); 0289 void signalRemovedItems(const QList<int>&); 0290 void signalImageListChanged(); 0291 void signalFoundRAWImages(bool); 0292 void signalItemClicked(QTreeWidgetItem*); 0293 void signalContextMenuRequested(); 0294 void signalXMLSaveItem(QXmlStreamWriter&, int); 0295 void signalXMLLoadImageElement(QXmlStreamReader&); 0296 void signalXMLCustomElements(QXmlStreamWriter&); 0297 void signalXMLCustomElements(QXmlStreamReader&); 0298 0299 public Q_SLOTS: 0300 0301 virtual void slotAddImages(const QList<QUrl>& list); 0302 virtual void slotRemoveItems(); 0303 0304 protected Q_SLOTS: 0305 0306 void slotProgressTimerDone(); 0307 0308 virtual void slotAddItems(); 0309 virtual void slotMoveUpItems(); 0310 virtual void slotMoveDownItems(); 0311 virtual void slotClearItems(); 0312 virtual void slotLoadItems(); 0313 virtual void slotSaveItems(); 0314 virtual void slotThumbnail(const LoadingDescription&, const QPixmap&); 0315 virtual void slotImageListChanged(); 0316 0317 private: 0318 0319 // Disable 0320 DItemsList() = delete; 0321 0322 class Private; 0323 Private* const d; 0324 }; 0325 0326 } // namespace Digikam 0327 0328 Q_DECLARE_OPERATORS_FOR_FLAGS(Digikam::DItemsList::ControlButtons) 0329 0330 #endif // DIGIKAM_DITEMS_LIST_H