File indexing completed on 2025-01-26 04:11:29
0001 /* 0002 * SPDX-FileCopyrightText: 2009 Cyrille Berger <cberger@cberger.net> 0003 * SPDX-FileCopyrightText: 2022 Dmitry Kazakov <dimula73@gmail.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 #include "KisRotationOption.h" 0008 0009 #include <kis_properties_configuration.h> 0010 #include <kis_paint_information.h> 0011 #include <KisStandardOptionData.h> 0012 #include <kis_paintop.h> 0013 0014 #include <KisPaintOpOptionUtils.h> 0015 namespace kpou = KisPaintOpOptionUtils; 0016 0017 0018 KisRotationOption::KisRotationOption(const KisPropertiesConfiguration *setting) 0019 : KisRotationOption(kpou::loadOptionData<KisRotationOptionData>(setting)) 0020 { 0021 } 0022 0023 KisRotationOption::KisRotationOption(const KisRotationOptionData &data) 0024 : KisCurveOption(data) 0025 { 0026 if (data.sensorStruct().sensorDrawingAngle.isActive) { 0027 m_fanCornersEnabled = 0028 data.sensorStruct().sensorDrawingAngle.fanCornersEnabled && 0029 !data.sensorStruct().sensorDrawingAngle.lockedAngleMode; 0030 m_fanCornersStep = qreal(data.sensorStruct().sensorDrawingAngle.fanCornersStep); 0031 } 0032 } 0033 0034 qreal KisRotationOption::apply(const KisPaintInformation & info) const 0035 { 0036 if (!isChecked()) return kisDegreesToRadians(info.canvasRotation()); 0037 0038 const bool absoluteAxesFlipped = info.canvasMirroredH() != info.canvasMirroredV(); 0039 0040 const qreal normalizedBaseAngle = -info.canvasRotation() / 360.0; 0041 0042 // we should invert scaling part because it is expected 0043 // to rotate the brush counterclockwise 0044 const qreal scalingPartCoeff = -1.0; 0045 0046 qreal value = computeRotationLikeValue(info, normalizedBaseAngle, absoluteAxesFlipped, scalingPartCoeff, info.isHoveringMode()); 0047 0048 /// flip to conform global legacy code 0049 /// we measure rotation in the opposite direction relative Qt's way 0050 value = 1.0 - value; 0051 0052 return normalizeAngle(value * M_PI); 0053 } 0054 0055 void KisRotationOption::applyFanCornersInfo(KisPaintOp *op) 0056 { 0057 if (!this->isChecked()) return; 0058 0059 /** 0060 * A special case for the Drawing Angle sensor, because it 0061 * changes the behavior of KisPaintOp::paintLine() 0062 */ 0063 op->setFanCornersInfo(m_fanCornersEnabled, m_fanCornersStep * M_PI / 180.0); 0064 }