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 "genericcolor.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 currentColorCielchD50() const
75 * @sa WRITE @ref setCurrentColorCielchD50()
76 * @sa NOTIFY @ref currentColorCielchD50Changed() */
77 // The Q_PROPERTY macro must be on a single line for correct compilation.
78 // clang-format is disabled here to prevent automatic line breaks.
79 // clang-format off
80 Q_PROPERTY(PerceptualColor::GenericColor currentColorCielchD50 READ currentColorCielchD50 WRITE setCurrentColorCielchD50 NOTIFY currentColorCielchD50Changed)
81 // clang-format on
82
83public:
84 Q_INVOKABLE explicit ChromaLightnessDiagram(const QSharedPointer<PerceptualColor::RgbColorSpace> &colorSpace, QWidget *parent = nullptr);
85 virtual ~ChromaLightnessDiagram() noexcept override;
86 /** @brief Getter for property @ref currentColorCielchD50
87 * @returns the property @ref currentColorCielchD50 */
88 [[nodiscard]] PerceptualColor::GenericColor currentColorCielchD50() const;
89 [[nodiscard]] virtual QSize minimumSizeHint() const override;
90 [[nodiscard]] virtual QSize sizeHint() const override;
91
92public Q_SLOTS:
93 void setCurrentColorCielchD50(const PerceptualColor::GenericColor &newCurrentColorCielchD50);
94
96 /** @brief Notify signal for property @ref currentColorCielchD50.
97 * @param newCurrentColorCielchD50 the new current color */
98 void currentColorCielchD50Changed(const PerceptualColor::GenericColor &newCurrentColorCielchD50);
99
100protected:
101 virtual void keyPressEvent(QKeyEvent *event) override;
102 virtual void mouseMoveEvent(QMouseEvent *event) override;
103 virtual void mousePressEvent(QMouseEvent *event) override;
104 virtual void mouseReleaseEvent(QMouseEvent *event) override;
105 virtual void paintEvent(QPaintEvent *event) override;
106 virtual void resizeEvent(QResizeEvent *event) override;
107
108private:
109 Q_DISABLE_COPY(ChromaLightnessDiagram)
110
111 /** @internal
112 *
113 * @brief Declare the private implementation as friend class.
114 *
115 * This allows the private class to access the protected members and
116 * functions of instances of <em>this</em> class. */
117 friend class ChromaLightnessDiagramPrivate;
118 /** @brief Pointer to implementation (pimpl) */
119 ConstPropagatingUniquePointer<ChromaLightnessDiagramPrivate> d_pointer;
120
121 /** @internal @brief Only for unit tests. */
122 friend class TestChromaLightnessDiagram;
123
124 /** @internal
125 * @brief Internal friend declaration.
126 *
127 * This class is used as child class in @ref WheelColorPicker.
128 * There is a tight collaboration. */
129 friend class WheelColorPicker;
130 /** @internal
131 * @brief Internal friend declaration.
132 *
133 * This class is used as child class in @ref WheelColorPicker.
134 * There is a tight collaboration. */
135 friend class WheelColorPickerPrivate;
136};
137
138} // namespace PerceptualColor
139
140#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
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:18:38 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.