File indexing completed on 2024-05-12 04:52:52
0001 /* 0002 SPDX-FileCopyrightText: 2013 Meltytech LLC 0003 SPDX-FileCopyrightText: 2013 Dan Dennedy <dan@dennedy.org> 0004 0005 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #pragma once 0009 0010 #include "utils/qcolorutils.h" 0011 0012 #include <QPainter> 0013 #include <QResizeEvent> 0014 #include <QWidget> 0015 0016 class QDoubleSpinBox; 0017 class QLabel; 0018 0019 class WheelContainer : public QWidget 0020 { 0021 Q_OBJECT 0022 public: 0023 explicit WheelContainer(QString id, QString name, NegQColor color, int unitSize, QWidget *parent = nullptr); 0024 QSize sizeHint() const override; 0025 QSize minimumSizeHint() const override; 0026 NegQColor color() const; 0027 void setColor(const QList <double> &values); 0028 void setFactorDefaultZero(qreal factor, qreal defvalue, qreal zero); 0029 const QList <double> getNiceParamValues() const; 0030 void setRedColor(double value); 0031 void setGreenColor(double value); 0032 void setBlueColor(double value); 0033 0034 public Q_SLOTS: 0035 void changeColor(const NegQColor &sourceColor, const NegQColor &color, bool createUndo); 0036 0037 Q_SIGNALS: 0038 void colorChange(const NegQColor &sourceColor, const NegQColor &color, bool createUndo); 0039 0040 protected: 0041 void mousePressEvent(QMouseEvent *event) override; 0042 void mouseMoveEvent(QMouseEvent *event) override; 0043 void mouseReleaseEvent(QMouseEvent *event) override; 0044 void focusOutEvent(QFocusEvent *event) override; 0045 void wheelEvent(QWheelEvent *event) override; 0046 void resizeEvent(QResizeEvent *event) override; 0047 void paintEvent(QPaintEvent *event) override; 0048 0049 private: 0050 QString m_id; 0051 QSize m_initialSize; 0052 QImage m_image; 0053 bool m_isMouseDown; 0054 QPointF m_lastPoint; 0055 int m_margin; 0056 int m_sliderWidth; 0057 int m_sliderBorder; 0058 QRegion m_wheelRegion; 0059 QRegion m_sliderRegion; 0060 NegQColor m_color; 0061 NegQColor m_defaultColor; 0062 NegQColor m_sourceColor; 0063 int m_unitSize; 0064 QString m_name; 0065 bool m_wheelClick; 0066 bool m_sliderClick; 0067 bool m_sliderFocus; 0068 0069 qreal m_sizeFactor = 1; 0070 qreal m_defaultValue = 1; 0071 qreal m_zeroShift = 0; 0072 0073 int wheelSize() const; 0074 int sliderHeight() const; 0075 NegQColor colorForPoint(const QPointF &point); 0076 QPointF pointForColor(); 0077 double yForColor(); 0078 void drawWheel(); 0079 void drawWheelDot(QPainter &painter); 0080 void drawSliderBar(QPainter &painter); 0081 void drawSlider(); 0082 const QString getParamValues() const; 0083 }; 0084 0085 class ColorWheel : public QWidget 0086 { 0087 Q_OBJECT 0088 public: 0089 explicit ColorWheel(const QString &id, const QString &name, const NegQColor &color, QWidget *parent = nullptr); 0090 NegQColor color() const; 0091 void setColor(const QList <double> &values); 0092 void setFactorDefaultZero(qreal factor, qreal defvalue, qreal zero); 0093 0094 private: 0095 WheelContainer *m_container; 0096 QLabel *m_wheelName; 0097 QDoubleSpinBox *m_redEdit; 0098 QDoubleSpinBox *m_greenEdit; 0099 QDoubleSpinBox *m_blueEdit; 0100 0101 Q_SIGNALS: 0102 void colorChange(const NegQColor &sourceColor, const NegQColor &color, bool createUndo); 0103 };