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

The resource item delegate for rendering the resource preview. More...

#include <KisResourceItemDelegate.h>

+ Inheritance diagram for KisResourceItemDelegate:

Public Member Functions

 KisResourceItemDelegate (QObject *parent=0)
 
void paint (QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const override
 
void setIsWidget (bool)
 
void setShowText (bool)
 
QSize sizeHint (const QStyleOptionViewItem &, const QModelIndex &) const override
 
 ~KisResourceItemDelegate () override
 

Private Attributes

KoCheckerBoardPainter m_checkerPainter
 
bool m_isWidget
 
bool m_showText
 
KisResourceThumbnailPainter m_thumbnailPainter
 

Detailed Description

The resource item delegate for rendering the resource preview.

Definition at line 18 of file KisResourceItemDelegate.h.

Constructor & Destructor Documentation

◆ KisResourceItemDelegate()

KisResourceItemDelegate::KisResourceItemDelegate ( QObject * parent = 0)
explicit

Definition at line 17 of file KisResourceItemDelegate.cpp.

18 : QAbstractItemDelegate(parent)
20 , m_showText(false)
21 , m_isWidget(false)
22{
23}
KoCheckerBoardPainter m_checkerPainter

◆ ~KisResourceItemDelegate()

KisResourceItemDelegate::~KisResourceItemDelegate ( )
inlineoverride

Definition at line 23 of file KisResourceItemDelegate.h.

23{}

Member Function Documentation

◆ paint()

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

Definition at line 35 of file KisResourceItemDelegate.cpp.

36{
37 if (!index.isValid()) return;
38 painter->save();
39
40 if (m_showText) {
41 QRect paintRect = QRect(option.rect.x(), option.rect.y(), option.rect.height(), option.rect.height());
42 QString resourceDisplayName = index.data(Qt::UserRole + KisAbstractResourceModel::Name).toString().replace("_", " "); // don't need underscores that might be part of the file name
43 painter->drawText(paintRect.width() + 10, option.rect.y() + option.rect.height() - 10, resourceDisplayName);
44
45 if (m_isWidget) { // Bundle Creator selected list...
46 QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
47
48 QImage preview;
49 if (!icon.isNull()) {
50 QSize iconSize = option.decorationSize; // or specify a desired size
51 QPixmap pixmap = icon.pixmap(iconSize);
52 preview = pixmap.toImage();
53 }
54
55 painter->drawImage(paintRect.x(), paintRect.y(), preview);
56 } else {
57 m_thumbnailPainter.paint(painter, index, paintRect, option.palette, false, true);
58 }
59
60 if (option.state & QStyle::State_Selected) {
61 painter->setCompositionMode(QPainter::CompositionMode_HardLight);
62 painter->setOpacity(1.0);
63 painter->fillRect(option.rect, option.palette.highlight());
64
65 // highlight is not strong enough to pick out preset. draw border around it.
66 painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
67 painter->setPen(QPen(option.palette.highlight(), 4, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
68 QRect selectedBorder = option.rect.adjusted(2 , 2, -2, -2); // constrict the rectangle so it doesn't bleed into other presets
69 painter->drawRect(selectedBorder);
70 }
71 } else {
72 m_thumbnailPainter.paint(painter, index, option.rect, option.palette, option.state & QStyle::State_Selected, true);
73 }
74 painter->restore();
75}
int iconSize(qreal width, qreal height)
KisResourceThumbnailPainter m_thumbnailPainter
void paint(QPainter *painter, const QModelIndex &index, QRect rect, const QPalette &palette, bool selected, bool addMargin) const

References iconSize(), m_isWidget, m_showText, m_thumbnailPainter, KisAbstractResourceModel::Name, and KisResourceThumbnailPainter::paint().

◆ setIsWidget()

void KisResourceItemDelegate::setIsWidget ( bool isWidget)

Definition at line 30 of file KisResourceItemDelegate.cpp.

31{
32 m_isWidget = isWidget;
33}

References m_isWidget.

◆ setShowText()

void KisResourceItemDelegate::setShowText ( bool showText)

Definition at line 25 of file KisResourceItemDelegate.cpp.

26{
27 m_showText = showText;
28}

References m_showText.

◆ sizeHint()

QSize KisResourceItemDelegate::sizeHint ( const QStyleOptionViewItem & optionItem,
const QModelIndex & index ) const
override

Definition at line 78 of file KisResourceItemDelegate.cpp.

79{
80 return optionItem.decorationSize;
81}

Member Data Documentation

◆ m_checkerPainter

KoCheckerBoardPainter KisResourceItemDelegate::m_checkerPainter
private

Definition at line 32 of file KisResourceItemDelegate.h.

◆ m_isWidget

bool KisResourceItemDelegate::m_isWidget
private

Definition at line 35 of file KisResourceItemDelegate.h.

◆ m_showText

bool KisResourceItemDelegate::m_showText
private

Definition at line 34 of file KisResourceItemDelegate.h.

◆ m_thumbnailPainter

KisResourceThumbnailPainter KisResourceItemDelegate::m_thumbnailPainter
private

Definition at line 33 of file KisResourceItemDelegate.h.


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