Changeset View
Changeset View
Standalone View
Standalone View
kstyle/widgets/combobox_p.h
- This file was added.
1 | #ifndef COMBOBOX_P_H_INCLUDED | ||||
---|---|---|---|---|---|
2 | #define COMBOBOX_P_H_INCLUDED | ||||
3 | | ||||
4 | #include "breezestyle.h" | ||||
5 | | ||||
6 | #include <QItemDelegate> | ||||
7 | | ||||
8 | namespace BreezePrivate | ||||
9 | { | ||||
10 | //* needed to have spacing added to items in combobox | ||||
11 | class ComboBoxItemDelegate : public QItemDelegate | ||||
12 | { | ||||
13 | public: | ||||
14 | //* constructor | ||||
15 | explicit ComboBoxItemDelegate(QAbstractItemView *parent) | ||||
16 | : QItemDelegate(parent) | ||||
17 | , _proxy(parent->itemDelegate()) | ||||
18 | , _itemMargin(Breeze::Metrics::ItemView_ItemMarginWidth) | ||||
19 | { | ||||
20 | } | ||||
21 | | ||||
22 | //* paint | ||||
23 | void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override | ||||
24 | { | ||||
25 | // call either proxy or parent class | ||||
26 | if (_proxy) | ||||
27 | _proxy.data()->paint(painter, option, index); | ||||
28 | else | ||||
29 | QItemDelegate::paint(painter, option, index); | ||||
30 | } | ||||
31 | | ||||
32 | //* size hint for index | ||||
33 | QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override | ||||
34 | { | ||||
35 | // get size from either proxy or parent class | ||||
36 | auto size(_proxy ? _proxy.data()->sizeHint(option, index) : QItemDelegate::sizeHint(option, index)); | ||||
37 | | ||||
38 | // adjust and return | ||||
39 | if (size.isValid()) { | ||||
40 | size.rheight() += _itemMargin * 2; | ||||
41 | } | ||||
42 | return size; | ||||
43 | } | ||||
44 | | ||||
45 | private: | ||||
46 | //* proxy | ||||
47 | Breeze::WeakPointer<QAbstractItemDelegate> _proxy; | ||||
48 | | ||||
49 | //* margin | ||||
50 | int _itemMargin; | ||||
51 | }; | ||||
52 | | ||||
53 | } | ||||
54 | | ||||
55 | #endif // COMBOBOX_P_H_INCLUDED |