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

#include <KisStorageChooserWidget.h>

+ Inheritance diagram for KisStorageChooserDelegate:

Public Member Functions

 KisStorageChooserDelegate (QObject *parent=0)
 
void paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
 
QSize sizeHint (const QStyleOptionViewItem &, const QModelIndex &) const override
 
 ~KisStorageChooserDelegate () override
 

Detailed Description

Definition at line 16 of file KisStorageChooserWidget.h.

Constructor & Destructor Documentation

◆ KisStorageChooserDelegate()

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

Definition at line 23 of file KisStorageChooserWidget.cpp.

24 : QAbstractItemDelegate(parent)
25{
26}

◆ ~KisStorageChooserDelegate()

KisStorageChooserDelegate::~KisStorageChooserDelegate ( )
inlineoverride

Definition at line 21 of file KisStorageChooserWidget.h.

21{}

Member Function Documentation

◆ paint()

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

Definition at line 28 of file KisStorageChooserWidget.cpp.

29{
30 if (!index.isValid()) return;
31
32 painter->save();
33
34 QString name = index.sibling(index.row(), KisStorageModel::DisplayName).data(Qt::DisplayRole).value<QString>();
35 QString location = index.sibling(index.row(), KisStorageModel::Location).data(Qt::DisplayRole).value<QString>();
36 bool active = index.data(Qt::UserRole + KisStorageModel::Active).value<bool>();
37 QString storageType = index.data(Qt::UserRole + KisStorageModel::StorageType).value<QString>();
38
39 QImage thumbnail = index.data(Qt::UserRole + + KisStorageModel::Thumbnail).value<QImage>();
40
41 qreal devicePixelRatioF = painter->device()->devicePixelRatioF();
42
43 if (thumbnail.isNull()) {
44 //fallback on cute icons.
45 thumbnail = koIcon("warning").pixmap(option.decorationSize).toImage();
46 if (storageType == "Folder") {
47 thumbnail = koIcon("document-open").pixmap(option.decorationSize).toImage();
48 }
49 else if (storageType == "Adobe Style Library") {
50 thumbnail = koIcon("layer-style-enabled").pixmap(option.decorationSize).toImage();
51 if (!thumbnail.isNull()) {
52 thumbnail = thumbnail.scaled(option.decorationSize, Qt::KeepAspectRatio, Qt::FastTransformation);
53 }
54 }
55 else if (storageType == "Adobe Brush Library") {
56 thumbnail = koIcon("select-all").pixmap(option.decorationSize).toImage();
57 }
58 else if (storageType == "Memory") {
59 if (location != "memory") {
60 thumbnail = koIcon("document-new").pixmap(option.decorationSize).toImage();
61 } else {
62 thumbnail = koIcon("drive-harddisk").pixmap(option.decorationSize).toImage();
63 }
64
65 }
66 else if (storageType == "Bundle") {
67 thumbnail = koIcon("bundle_archive").pixmap(option.decorationSize).toImage();
68 }
69
70 } else {
71 if (!thumbnail.isNull()) {
72 thumbnail = thumbnail.scaled(option.decorationSize*devicePixelRatioF, Qt::KeepAspectRatio, Qt::SmoothTransformation);
73 }
74 thumbnail.setDevicePixelRatio(devicePixelRatioF);
75 }
76
77 QColor penColor(option.palette.text().color());
78
79 QStyleOptionViewItem opt = option;
80
81 if (active) {
82 opt.state = QStyle::State_Sunken;
83 }
84
85 QApplication::style()->drawPrimitive(QStyle::PE_PanelButtonTool, &opt, painter);
86
87 painter->setPen(penColor);
88 painter->drawImage(option.rect.topLeft()+QPoint(4, 4), thumbnail, thumbnail.rect());
89
90
91 // Draw is active checkbox
92 QStyleOptionButton checkboxOption;
93 checkboxOption.rect = QRect(option.rect.x() + option.decorationSize.width() + 8,
94 option.rect.y() + option.rect.height() - 30,
95 20, 20);
96 checkboxOption.state = active ? QStyle::State_On : QStyle::State_Off;
97 QApplication::style()->drawControl(QStyle::CE_CheckBox, &checkboxOption, painter);
98
99
100 // Draw text
101 QRect text = option.rect;
102 text.setLeft(text.left()+option.decorationSize.width()+8);
103 text.setTop(text.top()+4);
104 painter->drawText(text, Qt::TextWordWrap, name.split("_").join(" "));
105
106 painter->restore();
107}
#define koIcon(name)
Use these macros for icons without any issues.
Definition kis_icon.h:25
const char * name(StandardAction id)

References KisStorageModel::Active, KisStorageModel::DisplayName, koIcon, KisStorageModel::Location, KisStorageModel::StorageType, and KisStorageModel::Thumbnail.

◆ sizeHint()

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

Definition at line 109 of file KisStorageChooserWidget.cpp.

110{
111 Q_UNUSED(index);
112 int w = 200;
113 int h = option.decorationSize.height()+8;
114 return QSize(w, h);
115}

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