digiKam
itemviewcategorized.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 : 2010-01-16
7  * Description : Qt item view for images
8  *
9  * Copyright (C) 2009-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  * Copyright (C) 2011-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * 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_ITEM_VIEW_CATEGORIZED_H
26 #define DIGIKAM_ITEM_VIEW_CATEGORIZED_H
27 
28 // Local includes
29 
30 #include "digikam_export.h"
31 #include "dcategorizedview.h"
33 
34 class QSortFilterProxyModel;
35 
36 namespace Digikam
37 {
38 
39 class DItemDelegate;
40 class ItemViewToolTip;
41 
42 class DIGIKAM_EXPORT ItemViewCategorized : public DCategorizedView,
44 {
45  Q_OBJECT
46 
47 public:
48 
49  explicit ItemViewCategorized(QWidget* const parent = nullptr);
50  ~ItemViewCategorized() override;
51 
52  DItemDelegate* delegate() const;
53  int numberOfSelectedIndexes() const;
54 
58  void toFirstIndex();
59  void toLastIndex();
60  void toNextIndex();
61  void toPreviousIndex();
62  void toIndex(const QModelIndex& index);
63  void awayFromSelection();
64 
68  void setScrollCurrentToCenter(bool enabled);
69 
73  void scrollToRelaxed(const QModelIndex& index, ScrollHint hint = EnsureVisible);
74 
75  void invertSelection();
76  void setSelectedIndexes(const QList<QModelIndex>& indexes);
77 
78  void setToolTipEnabled(bool enabled);
79  bool isToolTipEnabled() const;
80 
84  void setSpacing(int spacing);
85 
89  void setUsePointingHandCursor(bool useCursor);
90 
95  void setScrollStepGranularity(int factor);
96 
97  virtual QSortFilterProxyModel* filterModel() const = 0;
98  void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible) override;
99 
100 public Q_SLOTS:
101 
102  void showIndexNotification(const QModelIndex& index, const QString& message);
103  void hideIndexNotification();
104 
105  void cut() override { DragDropViewImplementation::cut(); }
106  void copy() override { DragDropViewImplementation::copy(); }
108 
109 Q_SIGNALS:
110 
115 
120 
121  void zoomOutStep();
122  void zoomInStep();
123 
128  void clicked(const QMouseEvent* e, const QModelIndex& index);
129  void entered(const QMouseEvent* e, const QModelIndex& index);
130 
134  void viewportClicked(const QMouseEvent* e);
135 
141  void keyPressed(QKeyEvent* e);
142 
143 
144 protected Q_SLOTS:
145 
146  void slotActivated(const QModelIndex& index);
147  void slotClicked(const QModelIndex& index);
148  void slotEntered(const QModelIndex& index);
149  void layoutAboutToBeChanged();
150  void layoutWasChanged();
151 
152  virtual void slotThemeChanged();
153  virtual void slotSetupChanged();
154 
155 protected:
156 
157  void encodeIsCutSelection(QMimeData* mime, bool isCutSelection);
158  bool decodeIsCutSelection(const QMimeData* mimeData);
159 
160  void setToolTip(ItemViewToolTip* tip);
161  void setItemDelegate(DItemDelegate* delegate);
162  void updateDelegateSizes();
163  void userInteraction();
164 
168  QModelIndex indexForCategoryAt(const QPoint& pos) const;
169 
171  void contextMenuEvent(QContextMenuEvent* event) override;
172  void keyPressEvent(QKeyEvent* event) override;
173  void leaveEvent(QEvent* event) override;
174  void mouseMoveEvent(QMouseEvent* event) override;
175  void mousePressEvent(QMouseEvent* event) override;
176  void mouseReleaseEvent(QMouseEvent* event) override;
177  void resizeEvent(QResizeEvent* e) override;
178  void reset() override;
179  void rowsAboutToBeRemoved(const QModelIndex& parent, int start, int end) override;
180  void rowsInserted(const QModelIndex& parent, int start, int end) override;
181  void rowsRemoved(const QModelIndex& parent, int start, int end) override;
182  void selectionChanged(const QItemSelection&, const QItemSelection&) override;
183  bool viewportEvent(QEvent* event) override;
184  void wheelEvent(QWheelEvent* event) override;
185  QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
186 
188  virtual void showContextMenuOnIndex(QContextMenuEvent* event, const QModelIndex& index);
189  virtual void showContextMenu(QContextMenuEvent* event);
190  virtual void indexActivated(const QModelIndex& index, Qt::KeyboardModifiers modifiers);
191 
197  virtual bool showToolTip(const QModelIndex& index,
198  QStyleOptionViewItem& option,
199  QHelpEvent* e = nullptr);
200 
202 
203 
206  QModelIndex mapIndexForDragDrop(const QModelIndex& index) const override;
207  QPixmap pixmapForDrag(const QList<QModelIndex>& indexes) const override;
208 
214  virtual QModelIndex nextIndexHint(const QModelIndex& indexToAnchor,
215  const QItemSelectionRange& removed) const;
216 
217 private Q_SLOTS:
218 
219  void slotGridSizeChanged(const QSize&);
220 
221 private:
222 
223  // Disable
224  ItemViewCategorized(const ItemViewCategorized&) = delete;
225  ItemViewCategorized& operator=(const ItemViewCategorized&) = delete;
226 
227 private:
228 
229  void ensureSelectionAfterChanges();
230 
231 private:
232 
233  class Private;
234  Private* const d;
235 };
236 
237 } // namespace Digikam
238 
239 #endif // DIGIKAM_ITEM_VIEW_CATEGORIZED_H
Item view for listing items.
Definition: dcategorizedview.h:49
Definition: ditemdelegate.h:42
Definition: dragdropimplementations.h:113
virtual void cut()
Definition: dragdropimplementations.cpp:140
virtual void copy()
Definition: dragdropimplementations.cpp:151
virtual void paste()
Definition: dragdropimplementations.cpp:162
Definition: itemviewcategorized.h:44
void clicked(const QMouseEvent *e, const QModelIndex &index)
virtual QSortFilterProxyModel * filterModel() const =0
void paste() override
Definition: itemviewcategorized.h:107
bool decodeIsCutSelection(const QMimeData *mimeData)
void viewportClicked(const QMouseEvent *e)
void encodeIsCutSelection(QMimeData *mime, bool isCutSelection)
void keyPressed(QKeyEvent *e)
void copy() override
Definition: itemviewcategorized.h:106
void cut() override
Definition: itemviewcategorized.h:105
void entered(const QMouseEvent *e, const QModelIndex &index)
Definition: itemviewtooltip.h:40
#define DECLARE_VIEW_DRAG_DROP_METHODS(ParentViewClass)
Definition: dragdropimplementations.h:155
Definition: datefolderview.cpp:43