Perceptual Color

swatchbook_p.h
1// SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR MIT
3
4#ifndef SWATCHBOOK_P_H
5#define SWATCHBOOK_P_H
6
7// Include the header of the public class of this private implementation.
8// #include "swatchbook.h"
9
10#include "constpropagatingrawpointer.h"
11#include "helper.h"
12#include "helperqttypes.h"
13#include <qcolor.h>
14#include <qglobal.h>
15#include <qnamespace.h>
16#include <qobject.h>
17#include <qpoint.h>
18#include <qsharedpointer.h>
19#include <qsize.h>
20#include <qstring.h>
21#include <qstyleoption.h>
22
23#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
24#include <qtmetamacros.h>
25#else
26#include <qobjectdefs.h>
27#endif
28
29namespace PerceptualColor
30{
31class SwatchBook;
32class RgbColorSpace;
33
34/** @internal
35 *
36 * @brief Private implementation within the <em>Pointer to
37 * implementation</em> idiom */
38class SwatchBookPrivate final : public QObject
39{
41
42public:
43 /**
44 * @brief Marks (symbols) for use in @ref SwatchBook.
45 */
46 enum class Mark {
47 Selection, /**< A mark that indicates the a given patch is the selected
48 one. */
49 Add /**< A mark that indicated that by clicking on the given empty
50 patch, a new color is added to this patch. */
51 };
52
53 explicit SwatchBookPrivate(SwatchBook *backLink, const PerceptualColor::Swatches &swatchGrid, Qt::Orientations wideSpacing);
54 /** @brief Default destructor
55 *
56 * The destructor is non-<tt>virtual</tt> because
57 * the class as a whole is <tt>final</tt>. */
58 ~SwatchBookPrivate() noexcept override = default;
59
60 [[nodiscard]] QSize colorPatchesSizeWithMargin() const;
61 [[nodiscard]] int cornerRadius() const;
62 void drawMark(const QPoint offset,
63 QPainter *widgetPainter,
64 const QColor color,
65 const SwatchBookPrivate::Mark markSymbol,
66 const QListSizeType row,
67 const QListSizeType column) const;
68 [[nodiscard]] int horizontalPatchSpacing() const;
69 void initStyleOption(QStyleOptionFrame *option) const;
70 [[nodiscard]] std::pair<QListSizeType, QListSizeType> logicalColumnRowFromPosition(const QPoint position) const;
71 [[nodiscard]] int normalPatchSpacing() const;
72 [[nodiscard]] QPoint offset(const QStyleOptionFrame &styleOptionFrame) const;
73 [[nodiscard]] QSize patchSizeInner() const;
74 [[nodiscard]] QSize patchSizeOuter() const;
75 void retranslateUi();
76 void selectSwatch(QListSizeType newCurrentColomn, QListSizeType newCurrentRow);
77 void selectSwatchFromCurrentColor();
78 void updateColorSchemeCache();
79 [[nodiscard]] int verticalPatchSpacing() const;
80 [[nodiscard]] int widePatchSpacing() const;
81
82 /** @brief The add mark to use, or an empty string if no
83 * add mark is available.
84 *
85 * The add mark is drawn above an empty patch.
86 *
87 * This variable contains the localized add mark string (if all its
88 * characters are available in the default font of this widget). An
89 * empty string otherwise.
90 *
91 * The value is set by @ref retranslateUi(). */
92 QString m_addMark;
93 /** @brief Internal storage for property @ref SwatchBook::currentColor
94 *
95 * QColor automatically initializes with an invalid color, just like it
96 * should be for the property @ref SwatchBook::currentColor, so no
97 * need to initialize here explicitly. */
98 QColor m_currentColor;
99 /**
100 * @brief Cache for the current color scheme of this widget.
101 *
102 * @sa @ref updateColorSchemeCache()
103 */
104 ColorSchemeType m_colorSchemeCache = ColorSchemeType::Light;
105 /** @brief Internal storage for property @ref SwatchBook::editable */
106 bool m_editable = false;
107 /** @brief Pointer to the RgbColorSpace object. */
108 QSharedPointer<PerceptualColor::RgbColorSpace> m_rgbColorSpace;
109 /** @brief Selected column.
110 *
111 * If one of the swatches in the book is selected, this is
112 * the index of the column.
113 * Otherwise, its <tt>-1</tt>. */
114 QListSizeType m_selectedColumn = -1;
115 /** @brief Selected row.
116 *
117 * If one of the swatches in the book is selected, this is
118 * the index of the row.
119 * Otherwise, its <tt>-1</tt>. */
120 QListSizeType m_selectedRow = -1;
121 /** @brief The selection mark to use, or an empty string if no
122 * selection mark is available.
123 *
124 * The selection mark is drawn above the patch that is currently selected.
125 *
126 * This variable contains the localized selection mark string (if all its
127 * characters are available in the default font of this widget). An
128 * empty string otherwise.
129 *
130 * The value is set by @ref retranslateUi(). */
131 QString m_selectionMark;
132 /** @brief Internal storage for property @ref SwatchBook::swatchGrid */
133 Swatches m_swatchGrid;
134 /** @brief List of axis where @ref widePatchSpacing should be used. */
135 const Qt::Orientations m_wideSpacing;
136
137private:
138 Q_DISABLE_COPY(SwatchBookPrivate)
139
140 /** @brief Pointer to the object from which <em>this</em> object
141 * is the private implementation. */
142 ConstPropagatingRawPointer<SwatchBook> q_pointer;
143};
144
145} // namespace PerceptualColor
146
147#endif // SWATCHBOOK_P_H
The namespace of this library.
Array2D< QColor > Swatches
Swatches organized in a grid.
Definition helper.h:262
ColorSchemeType
Represents the appearance of a theme.
Definition helper.h:41
Q_OBJECTQ_OBJECT
typedef Orientations
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 25 2025 12:03:13 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.