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

#include <kis_paintop_preset_icon_library.h>

+ Inheritance diagram for KisPaintopPresetIconLibrary:

Public Slots

QImage hueTransform (QImage img)
 
void updateIcon ()
 

Public Member Functions

QImage getImage ()
 
 KisPaintopPresetIconLibrary (QWidget *parent)
 
 ~KisPaintopPresetIconLibrary ()
 

Public Attributes

Ui_wdgpreseticonlibrary * ui
 

Private Attributes

QImage m_background
 
QStandardItemModel * m_baseModel
 
QStandardItemModel * m_optionalModel
 

Detailed Description

Definition at line 15 of file kis_paintop_preset_icon_library.h.

Constructor & Destructor Documentation

◆ KisPaintopPresetIconLibrary()

KisPaintopPresetIconLibrary::KisPaintopPresetIconLibrary ( QWidget * parent)

Definition at line 15 of file kis_paintop_preset_icon_library.cpp.

15 : QWidget(parent), ui(new Ui_wdgpreseticonlibrary)
16{
17 ui->setupUi(this);
18
19 ui->sldHue->setRange(0.0,360.0,1);
20 ui->sldHue->setSingleStep(1.0);
21 ui->sldHue->setPrefix(i18n("Hue:"));
22
23 ui->sldSat->setRange(-50.0,50.0,1);
24 ui->sldSat->setSingleStep(1.0);
25 ui->sldSat->setPrefix(i18n("Saturation:"));
26
27 ui->sldLevels->setRange(-50.0,50.0,1);
28 ui->sldLevels->setSingleStep(1.0);
29 ui->sldLevels->setPrefix(i18n("Mid-gray level:"));
30
31
32 m_baseModel = new QStandardItemModel();
33 ui->vwBase->setModel(m_baseModel);
34
35 m_optionalModel = new QStandardItemModel();
36 ui->vwOptional->setModel(m_optionalModel);
37
38 QStringList background_paths = KoResourcePaths::findAllAssets("data", "preset_icons/*.png");
39 if (background_paths.size()>0) {
40 m_background.load(background_paths.at(0));
41 m_background = m_background.scaled(200, 200);
42 }
43 ui->lblIconPreview->setPixmap(QPixmap::fromImage(m_background));
44
45
46 //empty default:
47
48 QImage empty = QImage(200, 200, QImage::Format_ARGB32);
49 empty.fill(Qt::transparent);
50 m_baseModel->appendRow(new QStandardItem(QIcon(QPixmap::fromImage(empty)), NULL));
51
52 QStringList toolIcon_paths = KoResourcePaths::findAllAssets("data", "preset_icons/tool_icons/*.png");
53 for (int i=0; i<toolIcon_paths.size(); i++) {
54 QImage pix;
55 pix.load(toolIcon_paths.at(i));
56 QStandardItem *image = new QStandardItem(QIcon(QPixmap::fromImage(pix)), NULL);
57 m_baseModel->appendRow(image);
58 }
59
60
61 empty = QImage(40, 40, QImage::Format_ARGB32);
62 empty.fill(Qt::transparent);
63 m_optionalModel->appendRow(new QStandardItem(QIcon(QPixmap::fromImage(empty)), NULL));
64
65 QStringList emblemIcon_paths = KoResourcePaths::findAllAssets("data", "preset_icons/emblem_icons/*.png");
66 for (int i=0; i<emblemIcon_paths.size(); i++) {
67 QImage pix;
68 pix.load(emblemIcon_paths.at(i));
69 QStandardItem *image = new QStandardItem(QIcon(QPixmap::fromImage(pix)), NULL);
70 m_optionalModel->appendRow(image);
71 }
72
73 connect(ui->vwBase->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(updateIcon()));
74 connect(ui->vwOptional->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(updateIcon()));
75 connect(ui->sldHue, SIGNAL(valueChanged(qreal)), this, SLOT(updateIcon()));
76 connect(ui->sldSat, SIGNAL(valueChanged(qreal)), this, SLOT(updateIcon()));
77 connect(ui->sldLevels, SIGNAL(valueChanged(qreal)), this, SLOT(updateIcon()));
78}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
static QStringList findAllAssets(const QString &type, const QString &filter=QString(), SearchOptions options=NoSearchOptions)

References connect(), KoResourcePaths::findAllAssets(), m_background, m_baseModel, m_optionalModel, ui, and updateIcon().

