kis_pressure_rate_option.cpp 2.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/* This file is part of the KDE project
 * Copyright (C) Boudewijn Rempt <boud@valdyas.org>, (C) 2008
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */
Halla Rempt's avatar
Halla Rempt committed
19

20
#include "kis_pressure_rate_option.h"
Halla Rempt's avatar
Halla Rempt committed
21 22


23
#include <klocale.h>
Halla Rempt's avatar
Halla Rempt committed
24 25

#include <kis_paint_device.h>
26
#include <widgets/kis_curve_widget.h>
Halla Rempt's avatar
Halla Rempt committed
27

28
#include <KoColor.h>
29
#include <KoColorSpaceConstants.h>
30 31

KisPressureRateOption::KisPressureRateOption()
32
    : KisCurveOption(i18n("Rate"), "Rate", KisPaintOpOption::generalCategory(), true)
33
{
34
}
35

36 37 38
void KisPressureRateOption::setRate(int rate)
{
    m_rate = rate;
39 40
}

Halla Rempt's avatar
Halla Rempt committed
41 42
int KisPressureRateOption::rate() const
{
43
    return m_rate;
Halla Rempt's avatar
Halla Rempt committed
44
}
45

Halla Rempt's avatar
Halla Rempt committed
46
void KisPressureRateOption::writeOptionSetting(KisPropertiesConfiguration* setting) const
47
{
Halla Rempt's avatar
Halla Rempt committed
48
    KisCurveOption::writeOptionSetting(setting);
49 50
    setting->setProperty("RateValue", m_rate);
    setting->setProperty("RateVersion", "2");
Halla Rempt's avatar
Halla Rempt committed
51 52 53 54
}

void KisPressureRateOption::readOptionSetting(const KisPropertiesConfiguration* setting)
{
Halla Rempt's avatar
Halla Rempt committed
55
    KisCurveOption::readOptionSetting(setting);
56 57 58
    if (setting->getString("RateVersion", "1") == "1") {
        m_rate = setting->getInt("RatePressure");
        setChecked(true);
59 60
    }
    else {
61 62
        m_rate = setting->getInt("RateValue");
    }
Halla Rempt's avatar
Halla Rempt committed
63 64
}

Halla Rempt's avatar
Halla Rempt committed
65
quint8 KisPressureRateOption::apply(quint8 opacity, const KisPaintInformation& info) const
Halla Rempt's avatar
Halla Rempt committed
66
{
67
    opacity = (m_rate * 255) / 100;
Halla Rempt's avatar
Halla Rempt committed
68 69

    if (isChecked()) {
70
        opacity = qBound((qint32)OPACITY_TRANSPARENT_U8,
71
                         (qint32)(double(opacity) * computeValue(info) / PRESSURE_DEFAULT),
72
                         (qint32)OPACITY_OPAQUE_U8);
73 74
    }

75
    return opacity;
76
}
Halla Rempt's avatar
Halla Rempt committed
77