| 28 | } |
| 29 | |
| 30 | void GradientDialogWidget::makeStops(){ |
| 31 | _stops.clear(); |
| 32 | QMap<int, QColor> colors = selectionColors(); |
| 33 | // If there's only a single color, put it at the beginning and end |
| 34 | if(colors.count() == 1){ |
| 35 | #if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) |
| 36 | QColor color = colors.first(); |
| 37 | #else |
| 38 | QColor color = colors.value(colors.keys().first()); |
| 39 | #endif |
| 40 | _stops.append(QGradientStop(0., color)); |
| 41 | _stops.append(QGradientStop(1., color)); |
| 42 | update(); |
| 43 | return; |
| 44 | } |
| 45 | // Add colors at 0 and 100 if needed |
| 46 | #if QT_VERSION >= QT_VERSION_CHECK(5, 2, 0) |
| 47 | if(!colors.contains(0)) |
| 48 | colors[0] = colors.first(); |
| 49 | if(!colors.contains(100)) |
| 50 | colors[100] = colors.last(); |
| 51 | #else |
| 52 | if(!colors.contains(0)) |
| 53 | colors[0] = colors.value(colors.keys().first()); |
| 54 | if(!colors.contains(100)) |
| 55 | colors[100] = colors.value(colors.keys().last()); |
| 56 | #endif |
| 57 | QMapIterator<int, QColor> i(colors); |
| 58 | while(i.hasNext()){ |
| 59 | i.next(); |
| 60 | _stops.append(QGradientStop(i.key() / 100., i.value())); |
| 61 | } |
| 62 | update(); |
| 63 | } |
| 64 | |
| 65 | QColor GradientDialogWidget::colorAt(int position){ |
| 66 | // Find which stops the position is between |