Krita Source Code Documentation
Loading...
Searching...
No Matches
DlgBundleManager::ItemDelegate Class Reference

#include <dlg_bundle_manager.h>

+ Inheritance diagram for DlgBundleManager::ItemDelegate:

Public Member Functions

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

Private Attributes

KisStorageFilterProxyModelm_bundleManagerProxyModel
 

Detailed Description

Definition at line 38 of file dlg_bundle_manager.h.

Constructor & Destructor Documentation

◆ ItemDelegate()

DlgBundleManager::ItemDelegate::ItemDelegate ( QObject * parent,
KisStorageFilterProxyModel * proxy )

Definition at line 44 of file dlg_bundle_manager.cpp.

45 : QStyledItemDelegate(parent)
47{
48
49}
KisStorageFilterProxyModel * m_bundleManagerProxyModel

Member Function Documentation

◆ paint()

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

Definition at line 59 of file dlg_bundle_manager.cpp.

60{
61 if (!index.isValid()) {
62 return;
63 }
64
65 QModelIndex sourceIndex = m_bundleManagerProxyModel->mapToSource(index);
66
67 int minMargin = 3;
68 int textMargin = 10;
69
70 painter->save();
71
72 // paint background
73 QColor bgColor = option.state & QStyle::State_Selected ?
74 qApp->palette().color(QPalette::Highlight) :
75 qApp->palette().color(QPalette::Base);
76
77 QBrush oldBrush(painter->brush());
78 QPen oldPen = painter->pen();
79
80 painter->setBrush(QBrush(bgColor));
81 painter->setPen(Qt::NoPen);
82 painter->drawRect(option.rect);
83
84 QRect paintRect = kisGrowRect(option.rect, -minMargin);
85 int height = paintRect.height();
86
87 // make border around active ones
88 bool active = KisStorageModel::instance()->data(sourceIndex, Qt::UserRole + KisStorageModel::Active).toBool();
89
90 if (active) {
91 QColor borderColor = option.state & QStyle::State_Selected ?
92 qApp->palette().color(QPalette::HighlightedText) :
93 qApp->palette().color(QPalette::Text);
94 painter->setBrush(Qt::NoBrush);
95 painter->setPen(QPen(borderColor));
96
97 QRect borderRect = kisGrowRect(paintRect, -painter->pen().widthF());
98
99 painter->drawRect(borderRect);
100
101 painter->setBrush(oldBrush);
102 painter->setPen(oldPen);
103
104 }
105
106 // paint the image
107 QImage thumbnail = KisStorageModel::instance()->data(sourceIndex, Qt::UserRole + KisStorageModel::Thumbnail).value<QImage>();
108
109 QRect iconRect = paintRect;
110 iconRect.setWidth(height);
111 painter->drawImage(iconRect, thumbnail);
112
113 QRect nameRect = paintRect;
114 nameRect.setX(paintRect.x() + height + textMargin);
115 nameRect.setWidth(paintRect.width() - height - 1.5*textMargin); // should be 2, but with 1.5 it's more clear that it's cropped when it is
116
117 QColor textColor = option.state & QStyle::State_Selected ?
118 qApp->palette().color(QPalette::HighlightedText) :
119 qApp->palette().color(QPalette::Text);
120 painter->setPen(QPen(textColor));
121
122 QTextOption textCenterOption;
123 textCenterOption.setAlignment(Qt::AlignVCenter);
124 textCenterOption.setWrapMode(QTextOption::NoWrap);
125 QString name = KisStorageModel::instance()->data(sourceIndex, Qt::UserRole + KisStorageModel::DisplayName).toString();
126 painter->drawText(nameRect, name, textCenterOption);
127
128 painter->restore();
129
130}
static KisStorageModel * instance()
QVariant data(const QModelIndex &index, int role) const override
T kisGrowRect(const T &rect, U offset)
Definition kis_global.h:186
const char * name(StandardAction id)

References KisStorageModel::Active, KisStorageModel::data(), KisStorageModel::DisplayName, KisStorageModel::instance(), kisGrowRect(), and KisStorageModel::Thumbnail.

◆ sizeHint()

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

Definition at line 51 of file dlg_bundle_manager.cpp.

52{
53 Q_UNUSED(option);
54 Q_UNUSED(index);
55
56 return QSize(100, 30);
57}

Member Data Documentation

◆ m_bundleManagerProxyModel

KisStorageFilterProxyModel* DlgBundleManager::ItemDelegate::m_bundleManagerProxyModel
private

Definition at line 47 of file dlg_bundle_manager.h.


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