void HSVRangeDisplay::paintEvent(QPaintEvent *) { QPainter painter(this); painter.drawImage(QPoint(0,0), m_image); // Draw the bounding rectangle for the HSVRange // This is a little tricky because the range can wrap in hue (Y) int left = sat2x(m_range.s.min); int width = val2x(m_range.v.min) - left; int top = hue2y(m_range.h.min); int height = hue2y(m_range.h.max) - top; if (height < 0) height += m_height; painter.setPen(Qt::white); painter.drawRect(left, top, width, height); painter.drawRect(left, top-m_height, width, height); }
void ColorPicker::paintEvent(QPaintEvent*) { int w = width() - 5; QRect r(0, foff, w, height() - 2*foff); int wi = r.width() - 2; int hi = r.height() - 2; if (!m_pix || m_pix->height() != hi || m_pix->width() != wi) { delete m_pix; QImage img(wi, hi, QImage::Format_RGB32); int y; uint *pixel = (uint *) img.scanLine(0); for (y = 0; y < hi; y++) { const uint *end = pixel + wi; int yh = y2hue(y+coff); int ys = y2sat(y+coff); int yg = y2gam(y+coff); while (pixel < end) { QColor c; c.setHsv(yh, ys, (int)(255*pow(0.7,yg/100.0))); *pixel = c.rgb(); ++pixel; } } m_pix = new QPixmap(QPixmap::fromImage(img)); } QPainter p(this); p.drawPixmap(1, coff, *m_pix); const QPalette &g = palette(); qDrawShadePanel(&p, r, g, true); p.setPen(g.foreground().color()); p.setBrush(g.foreground()); QPolygon a; int y = m_mode==Hue ? hue2y(m_hue) : m_mode==Saturation ? sat2y(m_sat) : gam2y(m_gam); a.setPoints(3, w, y, w+5, y+5, w+5, y-5); p.eraseRect(w, 0, 5, height()); p.drawPolygon(a); }