1 /* This file is part of the KDE project
2 * Copyright (c) 2009 Cyrille Berger <cberger@cberger.net>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19 #include "kis_pressure_rotation_option.h"
20 #include "kis_pressure_opacity_option.h"
21 #include "sensors/kis_dynamic_sensor_drawing_angle.h"
22 #include "sensors/kis_dynamic_sensor_fuzzy.h"
23 #include <klocalizedstring.h>
24 #include <kis_painter.h>
25 #include <brushengine/kis_paintop.h>
26 #include <KoColor.h>
27
KisPressureRotationOption()28 KisPressureRotationOption::KisPressureRotationOption()
29 : KisCurveOption("Rotation", KisPaintOpOption::GENERAL, false)
30 {
31 }
32
apply(const KisPaintInformation & info) const33 double KisPressureRotationOption::apply(const KisPaintInformation & info) const
34 {
35 if (!isChecked()) return kisDegreesToRadians(info.canvasRotation());
36
37 const bool absoluteAxesFlipped = info.canvasMirroredH() != info.canvasMirroredV();
38
39 const qreal normalizedBaseAngle = -info.canvasRotation() / 360.0;
40
41 qreal value = computeRotationLikeValue(info, normalizedBaseAngle, absoluteAxesFlipped);
42
43 // flip to conform global legacy code
44 value = 1.0 - value;
45
46 return normalizeAngle(value * M_PI);
47 }
48
readOptionSetting(const KisPropertiesConfigurationSP setting)49 void KisPressureRotationOption::readOptionSetting(const KisPropertiesConfigurationSP setting)
50 {
51 KisCurveOption::readOptionSetting(setting);
52 }
53
applyFanCornersInfo(KisPaintOp * op)54 void KisPressureRotationOption::applyFanCornersInfo(KisPaintOp *op)
55 {
56 KisDynamicSensorDrawingAngle *sensor = dynamic_cast<KisDynamicSensorDrawingAngle*>(this->sensor(ANGLE, true).data());
57
58 /**
59 * A special case for the Drawing Angle sensor, because it
60 * changes the behavior of KisPaintOp::paintLine()
61 */
62 if (sensor) {
63 op->setFanCornersInfo(sensor->fanCornersEnabled(), qreal(sensor->fanCornersStep()) * M_PI / 180.0);
64 }
65 }
66
intMinValue() const67 int KisPressureRotationOption::intMinValue() const
68 {
69 return -180;
70 }
71
intMaxValue() const72 int KisPressureRotationOption::intMaxValue() const
73 {
74 return 180;
75 }
76
valueSuffix() const77 QString KisPressureRotationOption::valueSuffix() const
78 {
79 return i18n("°");
80 }
81