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 setNeedIndexConversion (bool value)
 
void setShowText (bool)
 
QSize sizeHint (const QStyleOptionViewItem &, const QModelIndex &) const override
 
 ~KisResourceItemDelegate () override
 

Private Member Functions

QModelIndex convertToGlobalModelIndexIfNeeded (const QModelIndex &localIndex) const
 

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 18 of file KisResourceItemDelegate.cpp.

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

◆ ~KisResourceItemDelegate()

KisResourceItemDelegate::~KisResourceItemDelegate ( )
inlineoverride

Definition at line 23 of file KisResourceItemDelegate.h.

23{}

Member Function Documentation

◆ convertToGlobalModelIndexIfNeeded()

QModelIndex KisResourceItemDelegate::convertToGlobalModelIndexIfNeeded ( const QModelIndex & localIndex) const
private

Definition at line 36 of file KisResourceItemDelegate.cpp.

37{
38 if (!m_isWidget) return localIndex;
39
40 const int resourceId = localIndex.data(Qt::UserRole + KisAllResourcesModel::Id).toInt();
41 const QString resourceType = localIndex.data(Qt::UserRole + KisAllResourcesModel::ResourceType).toString();
42
43 auto *model = KisResourceModelProvider::resourceModel(resourceType);
44 QModelIndex globalIndex = model->indexForResourceId(resourceId);
45 return globalIndex;
46}
static KisAllResourcesModel * resourceModel(const QString &resourceType)

References KisAbstractResourceModel::Id, m_isWidget, KisResourceModelProvider::resourceModel(), and KisAbstractResourceModel::ResourceType.

◆ paint()

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

Definition at line 48 of file KisResourceItemDelegate.cpp.

49{
50 if (!index.isValid()) return;
51 painter->save();
52
53 if (m_showText) {
54 QRect paintRect = QRect(option.rect.x(), option.rect.y(), option.rect.height(), option.rect.height());
55 QString resourceDisplayName = index.data(Qt::UserRole + KisAbstractResourceModel::Name).toString().replace("_", " "); // don't need underscores that might be part of the file name
56 painter->drawText(paintRect.width() + 10, option.rect.y() + option.rect.height() - 10, resourceDisplayName);
57
58 const QModelIndex globalIndex = convertToGlobalModelIndexIfNeeded(index);
59 m_thumbnailPainter.paint(painter, globalIndex, paintRect, option.palette, false, true);
60
61 if (option.state & QStyle::State_Selected) {
62 painter->setCompositionMode(QPainter::CompositionMode_HardLight);
63 painter->setOpacity(1.0);
64 painter->fillRect(option.rect, option.palette.highlight());
65
66 // highlight is not strong enough to pick out preset. draw border around it.
67 painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
68 painter->setPen(QPen(option.palette.highlight(), 4, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
69 QRect selectedBorder = option.rect.adjusted(2 , 2, -2, -2); // constrict the rectangle so it doesn't bleed into other presets
70 painter->drawRect(selectedBorder);
71 }
72 } else {
73 const QModelIndex globalIndex = convertToGlobalModelIndexIfNeeded(index);
74 m_thumbnailPainter.paint(painter, globalIndex, option.rect, option.palette, option.state & QStyle::State_Selected, true);
75 }
76 painter->restore();
77}
QModelIndex convertToGlobalModelIndexIfNeeded(const QModelIndex &localIndex) const
KisResourceThumbnailPainter m_thumbnailPainter
void paint(QPainter *painter, const QModelIndex &index, QRect rect, const QPalette &palette, bool selected, bool addMargin) const

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

◆ setNeedIndexConversion()

void KisResourceItemDelegate::setNeedIndexConversion ( bool value)

When index conversion is set, the delegate will request only KisAbstractResourceModel::{Id,ResourceType,Name} from the local index and will use this info to resolve the index in the global resources model. It is necessary for, e.g. KisResourceItemListWidget in the bundle creator

Definition at line 31 of file KisResourceItemDelegate.cpp.

32{
33 m_isWidget = isWidget;
34}

References m_isWidget.

◆ setShowText()

void KisResourceItemDelegate::setShowText ( bool showText)

Definition at line 26 of file KisResourceItemDelegate.cpp.

27{
28 m_showText = showText;
29}

References m_showText.

◆ sizeHint()

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

Definition at line 80 of file KisResourceItemDelegate.cpp.

81{
82 Q_UNUSED(index);
83 return optionItem.decorationSize;
84}

Member Data Documentation

◆ m_checkerPainter

KoCheckerBoardPainter KisResourceItemDelegate::m_checkerPainter
private

Definition at line 43 of file KisResourceItemDelegate.h.

◆ m_isWidget

bool KisResourceItemDelegate::m_isWidget
private

Definition at line 46 of file KisResourceItemDelegate.h.

◆ m_showText

bool KisResourceItemDelegate::m_showText
private

Definition at line 45 of file KisResourceItemDelegate.h.

◆ m_thumbnailPainter

KisResourceThumbnailPainter KisResourceItemDelegate::m_thumbnailPainter
private

Definition at line 44 of file KisResourceItemDelegate.h.


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