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 40 of file dlg_bundle_manager.cpp.

41 : QStyledItemDelegate(parent)
43{
44
45}
KisStorageFilterProxyModel * m_bundleManagerProxyModel

Member Function Documentation

◆ paint()

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

Definition at line 55 of file dlg_bundle_manager.cpp.

56{
57 if (!index.isValid()) {
58 return;
59 }
60
61 QModelIndex sourceIndex = m_bundleManagerProxyModel->mapToSource(index);
62
63 int minMargin = 3;
64 int textMargin = 10;
65
66 painter->save();
67
68 // paint background
69 QColor bgColor = option.state & QStyle::State_Selected ?
70 qApp->palette().color(QPalette::Highlight) :
71 qApp->palette().color(QPalette::Base);
72
73 QBrush oldBrush(painter->brush());
74 QPen oldPen = painter->pen();
75
76 painter->setBrush(QBrush(bgColor));
77 painter->setPen(Qt::NoPen);
78 painter->drawRect(option.rect);
79
80 QRect paintRect = kisGrowRect(option.rect, -minMargin);
81 int height = paintRect.height();
82
83 // make border around active ones
84 bool active = KisStorageModel::instance()->data(sourceIndex, Qt::UserRole + KisStorageModel::Active).toBool();
85
86 if (active) {
87 QColor borderColor = option.state & QStyle::State_Selected ?
88 qApp->palette().color(QPalette::HighlightedText) :
89 qApp->palette().color(QPalette::Text);
90 painter->setBrush(Qt::NoBrush);
91 painter->setPen(QPen(borderColor));
92
93 QRect borderRect = kisGrowRect(paintRect, -painter->pen().widthF());
94
95 painter->drawRect(borderRect);
96
97 painter->setBrush(oldBrush);
98 painter->setPen(oldPen);
99
100 }
101
102 // paint the image
103 QImage thumbnail = KisStorageModel::instance()->data(sourceIndex, Qt::UserRole + KisStorageModel::Thumbnail).value<QImage>();
104
105 QRect iconRect = paintRect;
106 iconRect.setWidth(height);
107 painter->drawImage(iconRect, thumbnail);
108
109 QRect nameRect = paintRect;
110 nameRect.setX(paintRect.x() + height + textMargin);
111 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
112
113 QColor textColor = option.state & QStyle::State_Selected ?
114 qApp->palette().color(QPalette::HighlightedText) :
115 qApp->palette().color(QPalette::Text);
116 painter->setPen(QPen(textColor));
117
118 QTextOption textCenterOption;
119 textCenterOption.setAlignment(Qt::AlignVCenter);
120 textCenterOption.setWrapMode(QTextOption::NoWrap);
121 QString name = KisStorageModel::instance()->data(sourceIndex, Qt::UserRole + KisStorageModel::DisplayName).toString();
122 painter->drawText(nameRect, name, textCenterOption);
123
124 painter->restore();
125
126}
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 47 of file dlg_bundle_manager.cpp.

48{
49 Q_UNUSED(option);
50 Q_UNUSED(index);
51
52 return QSize(100, 30);
53}

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: