9 static const QString
prefsPath =
"Stored Gradients";
20 Preset blackAndWhite(
"B & W",
true);
21 blackAndWhite.
gradient.append(QGradientStop(0., QColor(0, 0, 0)));
22 blackAndWhite.
gradient.append(QGradientStop(1., QColor(255, 255, 255)));
24 fade.
gradient.append(QGradientStop(0., QColor(255, 255, 255)));
25 fade.
gradient.append(QGradientStop(1., QColor(255, 255, 255, 0)));
26 Preset rainbow(
"Rainbow",
true);
27 rainbow.
gradient.append(QGradientStop(0.00, QColor(255, 0, 0)));
28 rainbow.
gradient.append(QGradientStop(0.17, QColor(255, 255, 0)));
29 rainbow.
gradient.append(QGradientStop(0.33, QColor(0, 255, 0)));
30 rainbow.
gradient.append(QGradientStop(0.50, QColor(0, 255, 255)));
31 rainbow.
gradient.append(QGradientStop(0.67, QColor(0, 0, 255)));
32 rainbow.
gradient.append(QGradientStop(0.83, QColor(255, 0, 255)));
33 rainbow.
gradient.append(QGradientStop(1.00, QColor(255, 0, 0)));
40 foreach(
const QString& name, settings.
childGroups()){
41 QString pName = name.toLower();
44 SGroup group(settings, name);
46 QMap<int, QColor> colors;
47 foreach(
const QString& position, settings.
childKeys()){
48 int pos = position.toInt();
49 if(pos < 0 || pos > 100)
51 colors[pos] = settings.
value(position).value<QColor>();
53 if(colors.count() < 2)
56 QMapIterator<int, QColor> i(colors);
59 preset.
gradient.append(QGradientStop(i.key() / 100., i.value()));
72 if(result() != QDialog::Accepted)
80 QMapIterator<QString, Preset> i(
presets);
82 Preset preset = i.next().value();
85 foreach(
const QGradientStop& stop, preset.
gradient)
86 settings.
setValue(QString::number((
int)(stop.first * 100.)), stop.second);
95 QImage image(w, h, QImage::Format_RGB888);
96 QPainter painter(&image);
98 for(
int x = 0;
x < w;
x += 30){
99 for(
int y = 0;
y < h;
y += 30){
100 painter.fillRect(
x,
y, 15, 15, QColor(255, 255, 255));
101 painter.fillRect(
x + 15,
y, 15, 15, QColor(192, 192, 192));
102 painter.fillRect(
x,
y + 15, 15, 15, QColor(192, 192, 192));
103 painter.fillRect(
x + 15,
y + 15, 15, 15, QColor(255, 255, 255));
107 painter.setPen(QColor(0, 0, 0));
108 QLinearGradient gradient(1., 1., w - 1., h - 1.);
110 painter.setBrush(gradient);
111 painter.drawRect(0, 0, w - 1, h - 1);
112 return QPixmap::fromImage(image);
117 QMapIterator<QString, Preset> i(
presets);
120 const Preset& preset = i.value();
123 item->setSelected(
true);
133 ui->
stopBox->setTitle(QString(
"%1 points").arg(pCount));
134 if(!color.isValid()){
159 if(curName ==
"" || (curName == current.
name && current.
builtIn))
175 setPreset(current ? current->text().toLower() :
"");
189 QString pName = name.toLower();
193 QMessageBox::warning(
this,
"Error",
"Can't overwrite a built-in preset. Please choose a different name.");
196 }
else if(previous.
name !=
""){
198 if(QMessageBox::warning(
this,
"Warning", QString(
"Preset \"%1\" already exists. Replace?").arg(name), QMessageBox::StandardButtons(QMessageBox::Save | QMessageBox::Cancel)) != QMessageBox::Save){
215 if(QMessageBox::warning(
this,
"Warning", QString(
"Delete preset \"%1\"?").arg(current.
name), QMessageBox::StandardButtons(QMessageBox::Yes | QMessageBox::No)) != QMessageBox::Yes){
void currentChanged(QColor color, bool spontaneous, int position)
void setValue(const QString &key, const QVariant &value)
QStringList childKeys() const
GradientDialogWidget * widget
QMap< QString, Preset > presets
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
void on_presetDelete_clicked()
void on_stopPos_valueChanged(int arg1)
void on_presetList_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
void setupUi(QDialog *GradientDialog)
void on_stopOpacity_valueChanged(int arg1)
QGradientStops getGradient(const QGradientStops &prevGradient)
void setPreset(const QString &newPreset)
void on_presetName_textEdited(const QString &arg1)
static const QString prefsPath
GradientDialog(QWidget *parent=0)
void on_presetSave_clicked()
QStringList childGroups() const
QPushButton * presetDelete
void colorChanged(QColor color)
void addPreset(const Preset &preset)
QIcon makeIcon(const Preset &preset)