◆ ~KisPaintopPresetIconLibrary()

KisPaintopPresetIconLibrary::~KisPaintopPresetIconLibrary ( )

Definition at line 80 of file kis_paintop_preset_icon_library.cpp.

81{
82 delete ui;
83 m_optionalModel->clear();
84 delete m_optionalModel;
85 m_baseModel->clear();
86 delete m_baseModel;
87}

References m_baseModel, m_optionalModel, and ui.

Member Function Documentation

◆ getImage()

QImage KisPaintopPresetIconLibrary::getImage ( )

Definition at line 89 of file kis_paintop_preset_icon_library.cpp.

90{
91 QImage preset = m_background;
92 QImage base = QImage(200, 200, QImage::Format_ARGB32);
93 base.fill(Qt::transparent);
94 if (ui->vwBase->currentIndex().isValid()) {
95 base = m_baseModel->itemFromIndex(ui->vwBase->currentIndex())->icon().pixmap(QSize(200, 200)).toImage();
96 }
97 if (ui->sldHue->value()>0 || ui->sldSat->value()!=0.0 || ui->sldLevels->value()!=0.0) {
98 base = hueTransform(base);
99 }
100 QImage optional = QImage(40, 40, QImage::Format_ARGB32);
101 optional.fill(Qt::transparent);
102 if (ui->vwOptional->currentIndex().isValid()) {
103 optional = m_optionalModel->itemFromIndex(ui->vwOptional->currentIndex())->icon().pixmap(QSize(40, 40)).toImage();
104 }
105
106 QPainter p(&preset);
107 p.drawImage(0, 0, base);
108 int x = 35;
109 int y = 31;
110 p.drawImage(x, y, optional);
111 return preset;
112}
const Params2D p

References hueTransform(), m_background, m_baseModel, m_optionalModel, p, and ui.

◆ hueTransform

QImage KisPaintopPresetIconLibrary::hueTransform ( QImage img)
slot

Definition at line 114 of file kis_paintop_preset_icon_library.cpp.

115{
116 //This is a super simple levels operation instead of a regular lightness adjustment.
117 //This is so that we can keep the contrasts in the icon instead of making it
118 //just darker or lighter.
119 QVector<int> values(256);
120 values.fill(255);
121 int level = qMax(qMin( 28 + ( (int(ui->sldLevels->value()) + 50) * 2), 255), 0);
122 for (int v = 0; v < level; v++) {
123 values[v] = int((128.0 / qreal(level))*v);
124 }
125 for (int v = level; v < 255; v++) {
126 values[v] = qMax(qMin(int( (128.0 / qreal(255 - level)) *(v - level)+128.0), 255), 0);
127 }
128
129 //This is very slow by Krita standards, but we cannot get hsv transforms, ad the image is only 200x200.
130 for (int x = 0; x < img.width(); x++) {
131 for (int y = 0; y < img.height(); y++) {
132 QColor c = img.pixelColor(x, y);
133 int hue = c.hslHue()+(int)ui->sldHue->value();
134 if (hue > 360) {
135 hue -= 360;
136 }
137 int sat = qMax(qMin(c.hslSaturation() + int(ui->sldSat->value() * (255.0 / 100.0)), 255), 0);
138 c.setHsl(hue, sat, values.at(c.lightness()), c.alpha());
139 img.setPixelColor(x, y, c);
140 }
141 }
142 return img;
143}
qreal v

References ui, and v.

◆ updateIcon

void KisPaintopPresetIconLibrary::updateIcon ( )
slot

Definition at line 145 of file kis_paintop_preset_icon_library.cpp.

146{
147 ui->lblIconPreview->setPixmap(QPixmap::fromImage(getImage()));
148}

References getImage(), and ui.

Member Data Documentation

◆ m_background

QImage KisPaintopPresetIconLibrary::m_background
private

Definition at line 32 of file kis_paintop_preset_icon_library.h.

◆ m_baseModel

QStandardItemModel* KisPaintopPresetIconLibrary::m_baseModel
private

Definition at line 30 of file kis_paintop_preset_icon_library.h.

◆ m_optionalModel

QStandardItemModel* KisPaintopPresetIconLibrary::m_optionalModel
private

Definition at line 31 of file kis_paintop_preset_icon_library.h.

◆ ui

Ui_wdgpreseticonlibrary* KisPaintopPresetIconLibrary::ui

Definition at line 22 of file kis_paintop_preset_icon_library.h.


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