File indexing completed on 2025-01-26 04:11:27
0001 /* 0002 * SPDX-FileCopyrightText: 2022 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #include "KisDynamicSensorFactoryDrawingAngle.h" 0007 0008 #include <QCheckBox> 0009 #include <QLabel> 0010 #include <QHBoxLayout> 0011 #include <kis_slider_spin_box.h> 0012 0013 #include "KisDrawingAngleSensorModel.h" 0014 #include "KisWidgetConnectionUtils.h" 0015 #include "KisKritaSensorPack.h" 0016 0017 namespace { 0018 auto safeDereferenceDrawingAngleSensor = lager::lenses::getset( 0019 [](const KisCurveOptionDataCommon &data) -> KisDrawingAngleSensorData { 0020 const KisKritaSensorPack *pack = dynamic_cast<const KisKritaSensorPack*>(data.sensorData.constData()); 0021 if (pack) { 0022 return pack->constSensorsStruct().sensorDrawingAngle; 0023 } else { 0024 qWarning() << "safeDereferenceDrawingAngleSensor(get): failed to get a Krita sensor data"; 0025 return KisDrawingAngleSensorData(); 0026 } 0027 }, 0028 [](KisCurveOptionDataCommon data, KisDrawingAngleSensorData sensor) -> KisCurveOptionDataCommon { 0029 KisKritaSensorPack *pack = dynamic_cast<KisKritaSensorPack*>(data.sensorData.data()); 0030 if (pack) { 0031 pack->sensorsStruct().sensorDrawingAngle = sensor; 0032 } else { 0033 qWarning() << "safeDereferenceDrawingAngleSensor(set): failed to get a Krita sensor data"; 0034 } 0035 return data; 0036 }); 0037 } 0038 0039 KisDynamicSensorFactoryDrawingAngle::KisDynamicSensorFactoryDrawingAngle() 0040 : KisSimpleDynamicSensorFactory(DrawingAngleId.id(), 0, 360, i18n("0°"), i18n("360°"), i18n("°")) 0041 { 0042 0043 } 0044 0045 QWidget *KisDynamicSensorFactoryDrawingAngle::createConfigWidget(lager::cursor<KisCurveOptionDataCommon> data, QWidget *parent) 0046 { 0047 QWidget *widget = new QWidget(parent); 0048 0049 KisDrawingAngleSensorModel *model = 0050 new KisDrawingAngleSensorModel(data.zoom(safeDereferenceDrawingAngleSensor), widget); 0051 0052 using namespace KisWidgetConnectionUtils; 0053 0054 QCheckBox *chkLockedMode = new QCheckBox(i18nc("Lock Drawing angle at start of each stroke", "Lock"), widget); 0055 connectControl(chkLockedMode, model, "lockedAngleMode"); 0056 0057 QCheckBox *chkFanCorners = new QCheckBox(i18nc("Smoothing Drawing angle when a stroke is making a sharp turn", "Fan Corners"), widget); 0058 connectControl(chkFanCorners, model, "fanCornersEnabled"); 0059 0060 KisSliderSpinBox *intFanCornersStep = new KisSliderSpinBox(widget); 0061 intFanCornersStep->setRange(5, 90); 0062 intFanCornersStep->setSingleStep(1); 0063 intFanCornersStep->setSuffix(i18n("°")); 0064 connectControl(intFanCornersStep, model, "fanCornersStep"); 0065 0066 KisSliderSpinBox *angleOffset = new KisSliderSpinBox(widget); 0067 angleOffset->setRange(0, 359); 0068 angleOffset->setSingleStep(1); 0069 angleOffset->setSuffix(i18n("°")); 0070 connectControl(angleOffset, model, "angleOffset"); 0071 0072 QVBoxLayout *layout = new QVBoxLayout(widget); 0073 layout->addWidget(chkLockedMode); 0074 layout->addWidget(chkFanCorners); 0075 layout->addWidget(intFanCornersStep); 0076 layout->addWidget(new QLabel(i18n("Angle Offset"))); 0077 layout->addWidget(angleOffset); 0078 0079 return widget; 0080 } 0081