1 /***************************************************************************
2 * Copyright (C) 2005 by Jorge Cuadrado *
3 * kuadrosx@toonka.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 ***************************************************************************/
21 #include "gradientcreator.h"
23 #include <dcore/debug.h>
24 #include <dgui/application.h>
28 #include <dgui/imagebutton.h>
29 // #include <dgui/circlebutton.h>
30 #include <dgui/xyspinbox.h>
37 #include "private/gradientselector.h"
38 #include "private/gradientviewer.h"
41 namespace Components
{
43 struct GradientCreator::Private
45 GradientSelector
*selector
;
46 GradientViewer
*viewer
;
47 // DRadioButtonGroup *d->type, *d->spread ;
48 QComboBox
*type
, *spread
;
50 SpinControl
*spinControl
;
53 GradientCreator::GradientCreator(QWidget
*parent
)
54 : QFrame(parent
), d(new Private
)
56 QBoxLayout
*layout
= new QBoxLayout(QBoxLayout::LeftToRight
);
58 layout
->setSpacing(2);
62 QBoxLayout
*selectorAndViewer
= new QBoxLayout(QBoxLayout::TopToBottom
);
64 d
->selector
= new GradientSelector(this);
65 d
->viewer
= new GradientViewer(this);
67 connect(d
->viewer
, SIGNAL(gradientChanged()), this, SLOT(emitGradientChanged()));
68 layout
->addLayout(selectorAndViewer
);
70 selectorAndViewer
->addWidget(d
->viewer
);
71 selectorAndViewer
->addWidget(d
->selector
);
72 selectorAndViewer
->addStretch(2);
74 connect( d
->selector
, SIGNAL(gradientChanged( const QGradientStops
& )),this, SLOT(changeGradientStops( const QGradientStops
& )));
75 connect(d
->selector
, SIGNAL(arrowAdded()), this, SIGNAL(controlArrowAdded()));
79 QBoxLayout
*subLayout
= new QBoxLayout(QBoxLayout::TopToBottom
);
80 layout
->addLayout(subLayout
);
83 d
->type
= new QComboBox(this);
85 list
<< tr( "Linear" ) << tr( "Radial" ) << tr("Conical");
86 d
->type
->addItems ( list
);
87 connect( d
->type
, SIGNAL( activated ( int )),this, SLOT(changeType(int)));
88 subLayout
->addWidget( d
->type
);
90 d
->spread
= new QComboBox(this);
92 list
<< tr( "Pad" ) << tr( "Reflect" ) << tr("Repeat");
93 d
->spread
->addItems ( list
);
94 connect( d
->spread
, SIGNAL( activated ( int )),this, SLOT(changeSpread(int)));
95 subLayout
->addWidget( d
->spread
);
97 d
->radius
= new QSpinBox
;
98 d
->radius
->setValue(50);
100 connect(d
->radius
, SIGNAL(valueChanged(int)), d
->viewer
, SLOT(changeRadius(int)));
102 subLayout
->addWidget(d
->radius
);
104 subLayout
->setSpacing(2);
105 subLayout
->setMargin(2);
107 setFrameStyle(QFrame::StyledPanel
);
109 subLayout
->addStretch(2);
113 GradientCreator::~GradientCreator()
119 void GradientCreator::setCurrentColor(const QColor
&color
)
121 d
->selector
->setCurrentColor(color
);
122 d
->viewer
->createGradient();
123 emit
gradientChanged(QBrush(d
->viewer
->gradient()));
126 int GradientCreator::gradientType()
128 return d
->type
->currentIndex();
132 void GradientCreator::changeType(int type
)
134 d
->viewer
->changeType( type
);
136 if( type
== QGradient::RadialGradient
)
140 else if(d
->radius
->isVisible())
146 emitGradientChanged();
149 void GradientCreator::changeSpread(int spread
)
151 d
->viewer
->setSpread( spread
);
152 emitGradientChanged();
156 void GradientCreator::changeGradientStops( const QGradientStops
& stops
)
158 d
->viewer
->changeGradientStops( stops
);
159 emit
gradientChanged(d
->viewer
->gradient());
162 void GradientCreator::setGradient(const QBrush
& gradient
)
164 // blockSignals ( true);
165 const QGradient
*gr
= gradient
.gradient();
166 d
->type
->setCurrentIndex(gr
->type());
167 d
->spread
->setCurrentIndex(gr
->spread());
168 d
->selector
->setStops(gr
->stops());
169 d
->viewer
->setGradient( gr
);
172 if( gr
->type() == QGradient::RadialGradient
)
175 d
->radius
->setValue( (int) static_cast<const QRadialGradient
*>(gr
)->radius());
177 else if(d
->radius
->isVisible())
182 // blockSignals ( false);
185 void GradientCreator::emitGradientChanged()
187 d
->viewer
->changeGradientStops(d
->selector
->gradientStops());
188 emit
gradientChanged(d
->viewer
->gradient());
191 QBrush
GradientCreator::currentGradient()
193 return QBrush(d
->viewer
->gradient());
197 QSize
GradientCreator::sizeHint () const
199 QSize size
= QFrame::sizeHint();
201 return size
.expandedTo(QApplication::globalStrut());