1 /***************************************************************************
2 * Copyright (C) 2007 by Jorge Cuadrado *
3 * kuadrosxx@gmail.com *
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. *
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. *
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 ***************************************************************************/
23 #include "colorcreator.h"
24 #include "gradientcreator.h"
28 #include <QVBoxLayout>
31 struct Mixer::Private
{
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
);
77 void Mixer::setBrush( const QBrush
& brush
)
79 const QGradient
*gradient
= brush
.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
);
111 emit
brushChanged(QBrush(color
));
115 void Mixer::onGradientChanged(const QBrush
&brush
)
117 if(d
->gradientBox
->isChecked())
119 emit
brushChanged(brush
);