void HSVRangeDisplay::updateImage() { m_width = width(); m_height = height(); //printf("HSVRangeDisplay::updateImage(): %d x %d\n", m_width, m_height); m_image = QImage(m_width, m_height, QImage::Format_RGB16); if (!m_width || !m_height) return; for (int y = 0; y < m_height; y++) { uint16 hue = y2hue(y); uint16 *dest = (uint16*) m_image.scanLine(y); for (int x = 0; x < m_width/2; x++) { *dest++ = HSV(hue, x2sat(x), 255).toPixel<Pixel565>().rgb; } for (int x = m_width/2; x < m_width; x++) { *dest++ = HSV(hue, 255, x2val(x)).toPixel<Pixel565>().rgb; } } }
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); }
void ColorPicker::mousePressEvent(QMouseEvent *m) { if (m_mode==Hue) setHue(y2hue(m->y())); else if (m_mode==Saturation) setSat(y2sat(m->y())); else setGam(y2gam(m->y())); }