File indexing completed on 2025-01-26 04:11:28
0001 /* 0002 * SPDX-FileCopyrightText: 2010 Lukáš Tvrdý <lukast.dev@gmail.com> 0003 * SPDX-FileCopyrightText: 2022 Dmitry Kazakov <dimula73@gmail.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 #include "KisMirrorOption.h" 0008 0009 0010 #include <kis_properties_configuration.h> 0011 #include <kis_paint_information.h> 0012 #include <KisMirrorOptionData.h> 0013 #include <KisMirrorProperties.h> 0014 0015 #include <KisPaintOpOptionUtils.h> 0016 namespace kpou = KisPaintOpOptionUtils; 0017 0018 0019 KisMirrorOption::KisMirrorOption(const KisPropertiesConfiguration *setting) 0020 : KisMirrorOption(kpou::loadOptionData<KisMirrorOptionData>(setting)) 0021 { 0022 } 0023 0024 KisMirrorOption::KisMirrorOption(const KisMirrorOptionData &data) 0025 : KisCurveOption(data) 0026 , m_enableHorizontalMirror(data.enableHorizontalMirror) 0027 , m_enableVerticalMirror(data.enableVerticalMirror) 0028 { 0029 } 0030 0031 MirrorProperties KisMirrorOption::apply(const KisPaintInformation &info) const 0032 { 0033 int mirrorXIncrement = info.canvasMirroredH(); 0034 int mirrorYIncrement = info.canvasMirroredV(); 0035 bool coordinateSystemFlipped = false; 0036 0037 if (isChecked() && (m_enableHorizontalMirror || m_enableVerticalMirror)) { 0038 0039 qreal sensorResult = computeSizeLikeValue(info); 0040 0041 bool result = (sensorResult >= 0.5); 0042 0043 mirrorXIncrement += result && m_enableHorizontalMirror; 0044 mirrorYIncrement += result && m_enableVerticalMirror; 0045 coordinateSystemFlipped = result && 0046 (m_enableHorizontalMirror != m_enableVerticalMirror); 0047 } 0048 0049 MirrorProperties mirrors; 0050 0051 mirrors.verticalMirror = mirrorYIncrement % 2; 0052 mirrors.horizontalMirror = mirrorXIncrement % 2; 0053 mirrors.coordinateSystemFlipped = coordinateSystemFlipped; 0054 0055 return mirrors; 0056 }