File indexing completed on 2024-05-12 04:44:29
0001 // SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com> 0002 // SPDX-License-Identifier: BSD-2-Clause OR MIT 0003 0004 #ifndef CHROMAHUEDIAGRAM_P_H 0005 #define CHROMAHUEDIAGRAM_P_H 0006 0007 // Include the header of the public class of this private implementation. 0008 // #include "chromahuediagram.h" 0009 0010 #include "asyncimageprovider.h" 0011 #include "chromahueimageparameters.h" 0012 #include "colorwheelimage.h" 0013 #include "constpropagatingrawpointer.h" 0014 #include "lchdouble.h" 0015 #include "lcms2.h" 0016 #include <qglobal.h> 0017 #include <qpoint.h> 0018 #include <qsharedpointer.h> 0019 0020 namespace PerceptualColor 0021 { 0022 class ChromaHueDiagram; 0023 class RgbColorSpace; 0024 0025 /** @internal 0026 * 0027 * @brief Private implementation within the <em>Pointer to 0028 * implementation</em> idiom 0029 * 0030 * @anchor ChromaHueMeasurement <b>Measurement details:</b> The general 0031 * @ref measurementdetails "notes about measurement" apply also to this widget. 0032 * Furthermore, in this widget, when painting a pixel of the gamut, the color 0033 * of the pixel will be the color of the coordinate point at the center of the 0034 * pixel. So the pixel at position <tt>QPoint(x, y)</tt> gets the color that 0035 * corresponds to the coordinate point <tt>QPoint(x+0.5, y+0.5)</tt>. 0036 * Also, mouse events work with pixel position; so when reacting on mouse 0037 * events than it’s the center of the given mouse event pixel position that is 0038 * considered when processing the mouse event. */ 0039 class ChromaHueDiagramPrivate final 0040 { 0041 public: 0042 ChromaHueDiagramPrivate(ChromaHueDiagram *backLink, const QSharedPointer<PerceptualColor::RgbColorSpace> &colorSpace); 0043 /** @brief Default destructor 0044 * 0045 * The destructor is non-<tt>virtual</tt> because 0046 * the class as a whole is <tt>final</tt>. */ 0047 ~ChromaHueDiagramPrivate() noexcept = default; 0048 0049 // Member variables 0050 /** @brief The image of the chroma-hue diagram itself. */ 0051 AsyncImageProvider<ChromaHueImageParameters> m_chromaHueImage; 0052 /** @brief Properties for @ref m_chromaHueImage. */ 0053 ChromaHueImageParameters m_chromaHueImageParameters; 0054 /** @brief Internal storage of the @ref ChromaHueDiagram::currentColor() 0055 * property */ 0056 LchDouble m_currentColor; 0057 /** @brief Holds if currently a mouse event is active or not. 0058 * 0059 * Default value is <tt>false</tt>. 0060 * - A mouse event gets typically activated on 0061 * a @ref ChromaHueDiagram::mousePressEvent() 0062 * done within the gamut diagram. The value is set to <tt>true</tt>. 0063 * - While active, all @ref ChromaHueDiagram::mouseMoveEvent() will 0064 * move the diagram’s color handle. 0065 * - Once a @ref ChromaHueDiagram::mouseReleaseEvent() occurs, the value 0066 * is set to <tt>false</tt>. Further mouse movements will not move the 0067 * handle anymore. 0068 * 0069 * This is done because Qt’s default mouse tracking reacts on all clicks 0070 * within the whole widget. However, <em>this</em> widget is meant as a 0071 * circular widget, only reacting on mouse events within the circle; 0072 * this requires this custom implementation. */ 0073 bool m_isMouseEventActive = false; 0074 /** @brief Pointer to @ref RgbColorSpace object used to describe the 0075 * color space. */ 0076 QSharedPointer<PerceptualColor::RgbColorSpace> m_rgbColorSpace; 0077 /** @brief The image of the color wheel. */ 0078 ColorWheelImage m_wheelImage; 0079 0080 // Member functions 0081 [[nodiscard]] int diagramBorder() const; 0082 [[nodiscard]] QPointF diagramCenter() const; 0083 [[nodiscard]] qreal diagramOffset() const; 0084 [[nodiscard]] cmsCIELab fromWidgetPixelPositionToLab(const QPoint position) const; 0085 [[nodiscard]] bool isWidgetPixelPositionWithinMouseSensibleCircle(const QPoint widgetCoordinates) const; 0086 void setColorFromWidgetPixelPosition(const QPoint position); 0087 [[nodiscard]] QPointF widgetCoordinatesFromCurrentColor() const; 0088 0089 private: 0090 Q_DISABLE_COPY(ChromaHueDiagramPrivate) 0091 0092 /** @brief Pointer to the object from which <em>this</em> object 0093 * is the private implementation. */ 0094 ConstPropagatingRawPointer<ChromaHueDiagram> q_pointer; 0095 }; 0096 0097 } // namespace PerceptualColor 0098 0099 #endif // CHROMAHUEDIAGRAM_P_H