File indexing completed on 2024-05-19 04:45:54

0001 // SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
0002 // SPDX-License-Identifier: BSD-2-Clause OR MIT
0003 
0004 #ifndef WHEELCOLORPICKER_H
0005 #define WHEELCOLORPICKER_H
0006 
0007 #include "abstractdiagram.h"
0008 #include "constpropagatinguniquepointer.h"
0009 #include "importexport.h"
0010 #include "lchdouble.h"
0011 #include <qglobal.h>
0012 #include <qsharedpointer.h>
0013 #include <qsize.h>
0014 class QResizeEvent;
0015 class QWidget;
0016 
0017 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
0018 #include <qtmetamacros.h>
0019 #else
0020 #include <qobjectdefs.h>
0021 #include <qstring.h>
0022 class QObject;
0023 #endif
0024 
0025 namespace PerceptualColor
0026 {
0027 class RgbColorSpace;
0028 
0029 class WheelColorPickerPrivate;
0030 
0031 /** @brief Complete wheel-based color picker widget
0032  *
0033  * It is composed of a @ref ColorWheel and, in the middle of the wheel,
0034  * a chroma-lightness diagram.
0035  *
0036  * @image html WheelColorPicker.png "WheelColorPicker" width=200
0037  *
0038  * @internal
0039  *
0040  * @todo BUG: When the hue changes and the gamut gets smaller than the
0041  * current chroma-lightness value, then the marker is not moved into the
0042  * new gamut. But it should!
0043  *
0044  * @todo This class is a friend class of @ref ChromaLightnessDiagram
0045  * and of @ref ColorWheel. Would it be possible to not rely on this
0046  * friendship in the code of this class (or at least, to rely less
0047  * on it)?
0048  *
0049  * @todo Is the (double) focus indicator actually good design? Are there
0050  * better solutions?
0051  *
0052  * @todo Add <tt>QToolTip</tt> value explaining the accepted keys and mouse
0053  * movements (and also to other widgets). */
0054 class PERCEPTUALCOLOR_IMPORTEXPORT WheelColorPicker : public AbstractDiagram
0055 {
0056     Q_OBJECT
0057 
0058     /** @brief Currently selected color
0059      *
0060      * @sa READ @ref currentColor() const
0061      * @sa WRITE @ref setCurrentColor()
0062      * @sa NOTIFY @ref currentColorChanged() */
0063     Q_PROPERTY(PerceptualColor::LchDouble currentColor READ currentColor WRITE setCurrentColor NOTIFY currentColorChanged USER true)
0064 
0065 public:
0066     Q_INVOKABLE explicit WheelColorPicker(const QSharedPointer<PerceptualColor::RgbColorSpace> &colorSpace, QWidget *parent = nullptr);
0067     virtual ~WheelColorPicker() noexcept override;
0068     /** @brief Getter for property @ref currentColor
0069      *  @returns the property @ref currentColor */
0070     [[nodiscard]] PerceptualColor::LchDouble currentColor() const;
0071     [[nodiscard]] virtual QSize minimumSizeHint() const override;
0072     void setCurrentColor(const PerceptualColor::LchDouble &newCurrentColor);
0073     [[nodiscard]] virtual QSize sizeHint() const override;
0074 
0075 Q_SIGNALS:
0076     /** @brief Notify signal for property @ref currentColor.
0077      *  @param newCurrentColor the new current color */
0078     void currentColorChanged(const PerceptualColor::LchDouble &newCurrentColor);
0079 
0080 protected:
0081     virtual void resizeEvent(QResizeEvent *event) override;
0082 
0083 private:
0084     Q_DISABLE_COPY(WheelColorPicker)
0085 
0086     /** @internal
0087      *
0088      * @brief Declare the private implementation as friend class.
0089      *
0090      * This allows the private class to access the protected members and
0091      * functions of instances of <em>this</em> class. */
0092     friend class WheelColorPickerPrivate;
0093     /** @brief Pointer to implementation (pimpl) */
0094     ConstPropagatingUniquePointer<WheelColorPickerPrivate> d_pointer;
0095 
0096     /** @internal @brief Only for unit tests. */
0097     friend class TestWheelColorPicker;
0098 };
0099 
0100 } // namespace PerceptualColor
0101 
0102 #endif // WHEELCOLORPICKER_H