File indexing completed on 2024-05-26 04:32:51
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Mathias Wein <lynx.mw+kde@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #ifndef WGSHADESLIDER_H 0008 #define WGSHADESLIDER_H 0009 0010 #include "WGSelectorWidgetBase.h" 0011 0012 #include <KisVisualColorModel.h> 0013 0014 #include <QWidget> 0015 #include <QScopedPointer> 0016 #include <QVector4D> 0017 0018 class QImage; 0019 0020 class WGShadeSlider : public QWidget 0021 { 0022 Q_OBJECT 0023 public: 0024 explicit WGShadeSlider(WGSelectorDisplayConfigSP config, QWidget *parent = nullptr, KisVisualColorModelSP model = nullptr); 0025 ~WGShadeSlider() override; 0026 0027 void setGradient(const QVector4D &range, const QVector4D &offset); 0028 void setDisplayMode(bool slider, int numPatches = -1); 0029 void setModel(KisVisualColorModelSP model); 0030 QVector4D channelValues() const; 0031 const QImage* background(); 0032 0033 public Q_SLOTS: 0034 void slotSetChannelValues(const QVector4D &values); 0035 void resetHandle(); 0036 0037 protected Q_SLOTS: 0038 void slotDisplayConfigurationChanged(); 0039 0040 protected: 0041 QSize minimumSizeHint() const override; 0042 void mousePressEvent(QMouseEvent *event) override; 0043 void mouseMoveEvent(QMouseEvent *event) override; 0044 void mouseReleaseEvent(QMouseEvent *event) override; 0045 //void tabletEvent(QTabletEvent *event) override; 0046 void paintEvent(QPaintEvent*) override; 0047 void resizeEvent(QResizeEvent *) override; 0048 0049 bool adjustHandleValue(const QPointF &widgetPos); 0050 QPointF convertSliderValueToWidgetCoordinate(qreal value); 0051 qreal convertWidgetCoordinateToSliderValue(QPointF coordinate); 0052 QVector4D calculateChannelValues(qreal sliderPos) const; 0053 int getPatch(const QPointF pos) const; 0054 QRectF patchRect(int index) const; 0055 void recalculateParameters(); 0056 bool sizeRequirementsMet() const; 0057 QImage renderBackground(); 0058 /*! 0059 * \brief strokeRect 0060 * \param painter shall already be scaled so that 1 unit == 1 real Pixel 0061 * \param rect the rectangle to stroke in (logical) widget coordinates 0062 * \param pixelSize devicePixelRatioF() that was used to determine the real dimensions 0063 * \param shrinkX shrinks the rect by a multiple of the line width used to stroke 0064 */ 0065 void strokeRect(QPainter &painter, const QRectF &rect, qreal pixelSize, qreal shrinkX); 0066 0067 Q_SIGNALS: 0068 void sigChannelValuesChanged(const QVector4D &values); 0069 void sigInteraction(bool active); 0070 private: 0071 struct Private; 0072 const QScopedPointer<Private> m_d; 0073 }; 0074 0075 #endif // WGSHADESLIDER_H