6#include "colorwheelimage.h"
8#include "absolutecolor.h"
9#include "cielchd50values.h"
10#include "helperconstants.h"
11#include "helperconversion.h"
12#include "helpermath.h"
13#include "polarpointf.h"
14#include "rgbcolorspace.h"
18#include <qnamespace.h>
31ColorWheelImage::ColorWheelImage(
const QSharedPointer<PerceptualColor::RgbColorSpace> &colorSpace)
32 : m_rgbColorSpace(colorSpace)
45void ColorWheelImage::setBorder(
const qreal newBorder)
49 tempBorder = newBorder;
53 if (m_borderPhysical != tempBorder) {
54 m_borderPhysical = tempBorder;
78void ColorWheelImage::setDevicePixelRatioF(
const qreal newDevicePixelRatioF)
80 qreal tempDevicePixelRatioF;
81 if (newDevicePixelRatioF >= 1) {
82 tempDevicePixelRatioF = newDevicePixelRatioF;
84 tempDevicePixelRatioF = 1;
86 if (m_devicePixelRatioF != tempDevicePixelRatioF) {
87 m_devicePixelRatioF = tempDevicePixelRatioF;
100void ColorWheelImage::setImageSize(
const int newImageSize)
103 if (newImageSize >= 0) {
104 tempImageSize = newImageSize;
108 if (m_imageSizePhysical != tempImageSize) {
109 m_imageSizePhysical = tempImageSize;
122void ColorWheelImage::setWheelThickness(
const qreal newWheelThickness)
125 if (newWheelThickness >= 0) {
126 temp = newWheelThickness;
130 if (m_wheelThicknessPhysical != temp) {
131 m_wheelThicknessPhysical = temp;
146QImage ColorWheelImage::getImage()
149 if (!m_image.isNull()) {
156 if (m_imageSizePhysical <= 0) {
161 m_image =
QImage(
QSize(m_imageSizePhysical, m_imageSizePhysical),
166 const qreal outerCircleDiameter =
167 m_imageSizePhysical - 2 * m_borderPhysical;
170 if (outerCircleDiameter <= 0) {
175 m_image.setDevicePixelRatio(m_devicePixelRatioF);
186 const qreal
center = (m_imageSizePhysical - 1) /
static_cast<qreal
>(2);
187 m_image =
QImage(
QSize(m_imageSizePhysical, m_imageSizePhysical),
193 const qreal minimumRadius =
194 center - m_wheelThicknessPhysical - m_borderPhysical - overlap;
195 const qreal maximumRadius =
center - m_borderPhysical + overlap;
196 for (x = 0; x < m_imageSizePhysical; ++x) {
197 for (y = 0; y < m_imageSizePhysical; ++y) {
198 const PolarPointF polarCoordinates =
199 PolarPointF(
QPointF(x - center, center - y));
200 const bool inWheel = isInRange<qreal>(minimumRadius,
201 polarCoordinates.radius(),
204 const auto hue = polarCoordinates.angleDegree();
205 m_image.setPixelColor(
208 m_rgbColorSpace->maxChromaColorByCielchD50Hue360(hue));
220 const qreal circleRadius = outerCircleDiameter / 2;
221 const qreal cutOffThickness =
222 qSqrt(qPow(m_imageSizePhysical, 2) * 2) / 2
229 const qreal halfImageSize = m_imageSizePhysical /
static_cast<qreal
>(2);
230 myPainter.drawEllipse(
QPointF(halfImageSize, halfImageSize),
231 circleRadius + cutOffThickness / 2,
232 circleRadius + cutOffThickness / 2
236 const qreal innerCircleDiameter =
237 m_imageSizePhysical - 2 * (m_wheelThicknessPhysical + m_borderPhysical);
238 if (innerCircleDiameter > 0) {
243 myPainter.drawEllipse(
244 QRectF(m_wheelThicknessPhysical + m_borderPhysical,
245 m_wheelThicknessPhysical + m_borderPhysical,
247 innerCircleDiameter));
251 m_image.setDevicePixelRatio(m_devicePixelRatioF);
KGUIADDONS_EXPORT qreal hue(const QColor &)
The namespace of this library.
QTextStream & center(QTextStream &stream)