krita
kis_autogradient.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kis_autogradient.h"
00021
00022 #include <qpainter.h>
00023 #include <qcombobox.h>
00024
00025 #include <kcolorbutton.h>
00026 #include <knuminput.h>
00027 #include "kis_int_spinbox.h"
00028 #include "kis_gradient.h"
00029 #include "kis_autogradient_resource.h"
00030
00031 #include "kis_gradient_slider_widget.h"
00032
00033
00034
00035 KisAutogradient::KisAutogradient(QWidget *parent, const char* name, const QString& caption) : KisWdgAutogradient(parent, name)
00036 {
00037 setCaption(caption);
00038 m_autogradientResource = new KisAutogradientResource();
00039 m_autogradientResource->createSegment( INTERP_LINEAR, COLOR_INTERP_RGB, 0.0, 1.0, 0.5, Qt::black, Qt::white );
00040 connect(gradientSlider, SIGNAL( sigSelectedSegment( KisGradientSegment* ) ), SLOT( slotSelectedSegment(KisGradientSegment*) ));
00041 connect(gradientSlider, SIGNAL( sigChangedSegment(KisGradientSegment*) ), SLOT( slotChangedSegment(KisGradientSegment*) ));
00042 gradientSlider->setGradientResource( m_autogradientResource );
00043 connect(comboBoxColorInterpolationType, SIGNAL( activated(int) ), SLOT( slotChangedColorInterpolation(int) ));
00044 connect(comboBoxInterpolationType, SIGNAL( activated(int) ), SLOT( slotChangedInterpolation(int) ));
00045 connect(leftColorButton, SIGNAL( changed(const QColor&) ), SLOT( slotChangedLeftColor(const QColor&) ));
00046 connect(rightColorButton, SIGNAL( changed(const QColor&) ), SLOT( slotChangedRightColor(const QColor&) ));
00047
00048
00049 connect(intNumInputLeftOpacity, SIGNAL( valueChanged(int) ), SLOT( slotChangedLeftOpacity(int) ));
00050
00051 connect(intNumInputRightOpacity, SIGNAL( valueChanged(int) ), SLOT( slotChangedRightOpacity(int) ));
00052
00053 }
00054
00055 void KisAutogradient::activate()
00056 {
00057 paramChanged();
00058 }
00059
00060 void KisAutogradient::slotSelectedSegment(KisGradientSegment* segment)
00061 {
00062 leftColorButton->setColor( segment->startColor().color() );
00063 rightColorButton->setColor( segment->endColor().color() );
00064 comboBoxColorInterpolationType->setCurrentItem( segment->colorInterpolation() );
00065 comboBoxInterpolationType->setCurrentItem( segment->interpolation() );
00066
00067 int leftOpacity = qRound(segment->startColor().alpha() * 100);
00068 intNumInputLeftOpacity->setValue( leftOpacity );
00069
00070 int rightOpacity = qRound(segment->endColor().alpha() * 100);
00071 intNumInputRightOpacity->setValue( rightOpacity );
00072
00073 paramChanged();
00074 }
00075
00076 void KisAutogradient::slotChangedSegment(KisGradientSegment*)
00077 {
00078 paramChanged();
00079 }
00080
00081 void KisAutogradient::slotChangedInterpolation(int type)
00082 {
00083 KisGradientSegment* segment = gradientSlider->selectedSegment();
00084 if(segment)
00085 segment->setInterpolation( type );
00086 gradientSlider->update();
00087
00088 paramChanged();
00089 }
00090
00091 void KisAutogradient::slotChangedColorInterpolation(int type)
00092 {
00093 KisGradientSegment* segment = gradientSlider->selectedSegment();
00094 if(segment)
00095 segment->setColorInterpolation( type );
00096 gradientSlider->update();
00097
00098 paramChanged();
00099 }
00100
00101 void KisAutogradient::slotChangedLeftColor( const QColor& color)
00102 {
00103 KisGradientSegment* segment = gradientSlider->selectedSegment();
00104 if(segment)
00105 segment->setStartColor( Color( color, segment->startColor().alpha() ) );
00106 gradientSlider->update();
00107
00108 paramChanged();
00109 }
00110
00111 void KisAutogradient::slotChangedRightColor( const QColor& color)
00112 {
00113 KisGradientSegment* segment = gradientSlider->selectedSegment();
00114 if(segment)
00115 segment->setEndColor( Color( color, segment->endColor().alpha() ) );
00116 gradientSlider->repaint();
00117
00118 paramChanged();
00119 }
00120
00121 void KisAutogradient::slotChangedLeftOpacity( int value )
00122 {
00123 KisGradientSegment* segment = gradientSlider->selectedSegment();
00124 if(segment)
00125 segment->setStartColor( Color( segment->startColor().color(), (double)value / 100 ) );
00126 gradientSlider->repaint(false);
00127
00128 paramChanged();
00129 }
00130
00131 void KisAutogradient::slotChangedRightOpacity( int value )
00132 {
00133 KisGradientSegment* segment = gradientSlider->selectedSegment();
00134 if(segment)
00135 segment->setEndColor( Color( segment->endColor().color(), (double)value / 100 ) );
00136 gradientSlider->repaint(false);
00137
00138 paramChanged();
00139 }
00140
00141 void KisAutogradient::paramChanged()
00142 {
00143 m_autogradientResource->updatePreview ();
00144 emit activatedResource( m_autogradientResource );
00145 }
00146
00147 #include "kis_autogradient.moc"
|