10 connect(
this, SIGNAL(clicked()),
this, SLOT(
pickGradient()));
11 setAutoDefault(
false);
18 const int w = 130, h = 16;
19 QImage image(w, h, QImage::Format_RGB888);
20 QPainter painter(&image);
21 painter.setPen(Qt::NoPen);
22 painter.fillRect(0, 0, w, h, QColor(0, 0, 0));
24 for(
int x = 1;
x < w - 1;
x += h){
25 painter.fillRect(
x, 1, h / 2, h / 2 - 1, QColor(255, 255, 255));
26 painter.fillRect(
x + h / 2, 1, h / 2, h / 2 - 1, QColor(192, 192, 192));
27 painter.fillRect(
x, h / 2, h / 2, h / 2 - 1, QColor(192, 192, 192));
28 painter.fillRect(
x + h / 2, h / 2, h / 2, h / 2 - 1, QColor(255, 255, 255));
31 QLinearGradient gradient(1., 0., w - 1, 0.);
33 painter.fillRect(1, 1, w - 2, h - 2, QBrush(gradient));
34 setIconSize(QSize(w, h));
35 setIcon(QIcon(QPixmap::fromImage(image)));
42 QByteArray cString =
string.toLatin1();
43 const char* data = cString.data();
49 if(sscanf(data,
"%hhd:%2hhx%2hhx%2hhx%2hhx%n", &newpos, &a, &r, &g, &b, &scanned) != 5)
53 if(newpos <= pos || newpos > 100)
58 _stops.append(QGradientStop(pos / 100., QColor(r, g, b, a)));
62 if(sscanf(data,
"%2hhx%2hhx%2hhx%2hhx", &a, &r, &g, &b) == 4){
63 _stops.append(QGradientStop(0., QColor(r, g, b, a)));
64 _stops.append(QGradientStop(1., QColor(r, g, b, 0.)));
69 _stops.append(QGradientStop(0., QColor(255, 255, 255)));
70 _stops.append(QGradientStop(1., QColor(255, 255, 255)));
75 if(
_stops.last().first != 1.)
82 foreach(
const QGradientStop& stop,
_stops){
84 const QColor& color = stop.second;
85 result <<
string.sprintf(
"%d:%02x%02x%02x%02x", (
int)round(stop.first * 100.f), color.alpha(), color.red(), color.green(), color.blue());
87 return result.join(
" ");
QGradientStops getGradient(const QGradientStops &prevGradient)