File indexing completed on 2025-01-26 04:11:26

0001 /*
0002  * SPDX-FileCopyrightText: 2022 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "KisCurveOptionInputControlsStrategy.h"
0008 
0009 #include <QHBoxLayout>
0010 #include <QFont>
0011 
0012 #include <QSpinBox>
0013 #include <QDoubleSpinBox>
0014 
0015 #include <kis_algebra_2d.h>
0016 #include <KisMpl.h>
0017 
0018 #include <kis_curve_widget.h>
0019 #include <KisCurveWidgetControlsManager.h>
0020 #include <KisCurveRangeModelInterface.h>
0021 
0022 
0023 
0024 template<typename SpinBox>
0025 KisCurveOptionInputControlsStrategy<SpinBox>::
0026 KisCurveOptionInputControlsStrategy(KisCurveRangeModelInterface *rangeInterface,
0027                                     KisCurveWidget *curveWidget,
0028                                     QWidget *inPlaceholder, QWidget *outPlaceholder)
0029 {
0030     this->curveWidget = curveWidget;
0031 
0032     inSpinBox = new SpinBox(inPlaceholder);
0033     outSpinBox = new SpinBox(outPlaceholder);
0034 
0035     QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
0036     sizePolicy.setHorizontalStretch(0);
0037     sizePolicy.setVerticalStretch(0);
0038     sizePolicy.setHeightForWidth(inSpinBox->sizePolicy().hasHeightForWidth());
0039     inSpinBox->setSizePolicy(sizePolicy);
0040     outSpinBox->setSizePolicy(sizePolicy);
0041 
0042     inSpinBox->setMinimumSize(QSize(0, 0));
0043     outSpinBox->setMinimumSize(QSize(0, 0));
0044 
0045     QFont font;
0046     font.setPointSize(9);
0047     inSpinBox->setFont(font);
0048     outSpinBox->setFont(font);
0049 
0050     QHBoxLayout *inLayout = new QHBoxLayout(inPlaceholder);
0051     inLayout->addWidget(inSpinBox);
0052     inLayout->setMargin(0);
0053 
0054     QHBoxLayout *outLayout = new QHBoxLayout(outPlaceholder);
0055     outLayout->addWidget(outSpinBox);
0056     outLayout->setMargin(0);
0057 
0058     xValueSuffix = rangeInterface->xValueSuffix();
0059     yValueSuffix = rangeInterface->yValueSuffix();
0060     rangeValues = lager::with(rangeInterface->xMinValue(), rangeInterface->xMaxValue(),
0061                               rangeInterface->yMinValue(), rangeInterface->yMaxValue());
0062 
0063     xValueSuffix.bind(std::bind(&SpinBox::setSuffix, inSpinBox, std::placeholders::_1));
0064     yValueSuffix.bind(std::bind(&SpinBox::setSuffix, outSpinBox, std::placeholders::_1));
0065     rangeValues.bind(
0066                 kismpl::unzip_wrapper(std::bind(&KisCurveOptionInputControlsStrategy::updateCurveLabels, this,
0067                                                 std::placeholders::_1, std::placeholders::_2,
0068                                                 std::placeholders::_3, std::placeholders::_4)));
0069 
0070 }
0071 
0072 template<typename SpinBox>
0073 KisCurveOptionInputControlsStrategy<SpinBox>::~KisCurveOptionInputControlsStrategy()
0074 {
0075 }
0076 
0077 template<typename SpinBox>
0078 KisCurveOptionInputControlsStrategyFactory KisCurveOptionInputControlsStrategy<SpinBox>::factory()
0079 {
0080     return
0081         [] (KisCurveRangeModelInterface *rangeInterface,
0082             KisCurveWidget *curveWidget,
0083             QWidget *inPlaceholder, QWidget *outPlaceholder) {
0084             return new KisCurveOptionInputControlsStrategy<SpinBox>(rangeInterface,
0085                                                                     curveWidget,
0086                                                                     inPlaceholder,
0087                                                                     outPlaceholder);
0088 
0089         };
0090 }
0091 
0092 template<typename SpinBox>
0093 void KisCurveOptionInputControlsStrategy<SpinBox>::updateCurveLabels(qreal xMin, qreal xMax, qreal yMin, qreal yMax)
0094 {
0095     using ValueType = typename KisCurveWidgetControlsManager<SpinBox>::ValueType;
0096 
0097     curveControlsManager.reset(
0098                 new KisCurveWidgetControlsManager<SpinBox>(
0099                     curveWidget,
0100                     inSpinBox, outSpinBox,
0101                     KisAlgebra2D::lazyRound<ValueType>(xMin),
0102                     KisAlgebra2D::lazyRound<ValueType>(xMax),
0103                     KisAlgebra2D::lazyRound<ValueType>(yMin),
0104                     KisAlgebra2D::lazyRound<ValueType>(yMax)));
0105 }
0106 
0107 template class PAINTOP_EXPORT_INSTANCE KisCurveOptionInputControlsStrategy<QSpinBox>;
0108 template class PAINTOP_EXPORT_INSTANCE KisCurveOptionInputControlsStrategy<QDoubleSpinBox>;