| 15 | } |
| 16 | |
| 17 | void GradientButton::updateImage(){ |
| 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)); |
| 23 | if(_alpha){ |
| 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)); |
| 29 | } |
| 30 | } |
| 31 | QLinearGradient gradient(1., 0., w - 1, 0.); |
| 32 | gradient.setStops(_stops); |
| 33 | painter.fillRect(1, 1, w - 2, h - 2, QBrush(gradient)); |
| 34 | setIconSize(QSize(w, h)); |
| 35 | setIcon(QIcon(QPixmap::fromImage(image))); |
| 36 | } |
| 37 | |
| 38 | void GradientButton::fromString(const QString& string){ |
| 39 | // Clear existing stops |