! \reimp First copies a background image of the hue donut and its background color onto the frame, then draws the color triangle, and finally the selectors. */
| 529 | and finally the selectors. |
| 530 | */ |
| 531 | void QtColorTriangle::paintEvent(QPaintEvent *e) |
| 532 | { |
| 533 | QPainter p(this); |
| 534 | if (e->rect().intersects(contentsRect())) |
| 535 | p.setClipRegion(e->region().intersected(contentsRect())); |
| 536 | if (mustGenerateBackground) { |
| 537 | genBackground(); |
| 538 | mustGenerateBackground = false; |
| 539 | } |
| 540 | |
| 541 | // Blit the static generated background with the hue gradient onto |
| 542 | // the double buffer. |
| 543 | QImage buf = bg.copy(); |
| 544 | |
| 545 | // Draw the trigon |
| 546 | int h,s,v; |
| 547 | curColor.getHsv(&h, &s, &v); |
| 548 | |
| 549 | // Find the color with only the hue, and max value and saturation |
| 550 | QColor hueColor; |
| 551 | hueColor.setHsv(curHue, 255, 255); |
| 552 | |
| 553 | // Draw the triangle |
| 554 | drawTrigon(&buf, pa, pb, pc, hueColor); |
| 555 | |
| 556 | // Slow step: convert the image to a pixmap |
| 557 | QPixmap pix = QPixmap::fromImage(buf); |
| 558 | QPainter painter(&pix); |
| 559 | painter.setRenderHint(QPainter::Antialiasing); |
| 560 | |
| 561 | // Draw an outline of the triangle |
| 562 | QColor halfAlpha(0, 0, 0, 128); |
| 563 | painter.setPen(QPen(halfAlpha, 0)); |
| 564 | painter.drawLine(pa, pb); |
| 565 | painter.drawLine(pb, pc); |
| 566 | painter.drawLine(pc, pa); |
| 567 | |
| 568 | int ri, gi, bi; |
| 569 | hueColor.getRgb(&ri, &gi, &bi); |
| 570 | if ((ri * 30) + (gi * 59) + (bi * 11) > 12800) |
| 571 | painter.setPen(QPen(Qt::black, penWidth)); |
| 572 | else |
| 573 | painter.setPen(QPen(Qt::white, penWidth)); |
| 574 | painter.drawEllipse((int) (pd.x() - ellipseSize / 2.0), |
| 575 | (int) (pd.y() - ellipseSize / 2.0), |
| 576 | ellipseSize, ellipseSize); |
| 577 | |
| 578 | curColor.getRgb(&ri, &gi, &bi); |
| 579 | |
| 580 | // Find a color for painting the selector based on the brightness |
| 581 | // value of the color. |
| 582 | if ((ri * 30) + (gi * 59) + (bi * 11) > 12800) |
| 583 | painter.setPen(QPen(Qt::black, penWidth)); |
| 584 | else |
| 585 | painter.setPen(QPen(Qt::white, penWidth)); |
| 586 | |
| 587 | // Draw the selector ellipse. |
| 588 | painter.drawEllipse(QRectF(selectorPos.x() - ellipseSize / 2.0, |
nothing calls this directly
no test coverage detected