Perceptual Color

swatchbook.h
1// SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR MIT
3
4#ifndef SWATCHBOOK_H
5#define SWATCHBOOK_H
6
7#include "abstractdiagram.h"
8#include "constpropagatinguniquepointer.h"
9#include "helper.h"
10#include <qcolor.h>
11#include <qglobal.h>
12#include <qnamespace.h>
13#include <qsharedpointer.h>
14#include <qsize.h>
15class QEvent;
16class QKeyEvent;
17class QMouseEvent;
18class QPaintEvent;
19class QWidget;
20
21#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
22#include <qtmetamacros.h>
23#else
24#include <qobjectdefs.h>
25#include <qstring.h>
26class QObject;
27#endif
28
29namespace PerceptualColor
30{
31
32class RgbColorSpace;
33class SwatchBookPrivate;
34
35/** @internal
36 *
37 * @brief Shows colors swatches.
38 *
39 * @image html SwatchBook.png "SwatchBook"
40 *
41 * The user can select a color either by mouse click or by using the keyboard.
42 *
43 * The marker used to mark the currently selected color depends
44 * on the current translation; see @ref setTranslation for details.
45 *
46 * @internal
47 *
48 * @todo A design question: Should we draw margins around each individual
49 * color patch? Maybe rely on @ref ColorPatch somehow?
50 *
51 * @todo A design question: Should the size of the individual color patches
52 * be responsive, adopting the the widget size? */
53class SwatchBook : public AbstractDiagram
54{
56
57 /** @brief The current color.
58 *
59 * This property can contain any valid color, including colors
60 * that are not in the swatch book.
61 *
62 * If you set this property exactly to an RGB color that is in the
63 * swatch book, this particular swatch will show a selection mark.
64 * Otherwise, no selection mark will be visible.
65 *
66 * @sa @ref currentColor() const
67 * @sa @ref setCurrentColor()
68 * @sa @ref currentColorChanged() */
69 Q_PROPERTY(QColor currentColor READ currentColor WRITE setCurrentColor NOTIFY currentColorChanged)
70
71 /** @brief The swatchGrid that is displayed in the swatch book.
72 *
73 * The colors are in the current color space. The first dimension
74 * (@ref Array2D::iCount()) is interpreted as horizontal axis from
75 * left to right on LTR layouts, and the other way around on RTL
76 * layouts. The second dimension of the array (@ref Array2D::jCount())
77 * is interpreted as vertical axis, from top to bottom.
78 *
79 * @sa @ref swatchGrid() const
80 * @sa @ref setSwatchGrid()
81 * @sa @ref swatchGridChanged() */
82 Q_PROPERTY(Swatches swatchGrid READ swatchGrid WRITE setSwatchGrid NOTIFY swatchGridChanged)
83
84public:
85 Q_INVOKABLE explicit SwatchBook(const QSharedPointer<PerceptualColor::RgbColorSpace> &colorSpace,
86 const PerceptualColor::Swatches &swatchGrid,
87 Qt::Orientations wideSpacing,
88 QWidget *parent = nullptr);
89 virtual ~SwatchBook() noexcept override;
90 /** @brief Getter for property @ref currentColor
91 * @returns the property @ref currentColor */
92 [[nodiscard]] QColor currentColor() const;
93 [[nodiscard]] virtual QSize minimumSizeHint() const override;
94 /** @brief Getter for property @ref swatchGrid
95 * @returns the property @ref swatchGrid */
96 [[nodiscard]] Swatches swatchGrid() const;
97 [[nodiscard]] virtual QSize sizeHint() const override;
98
99public Q_SLOTS:
100 void setCurrentColor(const QColor &newCurrentColor);
101 void setSwatchGrid(const PerceptualColor::Swatches &newSwatchGrid);
102
104 /** @brief Notify signal for property @ref currentColor.
105 *
106 * @param newCurrentColor the new @ref currentColor */
107 void currentColorChanged(const QColor &newCurrentColor);
108 /** @brief Notify signal for property @ref swatchGrid.
109 *
110 * @param newSwatchGrid the new @ref swatchGrid */
111 void swatchGridChanged(const PerceptualColor::Swatches &newSwatchGrid);
112
113protected:
114 virtual void changeEvent(QEvent *event) override;
115 virtual void keyPressEvent(QKeyEvent *event) override;
116 virtual void mousePressEvent(QMouseEvent *event) override;
117 virtual void paintEvent(QPaintEvent *event) override;
118
119private:
120 Q_DISABLE_COPY(SwatchBook)
121
122 /** @internal
123 * @brief Declare the private implementation as friend class.
124 *
125 * This allows the private class to access the protected members and
126 * functions of instances of <em>this</em> class. */
127 friend class SwatchBookPrivate;
128 /** @brief Pointer to implementation (pimpl) */
129 ConstPropagatingUniquePointer<SwatchBookPrivate> d_pointer;
130
131 /** @internal @brief Only for unit tests. */
132 friend class TestSwatchBook;
133};
134
135} // namespace PerceptualColor
136
137#endif // SWATCHBOOK_H
The namespace of this library.
Array2D< QColor > Swatches
Swatches organized in a grid.
Definition helper.h:242
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
typedef Orientations
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.