1 /*
2  *  Copyright (c) 2010 Lukáš Tvrdý <lukast.dev@gmail.com>
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 
20 #include "kis_pressure_mirror_option.h"
21 
22 #include <klocalizedstring.h>
23 
24 #include <kis_paint_device.h>
25 #include <widgets/kis_curve_widget.h>
26 
27 #include <KoColor.h>
28 
KisPressureMirrorOption()29 KisPressureMirrorOption::KisPressureMirrorOption()
30     : KisCurveOption("Mirror", KisPaintOpOption::GENERAL, false)
31 {
32     m_enableHorizontalMirror = false;
33     m_enableVerticalMirror = false;
34 }
35 
enableHorizontalMirror(bool mirror)36 void KisPressureMirrorOption::enableHorizontalMirror(bool mirror)
37 {
38     m_enableHorizontalMirror = mirror;
39 }
40 
enableVerticalMirror(bool mirror)41 void KisPressureMirrorOption::enableVerticalMirror(bool mirror)
42 {
43     m_enableVerticalMirror = mirror;
44 }
45 
isHorizontalMirrorEnabled()46 bool KisPressureMirrorOption::isHorizontalMirrorEnabled()
47 {
48     return m_enableHorizontalMirror;
49 }
50 
isVerticalMirrorEnabled()51 bool KisPressureMirrorOption::isVerticalMirrorEnabled()
52 {
53     return m_enableVerticalMirror;
54 }
55 
writeOptionSetting(KisPropertiesConfigurationSP setting) const56 void KisPressureMirrorOption::writeOptionSetting(KisPropertiesConfigurationSP setting) const
57 {
58     KisCurveOption::writeOptionSetting(setting);
59     setting->setProperty(MIRROR_HORIZONTAL_ENABLED, m_enableHorizontalMirror);
60     setting->setProperty(MIRROR_VERTICAL_ENABLED, m_enableVerticalMirror);
61 }
62 
readOptionSetting(const KisPropertiesConfigurationSP setting)63 void KisPressureMirrorOption::readOptionSetting(const KisPropertiesConfigurationSP setting)
64 {
65     KisCurveOption::readOptionSetting(setting);
66     m_enableHorizontalMirror = setting->getBool(MIRROR_HORIZONTAL_ENABLED, false);
67     m_enableVerticalMirror = setting->getBool(MIRROR_VERTICAL_ENABLED, false);
68 }
69 
apply(const KisPaintInformation & info) const70 MirrorProperties KisPressureMirrorOption::apply(const KisPaintInformation& info) const
71 {
72     int mirrorXIncrement = info.canvasMirroredH();
73     int mirrorYIncrement = info.canvasMirroredV();
74     bool coordinateSystemFlipped = false;
75 
76     if (isChecked() && (m_enableHorizontalMirror || m_enableVerticalMirror)) {
77 
78         qreal sensorResult = computeSizeLikeValue(info);
79 
80         bool result = (sensorResult >= 0.5);
81 
82         mirrorXIncrement += result && m_enableHorizontalMirror;
83         mirrorYIncrement += result && m_enableVerticalMirror;
84         coordinateSystemFlipped = result &&
85                                   (m_enableHorizontalMirror != m_enableVerticalMirror);
86     }
87 
88     MirrorProperties mirrors;
89 
90     mirrors.verticalMirror = mirrorYIncrement % 2;
91     mirrors.horizontalMirror = mirrorXIncrement % 2;
92     mirrors.coordinateSystemFlipped = coordinateSystemFlipped;
93 
94     return mirrors;
95 }
96 
97 
98 
99