diff --git a/krita/data/CMakeLists.txt b/krita/data/CMakeLists.txt --- a/krita/data/CMakeLists.txt +++ b/krita/data/CMakeLists.txt @@ -13,6 +13,7 @@ add_subdirectory( paintoppresets ) add_subdirectory( palettes ) add_subdirectory( symbols ) +add_subdirectory( preset_icons ) ########### install files ############### diff --git a/krita/data/preset_icons/CMakeLists.txt b/krita/data/preset_icons/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/krita/data/preset_icons/CMakeLists.txt @@ -0,0 +1,8 @@ +add_subdirectory(tool_icons) +add_subdirectory(emblem_icons) +########### install files ############### + +install(FILES +background.png + DESTINATION ${DATA_INSTALL_DIR}/krita/preset_icons) + diff --git a/krita/data/preset_icons/background.png b/krita/data/preset_icons/background.png new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@ + + wdgpreseticonlibrary + + + + 0 + 0 + 536 + 505 + + + + Form + + + + + + + + Base image: + + + + + + + + 0 + 20 + + + + + + + + + 0 + 20 + + + + + + + + Base tool image to base this preset on. + + + QAbstractItemView::NoEditTriggers + + + + 80 + 80 + + + + false + + + false + + + false + + + 80 + + + false + + + false + + + false + + + 80 + + + false + + + + + + + Upper left emblem indicating a special feature of the brush. + + + QAbstractItemView::NoEditTriggers + + + + 40 + 40 + + + + false + + + false + + + false + + + 40 + + + 24 + + + false + + + false + + + 40 + + + false + + + + + + + Extra icon: + + + + + + + Color adjustment: + + + + + + + + 200 + 200 + + + + + + + + + + + + 0 + 20 + + + + + + + + + + + KisDoubleSliderSpinBox + QWidget +
kis_slider_spin_box.h
+ 1 +
+
+ + +
diff --git a/libs/ui/forms/wdgsavebrushpreset.ui b/libs/ui/forms/wdgsavebrushpreset.ui --- a/libs/ui/forms/wdgsavebrushpreset.ui +++ b/libs/ui/forms/wdgsavebrushpreset.ui @@ -6,8 +6,8 @@ 0 0 - 450 - 312 + 457 + 332 @@ -155,6 +155,13 @@ + + + Load from Icon Library + + + + Clear Thumbnail diff --git a/libs/ui/widgets/kis_paintop_preset_icon_library.h b/libs/ui/widgets/kis_paintop_preset_icon_library.h new file mode 100644 --- /dev/null +++ b/libs/ui/widgets/kis_paintop_preset_icon_library.h @@ -0,0 +1,48 @@ +/* This file is part of the KDE project + * Copyright (C) 2017 Wolthera van Hövell tot Westerflier + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +#ifndef KIS_PAINTOP_PRESET_ICON_LIBRARY_H +#define KIS_PAINTOP_PRESET_ICON_LIBRARY_H + +#include +#include +#include "ui_wdgpreseticonlibrary.h" + +class Ui_wdgpreseticonlibrary; + +class KisPaintopPresetIconLibrary : public QWidget +{ + Q_OBJECT +public: + KisPaintopPresetIconLibrary(QWidget *parent); + ~KisPaintopPresetIconLibrary(); + + Ui_wdgpreseticonlibrary *ui; + + QImage getImage(); +public Q_SLOTS: + QImage hueTransform(QImage img); + void updateIcon(); + +private: + QStandardItemModel *m_baseModel; + QStandardItemModel *m_optionalModel; + QImage m_background; +}; + +#endif // KIS_PAINTOP_PRESET_ICON_LIBRARY_H diff --git a/libs/ui/widgets/kis_paintop_preset_icon_library.cpp b/libs/ui/widgets/kis_paintop_preset_icon_library.cpp new file mode 100644 --- /dev/null +++ b/libs/ui/widgets/kis_paintop_preset_icon_library.cpp @@ -0,0 +1,175 @@ +/* This file is part of the KDE project + * Copyright (C) 2017 Wolthera van Hövell tot Westerflier + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +#include "kis_paintop_preset_icon_library.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +KisPaintopPresetIconLibrary::KisPaintopPresetIconLibrary(QWidget *parent): QWidget(parent), ui(new Ui_wdgpreseticonlibrary) +{ + ui->setupUi(this); + + ui->sldHue->setRange(0.0,360.0,1); + ui->sldHue->setSingleStep(1.0); + ui->sldHue->setPrefix(i18n("Hue:")); + + ui->sldSat->setRange(-50.0,50.0,1); + ui->sldSat->setSingleStep(1.0); + ui->sldSat->setPrefix(i18n("Saturation:")); + + ui->sldLevels->setRange(-50.0,50.0,1); + ui->sldLevels->setSingleStep(1.0); + ui->sldLevels->setPrefix(i18n("Mid-gray level:")); + + + m_baseModel = new QStandardItemModel(); + ui->vwBase->setModel(m_baseModel); + + m_optionalModel = new QStandardItemModel(); + ui->vwOptional->setModel(m_optionalModel); + + QStringList background_paths = KoResourcePaths::findAllResources("data", "preset_icons/*.png"); + if (background_paths.size()>0) { + m_background.load(background_paths.at(0)); + m_background = m_background.scaled(200, 200); + } + ui->lblIconPreview->setPixmap(QPixmap::fromImage(m_background)); + + + //empty default: + + QImage empty = QImage(200, 200, QImage::Format_ARGB32); + empty.fill(Qt::transparent); + QList row; + row.append(new QStandardItem(QIcon(QPixmap::fromImage(empty)), QString(""))); + + QStringList toolIcon_paths = KoResourcePaths::findAllResources("data", "preset_icons/tool_icons/*.png"); + for (int i=0; i2) { + m_baseModel->appendRow(row); + row.clear(); + } + } + if (row.size()>0) { + m_baseModel->appendRow(row); + } + + empty = QImage(40, 40, QImage::Format_ARGB32); + empty.fill(Qt::transparent); + row.clear(); + row.append(new QStandardItem(QIcon(QPixmap::fromImage(empty)), QString(""))); + + QStringList emblemIcon_paths = KoResourcePaths::findAllResources("data", "preset_icons/emblem_icons/*.png"); + for (int i=0; i4) { + m_optionalModel->appendRow(row); + row.clear(); + } + } + if (row.size()>0) { + m_optionalModel->appendRow(row); + } + + connect(ui->vwBase, SIGNAL(clicked(const QModelIndex)), this, SLOT(updateIcon())); + connect(ui->vwOptional, SIGNAL(clicked(const QModelIndex)), this, SLOT(updateIcon())); + connect(ui->sldHue, SIGNAL(valueChanged(qreal)), this, SLOT(updateIcon())); + connect(ui->sldSat, SIGNAL(valueChanged(qreal)), this, SLOT(updateIcon())); + connect(ui->sldLevels, SIGNAL(valueChanged(qreal)), this, SLOT(updateIcon())); +} + +KisPaintopPresetIconLibrary::~KisPaintopPresetIconLibrary() +{ + delete ui; +} + +QImage KisPaintopPresetIconLibrary::getImage() +{ + QImage preset = m_background; + QImage base = QImage(200, 200, QImage::Format_ARGB32); + base.fill(Qt::transparent); + if (ui->vwBase->currentIndex().isValid()) { + base = m_baseModel->itemFromIndex(ui->vwBase->currentIndex())->icon().pixmap(QSize(200, 200)).toImage(); + } + base = hueTransform(base); + QImage optional = QImage(40, 40, QImage::Format_ARGB32); + optional.fill(Qt::transparent); + if (ui->vwOptional->currentIndex().isValid()) { + optional = m_optionalModel->itemFromIndex(ui->vwOptional->currentIndex())->icon().pixmap(QSize(40, 40)).toImage(); + } + + QPainter p(&preset); + p.drawImage(0, 0, base); + int x = 35; + int y = 31; + p.drawImage(x, y, optional); + return preset; +} + +QImage KisPaintopPresetIconLibrary::hueTransform(QImage img) +{ + //This is a super simple levels operation instead of a regular lightness adjustment. + //This is so that we can keep the contrasts in the icon instead of making it + //just darker or lighter. + QVector values(255); + values.fill(255); + int level = qMax(qMin( 28 + ( ((int)ui->sldLevels->value() + 50) * 2), 255), 0); + for (int v=0; vsldHue->value(); + if (hue>360) { + hue-=360; + } + int sat = qMax(qMin(c.hslSaturation()+(int)(ui->sldSat->value()*(255/100)), 255), 0); + c.setHsl(hue, sat, values.at(c.lightness()), c.alpha()); + img.setPixelColor(x, y, c); + } + } + return img; +} + +void KisPaintopPresetIconLibrary::updateIcon() +{ + ui->lblIconPreview->setPixmap(QPixmap::fromImage(getImage())); +} + + diff --git a/libs/ui/widgets/kis_paintop_presets_save.h b/libs/ui/widgets/kis_paintop_presets_save.h --- a/libs/ui/widgets/kis_paintop_presets_save.h +++ b/libs/ui/widgets/kis_paintop_presets_save.h @@ -67,6 +67,7 @@ void savePreset(); void loadScratchpadThumbnail(); void loadExistingThumbnail(); + void loadImageFromLibrary(); private: diff --git a/libs/ui/widgets/kis_paintop_presets_save.cpp b/libs/ui/widgets/kis_paintop_presets_save.cpp --- a/libs/ui/widgets/kis_paintop_presets_save.cpp +++ b/libs/ui/widgets/kis_paintop_presets_save.cpp @@ -21,12 +21,15 @@ #include #include #include +#include +#include #include #include "KisImportExportManager.h" #include "QDesktopServices" #include "kis_resource_server_provider.h" +#include KisPresetSaveWidget::KisPresetSaveWidget(QWidget * parent) @@ -44,6 +47,7 @@ connect(loadScratchPadThumbnailButton, SIGNAL(clicked(bool)), this, SLOT(loadScratchpadThumbnail())); connect(loadExistingThumbnailButton, SIGNAL(clicked(bool)), this, SLOT(loadExistingThumbnail())); + connect(loadIconLibraryThumbnailButton, SIGNAL(clicked(bool)), this, SLOT(loadImageFromLibrary())); connect(savePresetButton, SIGNAL(clicked(bool)), this, SLOT(savePreset())); connect(cancelButton, SIGNAL(clicked(bool)), this, SLOT(close())); @@ -126,6 +130,28 @@ brushPresetThumbnailWidget->paintPresetImage(); } +void KisPresetSaveWidget::loadImageFromLibrary() +{ + //add dialog code here. + QDialog *dlg = new QDialog(this); + dlg->setWindowTitle(i18n("Preset Icon Library")); + QVBoxLayout *layout = new QVBoxLayout(); + dlg->setLayout(layout); + KisPaintopPresetIconLibrary *libWidget = new KisPaintopPresetIconLibrary(dlg); + layout->addWidget(libWidget); + QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, dlg); + connect(buttons, SIGNAL(accepted()), dlg, SLOT(accept())); + connect(buttons, SIGNAL(rejected()), dlg, SLOT(reject())); + layout->addWidget(buttons); + + //if dialog accepted, get image. + if (dlg->exec()==QDialog::Accepted) { + + QImage presetImage = libWidget->getImage(); + brushPresetThumbnailWidget->paintCustomImage(presetImage); + } +} + void KisPresetSaveWidget::setFavoriteResourceManager(KisFavoriteResourceManager * favManager) { m_favoriteResourceManager = favManager;