File indexing completed on 2025-03-09 04:28:22
0001 /* 0002 SPDX-FileCopyrightText: 2016 Nicolas Carion 0003 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 #pragma once 0007 0008 #include "../abstractparamwidget.hpp" 0009 #include "bezier/beziersplineeditor.h" 0010 #include "cubic/kis_curve_widget.h" 0011 #include "ui_bezierspline_ui.h" 0012 #include "widgets/dragvalue.h" 0013 0014 template <typename CurveWidget_t> class ValueLabel; 0015 0016 /** @brief Class representing a curve and some additional controls 0017 */ 0018 template <typename CurveWidget_t> class CurveParamWidget : public AbstractParamWidget 0019 { 0020 public: 0021 ~CurveParamWidget() override = default; 0022 CurveParamWidget(std::shared_ptr<AssetParameterModel> model, QModelIndex index, QWidget *parent); 0023 0024 enum class CurveModes { Red = 0, Green = 1, Blue = 2, Luma = 3, Alpha = 4, RGB = 5, Hue = 6, Saturation = 7 }; 0025 /** @brief sets the mode of the curve. This affects the background that is displayed. 0026 * The list of available modes depends on the CurveWidget that we have 0027 */ 0028 void setMode(CurveModes mode); 0029 0030 /** @brief Stringify the content of the curve 0031 */ 0032 QString toString() const; 0033 0034 using Point_t = typename CurveWidget_t::Point_t; 0035 /** @brief returns the list of points on the curve 0036 */ 0037 QList<Point_t> getPoints() { return m_edit->getPoints(); } 0038 0039 /** @brief Set the maximal number of points on the curve. This function is only available for KisCurveWidget. 0040 */ 0041 void setMaxPoints(int max); 0042 0043 /** @brief Helper function to convert a mode to the corresponding ColorsRGB value. 0044 This avoids using potentially non consistent intermediate cast to int 0045 */ 0046 static ColorTools::ColorsRGB modeToColorsRGB(CurveModes mode); 0047 0048 protected: 0049 void deleteIrrelevantItems(); 0050 void setupLayoutPoint(); 0051 void setupLayoutHandles(); 0052 void slotGridChange(); 0053 void slotShowPixmap(bool show); 0054 void slotUpdatePointEntries(const BPoint &p, bool extremal); 0055 void slotUpdatePointEntries(const QPointF &p, bool extremal); 0056 void slotUpdatePointP(double /*value*/, bool final); 0057 void slotUpdatePointH1(double /*value*/, bool final); 0058 void slotUpdatePointH2(double /*value*/, bool final); 0059 void slotSetHandlesLinked(bool linked); 0060 void slotShowAllHandles(bool show); 0061 void resizeEvent(QResizeEvent *event) override; 0062 0063 public Q_SLOTS: 0064 /** @brief Toggle the comments on or off 0065 */ 0066 void slotShowComment(bool show) override; 0067 0068 /** @brief refresh the properties to reflect changes in the model 0069 */ 0070 void slotRefresh() override; 0071 0072 private: 0073 Ui::BezierSpline_UI m_ui; 0074 DragValue *m_pX; 0075 DragValue *m_pY; 0076 DragValue *m_h1X; 0077 DragValue *m_h1Y; 0078 DragValue *m_h2X; 0079 DragValue *m_h2Y; 0080 CurveWidget_t *m_edit; 0081 CurveModes m_mode; 0082 bool m_showPixmap; 0083 0084 ValueLabel<CurveWidget_t> *m_leftParam, *m_bottomParam; 0085 }; 0086 0087 #include "curveparamwidget.ipp"