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"
19#include "rgbcolorspace.h"
21#include <qapplication.h>
27#include <qsharedpointer.h>
41 , d_pointer(new WheelColorPickerPrivate(this))
43 d_pointer->m_rgbColorSpace = colorSpace;
44 d_pointer->m_colorWheel =
new ColorWheel(colorSpace,
this);
45 d_pointer->m_chromaLightnessDiagram =
new ChromaLightnessDiagram(
51 d_pointer->m_colorWheel);
52 d_pointer->m_colorWheel->setFocusProxy(d_pointer->m_chromaLightnessDiagram);
53 d_pointer->resizeChildWidgets();
57 d_pointer->m_colorWheel,
60 [
this](
const qreal newHue) {
61 GenericColor lch = d_pointer->m_chromaLightnessDiagram->currentColorCielchD50();
65 lch = d_pointer->m_rgbColorSpace->reduceCielchD50ChromaToFitIntoGamut(lch);
66 d_pointer->m_chromaLightnessDiagram->setCurrentColorCielchD50(lch);
68 connect(d_pointer->m_chromaLightnessDiagram,
69 &ChromaLightnessDiagram::currentColorCielchD50Changed,
80 &WheelColorPickerPrivate::handleFocusChanged);
86 d_pointer->m_rgbColorSpace->reduceCielchD50ChromaToFitIntoGamut(
88 CielchD50Values::srgbVersatileInitialColor));
101 : q_pointer(backLink)
120void WheelColorPickerPrivate::handleFocusChanged(
QWidget *old,
QWidget *now)
122 if ((old == m_chromaLightnessDiagram) || (now == m_chromaLightnessDiagram)) {
123 m_colorWheel->update();
135 d_pointer->resizeChildWidgets();
143QSizeF WheelColorPickerPrivate::optimalChromaLightnessDiagramSize()
const
164 const qreal r = 100.0 / m_rgbColorSpace->profileMaximumCielchD50Chroma();
165 const qreal h = m_chromaLightnessDiagram->d_pointer->leftBorderPhysical()
166 + m_chromaLightnessDiagram->d_pointer->defaultBorderPhysical();
167 const qreal v = 2 * m_chromaLightnessDiagram->d_pointer->defaultBorderPhysical();
168 const qreal d = m_colorWheel->d_pointer->innerDiameter();
251 const qreal x = (1 + qPow(r, 2));
258 + qPow((h + r * v) / x, 2)
260 - (h * h + v * v) / x)
263 const qreal b = r * a;
278void WheelColorPickerPrivate::resizeChildWidgets()
282 m_colorWheel->resize(q_pointer->size());
285 const QSizeF widgetSize = optimalChromaLightnessDiagramSize();
289 const qreal radius = m_colorWheel->maximumWidgetSquareSize() / 2.0;
290 const QPointF widgetTopLeftPos(
292 radius - widgetSize.
width() / 2.0,
294 radius - widgetSize.
height() / 2.0);
298 QRectF diagramGeometry(widgetTopLeftPos, widgetSize);
302 diagramGeometry.setLeft(ceil(diagramGeometry.left()));
303 diagramGeometry.setTop(ceil(diagramGeometry.top()));
305 diagramGeometry.setRight(floor(diagramGeometry.right()));
306 diagramGeometry.setBottom(floor(diagramGeometry.bottom()));
316 m_chromaLightnessDiagram->setGeometry(diagramGeometry.toRect());
323 return d_pointer->m_chromaLightnessDiagram->currentColorCielchD50();
332 d_pointer->m_chromaLightnessDiagram->setCurrentColorCielchD50(newCurrentColorCielchD50);
337 d_pointer->m_colorWheel->setHue(d_pointer->m_chromaLightnessDiagram->currentColorCielchD50().third);
349 const QSizeF minimumDiagramSize =
351 d_pointer->m_chromaLightnessDiagram->minimumSizeHint()
356 const int diameterForMinimumDiagramSize =
362 qSqrt(qPow(minimumDiagramSize.
width(), 2) + qPow(minimumDiagramSize.
height(), 2)))
364 + d_pointer->m_colorWheel->gradientThickness()
366 + d_pointer->m_colorWheel->d_pointer->border();
368 const QSize sizeForMinimumDiagramSize(diameterForMinimumDiagramSize,
369 diameterForMinimumDiagramSize
372 return sizeForMinimumDiagramSize
374 .
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 currentColorCielchD50Changed(const PerceptualColor::GenericColor &newCurrentColorCielchD50)
Notify signal for property currentColorCielchD50.
void setCurrentColorCielchD50(const PerceptualColor::GenericColor &newCurrentColorCielchD50)
Setter for the currentColorCielchD50() property.
PerceptualColor::GenericColor currentColorCielchD50
Currently selected color.
virtual ~WheelColorPicker() noexcept override
Default destructor.
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