Perceptual Color

colorwheelimage.h
1// SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR MIT
3
4#ifndef COLORWHEELIMAGE_H
5#define COLORWHEELIMAGE_H
6
7#include <qglobal.h>
8#include <qimage.h>
9#include <qsharedpointer.h>
10
11namespace PerceptualColor
12{
13class RgbColorSpace;
14
15/** @internal
16 *
17 * @brief An image of a color wheel.
18 *
19 * The image has properties that can be accessed by the corresponding setters
20 * and getters.
21 *
22 * This class has a cache. The data is cached because it is expensive to
23 * calculate it again and again on the fly.
24 *
25 * When changing one of the properties, the image is <em>not</em> calculated
26 * immediately. But the old image in the cache is deleted, so that this
27 * memory becomes immediately available. Once you use @ref getImage() the next
28 * time, a new image is calculated and cached. As long as you do not change
29 * the properties, the next call of @ref getImage() will be very fast, as
30 * it returns just the cache.
31 *
32 * This class is intended for usage in widgets that need to display a
33 * color wheel. It is recommended to update the properties of this class as
34 * early as possible: If your widget is resized, use immediately also
35 * @ref setImageSize to update this object. (This will reduce your memory
36 * usage, as no memory will be hold for data that will not be
37 * needed again.)
38 *
39 * This class supports HiDPI via its @ref setDevicePixelRatioF function.
40 *
41 * @note Resetting a property to its very same value does not trigger an
42 * image calculation. So, if the border is 5, and you call @ref setBorder
43 * <tt>(5)</tt>, than this will not trigger an image calculation, but the
44 * cache stays valid and available.
45 *
46 * @note This class is not based on <tt>QCache</tt> or <tt>QPixmapCache</tt>
47 * because the semantic is different.
48 *
49 * @note This class is not part of the public API, but just for internal
50 * usage. Therefore, its interface is incomplete and contains only the
51 * functions that are really used in the rest of the source code (property
52 * setters are available, but getters might be missing), and it does not use
53 * the pimpl idiom either.
54 *
55 * @internal
56 *
57 * @todo Port this class to @ref AsyncImageProvider, and do so with
58 * interlacing support. */
59class ColorWheelImage final
60{
61public:
62 explicit ColorWheelImage(const QSharedPointer<PerceptualColor::RgbColorSpace> &colorSpace);
63 [[nodiscard]] QImage getImage();
64 void setBorder(const qreal newBorder);
65 void setDevicePixelRatioF(const qreal newDevicePixelRatioF);
66 void setImageSize(const int newImageSize);
67 void setWheelThickness(const qreal newWheelThickness);
68
69private:
70 Q_DISABLE_COPY(ColorWheelImage)
71
72 /** @internal @brief Only for unit tests. */
73 friend class TestColorWheelImage;
74
75 /** @brief Internal store for the border size, measured in physical pixels.
76 *
77 * @sa @ref setBorder() */
78 qreal m_borderPhysical = 0;
79 /** @brief Internal storage of the device pixel ratio as floating point.
80 *
81 * @sa @ref setDevicePixelRatioF() */
82 qreal m_devicePixelRatioF = 1;
83 /** @brief Internal storage of the image (cache).
84 *
85 * - If <tt>m_image.isNull()</tt> than either no cache is available
86 * or @ref m_imageSizePhysical is <tt>0</tt>. Before using it,
87 * a new image has to be rendered. (If @ref m_imageSizePhysical
88 * is <tt>0</tt>, this will be extremely fast.)
89 * - If <tt>m_image.isNull()</tt> is <tt>false</tt>, than the cache
90 * is valid and can be used directly. */
91 QImage m_image;
92 /** @brief Internal store for the image size, measured in physical pixels.
93 *
94 * @sa @ref setImageSize() */
95 int m_imageSizePhysical = 0;
96 /** @brief Pointer to @ref RgbColorSpace object */
98 /** @brief Internal store for the image size, measured in physical pixels.
99 *
100 * @sa @ref setWheelThickness() */
101 qreal m_wheelThicknessPhysical = 0;
102};
103
104} // namespace PerceptualColor
105
106#endif // COLORWHEELIMAGE_H
The namespace of this library.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:48:43 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.