krita

kis_autogradient.cc

00001 /*
00002  *  Copyright (c) 2004 Cyrille Berger <cberger@cberger.net>
00003  *                2004 Sven Langkamp <longamp@reallygood.de>
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
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 /****************************** KisAutogradient ******************************/
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 //     intNumInputLeftOpacity->setRange( 0, 100, false);
00049     connect(intNumInputLeftOpacity, SIGNAL( valueChanged(int) ), SLOT( slotChangedLeftOpacity(int) ));
00050 //     intNumInputRightOpacity->setRange( 0, 100, false);
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"
KDE Home | KDE Accessibility Home | Description of Access Keys