krita/plugins/paintops/libpaintop

kis_curve_option.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002  * Copyright (C) Boudewijn Rempt <boud@valdyas.org>, (C) 2008
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public License
00015  * along with this library; see the file COPYING.LIB.  If not, write to
00016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  */
00019 #include "kis_curve_option.h"
00020 
00021 
00022 KisCurveOption::KisCurveOption(const QString & label, const QString& name, bool checked)
00023         : m_label(label)
00024         , m_sensor(0)
00025         , m_customCurve(false)
00026         , m_name(name)
00027         , m_checkable(true)
00028         , m_checked(checked)
00029 {
00030     setSensor(KisDynamicSensor::id2Sensor(PressureId.id()));
00031 }
00032 
00033 KisCurveOption::~KisCurveOption()
00034 {
00035 }
00036 
00037 const QString & KisCurveOption::label() const
00038 {
00039     return m_label;
00040 }
00041 
00042 KisCubicCurve KisCurveOption::curve() const
00043 {
00044     return m_curve;
00045 }
00046 
00047 void KisCurveOption::setCurve(const KisCubicCurve& curve)
00048 {
00049     m_curve = curve;
00050     m_customCurve = true;
00051 }
00052 
00053 void KisCurveOption::writeOptionSetting(KisPropertiesConfiguration* setting) const
00054 {
00055     if (m_checkable) {
00056         setting->setProperty("Pressure" + m_name, isChecked());
00057     }
00058     setting->setProperty("Custom" + m_name, m_customCurve);
00059     setting->setProperty(QString(m_name + "Sensor"), sensor()->toXML());
00060     if (m_customCurve) {
00061         setting->setProperty("Curve" + m_name, qVariantFromValue(m_curve));
00062     }
00063 }
00064 
00065 void KisCurveOption::readOptionSetting(const KisPropertiesConfiguration* setting)
00066 {
00067     if (m_checkable) {
00068         setChecked(setting->getBool("Pressure" + m_name, false));
00069     }
00070     m_customCurve = setting->getBool("Custom" + m_name, false);
00071     setSensor(KisDynamicSensor::createFromXML(setting->getString(QString(m_name + "Sensor"))));
00072     if (m_customCurve) {
00073         m_curve = setting->getCubicCurve("Curve" + m_name);
00074     }
00075 }
00076 
00077 void KisCurveOption::setSensor(KisDynamicSensor* sensor)
00078 {
00079     delete m_sensor;
00080     m_sensor = sensor;
00081 }
00082 
00083 KisDynamicSensor* KisCurveOption::sensor() const
00084 {
00085     return m_sensor;
00086 }
00087 
00088 bool KisCurveOption::isCheckable()
00089 {
00090     return m_checkable;
00091 }
00092 
00093 bool KisCurveOption::isChecked() const
00094 {
00095     return m_checked;
00096 }
00097 
00098 void KisCurveOption::setChecked(bool checked)
00099 {
00100     m_checked = checked;
00101 }