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

0001 /*
0002     SPDX-FileCopyrightText: 2013-2014 Meltytech LLC
0003     SPDX-FileCopyrightText: 2013-2014 Dan Dennedy <dan@dennedy.org>
0004     SPDX-FileCopyrightText: 2013-2014 Brian Matherly <pez4brian@yahoo.com>
0005     SPDX-FileCopyrightText: Jean-Baptiste Mardelle <jb@kdenlive.org> small adaptations for Kdenlive
0006 
0007     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0008 */
0009 
0010 #pragma once
0011 
0012 #include "utils/qcolorutils.h"
0013 
0014 #include <QImage>
0015 #include <QQuickPaintedItem>
0016 
0017 class ColorWheelItem : public QQuickPaintedItem
0018 {
0019     Q_OBJECT
0020     Q_PROPERTY(QColor color READ color NOTIFY colorChanged)
0021     Q_PROPERTY(double red READ red)
0022     Q_PROPERTY(double green READ green)
0023     Q_PROPERTY(double blue READ blue)
0024 public:
0025     explicit ColorWheelItem(QQuickItem *parent = 0);
0026     QColor color();
0027     void setColor(const NegQColor &color);
0028     Q_INVOKABLE void setColor(double r, double g, double b);
0029     double red();
0030     double green();
0031     double blue();
0032     Q_INVOKABLE void setFactorDefaultZero(qreal factor, qreal defvalue, qreal zero);
0033 
0034 Q_SIGNALS:
0035     void colorChanged();
0036 
0037 protected:
0038     void mousePressEvent(QMouseEvent *event);
0039     void mouseMoveEvent(QMouseEvent *event);
0040     void mouseReleaseEvent(QMouseEvent *event);
0041     void hoverMoveEvent(QHoverEvent *event);
0042     void paint(QPainter *painter);
0043 
0044 private:
0045     QImage m_image;
0046     QPoint m_lastPoint;
0047     QSize m_size;
0048     int m_margin;
0049     QRegion m_wheelRegion;
0050     QRegion m_sliderRegion;
0051     NegQColor m_color;
0052     bool m_isInWheel;
0053     bool m_isInSquare;
0054     qreal m_sizeFactor;
0055     qreal m_defaultValue;
0056     qreal m_zeroShift;
0057 
0058     int wheelSize() const;
0059     NegQColor colorForPoint(const QPoint &point);
0060     void drawWheel();
0061     void drawWheelDot(QPainter &painter);
0062     void drawSliderBar(QPainter &painter);
0063     void drawSlider();
0064     void updateCursor(const QPoint &pos);
0065 };