1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QLISTVIEW_H |
5 | #define QLISTVIEW_H |
6 | |
7 | #include <QtWidgets/qtwidgetsglobal.h> |
8 | #include <QtWidgets/qabstractitemview.h> |
9 | |
10 | QT_REQUIRE_CONFIG(listview); |
11 | |
12 | QT_BEGIN_NAMESPACE |
13 | |
14 | class QListViewPrivate; |
15 | |
16 | class Q_WIDGETS_EXPORT QListView : public QAbstractItemView |
17 | { |
18 | Q_OBJECT |
19 | Q_PROPERTY(Movement movement READ movement WRITE setMovement) |
20 | Q_PROPERTY(Flow flow READ flow WRITE setFlow) |
21 | Q_PROPERTY(bool isWrapping READ isWrapping WRITE setWrapping) |
22 | Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode) |
23 | Q_PROPERTY(LayoutMode layoutMode READ layoutMode WRITE setLayoutMode) |
24 | Q_PROPERTY(int spacing READ spacing WRITE setSpacing) |
25 | Q_PROPERTY(QSize gridSize READ gridSize WRITE setGridSize) |
26 | Q_PROPERTY(ViewMode viewMode READ viewMode WRITE setViewMode) |
27 | Q_PROPERTY(int modelColumn READ modelColumn WRITE setModelColumn) |
28 | Q_PROPERTY(bool uniformItemSizes READ uniformItemSizes WRITE setUniformItemSizes) |
29 | Q_PROPERTY(int batchSize READ batchSize WRITE setBatchSize) |
30 | Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap) |
31 | Q_PROPERTY(bool selectionRectVisible READ isSelectionRectVisible WRITE setSelectionRectVisible) |
32 | Q_PROPERTY(Qt::Alignment itemAlignment READ itemAlignment WRITE setItemAlignment) |
33 | |
34 | public: |
35 | enum Movement { Static, Free, Snap }; |
36 | Q_ENUM(Movement) |
37 | enum Flow { LeftToRight, TopToBottom }; |
38 | Q_ENUM(Flow) |
39 | enum ResizeMode { Fixed, Adjust }; |
40 | Q_ENUM(ResizeMode) |
41 | enum LayoutMode { SinglePass, Batched }; |
42 | Q_ENUM(LayoutMode) |
43 | enum ViewMode { ListMode, IconMode }; |
44 | Q_ENUM(ViewMode) |
45 | |
46 | explicit QListView(QWidget *parent = nullptr); |
47 | ~QListView(); |
48 | |
49 | void setMovement(Movement movement); |
50 | Movement movement() const; |
51 | |
52 | void setFlow(Flow flow); |
53 | Flow flow() const; |
54 | |
55 | void setWrapping(bool enable); |
56 | bool isWrapping() const; |
57 | |
58 | void setResizeMode(ResizeMode mode); |
59 | ResizeMode resizeMode() const; |
60 | |
61 | void setLayoutMode(LayoutMode mode); |
62 | LayoutMode layoutMode() const; |
63 | |
64 | void setSpacing(int space); |
65 | int spacing() const; |
66 | |
67 | void setBatchSize(int batchSize); |
68 | int batchSize() const; |
69 | |
70 | void setGridSize(const QSize &size); |
71 | QSize gridSize() const; |
72 | |
73 | void setViewMode(ViewMode mode); |
74 | ViewMode viewMode() const; |
75 | |
76 | void clearPropertyFlags(); |
77 | |
78 | bool isRowHidden(int row) const; |
79 | void setRowHidden(int row, bool hide); |
80 | |
81 | void setModelColumn(int column); |
82 | int modelColumn() const; |
83 | |
84 | void setUniformItemSizes(bool enable); |
85 | bool uniformItemSizes() const; |
86 | |
87 | void setWordWrap(bool on); |
88 | bool wordWrap() const; |
89 | |
90 | void setSelectionRectVisible(bool show); |
91 | bool isSelectionRectVisible() const; |
92 | |
93 | void setItemAlignment(Qt::Alignment alignment); |
94 | Qt::Alignment itemAlignment() const; |
95 | |
96 | QRect visualRect(const QModelIndex &index) const override; |
97 | void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) override; |
98 | QModelIndex indexAt(const QPoint &p) const override; |
99 | |
100 | void doItemsLayout() override; |
101 | void reset() override; |
102 | void setRootIndex(const QModelIndex &index) override; |
103 | |
104 | Q_SIGNALS: |
105 | void indexesMoved(const QModelIndexList &indexes); |
106 | |
107 | protected: |
108 | QListView(QListViewPrivate &, QWidget *parent = nullptr); |
109 | |
110 | bool event(QEvent *e) override; |
111 | |
112 | void scrollContentsBy(int dx, int dy) override; |
113 | |
114 | void resizeContents(int width, int height); |
115 | QSize contentsSize() const; |
116 | |
117 | void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, |
118 | const QList<int> &roles = QList<int>()) override; |
119 | void rowsInserted(const QModelIndex &parent, int start, int end) override; |
120 | void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) override; |
121 | |
122 | void mouseMoveEvent(QMouseEvent *e) override; |
123 | void mouseReleaseEvent(QMouseEvent *e) override; |
124 | #if QT_CONFIG(wheelevent) |
125 | void wheelEvent(QWheelEvent *e) override; |
126 | #endif |
127 | |
128 | void timerEvent(QTimerEvent *e) override; |
129 | void resizeEvent(QResizeEvent *e) override; |
130 | #if QT_CONFIG(draganddrop) |
131 | void dragMoveEvent(QDragMoveEvent *e) override; |
132 | void dragLeaveEvent(QDragLeaveEvent *e) override; |
133 | void dropEvent(QDropEvent *e) override; |
134 | void startDrag(Qt::DropActions supportedActions) override; |
135 | #endif // QT_CONFIG(draganddrop) |
136 | |
137 | void initViewItemOption(QStyleOptionViewItem *option) const override; |
138 | void paintEvent(QPaintEvent *e) override; |
139 | |
140 | int horizontalOffset() const override; |
141 | int verticalOffset() const override; |
142 | QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override; |
143 | QRect rectForIndex(const QModelIndex &index) const; |
144 | void setPositionForIndex(const QPoint &position, const QModelIndex &index); |
145 | |
146 | void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) override; |
147 | QRegion visualRegionForSelection(const QItemSelection &selection) const override; |
148 | QModelIndexList selectedIndexes() const override; |
149 | |
150 | void updateGeometries() override; |
151 | |
152 | bool isIndexHidden(const QModelIndex &index) const override; |
153 | |
154 | void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override; |
155 | void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) override; |
156 | |
157 | QSize viewportSizeHint() const override; |
158 | |
159 | private: |
160 | int visualIndex(const QModelIndex &index) const; |
161 | friend class QCommonListViewBase; |
162 | |
163 | Q_DECLARE_PRIVATE(QListView) |
164 | Q_DISABLE_COPY(QListView) |
165 | }; |
166 | |
167 | QT_END_NAMESPACE |
168 | |
169 | #endif // QLISTVIEW_H |
170 | |