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 <qcolor.h>
10#include <qglobal.h>
11#include <qnamespace.h>
12#include <qsharedpointer.h>
13#include <qsize.h>
14class QEvent;
15class QKeyEvent;
16class QMouseEvent;
17class QPaintEvent;
18class QWidget;
19
20#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
21#include <qtmetamacros.h>
22#else
23#include <qobjectdefs.h>
24#include <qstring.h>
25class QObject;
26#endif
27
28namespace PerceptualColor
29{
30
31template<typename T>
32class Array2D;
33class RgbColorSpace;
34class SwatchBookPrivate;
35
36/** @internal
37 *
38 * @brief Shows colors swatches.
39 *
40 * @image html SwatchBook.png "SwatchBook"
41 *
42 * The user can select a color either by mouse click or by using the keyboard.
43 *
44 * The marker used to mark the currently selected color depends
45 * on the current translation; see @ref setTranslation for details.
46 *
47 * @internal
48 *
49 * @todo A design question: Should we draw margins around each individual
50 * color patch? Maybe rely on @ref ColorPatch somehow?
51 *
52 * @todo A design question: Should the size of the individual color patches
53 * be responsive, adopting the the widget size? */
54class SwatchBook : public AbstractDiagram
55{
57
58 /** @brief The current color.
59 *
60 * This property can contain any valid color, including colors
61 * that are not in the swatch book.
62 *
63 * If you set this property exactly to an RGB color that is in the
64 * swatch book, this particular swatch will show a selection mark.
65 * Otherwise, no selection mark will be visible.
66 *
67 * @sa @ref currentColor() const
68 * @sa @ref setCurrentColor()
69 * @sa @ref currentColorChanged() */
70 Q_PROPERTY(QColor currentColor READ currentColor WRITE setCurrentColor NOTIFY currentColorChanged)
71
72public:
73 Q_INVOKABLE explicit SwatchBook(const QSharedPointer<PerceptualColor::RgbColorSpace> &colorSpace,
74 const Array2D<QColor> &swatches,
75 Qt::Orientations wideSpacing,
76 QWidget *parent = nullptr);
77 virtual ~SwatchBook() noexcept override;
78 /** @brief Getter for property @ref currentColor
79 * @returns the property @ref currentColor */
80 [[nodiscard]] QColor currentColor() const;
81 [[nodiscard]] virtual QSize minimumSizeHint() const override;
82 [[nodiscard]] virtual QSize sizeHint() const override;
83
84public Q_SLOTS:
85 void setCurrentColor(const QColor &newCurrentColor);
86
88 /** @brief Notify signal for property @ref currentColor.
89 *
90 * @param newCurrentColor the new @ref currentColor */
91 void currentColorChanged(const QColor &newCurrentColor);
92
93protected:
94 virtual void changeEvent(QEvent *event) override;
95 virtual void keyPressEvent(QKeyEvent *event) override;
96 virtual void mousePressEvent(QMouseEvent *event) override;
97 virtual void paintEvent(QPaintEvent *event) override;
98
99private:
100 Q_DISABLE_COPY(SwatchBook)
101
102 /** @internal
103 * @brief Declare the private implementation as friend class.
104 *
105 * This allows the private class to access the protected members and
106 * functions of instances of <em>this</em> class. */
107 friend class SwatchBookPrivate;
108 /** @brief Pointer to implementation (pimpl) */
109 ConstPropagatingUniquePointer<SwatchBookPrivate> d_pointer;
110
111 /** @internal @brief Only for unit tests. */
112 friend class TestSwatchBook;
113};
114
115} // namespace PerceptualColor
116
117#endif // SWATCHBOOK_H
The namespace of this library.
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 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.