DtkWidget
DTK Widget module
载入中...
搜索中...
未找到
dstyleditemdelegate.h
1// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DSTYLEDITEMDELEGATE_H
6#define DSTYLEDITEMDELEGATE_H
7
8#include <dtkwidget_global.h>
9#include <DObject>
10#include <DPalette>
11#include <DFontSizeManager>
12
13#include <QAction>
14#include <QStyledItemDelegate>
15#include <QStandardItem>
16#include <QAbstractItemView>
17
18DGUI_BEGIN_NAMESPACE
19class DDciIcon;
20DGUI_END_NAMESPACE
21
22DWIDGET_BEGIN_NAMESPACE
23
24class DViewItemActionPrivate;
25class DViewItemAction : public QAction, public DCORE_NAMESPACE::DObject
26{
27 Q_OBJECT
28 D_DECLARE_PRIVATE(DViewItemAction)
29
30public:
31 explicit DViewItemAction(Qt::Alignment alignment = Qt::Alignment(), const QSize &iconSize = QSize(),
32 const QSize &maxSize = QSize(), bool clickable = false);
33#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0)
34 D_DECL_DEPRECATED explicit DViewItemAction(Qt::Alignment alignment, const QSize &iconSize,
35 const QSize &maxSize, bool clickable, QObject *parent);
36#endif
37
38 Qt::Alignment alignment() const;
39 QSize iconSize() const;
40 QSize maximumSize() const;
41
42 QMargins clickAreaMargins() const;
43 void setClickAreaMargins(const QMargins &margins);
44
45 void setTextColorRole(DPalette::ColorType role);
46 void setTextColorRole(DPalette::ColorRole role);
47 DPalette::ColorType textColorType() const;
48 DPalette::ColorRole textColorRole() const;
49
50 void setFontSize(DFontSizeManager::SizeType size);
51 QFont font() const;
52
53 bool isClickable() const;
54
55 void setWidget(QWidget *widget);
56 QWidget *widget() const;
57
58 void setDciIcon(const DDciIcon &dciIcon);
59 DDciIcon dciIcon() const;
60};
61typedef QList<DViewItemAction *> DViewItemActionList;
62
63class DStyledItemDelegatePrivate;
64class DStyledItemDelegate : public QStyledItemDelegate, public DCORE_NAMESPACE::DObject
65{
66 Q_OBJECT
67 D_DECLARE_PRIVATE(DStyledItemDelegate)
68
69 Q_PROPERTY(BackgroundType backgroundType READ backgroundType WRITE setBackgroundType)
70 Q_PROPERTY(QMargins margins READ margins WRITE setMargins)
71 Q_PROPERTY(QSize itemSize READ itemSize WRITE setItemSize)
72
73public:
74 enum BackgroundType {
75 NoBackground = 0,
76 ClipCornerBackground = 1,
77 RoundedBackground = 2,
78 BackgroundType_Mask = 0xff,
79 NoNormalState = 0x100
80 };
81
82 explicit DStyledItemDelegate(QAbstractItemView *parent = nullptr);
83
84 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
85 QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
86
87 void updateEditorGeometry(QWidget *editor,
88 const QStyleOptionViewItem &option,
89 const QModelIndex &index) const override;
90
91 BackgroundType backgroundType() const;
92 QMargins margins() const;
93 QSize itemSize() const;
94 int spacing() const;
95
96public Q_SLOTS:
97 void setBackgroundType(BackgroundType backgroundType);
98 void setMargins(const QMargins margins);
99 void setItemSize(QSize itemSize);
100 void setItemSpacing(int spacing);
101
102protected:
103 void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const override;
104 bool eventFilter(QObject *object, QEvent *event) override;
105};
106
107class DStandardItem : public QStandardItem
108{
109public:
110 using QStandardItem::QStandardItem;
111 virtual ~DStandardItem();
112
113 void setActionList(Qt::Edge edge, const DViewItemActionList &list);
114 DViewItemActionList actionList(Qt::Edge edge) const;
115
116 void setTextActionList(const DViewItemActionList &list);
117 DViewItemActionList textActionList() const;
118
119 void setTextColorRole(DPalette::ColorType role);
120 void setTextColorRole(DPalette::ColorRole role);
121 DPalette::ColorType textColorType() const;
122 DPalette::ColorRole textColorRole() const;
123
124 void setBackgroundRole(DPalette::ColorType role);
125 void setBackgroundRole(DPalette::ColorRole role);
126 DPalette::ColorType backgroundType() const;
127 DPalette::ColorRole backgroundRole() const;
128
129 void setFontSize(DFontSizeManager::SizeType size);
130 QFont font() const;
131
132 void setDciIcon(const DDciIcon &dciIcon);
133 DDciIcon dciIcon() const;
134
135 virtual QStandardItem *clone() const override;
136};
137
138DWIDGET_END_NAMESPACE
139
140Q_DECLARE_METATYPE(DTK_WIDGET_NAMESPACE::DViewItemActionList)
141
142#endif // DSTYLEDITEMDELEGATE_H
提供标准项 item,通常用于模型/视图,或模型-代理-视图里面,用以提供标准的 item 控件.
Definition dstyleditemdelegate.h:108
Definition dstyleditemdelegate.h:65
是一个 action 活动, 其默认是不能被点击的.
Definition dstyleditemdelegate.h:26