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

#include <KisPaletteDelegate.h>

+ Inheritance diagram for KisPaletteDelegate:

Public Member Functions

 KisPaletteDelegate (QObject *parent=0)
 
void paint (QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const override
 
void setCrossedKeyword (const QString &value)
 
QSize sizeHint (const QStyleOptionViewItem &option, const QModelIndex &) const override
 
 ~KisPaletteDelegate () override
 

Private Attributes

QString m_crossedKeyword
 

Static Private Attributes

static const int BORDER_WIDTH = 3
 

Detailed Description

Definition at line 15 of file KisPaletteDelegate.h.

Constructor & Destructor Documentation

◆ KisPaletteDelegate()

KisPaletteDelegate::KisPaletteDelegate ( QObject * parent = 0)

Definition at line 17 of file kis_palette_delegate.cpp.

18 : QAbstractItemDelegate(parent)
19{
20}

◆ ~KisPaletteDelegate()

KisPaletteDelegate::~KisPaletteDelegate ( )
override

Definition at line 22 of file kis_palette_delegate.cpp.

23{
24}

Member Function Documentation

◆ paint()

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

Definition at line 31 of file kis_palette_delegate.cpp.

32{
33 painter->save();
34
35 if (! index.isValid())
36 return;
37
38 const bool isSelected = option.state & QStyle::State_Selected;
39 const int minSize = qMin(option.rect.width(), option.rect.height());
40 const int maxWidth = qBound(2, minSize / 6, 4);
41 const int width = isSelected ? maxWidth : 1;
42
43 if (qvariant_cast<bool>(index.data(KisPaletteModel::IsHeaderRole))) {
44 QString name = qvariant_cast<QString>(index.data(Qt::DisplayRole));
45 if (isSelected) {
46 painter->fillRect(option.rect, option.palette.highlight());
47 }
48 QRect paintRect = kisGrowRect(option.rect, -width);
49 painter->drawText(paintRect, name);
50 } else {
51 if (isSelected) {
52 painter->fillRect(option.rect, option.palette.highlight());
53 }
54 QRect paintRect = kisGrowRect(option.rect, -width);
55 QBrush brush = qvariant_cast<QBrush>(index.data(Qt::BackgroundRole));
56 painter->fillRect(paintRect, brush);
57 }
58 painter->restore();
59
60 QString name = qvariant_cast<QString>(index.data(Qt::DisplayRole));
61 if (!m_crossedKeyword.isNull() && name.toLower().contains(m_crossedKeyword)) {
62 QRect crossRect = kisGrowRect(option.rect, -maxWidth);
63
64 painter->save();
65 painter->setRenderHint(QPainter::Antialiasing, true);
66 painter->setPen(QPen(Qt::white, 2.5));
67 painter->drawLine(crossRect.topLeft(), crossRect.bottomRight());
68 painter->setPen(QPen(Qt::red, 1.0));
69 painter->drawLine(crossRect.topLeft(), crossRect.bottomRight());
70 painter->restore();
71 }
72}
T kisGrowRect(const T &rect, U offset)
Definition kis_global.h:186
const char * name(StandardAction id)

References kisGrowRect(), and m_crossedKeyword.

◆ setCrossedKeyword()

void KisPaletteDelegate::setCrossedKeyword ( const QString & value)
inline

Definition at line 23 of file KisPaletteDelegate.h.

24 {
26 }
float value(const T *src, size_t ch)

References value().

◆ sizeHint()

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

Definition at line 74 of file kis_palette_delegate.cpp.

75{
76 return option.decorationSize;
77}

Member Data Documentation

◆ BORDER_WIDTH

const int KisPaletteDelegate::BORDER_WIDTH = 3
staticprivate

Definition at line 18 of file KisPaletteDelegate.h.

◆ m_crossedKeyword

QString KisPaletteDelegate::m_crossedKeyword
private

Definition at line 32 of file KisPaletteDelegate.h.


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