File indexing completed on 2024-12-22 04:13:15

0001 /*
0002  * This file is part of Krita
0003  *
0004  * SPDX-FileCopyrightText: 2021 Deif Lou <ginoba@gmail.com>
0005  *
0006  * SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #include "KisAutoLevelsWidget.h"
0010 
0011 #include <KisSpinBoxI18nHelper.h>
0012 
0013 KisAutoLevelsWidget::KisAutoLevelsWidget(QWidget *parent)
0014     : QWidget(parent)
0015 {
0016     m_ui.setupUi(this);
0017 
0018     KisSpinBoxI18nHelper::setText(m_ui.sliderShadowsClipping,
0019                                   i18nc("{n} is the number value, % is the percent sign", "{n}%"));
0020     m_ui.sliderShadowsClipping->setRange(0.0, 10.0, 2);
0021     m_ui.sliderShadowsClipping->setValue(0.1);
0022     m_ui.sliderShadowsClipping->setSingleStep(0.1);
0023 
0024     m_ui.sliderHighlightsClipping->setSuffix(m_ui.sliderShadowsClipping->suffix());
0025     m_ui.sliderHighlightsClipping->setRange(0.0, 10.0, 2);
0026     m_ui.sliderHighlightsClipping->setValue(0.1);
0027     m_ui.sliderHighlightsClipping->setSingleStep(0.1);
0028 
0029     m_ui.sliderShadowsAndLightsMaximumOffset->setSuffix(m_ui.sliderShadowsClipping->suffix());
0030     m_ui.sliderShadowsAndLightsMaximumOffset->setRange(0.0, 100.0, 2);
0031     m_ui.sliderShadowsAndLightsMaximumOffset->setValue(100.0);
0032 
0033     m_ui.sliderMidtonesAdjustmentAmount->setSuffix(m_ui.sliderShadowsClipping->suffix());
0034     m_ui.sliderMidtonesAdjustmentAmount->setRange(0.0, 100.0, 2);
0035     m_ui.sliderMidtonesAdjustmentAmount->setValue(50.0);
0036 
0037     connect(m_ui.comboBoxShadowsAndLightsMethod, SIGNAL(currentIndexChanged(int)), SIGNAL(parametersChanged()));
0038     connect(m_ui.sliderShadowsClipping, SIGNAL(valueChanged(qreal)), SIGNAL(parametersChanged()));
0039     connect(m_ui.sliderHighlightsClipping, SIGNAL(valueChanged(qreal)), SIGNAL(parametersChanged()));
0040     connect(m_ui.sliderShadowsAndLightsMaximumOffset, SIGNAL(valueChanged(qreal)), SIGNAL(parametersChanged()));
0041     connect(m_ui.comboBoxMidtonesMethod, SIGNAL(currentIndexChanged(int)), SIGNAL(parametersChanged()));
0042     connect(m_ui.sliderMidtonesAdjustmentAmount, SIGNAL(valueChanged(qreal)), SIGNAL(parametersChanged()));
0043     connect(m_ui.buttonShadowsColor, SIGNAL(changed(const KoColor&)), SIGNAL(parametersChanged()));
0044     connect(m_ui.buttonHighlightsColor, SIGNAL(changed(const KoColor&)), SIGNAL(parametersChanged()));
0045     connect(m_ui.buttonMidtonesColor, SIGNAL(changed(const KoColor&)), SIGNAL(parametersChanged()));
0046 }
0047 
0048 KisAutoLevelsWidget::~KisAutoLevelsWidget()
0049 {}
0050 
0051 KisAutoLevels::ShadowsAndHighlightsAdjustmentMethod KisAutoLevelsWidget::shadowsAndHighlightsAdjustmentMethod() const
0052 {
0053     return static_cast<KisAutoLevels::ShadowsAndHighlightsAdjustmentMethod>(m_ui.comboBoxShadowsAndLightsMethod->currentIndex());
0054 }
0055 
0056 qreal KisAutoLevelsWidget::shadowsClipping() const
0057 {
0058     return m_ui.sliderShadowsClipping->value();
0059 }
0060 
0061 qreal KisAutoLevelsWidget::highlightsClipping() const
0062 {
0063     return m_ui.sliderHighlightsClipping->value();
0064 }
0065 
0066 qreal KisAutoLevelsWidget::maximumInputBlackAndWhiteOffset() const
0067 {
0068     return m_ui.sliderShadowsAndLightsMaximumOffset->value();
0069 }
0070 
0071 KisAutoLevels::MidtonesAdjustmentMethod KisAutoLevelsWidget::midtonesAdjustmentMethod() const
0072 {
0073     return static_cast<KisAutoLevels::MidtonesAdjustmentMethod>(m_ui.comboBoxMidtonesMethod->currentIndex());
0074 }
0075 
0076 qreal KisAutoLevelsWidget::midtonesAdjustmentAmount() const
0077 {
0078     return m_ui.sliderMidtonesAdjustmentAmount->value();
0079 }
0080 
0081 KoColor KisAutoLevelsWidget::outputShadowsColor() const
0082 {
0083     return m_ui.buttonShadowsColor->color();
0084 }
0085 
0086 KoColor KisAutoLevelsWidget::outputHighlightsColor() const
0087 {
0088     return m_ui.buttonHighlightsColor->color();
0089 }
0090 
0091 KoColor KisAutoLevelsWidget::outputMidtonesColor() const
0092 {
0093     return m_ui.buttonMidtonesColor->color();
0094 }
0095 
0096 void KisAutoLevelsWidget::setShadowsAndHighlightsAdjustmentMethod(KisAutoLevels::ShadowsAndHighlightsAdjustmentMethod newMethod)
0097 {
0098     m_ui.comboBoxShadowsAndLightsMethod->setCurrentIndex(static_cast<int>(newMethod));
0099 }
0100 
0101 void KisAutoLevelsWidget::setShadowsClipping(qreal newShadowsClipping)
0102 {
0103     m_ui.sliderShadowsClipping->setValue(newShadowsClipping);
0104 }
0105 
0106 void KisAutoLevelsWidget::setHighlightsClipping(qreal newHighlightsClipping)
0107 {
0108     m_ui.sliderHighlightsClipping->setValue(newHighlightsClipping);
0109 }
0110 
0111 void KisAutoLevelsWidget::setMaximumInputBlackAndWhiteOffset(qreal newMaximumInputBlackAndWhiteOffset)
0112 {
0113     m_ui.sliderShadowsAndLightsMaximumOffset->setValue(newMaximumInputBlackAndWhiteOffset);
0114 }
0115 
0116 void KisAutoLevelsWidget::setMidtonesAdjustmentMethod(KisAutoLevels::MidtonesAdjustmentMethod newMethod)
0117 {
0118     m_ui.comboBoxMidtonesMethod->setCurrentIndex(static_cast<int>(newMethod));
0119 }
0120 
0121 void KisAutoLevelsWidget::setMidtonesAdjustmentAmount(qreal newMidtonesAdjustmentAmount)
0122 {
0123     m_ui.sliderMidtonesAdjustmentAmount->setValue(newMidtonesAdjustmentAmount);
0124 }
0125 
0126 void KisAutoLevelsWidget::setShadowsColor(const KoColor &newShadowsColor)
0127 {
0128     m_ui.buttonShadowsColor->setColor(newShadowsColor);
0129 }
0130 
0131 void KisAutoLevelsWidget::setHighlightsColor(const KoColor &newHighlightsColor)
0132 {
0133     m_ui.buttonHighlightsColor->setColor(newHighlightsColor);
0134 }
0135 
0136 void KisAutoLevelsWidget::setMidtonesColor(const KoColor &newMidtonesColor)
0137 {
0138     m_ui.buttonMidtonesColor->setColor(newMidtonesColor);
0139 }
0140 
0141 void KisAutoLevelsWidget::lockShadowsAndHighlightsAdjustmentMethod()
0142 {
0143     m_ui.comboBoxShadowsAndLightsMethod->setEnabled(false);
0144 }
0145 
0146 void KisAutoLevelsWidget::unlockShadowsAndHighlightsAdjustmentMethod()
0147 {
0148     m_ui.comboBoxShadowsAndLightsMethod->setEnabled(true);
0149 }