| 1 |
/* |
| 2 |
* libkysdk-qtwidgets's Library |
| 3 |
* |
| 4 |
* Copyright (C) 2023, KylinSoft Co., Ltd. |
| 5 |
* |
| 6 |
* This library is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public |
| 8 |
* License as published by the Free Software Foundation; either |
| 9 |
* version 3 of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this library. If not, see <https://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
* Authors: Zhenyu Wang <[email protected]> |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
#ifndef KLISTVIEWDELEGATE_H |
| 24 |
#define KLISTVIEWDELEGATE_H |
| 25 |
|
| 26 |
#include "themeController.h" |
| 27 |
#include <QAbstractItemView> |
| 28 |
#include <QPixmap> |
| 29 |
#include <QStyleOptionViewItem> |
| 30 |
#include <QStyledItemDelegate> |
| 31 |
|
| 32 |
namespace kdk |
| 33 |
{ |
| 34 |
|
| 35 |
/** |
| 36 |
* @defgroup ListViewModule |
| 37 |
*/ |
| 38 |
|
| 39 |
class KListViewDelegatePrivate; |
| 40 |
|
| 41 |
/** |
| 42 |
* @brief 配合KListview可以提供一个图片两行文字的显示效果,若只有一行文字,则对于 icon 居中显示 。 |
| 43 |
* @since 1.2.0 |
| 44 |
*/ |
| 45 |
class KListViewDelegate : public QStyledItemDelegate, public ThemeController |
| 46 |
{ |
| 47 |
Q_OBJECT |
| 48 |
public: |
| 49 |
KListViewDelegate(QAbstractItemView *parent); |
| 50 |
~KListViewDelegate(); |
| 51 |
|
| 52 |
protected: |
| 53 |
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; // 重写绘制事件 |
| 54 |
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; |
| 55 |
|
| 56 |
private: |
| 57 |
Q_DECLARE_PRIVATE(KListViewDelegate); |
| 58 |
KListViewDelegatePrivate *const d_ptr; |
| 59 |
}; |
| 60 |
} |
| 61 |
#endif // KLISTVIEWDELEGATE_H |