DtkWidget
DTK Widget module
载入中...
搜索中...
未找到
dsimplelistview.h
1// SPDX-FileCopyrightText: 2011 - 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DSIMPLELISTVIEW_H
6#define DSIMPLELISTVIEW_H
7
8#include <DObject>
9#include <DSimpleListItem>
10#include <dtkwidget_global.h>
11#include <QPixmap>
12#include <QTimer>
13#include <QWidget>
14
15DWIDGET_BEGIN_NAMESPACE
16
17typedef bool (* SortAlgorithm) (const DSimpleListItem *item1, const DSimpleListItem *item2, bool descendingSort);
18typedef bool (* SearchAlgorithm) (const DSimpleListItem *item, QString searchContent);
19
20class DSimpleListViewPrivate;
21class LIBDTKWIDGETSHARED_EXPORT DSimpleListView : public QWidget, public DTK_CORE_NAMESPACE::DObject
22{
23 Q_OBJECT
24
25public:
26 explicit DSimpleListView(QWidget *parent = 0);
28
29 // DSimpleListView interfaces.
30
31 /*
32 * Set row height of DSimpleListView.
33 *
34 * \height the height of row
35 */
36 void setRowHeight(int height);
37
38 /*
39 * Set column titles, widths and height.
40 * If you want some column use expand space, please set width with -1
41 * Only allowed one -1 to set in width list.
42 *
43 * \titles a list to contains titles
44 * \widths the width of column, list length same as titles list
45 * \height height of titlebar, don't display titlebar if set height with 0
46 */
47 void setColumnTitleInfo(QList<QString> titles, QList<int> widths, int height);
48
49 /*
50 * Set column hide flags.
51 * At least have false in hide flags list, and hide flags count must same as titles list.
52 *
53 * \toggleHideFlags the hide flags to control column wether toggle show/hide.
54 * \alwaysVisibleColumn the column index that column is always visible, default is -1, mean no column can always visible.
55 */
56 void setColumnHideFlags(QList<bool> toggleHideFlags, int alwaysVisibleColumn=-1);
57
58 /*
59 * Set column sorting algorithms.
60 * Note SortAlgorithm function type must be 'static', otherwise function pointer can't match type.
61 *
62 * \algorithms a list of SortAlgorithm, SortAlgorithm is function pointer, it's type is: 'bool (*) (const DSimpleListItem *item1, const DSimpleListItem *item2, bool descendingSort)'
63 * \sortColumn default sort column, -1 mean don't sort any column default
64 * \descendingSort whether sort column descending, default is false
65 */
66 void setColumnSortingAlgorithms(QList<SortAlgorithm> *algorithms, int sortColumn=-1, bool descendingSort=false);
67
68 /*
69 * Set search algorithm to filter match items.
70 *
71 * \algorithm the search algorithm, it's type is: 'bool (*) (const DSimpleListItem *item, QString searchContent)'
72 */
73 void setSearchAlgorithm(SearchAlgorithm algorithm);
74
75 /*
76 * Set radius to clip listview.
77 *
78 * \radius the radius of clip area, default is 0 pixel.
79 */
80 void setClipRadius(int radius);
81
82 /*
83 * Set frame details.
84 *
85 * \enableFrame draw frame if enableFrame is true, default is false
86 * the frame color, default is black
87 * \opacity the frame opacity, default is 0.1
88 */
89 void setFrame(bool enableFrame, QColor color=QColor("#000000"), double opacity=0.1);
90
91 /*
92 * Add DSimpleListItem list to ListView.
93 * If user has click title to sort, sort items after add items to list.
94 *
95 * \items List of LiteItem*
96 */
97 void addItems(QList<DSimpleListItem*> items);
98
99 /*
100 * Remove DSimpleListItem from list.
101 *
102 * \item item to remove
103 */
104 void removeItem(DSimpleListItem* item);
105
106 /*
107 * Clear items from DSimpleListView.
108 */
109 void clearItems();
110
111 /*
112 * Add DSimpleListItem list to mark selected effect in ListView.
113 *
114 * \items List of DSimpleListItem* to mark selected
115 * \recordLastSelection record last selection item to make selected operation continuously, default is true
116 */
117 void addSelections(QList<DSimpleListItem*> items, bool recordLastSelection=true);
118
119 /*
120 * Clear selection items from DSimpleListView.
121 *
122 * \clearLastSelection clear last selection item if option is true, default is true
123 */
124 void clearSelections(bool clearLastSelection=true);
125
126 /*
127 * Get selection items.
128 *
129 * \return List of DSimpleListItem* to mark selected
130 */
131 QList<DSimpleListItem*> getSelections();
132
133 /*
134 * Refresh all items in DSimpleListView.
135 * This function is different that addItems is: it will clear items first before add new items.
136 * This function will keep selection status and scroll offset when add items.
137 *
138 * \items List of DSimpleListItem* to add
139 */
140 void refreshItems(QList<DSimpleListItem*> items);
141
142 /*
143 * Search
144 */
145 void search(QString searchContent);
146
147 /*
148 * Set single selection.
149 */
150 void setSingleSelect(bool singleSelect);
151
152 /*
153 * Keep select items when click blank area.
154 */
155 void keepSelectWhenClickBlank(bool keep);
156
157 // DSimpleListView operations.
158 void selectAllItems();
159 void selectFirstItem();
160 void selectLastItem();
161 void selectNextItem();
162 void selectPrevItem();
163
164 void shiftSelectPageDown();
165 void shiftSelectPageUp();
166 void shiftSelectToEnd();
167 void shiftSelectToHome();
168 void shiftSelectToNext();
169 void shiftSelectToPrev();
170
171 void scrollPageDown();
172 void scrollPageUp();
173
174 void ctrlScrollPageDown();
175 void ctrlScrollPageUp();
176 void ctrlScrollToEnd();
177 void ctrlScrollToHome();
178
179protected:
180 virtual void leaveEvent(QEvent * event);
181
182 QPixmap arrowDownDarkHoverImage;
183 QPixmap arrowDownDarkNormalImage;
184 QPixmap arrowDownDarkPressImage;
185 QPixmap arrowDownHoverImage;
186 QPixmap arrowDownLightHoverImage;
187 QPixmap arrowDownLightNormalImage;
188 QPixmap arrowDownLightPressImage;
189 QPixmap arrowDownNormalImage;
190 QPixmap arrowDownPressImage;
191 QPixmap arrowUpDarkHoverImage;
192 QPixmap arrowUpDarkNormalImage;
193 QPixmap arrowUpDarkPressImage;
194 QPixmap arrowUpHoverImage;
195 QPixmap arrowUpLightHoverImage;
196 QPixmap arrowUpLightNormalImage;
197 QPixmap arrowUpLightPressImage;
198 QPixmap arrowUpNormalImage;
199 QPixmap arrowUpPressImage;
200 QString backgroundColor = "#ffffff";
201 QString scrollbarColor = "#ffffff";
202 QString searchColor = "#000000";
203 QString titleAreaColor = "#ffffff";
204 QString titleColor = "#000000";
205 QString titleLineColor = "#000000";
206 QColor frameColor = QColor("#000000");
207 double backgroundOpacity = 0.03;
208 double frameOpacity = 0.1;
209 double titleAreaOpacity = 0.02;
210 int titleSize = 10;
211 qreal scrollbarFrameHoverOpacity = 0;
212 qreal scrollbarFrameNormalOpacity = 0;
213 qreal scrollbarFramePressOpacity = 0;
214 qreal scrollbarHoverOpacity = 0.7;
215 qreal scrollbarNormalOpacity = 0.5;
216 qreal scrollbarPressOpacity = 0.8;
217
218Q_SIGNALS:
219 void rightClickItems(QPoint pos, QList<DSimpleListItem*> items);
220 void changeColumnVisible(int index, bool visible, QList<bool> columnVisibles);
221 void changeSortingStatus(int index, bool sortingOrder);
222 void changeHoverItem(QPoint pos, DSimpleListItem* item, int columnIndex);
223
224 void mouseHoverChanged(DSimpleListItem* oldItem, DSimpleListItem* newItem, int columnIndex, QPoint pos);
225 void mousePressChanged(DSimpleListItem* item, int columnIndex, QPoint pos);
226 void mouseReleaseChanged(DSimpleListItem* item, int columnIndex, QPoint pos);
227
228protected:
229 bool eventFilter(QObject *, QEvent *event);
230 void keyPressEvent(QKeyEvent *keyEvent);
231 void mouseMoveEvent(QMouseEvent *mouseEvent);
232 void mousePressEvent(QMouseEvent *mouseEvent);
233 void mouseReleaseEvent(QMouseEvent *mouseEvent);
234 void paintEvent(QPaintEvent *);
235 void wheelEvent(QWheelEvent *event);
236
237 void paintScrollbar(QPainter *painter);
238
239 void selectPrevItemWithOffset(int scrollOffset);
240 void selectNextItemWithOffset(int scrollOffset);
241 void shiftSelectNextItemWithOffset(int scrollOffset);
242 void shiftSelectPrevItemWithOffset(int scrollOffset);
243
244 int getBottomRenderOffset();
245 int getScrollbarY();
246 int getScrollAreaHeight();
247 int getScrollbarHeight();
248
249 QList<int> getRenderWidths();
250
251 void shiftSelectItemsWithBound(int selectionStartIndex, int selectionEndIndex);
252 int adjustRenderOffset(int offset);
253
254 void startScrollbarHideTimer();
255
256 bool isMouseAtScrollArea(int x);
257 bool isMouseAtTitleArea(int y);
258
259 QList<bool> columnVisibles;
260
261private Q_SLOTS:
262 void hideScrollbar();
263
264private:
265 D_DECLARE_PRIVATE(DSimpleListView)
266};
267
268DWIDGET_END_NAMESPACE
269
270#endif
DSimpleListItem 是 DSimpleListView 的接口,得到 DSimpleListView 传递过来的 QPainter、列信息、表格矩形数据后,由开发者完全控制行内容的绘制.
Definition dsimplelistitem.h:15
DSimpleListView 是 deepin 基于 QWidget 从零绘制的列表控件.
Definition dsimplelistview.h:22