Warning, file /graphics/kolourpaint/widgets/imagelib/effects/kpEffectFlattenWidget.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 
0002 /*
0003    Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
0004    All rights reserved.
0005 
0006    Redistribution and use in source and binary forms, with or without
0007    modification, are permitted provided that the following conditions
0008    are met:
0009 
0010    1. Redistributions of source code must retain the above copyright
0011       notice, this list of conditions and the following disclaimer.
0012    2. Redistributions in binary form must reproduce the above copyright
0013       notice, this list of conditions and the following disclaimer in the
0014       documentation and/or other materials provided with the distribution.
0015 
0016    THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0017    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0018    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0019    IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0020    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
0021    NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0022    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0023    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0024    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
0025    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0026 */
0027 
0028 
0029 #define DEBUG_KP_EFFECT_FLATTEN 0
0030 
0031 
0032 #include "kpEffectFlattenWidget.h"
0033 
0034 #include "kpDefs.h"
0035 #include "imagelib/effects/kpEffectFlatten.h"
0036 #include "commands/imagelib/effects/kpEffectFlattenCommand.h"
0037 #include "kpLogCategories.h"
0038 
0039 #include <KColorButton>
0040 #include <KSharedConfig>
0041 #include <KConfigGroup>
0042 #include <KLocalizedString>
0043 
0044 #include <QCheckBox>
0045 #include <QVBoxLayout>
0046 
0047 // public static
0048 QColor kpEffectFlattenWidget::s_lastColor1;
0049 QColor kpEffectFlattenWidget::s_lastColor2;
0050 
0051 kpEffectFlattenWidget::kpEffectFlattenWidget (bool actOnSelection,
0052                                               QWidget *parent)
0053     : kpEffectWidgetBase (actOnSelection, parent)
0054 {
0055     if (!s_lastColor1.isValid () || !s_lastColor2.isValid ())
0056     {
0057         KConfigGroup cfgGroupSaver (KSharedConfig::openConfig (), QStringLiteral(kpSettingsGroupFlattenEffect));
0058 
0059         s_lastColor1 = cfgGroupSaver.readEntry (kpSettingFlattenEffectColor1, QColor ());
0060         if (!s_lastColor1.isValid ()) {
0061             s_lastColor1 = Qt::red;
0062         }
0063 
0064         s_lastColor2 = cfgGroupSaver.readEntry (kpSettingFlattenEffectColor2, QColor ());
0065         if (!s_lastColor2.isValid ()) {
0066             s_lastColor2 = Qt::blue;
0067         }
0068     }
0069 
0070 
0071     m_enableCheckBox = new QCheckBox (i18n ("E&nable"), this);
0072 
0073     m_color1Button = new KColorButton (s_lastColor1, this);
0074     m_color2Button = new KColorButton (s_lastColor2, this);
0075 
0076 
0077     m_color1Button->setEnabled (false);
0078     m_color2Button->setEnabled (false);
0079 
0080     auto *lay = new QVBoxLayout (this);
0081     lay->setContentsMargins(0, 0, 0, 0);
0082     lay->addWidget (m_enableCheckBox);
0083     lay->addWidget (m_color1Button);
0084     lay->addWidget (m_color2Button);
0085 
0086     connect (m_enableCheckBox, &QCheckBox::toggled,
0087              this, &kpEffectFlattenWidget::slotEnableChanged);
0088 
0089     connect (m_color1Button, &KColorButton::changed,
0090              this, &kpEffectFlattenWidget::settingsChanged);
0091 
0092     connect (m_color2Button, &KColorButton::changed,
0093              this, &kpEffectFlattenWidget::settingsChanged);
0094 }
0095 
0096 kpEffectFlattenWidget::~kpEffectFlattenWidget ()
0097 {
0098     s_lastColor1 = color1 ();
0099     s_lastColor2 = color2 ();
0100 
0101 
0102     KConfigGroup cfg (KSharedConfig::openConfig (), QStringLiteral(kpSettingsGroupFlattenEffect));
0103 
0104     cfg.writeEntry (kpSettingFlattenEffectColor1, s_lastColor1);
0105     cfg.writeEntry (kpSettingFlattenEffectColor2, s_lastColor2);
0106     cfg.sync ();
0107 }
0108 
0109 
0110 // public
0111 QColor kpEffectFlattenWidget::color1 () const
0112 {
0113     return m_color1Button->color ();
0114 }
0115 
0116 // public
0117 QColor kpEffectFlattenWidget::color2 () const
0118 {
0119     return m_color2Button->color ();
0120 }
0121 
0122 
0123 //
0124 // kpEffectFlattenWidget implements kpEffectWidgetBase interface
0125 //
0126 
0127 // public virtual [base kpEffectWidgetBase]
0128 QString kpEffectFlattenWidget::caption () const
0129 {
0130     return i18n ("Colors");
0131 }
0132 
0133 
0134 // public virtual [base kpEffectWidgetBase]
0135 bool kpEffectFlattenWidget::isNoOp () const
0136 {
0137     return !m_enableCheckBox->isChecked ();
0138 }
0139 
0140 // public virtual [base kpEffectWidgetBase]
0141 kpImage kpEffectFlattenWidget::applyEffect (const kpImage &image)
0142 {
0143 #if DEBUG_KP_EFFECT_FLATTEN
0144     qCDebug(kpLogWidgets) << "kpEffectFlattenWidget::applyEffect() nop="
0145                << isNoOp () << endl;
0146 #endif
0147 
0148     if (isNoOp ()) {
0149         return image;
0150     }
0151 
0152     return kpEffectFlatten::applyEffect (image, color1 (), color2 ());
0153 }
0154 
0155 
0156 // public virtual [base kpEffectWidgetBase]
0157 kpEffectCommandBase *kpEffectFlattenWidget::createCommand (
0158         kpCommandEnvironment *cmdEnviron) const
0159 {
0160     return new kpEffectFlattenCommand (color1 (), color2 (),
0161                                        m_actOnSelection,
0162                                        cmdEnviron);
0163 }
0164 
0165 
0166 // protected slot:
0167 void kpEffectFlattenWidget::slotEnableChanged (bool enable)
0168 {
0169 #if DEBUG_KP_EFFECT_FLATTEN
0170     qCDebug(kpLogWidgets) << "kpEffectFlattenWidget::slotEnableChanged(" << enable
0171                << ") enableButton=" << m_enableCheckBox->isChecked ()
0172                << endl;
0173 #endif
0174 
0175     m_color1Button->setEnabled (enable);
0176     m_color2Button->setEnabled (enable);
0177 
0178     Q_EMIT settingsChanged ();
0179 }
0180 
0181 #include "moc_kpEffectFlattenWidget.cpp"