- Save/load palettes properly
[dashstudio.git] / src / components / colorpalette / mixer.cpp
blobb9e021229eaf38155576e2c65074f3dc1896d91f
1 /***************************************************************************
2 * Copyright (C) 2007 by Jorge Cuadrado *
3 * kuadrosxx@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "mixer.h"
23 #include "colorcreator.h"
24 #include "gradientcreator.h"
27 //Qt
28 #include <QVBoxLayout>
29 #include <QGroupBox>
31 struct Mixer::Private {
32 ColorCreator *mixer;
33 Component::GradientCreator *gradientCreator;
34 QGroupBox *gradientBox;
37 Mixer::Mixer(QWidget *parent)
38 : QWidget(parent), d (new Private)
40 setWindowTitle("Color Mixer");
43 QGroupBox *colorBox = new QGroupBox("Color");
44 QVBoxLayout *colorBoxLayout = new QVBoxLayout(colorBox);
46 QVBoxLayout *layout = new QVBoxLayout(this);
48 d->mixer = new ColorCreator(colorBox);
49 connect(d->mixer, SIGNAL(colorChanged(const QColor &)), this, SLOT(onColorChanged(const QColor &)));
50 colorBoxLayout->addWidget(d->mixer);
53 layout->addWidget(colorBox);
55 d->gradientBox = new QGroupBox("Gradient");
57 QVBoxLayout *gradientBoxLayout = new QVBoxLayout(d->gradientBox);
59 d->gradientBox->setCheckable(true);
60 d->gradientBox->setChecked(false);
62 d->gradientCreator = new Component::GradientCreator;
63 gradientBoxLayout->addWidget(d->gradientCreator);
64 connect(d->gradientCreator, SIGNAL(gradientChanged(const QBrush &)), this, SLOT(onGradientChanged(const QBrush &)));
66 colorBoxLayout->addWidget(d->mixer);
68 layout->addWidget(d->gradientBox);
72 Mixer::~Mixer()
74 delete d;
77 void Mixer::setBrush( const QBrush & brush)
79 const QGradient *gradient = brush.gradient();
81 if(gradient)
83 d->gradientBox->setChecked(true);
84 d->gradientCreator->setGradient(brush);
86 else if(brush.color().isValid())
88 d->gradientBox->setChecked(false);
89 d->mixer->setColor(brush.color());
93 QBrush Mixer::brush() const
95 if(d->gradientBox->isChecked())
97 return d->gradientCreator->currentGradient();
100 return QBrush(d->mixer->color());
103 void Mixer::onColorChanged( const QColor & color )
105 if(d->gradientBox->isChecked())
107 d->gradientCreator->setCurrentColor(color);
109 else
111 emit brushChanged(QBrush(color));
115 void Mixer::onGradientChanged(const QBrush &brush)
117 if(d->gradientBox->isChecked())
119 emit brushChanged(brush);