137 if (
m_d->imageNeedsUpdate) {
139 m_d->imageNeedsUpdate =
false;
141 QPainter painter(
this);
142 painter.drawImage(0, 0,
m_d->background);
143 painter.scale(1.0/devicePixelRatioF(), 1.0/devicePixelRatioF());
145 if (
m_d->sliderMode) {
147 int sliderX = qRound(sliderPos.x());
148 handleRect = QRectF(sliderX -
m_d->cursorWidth/2, 0,
m_d->cursorWidth, height());
149 }
else if (
m_d->handleValue >= 0) {
152 if (handleRect.isValid()) {
153 QPen pen(QColor(175,175,175),
m_d->lineWidth, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin);
155 strokeRect(painter, handleRect, devicePixelRatioF(), 0);
156 pen.setColor(QColor(75,75,75));
158 strokeRect(painter, handleRect, devicePixelRatioF(), 1);
244 if (
m_d->sliderMode) {
245 delta = (float)sliderPos;
246 }
else if (sliderPos >= 0 ||
m_d->numPatches > 1) {
247 delta = 2.0f * float(sliderPos)/(
m_d->numPatches - 1.0f) - 1.0f;
250 QVector4D channelVec =
m_d->baseValues +
m_d->offset + delta *
m_d->range;
252 if (
m_d->selectorModel->isHSXModel()) {
253 channelVec[0] = (float)fmod(channelVec[0], 1.0);
254 if (channelVec[0] < 0) {
255 channelVec[0] += 1.f;
259 channelVec[0] = qBound(0.f, channelVec[0], 1.f);
262 for (
int i = 1; i < 3; i++) {
263 channelVec[i] = qBound(0.f, channelVec[i], 1.f);
279 qreal patchWidth = width() / qreal(
m_d->numPatches);
281 QPointF topLeft(index * patchWidth + margin, 0);
282 QPointF bottomRight((index+1) * patchWidth - margin, height());
283 return QRectF(topLeft, bottomRight);
313 if (!
m_d->widgetSizeOk || !
m_d->selectorModel || !
m_d->selectorModel->colorSpace()) {
319 const qreal deviceDivider = 1.0 / devicePixelRatioF();
320 const int deviceWidth = qCeil(width() * devicePixelRatioF());
321 const int deviceHeight = qCeil(height() * devicePixelRatioF());
322 if (
m_d->sliderMode) {
324 const quint32 pixelSize = currentCS->
pixelSize();
325 quint32 imageSize = deviceWidth * pixelSize;
326 QScopedArrayPointer<quint8> raw(
new quint8[imageSize] {});
327 quint8 *dataPtr = raw.data();
329 for (
int x = 0; x < deviceWidth; x++, dataPtr += pixelSize) {
332 KoColor c =
m_d->selectorModel->convertChannelValuesToKoColor(coordinates);
333 memcpy(dataPtr, c.
data(), pixelSize);
336 QImage image =
m_d->displayConfig->displayConverter()->toQImage(currentCS, raw.data(), {deviceWidth, 1},
337 m_d->displayConfig->previewInPaintingCS());
338 image = image.scaled(QSize(deviceWidth, deviceHeight));
340 QPainter painter(&image);
341 QPen pen(QColor(175,175,175),
m_d->lineWidth, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin);
343 strokeRect(painter, QRectF(
m_d->leftStart, 0,
m_d->cursorWidth, height()), devicePixelRatioF(), 0);
344 pen.setColor(QColor(75,75,75));
346 strokeRect(painter, QRectF(
m_d->leftStart, 0,
m_d->cursorWidth, height()), devicePixelRatioF(), 1);
348 image.setDevicePixelRatio(devicePixelRatioF());
351 QImage image(deviceWidth, deviceHeight, QImage::Format_ARGB32);
352 image.fill(Qt::transparent);
353 image.setDevicePixelRatio(devicePixelRatioF());
354 QPainter painter(&image);
355 painter.setPen(Qt::NoPen);
357 for (
int i = 0; i <
m_d->numPatches; i++) {
359 KoColor col =
m_d->selectorModel->convertChannelValuesToKoColor(values);
360 QColor qCol =
m_d->displayConfig->displayConverter()->
toQColor(col,
m_d->displayConfig->previewInPaintingCS());
361 painter.setBrush(qCol);
370 qreal lineWidth = painter.pen().widthF();
371 QPointF topLeft(qRound(
rect.left() * pixelSize) + (shrinkX + 0.5) * lineWidth,
372 qRound(
rect.top() * pixelSize) + 0.5 * lineWidth);
373 QPointF bottomRight(qRound(
rect.right() * pixelSize) - (shrinkX + 0.5) * lineWidth,
374 qRound(
rect.bottom() * pixelSize) - 0.5 * lineWidth);
375 painter.drawRect(QRectF(topLeft, bottomRight));