101 mixOp->mixColors(colors, weights, 2, color.data());
223 : KSelector(orientation, parent)
228 connect(
d->displayRenderer, SIGNAL(displayConfigurationChanged()), SLOT(update()), Qt::UniqueConnection);
229 connect(&
d->updateCompressor, SIGNAL(timeout()), SLOT(update()), Qt::UniqueConnection);
257 d->minColor = HSVColor(minH, minS, minV);
258 d->maxColor = HSVColor(maxH, maxS, maxV);
261 minQ.setHsvF(minH, minS, minV);
262 maxQ.setHsvF(maxH, maxS, maxV);
263 d->minKoColor.fromQColor(minQ);
264 d->maxKoColor.fromQColor(maxQ);
267 d->updateCompressor.start();
284 QPixmap checker(8, 8);
285 QPainter
p(&checker);
286 p.fillRect(0, 0, 4, 4, Qt::lightGray);
287 p.fillRect(4, 0, 4, 4, Qt::darkGray);
288 p.fillRect(0, 4, 4, 4, Qt::darkGray);
289 p.fillRect(4, 4, 4, 4, Qt::lightGray);
292 QRect contentsRect_(contentsRect());
293 painter->fillRect(contentsRect_, QBrush(checker));
295 if (!
d->upToDate ||
d->pixmap.isNull() ||
d->pixmap.width() != contentsRect_.width()
296 ||
d->pixmap.height() != contentsRect_.height())
298 std::unique_ptr<Mixer> m;
299 switch (
d->mixMode) {
301 m = std::make_unique<ColorSpaceMixer>(
d->minKoColor,
d->maxKoColor,
d->displayRenderer);
309 m = std::make_unique<HsxMixer>(
d->minColor,
d->maxColor,
d->circularHue,
d->mixMode);
313 QImage image(contentsRect_.width(), contentsRect_.height(), QImage::Format_ARGB32);
315 if (orientation() == Qt::Horizontal) {
316 if (contentsRect_.width() > 0) {
317 for (
int x = 0; x < contentsRect_.width(); x++) {
318 const qreal t =
static_cast<qreal
>(x) / (contentsRect_.width() - 1);
320 for (
int y = 0; y < contentsRect_.height(); y++) {
321 image.setPixel(x, y, m->mix(t).rgba());
326 if (contentsRect_.height() > 0) {
327 for (
int y = 0; y < contentsRect_.height(); y++) {
328 const qreal t =
static_cast<qreal
>(y) / (contentsRect_.height() - 1);
330 for (
int x = 0; x < contentsRect_.width(); x++) {
331 image.setPixel(x, y, m->mix(t).rgba());
337 d->pixmap = QPixmap::fromImage(image);
341 painter->drawPixmap(contentsRect_,
d->pixmap, QRect(0, 0,
d->pixmap.width(),
d->pixmap.height()));
346 int w = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
347 int iw = (w < FRAME_SIZE) ? FRAME_SIZE : w;
349 double t =
static_cast<double>(
value - minimum()) /
static_cast<double>(maximum() - minimum());
350 if (orientation() == Qt::Vertical) {
351 p.setY(height() - iw - 1 - (height() - 2 * iw - 1) * t);
353 if (arrowDirection() == Qt::RightArrow) {
356 p.setX(width() - FRAME_SIZE);
359 p.setX(iw + (width() - 2 * iw - 1) * t);
361 if (arrowDirection() == Qt::DownArrow) {
364 p.setY(height() - FRAME_SIZE);
373 painter->setPen(QPen(
palette().text().color(), 0));
374 painter->setBrush(
palette().text());
378 o.state &= ~QStyle::State_MouseOver;
383 if (orientation() == Qt::Vertical) {
384 o.rect = QRect(pos.x(), pos.y() - ARROW_SIZE / 2, ARROW_SIZE, ARROW_SIZE);
386 o.rect = QRect(pos.x() - ARROW_SIZE / 2, pos.y(), ARROW_SIZE, ARROW_SIZE);
389 QStyle::PrimitiveElement arrowPE;
390 switch (arrowDirection()) {
392 arrowPE = QStyle::PE_IndicatorArrowUp;
395 arrowPE = QStyle::PE_IndicatorArrowDown;
398 arrowPE = QStyle::PE_IndicatorArrowRight;
401 arrowPE = QStyle::PE_IndicatorArrowLeft;
404 arrowPE = QStyle::PE_IndicatorArrowLeft;
408 style()->drawPrimitive(arrowPE, &o, painter,
this);
void HSYToRGB(const qreal h, const qreal s, const qreal y, qreal *red, qreal *green, qreal *blue, qreal R, qreal G, qreal B)