File indexing completed on 2025-01-12 04:00:37
0001 0002 /* 0003 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org> 0004 Copyright (c) 2006 Mike Gashler <gashlerm@yahoo.com> 0005 All rights reserved. 0006 0007 Redistribution and use in source and binary forms, with or without 0008 modification, are permitted provided that the following conditions 0009 are met: 0010 0011 1. Redistributions of source code must retain the above copyright 0012 notice, this list of conditions and the following disclaimer. 0013 2. Redistributions in binary form must reproduce the above copyright 0014 notice, this list of conditions and the following disclaimer in the 0015 documentation and/or other materials provided with the distribution. 0016 0017 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 0018 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 0019 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 0020 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 0021 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 0022 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0023 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0024 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0025 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 0026 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0027 */ 0028 0029 0030 #include "kpEffectToneEnhanceWidget.h" 0031 0032 #include "imagelib/effects/kpEffectToneEnhance.h" 0033 #include "commands/imagelib/effects/kpEffectToneEnhanceCommand.h" 0034 #include "pixmapfx/kpPixmapFX.h" 0035 0036 #include <QGridLayout> 0037 #include <QLabel> 0038 0039 #include "kpLogCategories.h" 0040 #include <KLocalizedString> 0041 0042 kpEffectToneEnhanceWidget::kpEffectToneEnhanceWidget (bool actOnSelection, 0043 QWidget *parent) 0044 : kpEffectWidgetBase (actOnSelection, parent), 0045 m_granularityInput (nullptr), 0046 m_amountInput (nullptr) 0047 0048 { 0049 auto *lay = new QGridLayout (this); 0050 lay->setContentsMargins(0, 0, 0, 0); 0051 0052 // See kpEffectToneEnhance::applyEffect(). 0053 0054 auto *granularityLabel = new QLabel (i18n ("&Granularity:"), this); 0055 0056 auto *amountLabel = new QLabel (i18n ("&Amount:"), this); 0057 0058 m_granularityInput = new kpDoubleNumInput (this); 0059 m_granularityInput->setRange (0, 1, 0.1/*step*/); 0060 0061 m_amountInput = new kpDoubleNumInput (this); 0062 m_amountInput->setRange (0, 1, 0.1/*step*/); 0063 0064 granularityLabel->setBuddy (m_granularityInput); 0065 amountLabel->setBuddy (m_amountInput); 0066 0067 0068 lay->addWidget (granularityLabel, 0, 0); 0069 lay->addWidget (m_granularityInput, 0, 1); 0070 0071 lay->addWidget (amountLabel, 1, 0); 0072 lay->addWidget (m_amountInput, 1, 1); 0073 0074 lay->setColumnStretch (1, 1); 0075 0076 0077 connect (m_granularityInput, &kpDoubleNumInput::valueChanged, 0078 this, &kpEffectToneEnhanceWidget::settingsChangedDelayed); 0079 0080 connect (m_amountInput, &kpDoubleNumInput::valueChanged, 0081 this, &kpEffectToneEnhanceWidget::settingsChangedDelayed); 0082 0083 } 0084 0085 kpEffectToneEnhanceWidget::~kpEffectToneEnhanceWidget () = default; 0086 0087 0088 // public virtual [base kpEffectWidgetBase] 0089 QString kpEffectToneEnhanceWidget::caption () const 0090 { 0091 // TODO: Why doesn't this have a caption? Ditto for the other effects. 0092 return {}; 0093 } 0094 0095 0096 // private 0097 double kpEffectToneEnhanceWidget::amount () const 0098 { 0099 return m_amountInput ? m_amountInput->value () : 0; 0100 } 0101 0102 // private 0103 double kpEffectToneEnhanceWidget::granularity () const 0104 { 0105 return m_granularityInput ? m_granularityInput->value () : 0; 0106 } 0107 0108 0109 // public virtual [base kpEffectWidgetBase] 0110 bool kpEffectToneEnhanceWidget::isNoOp () const 0111 { 0112 // If the "amount" is 0, nothing happens regardless of the granularity. 0113 // Note that if "granularity" is 0 but "amount" > 0, the effect _is_ active. 0114 // Therefore, "granularity" should have no involvement in this check. 0115 if (amount () == 0) { 0116 return true; 0117 } 0118 0119 return false; 0120 } 0121 0122 // public virtual [base kpEffectWidgetBase] 0123 kpImage kpEffectToneEnhanceWidget::applyEffect (const kpImage &image) 0124 { 0125 return kpEffectToneEnhance::applyEffect (image, 0126 granularity (), amount ()); 0127 } 0128 0129 // public virtual [base kpEffectWidgetBase] 0130 kpEffectCommandBase *kpEffectToneEnhanceWidget::createCommand ( 0131 kpCommandEnvironment *cmdEnviron) const 0132 { 0133 return new kpEffectToneEnhanceCommand (granularity (), amount (), 0134 m_actOnSelection, 0135 cmdEnviron); 0136 } 0137 0138 #include "moc_kpEffectToneEnhanceWidget.cpp"