digiKam
ditemslist.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2008-05-21
7  * Description : widget to display a list of items
8  *
9  * Copyright (C) 2006-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2008-2010 by Andi Clemens <andi dot clemens at googlemail dot com>
11  * Copyright (C) 2009-2010 by Luka Renko <lure at kubuntu dot org>
12  *
13  * This program is free software; you can redistribute it
14  * and/or modify it under the terms of the GNU General
15  * Public License as published by the Free Software Foundation;
16  * either version 2, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_DITEMS_LIST_H
26 #define DIGIKAM_DITEMS_LIST_H
27 
28 // Qt includes
29 
30 #include <QPushButton>
31 #include <QStringList>
32 #include <QTreeWidget>
33 #include <QWidget>
34 #include <QXmlStreamWriter>
35 #include <QXmlStreamReader>
36 #include <QIcon>
37 #include <QUrl>
38 
39 // Local includes
40 
41 #include "loadingdescription.h"
42 #include "digikam_export.h"
43 #include "dinfointerface.h"
44 
45 namespace Digikam
46 {
47 
48 class DItemsList;
49 class DItemsListView;
50 
56 typedef bool (*DItemsListIsLessThanHandler)(const QTreeWidgetItem* current, const QTreeWidgetItem& other);
57 
58 class DIGIKAM_EXPORT DItemsListViewItem : public QTreeWidgetItem
59 {
60 
61 public:
62 
63  enum State
64  {
67  Failed
68  };
69 
70 public:
71 
72  explicit DItemsListViewItem(DItemsListView* const view, const QUrl& url);
73  ~DItemsListViewItem() override;
74 
75  bool hasValidThumbnail() const;
76 
77  void setUrl(const QUrl& url);
78  QUrl url() const;
79 
80  void setComments(const QString& comments);
81  QString comments() const;
82 
83  void setTags(const QStringList& tags);
84  QStringList tags() const;
85 
86  void setRating(int rating);
87  int rating() const;
88 
89  void setThumb(const QPixmap& pix, bool hasThumb=true);
90  void setProgressAnimation(const QPixmap& pix);
91 
92  void setProcessedIcon(const QIcon& icon);
93  void setState(State state);
94  State state() const;
95 
96  void updateInformation();
97 
99 
104  virtual void updateItemWidgets() {};
105 
106 protected:
107 
108  DItemsListView* view() const;
109 
110 private:
111 
112  void setPixmap(const QPixmap& pix);
113  bool operator<(const QTreeWidgetItem& other) const override;
114 
115 private:
116 
117  class Private;
118  Private* const d;
119 
120 private:
121 
122  Q_DISABLE_COPY(DItemsListViewItem)
123 };
124 
125 // -------------------------------------------------------------------------
126 
127 class DIGIKAM_EXPORT DItemsListView : public QTreeWidget
128 {
129  Q_OBJECT
130 
131 public:
132 
134  {
135  Thumbnail = 0,
142  User6
143  };
144 
145 public:
146 
147  explicit DItemsListView(DItemsList* const parent);
148  ~DItemsListView() override;
149 
150  void setColumnLabel(ColumnType column, const QString& label);
151  void setColumnEnabled(ColumnType column, bool enable);
152  void setColumn(ColumnType column, const QString& label, bool enable);
153 
154  DItemsListViewItem* findItem(const QUrl& url);
155  QModelIndex indexFromItem(DItemsListViewItem* item,
156  int column = 0) const;
157 
158  DItemsListViewItem* getCurrentItem() const;
159 
160  DInfoInterface* iface() const;
161  DItemsListIsLessThanHandler isLessThanHandler() const;
162 
163 Q_SIGNALS:
164 
166  void signalItemClicked(QTreeWidgetItem*);
168 
169 private Q_SLOTS:
170 
171  void slotItemClicked(QTreeWidgetItem* item, int column);
172 
173 public:
174 
175  void enableDragAndDrop(const bool enable = true);
176 
177 private:
178 
179  void dragEnterEvent(QDragEnterEvent* e) override;
180  void dragMoveEvent(QDragMoveEvent* e) override;
181  void dropEvent(QDropEvent* e) override;
182  void contextMenuEvent(QContextMenuEvent* e) override;
183 
184  void drawRow(QPainter* p,
185  const QStyleOptionViewItem& opt,
186  const QModelIndex& index) const override;
187 
188 private:
189 
190  QTreeWidgetItem* m_itemDraged;
191 };
192 
193 // -------------------------------------------------------------------------
194 
195 class DIGIKAM_EXPORT DItemsList : public QWidget
196 {
197  Q_OBJECT
198 
199 public:
200 
202  {
203  NoControlButtons = 0,
207  ControlButtonsBelow
208  };
209 
211  {
212  Add = 0x1,
213  Remove = 0x2,
214  MoveUp = 0x4,
215  MoveDown = 0x8,
216  Clear = 0x10,
217  Load = 0x20,
218  Save = 0x40
219  };
220  Q_DECLARE_FLAGS(ControlButtons, ControlButton)
221 
222 public:
223 
224  explicit DItemsList(QWidget* const parent);
225  ~DItemsList() override;
226 
227  void setAllowRAW(bool allow);
228  void setAllowDuplicate(bool allow);
229 
230  void loadImagesFromCurrentSelection();
231 
235  void loadImagesFromCurrentAlbum();
236 
240  bool checkSelection();
241 
242  void setIconSize(int size);
243  int iconSize() const;
244 
245  DItemsListView* listView() const;
246 
247  void processing(const QUrl& url);
248  void processed(const QUrl& url, bool success);
249  void cancelProcess();
250  void clearProcessedStatus();
251 
252  void setControlButtons(ControlButtons buttonMask);
253  void setControlButtonsPlacement(ControlButtonPlacement placement);
254  void enableControlButtons(bool enable = true);
255  void enableDragAndDrop(const bool enable = true);
256 
257  void updateThumbnail(const QUrl& url);
258 
259  virtual QList<QUrl> imageUrls(bool onlyUnprocessed = false) const;
260  virtual void removeItemByUrl(const QUrl& url);
261 
262  void setCurrentUrl(const QUrl& url);
263  QUrl getCurrentUrl() const;
264 
265  void setIface(DInfoInterface* const iface);
266  DInfoInterface* iface() const;
267 
269 
273  void setIsLessThanHandler(DItemsListIsLessThanHandler fncptr);
274  DItemsListIsLessThanHandler isLessThanHandler() const;
276 
277 Q_SIGNALS:
278 
285  void signalItemClicked(QTreeWidgetItem*);
287  void signalXMLSaveItem(QXmlStreamWriter&, int);
288  void signalXMLLoadImageElement(QXmlStreamReader&);
289  void signalXMLCustomElements(QXmlStreamWriter&);
290  void signalXMLCustomElements(QXmlStreamReader&);
291 
292 public Q_SLOTS:
293 
294  virtual void slotAddImages(const QList<QUrl>& list);
295  virtual void slotRemoveItems();
296 
297 protected Q_SLOTS:
298 
299  void slotProgressTimerDone();
300 
301  virtual void slotAddItems();
302  virtual void slotMoveUpItems();
303  virtual void slotMoveDownItems();
304  virtual void slotClearItems();
305  virtual void slotLoadItems();
306  virtual void slotSaveItems();
307  virtual void slotThumbnail(const LoadingDescription&, const QPixmap&);
308  virtual void slotImageListChanged();
309 
310 
311 private:
312 
313  // Disable
314  DItemsList() = delete;
315 
316  class Private;
317  Private* const d;
318 };
319 
320 } // namespace Digikam
321 
322 Q_DECLARE_OPERATORS_FOR_FLAGS(Digikam::DItemsList::ControlButtons)
323 
324 #endif // DIGIKAM_DITEMS_LIST_H
Definition: dinfointerface.h:56
Definition: ditemslist.h:59
State
Definition: ditemslist.h:64
@ Success
Definition: ditemslist.h:66
@ Waiting
Definition: ditemslist.h:65
void setIsLessThanHandler(DItemsListIsLessThanHandler fncptr)
virtual void updateItemWidgets()
Definition: ditemslist.h:104
Definition: ditemslist.h:128
void signalAddedDropedItems(const QList< QUrl > &)
ColumnType
Definition: ditemslist.h:134
@ Filename
Definition: ditemslist.h:136
@ User3
Definition: ditemslist.h:139
@ User5
Definition: ditemslist.h:141
@ User1
Definition: ditemslist.h:137
@ User4
Definition: ditemslist.h:140
@ User2
Definition: ditemslist.h:138
void signalItemClicked(QTreeWidgetItem *)
Definition: ditemslist.h:196
void signalItemClicked(QTreeWidgetItem *)
void signalRemovedItems(const QList< int > &)
ControlButtonPlacement
Definition: ditemslist.h:202
@ ControlButtonsLeft
Definition: ditemslist.h:204
@ ControlButtonsAbove
Definition: ditemslist.h:206
@ ControlButtonsRight
Definition: ditemslist.h:205
void signalAddItems(const QList< QUrl > &)
ControlButton
Definition: ditemslist.h:211
void signalXMLSaveItem(QXmlStreamWriter &, int)
void signalFoundRAWImages(bool)
void signalXMLCustomElements(QXmlStreamReader &)
void signalXMLLoadImageElement(QXmlStreamReader &)
void signalXMLCustomElements(QXmlStreamWriter &)
void signalImageListChanged()
void signalContextMenuRequested()
Definition: loadingdescription.h:45
Definition: datefolderview.cpp:43
bool(* DItemsListIsLessThanHandler)(const QTreeWidgetItem *current, const QTreeWidgetItem &other)
Definition: ditemslist.h:56
bool operator<(const WSAlbum &first, const WSAlbum &second)
Definition: wstalker.cpp:47
Definition: abstractalbumtreeview_p.h:85