Krita Source Code Documentation
Loading...
Searching...
No Matches
KisCategorizedItemDelegate Class Reference

#include <kis_categorized_item_delegate.h>

+ Inheritance diagram for KisCategorizedItemDelegate:

Public Member Functions

 KisCategorizedItemDelegate (QObject *parent)
 
void paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
 
QSize sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const override
 

Private Member Functions

void paintTriangle (QPainter *painter, qint32 x, qint32 y, qint32 size, bool rotate) const
 

Private Attributes

qint32 m_minimumItemHeight
 

Detailed Description

This delegate draw categories using information from a QSortFilterProxyModel.

Definition at line 18 of file kis_categorized_item_delegate.h.

Constructor & Destructor Documentation

◆ KisCategorizedItemDelegate()

KisCategorizedItemDelegate::KisCategorizedItemDelegate ( QObject * parent)

Definition at line 24 of file kis_categorized_item_delegate.cpp.

25 : QStyledItemDelegate(parent),
27{
28}

Member Function Documentation

◆ paint()

void KisCategorizedItemDelegate::paint ( QPainter * painter,
const QStyleOptionViewItem & option,
const QModelIndex & index ) const
override

Definition at line 30 of file kis_categorized_item_delegate.cpp.

31{
32 painter->resetTransform();
33
34 if(!index.data(__CategorizedListModelBase::IsHeaderRole).toBool()) {
35 QStyleOptionViewItem sovi(option);
36
37 if (index.data(__CategorizedListModelBase::isLockableRole).toBool()) {
38
39 const int iconSize = qMax(16, m_minimumItemHeight - 2);
40 bool locked = index.data(__CategorizedListModelBase::isLockedRole).toBool();
41
42
43 QIcon icon = locked ? KisIconUtils::loadIcon(koIconName("layer-locked")) : KisIconUtils::loadIcon(koIconName("layer-unlocked"));
44
45 // to be able to make an icon more transparent. we need to create a new image
46 // and use the QPainter to make a more transparent version of it.
47 QImage image(iconSize, iconSize, QImage::Format_ARGB32_Premultiplied);
48 image.fill(Qt::transparent); // needs to happen, otherwise 'junk' pixels are used (looks bad)
49
50 QPainter p(&image);
51 p.setCompositionMode(QPainter::CompositionMode_Source);
52
53
54 // make unlocked icons more hidden
55 if (locked) {
56 p.setOpacity(1.0);
57 } else {
58 p.setOpacity(0.14);
59 }
60
61 p.drawPixmap(0, 0, icon.pixmap(iconSize, QIcon::Normal) );
62 p.end();
63
64 icon = QIcon( QPixmap::fromImage(image) ); // the new icon is ready
65
66
67
68 sovi.decorationPosition = QStyleOptionViewItem::Right;
69 sovi.decorationAlignment = Qt::AlignRight;
70 sovi.decorationSize = QSize(iconSize, iconSize);
71 sovi.features |= QStyleOptionViewItem::HasDecoration;
72 sovi.icon = icon;
73
74 }
75
76 QStyledItemDelegate::paint(painter, sovi, index);
77 painter->setOpacity(1);
78 }
79 else {
80 QPalette palette = QApplication::palette();
81 if(option.state & QStyle::State_MouseOver)
82 painter->fillRect(option.rect, palette.midlight());
83 else
84 painter->fillRect(option.rect, palette.button());
85
86 painter->setBrush(palette.buttonText());
87 painter->drawText(option.rect, index.data().toString(), QTextOption(Qt::AlignVCenter|Qt::AlignHCenter));
88
90 painter,
91 option.rect.x(),
92 option.rect.y(),
93 option.rect.height(),
95 );
96 }
97 painter->resetTransform();
98}
const Params2D p
int iconSize(qreal width, qreal height)
void paintTriangle(QPainter *painter, qint32 x, qint32 y, qint32 size, bool rotate) const
#define koIconName(name)
Definition kis_icon.h:27
QIcon loadIcon(const QString &name)
rgba palette[MAX_PALETTE]
Definition palette.c:35

References __CategorizedListModelBase::ExpandCategoryRole, iconSize(), __CategorizedListModelBase::IsHeaderRole, __CategorizedListModelBase::isLockableRole, __CategorizedListModelBase::isLockedRole, koIconName, KisIconUtils::loadIcon(), m_minimumItemHeight, p, paintTriangle(), and palette.

◆ paintTriangle()

void KisCategorizedItemDelegate::paintTriangle ( QPainter * painter,
qint32 x,
qint32 y,
qint32 size,
bool rotate ) const
private

Definition at line 129 of file kis_categorized_item_delegate.cpp.

130{
131 QPolygonF triangle;
132 triangle.push_back(QPointF(-0.2,-0.2));
133 triangle.push_back(QPointF( 0.2,-0.2));
134 triangle.push_back(QPointF( 0.0, 0.2));
135
136 QTransform transform;
137 transform.translate(x + size/2, y + size/2);
138 transform.scale(size, size);
139
140 if(rotate)
141 transform.rotate(-90);
142
143 QPalette palette = QApplication::palette();
144 painter->setBrush(palette.buttonText());
145 painter->drawPolygon(transform.map(triangle));
146}

References palette.

◆ sizeHint()

QSize KisCategorizedItemDelegate::sizeHint ( const QStyleOptionViewItem & option,
const QModelIndex & index ) const
override

Make all the items, including the ones having checkboxes look the same.

Definition at line 100 of file kis_categorized_item_delegate.cpp.

101{
102 //on first calling this calculates the minimal height of the items
103 if (m_minimumItemHeight == 0) {
104 for(int i=0; i<index.model()->rowCount(); i++) {
105 QSize indexSize = QStyledItemDelegate::sizeHint(option, index.model()->index(i, 0));
106 m_minimumItemHeight = qMax(m_minimumItemHeight, indexSize.height());
107
112 QStyle *style = QApplication::style();
113 QStyleOptionButton so;
114 QSize size = style->sizeFromContents(QStyle::CT_CheckBox, &so, QSize(), 0);
115
117 }
118 }
119
120 int width = QStyledItemDelegate::sizeHint(option, index).width();
121
122 if (index.data(__CategorizedListModelBase::isLockableRole).toBool()) {
123 width += m_minimumItemHeight;
124 }
125
126 return QSize(width, m_minimumItemHeight);
127}
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References __CategorizedListModelBase::isLockableRole, and m_minimumItemHeight.

Member Data Documentation

◆ m_minimumItemHeight

qint32 KisCategorizedItemDelegate::m_minimumItemHeight
mutableprivate

Definition at line 27 of file kis_categorized_item_delegate.h.


The documentation for this class was generated from the following files: