File indexing completed on 2025-01-26 04:11:25

0001 /*
0002  *  SPDX-FileCopyrightText: 2017 Scott Petrovic <scottpetrovic@gmail.com>
0003 
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "kis_texture_chooser.h"
0008 #include "kis_texture_option.h"
0009 #include <KoCompositeOpRegistry.h>
0010 
0011 #include <KisGradientChooser.h>
0012 
0013 KisTextureChooser::KisTextureChooser(KisBrushTextureFlags flags, QWidget *parent)
0014     : QWidget(parent)
0015 {
0016     setupUi(this);
0017 
0018     textureSelectorWidget->setGrayscalePreview(true);
0019     textureSelectorWidget->setCurrentItem(0);
0020 
0021     scaleSlider->setRange(0.0, 2.0, 2);
0022     scaleSlider->setSingleStep(0.01);
0023     scaleSlider->setValue(1.0);
0024     scaleSlider->addMultiplier(0.1);
0025     scaleSlider->addMultiplier(2);
0026     scaleSlider->addMultiplier(10);
0027 
0028     brightnessSlider->setRange(-1.0, 1.0, 2);
0029     brightnessSlider->setSingleStep(0.01);
0030     brightnessSlider->setValue(0.0);
0031     brightnessSlider->setToolTip(i18n("Makes texture lighter or darker"));
0032 
0033     contrastSlider->setRange(0.0, 2.0, 2);
0034     contrastSlider->setSingleStep(0.01);
0035     contrastSlider->setValue(1.0);
0036 
0037     neutralPointSlider->setRange(0.0, 1.0, 2);
0038     neutralPointSlider->setSingleStep(0.01);
0039     neutralPointSlider->setValue(0.5);
0040     neutralPointSlider->setToolTip(i18n("Set gray value to be considered neutral for lightness mode"));
0041 
0042     offsetSliderX->setSuffix(i18n(" px"));
0043 
0044     offsetSliderY->setSuffix(i18n(" px"));
0045 
0046 
0047     QVector<std::pair<QString, int>> texturingModes;
0048 
0049     texturingModes
0050         << std::make_pair(KoCompositeOpRegistry::instance().getKoID(COMPOSITE_MULT).name(), KisTextureOptionData::MULTIPLY)
0051         << std::make_pair(KoCompositeOpRegistry::instance().getKoID(COMPOSITE_SUBTRACT).name(), KisTextureOptionData::SUBTRACT);
0052 
0053     if (flags & SupportsLightnessMode) {
0054         texturingModes << std::make_pair(i18nc("Lightness Map blend mode for brush texture", "Lightness Map"), KisTextureOptionData::LIGHTNESS);
0055     }
0056 
0057     if (flags & SupportsGradientMode) {
0058         texturingModes << std::make_pair(i18nc("Gradient Map blend mode for brush texture", "Gradient Map"), KisTextureOptionData::GRADIENT);
0059     }
0060 
0061     texturingModes
0062         << std::make_pair(KoCompositeOpRegistry::instance().getKoID(COMPOSITE_DARKEN).name(), KisTextureOptionData::DARKEN)
0063         << std::make_pair(KoCompositeOpRegistry::instance().getKoID(COMPOSITE_OVERLAY).name(), KisTextureOptionData::OVERLAY)
0064         << std::make_pair(KoCompositeOpRegistry::instance().getKoID(COMPOSITE_DODGE).name(), KisTextureOptionData::COLOR_DODGE)
0065         << std::make_pair(KoCompositeOpRegistry::instance().getKoID(COMPOSITE_BURN).name(), KisTextureOptionData::COLOR_BURN)
0066         << std::make_pair(KoCompositeOpRegistry::instance().getKoID(COMPOSITE_LINEAR_DODGE).name(), KisTextureOptionData::LINEAR_DODGE)
0067         << std::make_pair(KoCompositeOpRegistry::instance().getKoID(COMPOSITE_LINEAR_BURN).name(), KisTextureOptionData::LINEAR_BURN)
0068         << std::make_pair(KoCompositeOpRegistry::instance().getKoID(COMPOSITE_HARD_MIX_PHOTOSHOP).name(), KisTextureOptionData::HARD_MIX_PHOTOSHOP)
0069         << std::make_pair(KoCompositeOpRegistry::instance().getKoID(COMPOSITE_HARD_MIX_SOFTER_PHOTOSHOP).name(), KisTextureOptionData::HARD_MIX_SOFTER_PHOTOSHOP)
0070         << std::make_pair(i18nc("Height blend mode for brush texture", "Height"), KisTextureOptionData::HEIGHT)
0071         << std::make_pair(i18nc("Linear Height blend mode for brush texture", "Linear Height"), KisTextureOptionData::LINEAR_HEIGHT)
0072         << std::make_pair(i18nc("Height (Photoshop) blend mode for brush texture", "Height (Photoshop)"), KisTextureOptionData::HEIGHT_PHOTOSHOP)
0073         << std::make_pair(i18nc("Linear Height (Photoshop) blend mode for brush texture", "Linear Height (Photoshop)"), KisTextureOptionData::LINEAR_HEIGHT_PHOTOSHOP);
0074 
0075     for (auto it = texturingModes.begin(); it != texturingModes.end(); ++it) {
0076         cmbTexturingMode->addItem(it->first, it->second);
0077     }
0078 
0079     cmbTexturingMode->setCurrentIndex(KisTextureOptionData::SUBTRACT);
0080 
0081     QStringList cutOffPolicies;
0082     cutOffPolicies << i18n("Cut Off Disabled") << i18n("Cut Off Brush") << i18n("Cut Off Pattern");
0083     cmbCutoffPolicy->addItems(cutOffPolicies);
0084 
0085 
0086     cutoffSlider->setToolTip(i18n("When pattern texture values are outside the range specified"
0087                                   " by the slider, the cut-off policy will be applied."));
0088 
0089     chkInvert->setChecked(false);
0090 
0091 }
0092 
0093 KisTextureChooser::~KisTextureChooser()
0094 {
0095 
0096 }
0097 
0098 bool KisTextureChooser::selectTexturingMode(KisTextureOptionData::TexturingMode mode)
0099 {
0100     int i = 0;
0101     for (; i < cmbTexturingMode->count(); i++) {
0102         if (cmbTexturingMode->itemData(i) == mode) {
0103             cmbTexturingMode->setCurrentIndex(i);
0104         }
0105     }
0106 
0107     return i < cmbTexturingMode->count();
0108 }
0109 
0110 KisTextureOptionData::TexturingMode KisTextureChooser::texturingMode() const
0111 {
0112     return KisTextureOptionData::TexturingMode(cmbTexturingMode->currentData().value<int>());
0113 }