Ejemplo n.º 1
0
void ColorScaleButton::paintScale(QPainter *painter, const QRect &baseRect,
                                  const ColorScale &colorScale) {
  QRect rect = baseRect;
  rect.setX(rect.x() + 2);
  rect.setY(rect.y() + 2);
  rect.setWidth(rect.width() - 4);
  rect.setHeight(rect.height() - 4);

  QLinearGradient grad(QPointF(rect.x(), rect.y()), QPointF(rect.x() + rect.width(), rect.y()));
  std::map<float, Color> stops = colorScale.getColorMap();

  for (std::map<float, Color>::iterator it = stops.begin(); it != stops.end(); ++it)
    grad.setColorAt(it->first, colorToQColor(it->second));

  painter->setBrush(QBrush(grad));

  painter->drawRect(rect);
}