Perceptual Color

chromalightnessdiagram.h
1// SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR MIT
3
4#ifndef CHROMALIGHTNESSDIAGRAM_H
5#define CHROMALIGHTNESSDIAGRAM_H
6
7#include "abstractdiagram.h"
8#include "constpropagatinguniquepointer.h"
9#include "lchdouble.h"
10#include <qglobal.h>
11#include <qsharedpointer.h>
12#include <qsize.h>
13
14#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
15#include <qtmetamacros.h>
16#else
17#include <qobjectdefs.h>
18#include <qstring.h>
19class QObject;
20#endif
21
22class QKeyEvent;
23class QMouseEvent;
24class QPaintEvent;
25class QResizeEvent;
26class QWidget;
27
28namespace PerceptualColor
29{
30class ChromaLightnessDiagramPrivate;
31
32class RgbColorSpace;
33
34/** @internal
35 *
36 * @brief A widget that displays a chroma-lightness diagram.
37 *
38 * This widget displays a chroma-lightness diagram for a given hue.
39 *
40 * @image html ChromaLightnessDiagram.png "ChromaLightnessDiagram" width=250
41 *
42 * The widget shows the chroma-lightness diagram at the whole widget extend.
43 * - Vertically the lightness from 0 (bottom) to 100 (top).
44 * - Horizontally the chroma from 0 (left) to a higher value (right). The same
45 * scale is used like for the vertical axis: So if the widget size is a
46 * square, both chroma and lightness range from 0 to 100. If the widget
47 * width is twice the height, the lightness ranges from 0 to 100
48 * and the chroma ranges from 0 to 200.
49 *
50 * @internal
51 *
52 * @note This class is not part of the public API because its interface
53 * is not polished enough. Notably it does not automatically scale the
54 * diagram to fit a given gamut (means: to fit up to a given maximum
55 * chroma). Even if we would fix this: We would need a public API
56 * that is widthForHeight-dependent to allow the library user to
57 * comfortably make use of this!
58 *
59 * @todo What to do if a gamut allows lightness < 0 or lightness > 100 ???
60 * What if a part of the gamut at the right is not displayed? (Thought
61 * this means that @ref RgbColorSpace has a bug.) Shouldn’t this be
62 * controlled?) Maybe it would be better to control this
63 * within @ref RgbColorSpace … */
64class ChromaLightnessDiagram : public AbstractDiagram
65{
67
68 /** @brief Currently selected color
69 *
70 * The widget allows the user to change the LCH chroma and the
71 * LCH lightness values. However, the LCH hue value cannot be
72 * changed by the user, but only by the programmer through this property.
73 *
74 * @sa READ @ref currentColor() const
75 * @sa WRITE @ref setCurrentColor()
76 * @sa NOTIFY @ref currentColorChanged() */
77 Q_PROPERTY(PerceptualColor::LchDouble currentColor READ currentColor WRITE setCurrentColor NOTIFY currentColorChanged)
78
79public:
80 Q_INVOKABLE explicit ChromaLightnessDiagram(const QSharedPointer<PerceptualColor::RgbColorSpace> &colorSpace, QWidget *parent = nullptr);
81 virtual ~ChromaLightnessDiagram() noexcept override;
82 /** @brief Getter for property @ref currentColor
83 * @returns the property @ref currentColor */
84 [[nodiscard]] PerceptualColor::LchDouble currentColor() const;
85 [[nodiscard]] virtual QSize minimumSizeHint() const override;
86 [[nodiscard]] virtual QSize sizeHint() const override;
87
88public Q_SLOTS:
89 void setCurrentColor(const PerceptualColor::LchDouble &newCurrentColor);
90
92 /** @brief Notify signal for property @ref currentColor.
93 * @param newCurrentColor the new current color */
94 void currentColorChanged(const PerceptualColor::LchDouble &newCurrentColor);
95
96protected:
97 virtual void keyPressEvent(QKeyEvent *event) override;
98 virtual void mouseMoveEvent(QMouseEvent *event) override;
99 virtual void mousePressEvent(QMouseEvent *event) override;
100 virtual void mouseReleaseEvent(QMouseEvent *event) override;
101 virtual void paintEvent(QPaintEvent *event) override;
102 virtual void resizeEvent(QResizeEvent *event) override;
103
104private:
105 Q_DISABLE_COPY(ChromaLightnessDiagram)
106
107 /** @internal
108 *
109 * @brief Declare the private implementation as friend class.
110 *
111 * This allows the private class to access the protected members and
112 * functions of instances of <em>this</em> class. */
113 friend class ChromaLightnessDiagramPrivate;
114 /** @brief Pointer to implementation (pimpl) */
115 ConstPropagatingUniquePointer<ChromaLightnessDiagramPrivate> d_pointer;
116
117 /** @internal @brief Only for unit tests. */
118 friend class TestChromaLightnessDiagram;
119
120 /** @internal
121 * @brief Internal friend declaration.
122 *
123 * This class is used as child class in @ref WheelColorPicker.
124 * There is a tight collaboration. */
125 friend class WheelColorPicker;
126 /** @internal
127 * @brief Internal friend declaration.
128 *
129 * This class is used as child class in @ref WheelColorPicker.
130 * There is a tight collaboration. */
131 friend class WheelColorPickerPrivate;
132};
133
134} // namespace PerceptualColor
135
136#endif // CHROMALIGHTNESSDIAGRAM_H
The namespace of this library.
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
virtual bool event(QEvent *event) override
A LCH color (Oklch, CielchD50, CielchD65…)
Definition lchdouble.h:50
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:36 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.