6#include "wheelcolorpicker.h"
8#include "wheelcolorpicker_p.h"
10#include "abstractdiagram.h"
11#include "chromalightnessdiagram.h"
12#include "chromalightnessdiagram_p.h"
13#include "cielchd50values.h"
14#include "colorwheel.h"
15#include "colorwheel_p.h"
16#include "constpropagatingrawpointer.h"
17#include "constpropagatinguniquepointer.h"
18#include "helperconstants.h"
20#include "rgbcolorspace.h"
22#include <qapplication.h>
28#include <qsharedpointer.h>
42 , d_pointer(new WheelColorPickerPrivate(this))
44 d_pointer->m_rgbColorSpace = colorSpace;
45 d_pointer->m_colorWheel =
new ColorWheel(colorSpace,
this);
46 d_pointer->m_chromaLightnessDiagram =
new ChromaLightnessDiagram(
52 d_pointer->m_colorWheel);
53 d_pointer->m_colorWheel->setFocusProxy(d_pointer->m_chromaLightnessDiagram);
54 d_pointer->resizeChildWidgets();
58 d_pointer->m_colorWheel,
61 [
this](
const qreal newHue) {
62 LchDouble lch = d_pointer->m_chromaLightnessDiagram->currentColor();
66 lch = d_pointer->m_rgbColorSpace->reduceCielchD50ChromaToFitIntoGamut(lch);
67 d_pointer->m_chromaLightnessDiagram->setCurrentColor(lch);
69 connect(d_pointer->m_chromaLightnessDiagram,
70 &ChromaLightnessDiagram::currentColorChanged,
81 &WheelColorPickerPrivate::handleFocusChanged);
87 d_pointer->m_rgbColorSpace->reduceCielchD50ChromaToFitIntoGamut(
89 CielchD50Values::srgbVersatileInitialColor));
102 : q_pointer(backLink)
121void WheelColorPickerPrivate::handleFocusChanged(
QWidget *old,
QWidget *now)
123 if ((old == m_chromaLightnessDiagram) || (now == m_chromaLightnessDiagram)) {
124 m_colorWheel->update();
136 d_pointer->resizeChildWidgets();
144QSizeF WheelColorPickerPrivate::optimalChromaLightnessDiagramSize()
const
165 const qreal r = 100.0 / m_rgbColorSpace->profileMaximumCielchD50Chroma();
166 const qreal h = m_chromaLightnessDiagram->d_pointer->leftBorderPhysical()
167 + m_chromaLightnessDiagram->d_pointer->defaultBorderPhysical();
168 const qreal v = 2 * m_chromaLightnessDiagram->d_pointer->defaultBorderPhysical();
169 const qreal d = m_colorWheel->d_pointer->innerDiameter();
252 const qreal x = (1 + qPow(r, 2));
259 + qPow((h + r * v) / x, 2)
261 - (h * h + v * v) / x)
264 const qreal b = r * a;
279void WheelColorPickerPrivate::resizeChildWidgets()
283 m_colorWheel->resize(q_pointer->size());
286 const QSizeF widgetSize = optimalChromaLightnessDiagramSize();
290 const qreal radius = m_colorWheel->maximumWidgetSquareSize() / 2.0;
291 const QPointF widgetTopLeftPos(
293 radius - widgetSize.
width() / 2.0,
295 radius - widgetSize.
height() / 2.0);
299 QRectF diagramGeometry(widgetTopLeftPos, widgetSize);
303 diagramGeometry.setLeft(ceil(diagramGeometry.left()));
304 diagramGeometry.setTop(ceil(diagramGeometry.top()));
306 diagramGeometry.setRight(floor(diagramGeometry.right()));
307 diagramGeometry.setBottom(floor(diagramGeometry.bottom()));
317 m_chromaLightnessDiagram->setGeometry(diagramGeometry.toRect());
324 return d_pointer->m_chromaLightnessDiagram->currentColor();
333 d_pointer->m_chromaLightnessDiagram->setCurrentColor(newCurrentColor);
338 d_pointer->m_colorWheel->setHue(d_pointer->m_chromaLightnessDiagram->currentColor().h);
350 const QSizeF minimumDiagramSize =
352 d_pointer->m_chromaLightnessDiagram->minimumSizeHint()
357 const int diameterForMinimumDiagramSize =
363 qSqrt(qPow(minimumDiagramSize.
width(), 2) + qPow(minimumDiagramSize.
height(), 2)))
365 + d_pointer->m_colorWheel->gradientThickness()
367 + d_pointer->m_colorWheel->d_pointer->border();
369 const QSize sizeForMinimumDiagramSize(diameterForMinimumDiagramSize,
370 diameterForMinimumDiagramSize
373 return sizeForMinimumDiagramSize
375 .
expandedTo(d_pointer->m_colorWheel->minimumSizeHint());
Base class for LCH diagrams.
void hueChanged(const qreal newHue)
Notify signal for property hue.
Complete wheel-based color picker widget.
virtual QSize sizeHint() const override
Recommended minimum size for the widget.
void currentColorChanged(const PerceptualColor::LchDouble &newCurrentColor)
Notify signal for property currentColor.
PerceptualColor::LchDouble currentColor
Currently selected color.
virtual ~WheelColorPicker() noexcept override
Default destructor.
void setCurrentColor(const PerceptualColor::LchDouble &newCurrentColor)
Setter for the currentColor() property.
virtual QSize minimumSizeHint() const override
Recommended size for the widget.
Q_INVOKABLE WheelColorPicker(const QSharedPointer< PerceptualColor::RgbColorSpace > &colorSpace, QWidget *parent=nullptr)
Constructor.
virtual void resizeEvent(QResizeEvent *event) override
React on a resize event.
The namespace of this library.
void focusChanged(QWidget *old, QWidget *now)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QSize expandedTo(const QSize &otherSize) const const
qreal height() const const
qreal width() const const
A LCH color (Oklch, CielchD50, CielchD65…)