chalk

kis_autogradient.cpp
1/*
2 * Copyright (c) 2004 Cyrille Berger <cberger@cberger.net>
3 * 2004 Sven Langkamp <longamp@reallygood.de>
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 Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20#include "kis_autogradient.h"
21
22#include <tqpainter.h>
23#include <tqcombobox.h>
24
25#include <kcolorbutton.h>
26#include <knuminput.h>
27#include "kis_int_spinbox.h"
28#include "kis_gradient.h"
29#include "kis_autogradient_resource.h"
30
31#include "kis_gradient_slider_widget.h"
32
33/****************************** KisAutogradient ******************************/
34
35KisAutogradient::KisAutogradient(TQWidget *parent, const char* name, const TQString& caption) : KisWdgAutogradient(parent, name)
36{
37 setCaption(caption);
38 m_autogradientResource = new KisAutogradientResource();
39 m_autogradientResource->createSegment( INTERP_LINEAR, COLOR_INTERP_RGB, 0.0, 1.0, 0.5, TQt::black, TQt::white );
40 connect(gradientSlider, TQ_SIGNAL( sigSelectedSegment( KisGradientSegment* ) ), TQ_SLOT( slotSelectedSegment(KisGradientSegment*) ));
41 connect(gradientSlider, TQ_SIGNAL( sigChangedSegment(KisGradientSegment*) ), TQ_SLOT( slotChangedSegment(KisGradientSegment*) ));
42 gradientSlider->setGradientResource( m_autogradientResource );
43 connect(comboBoxColorInterpolationType, TQ_SIGNAL( activated(int) ), TQ_SLOT( slotChangedColorInterpolation(int) ));
44 connect(comboBoxInterpolationType, TQ_SIGNAL( activated(int) ), TQ_SLOT( slotChangedInterpolation(int) ));
45 connect(leftColorButton, TQ_SIGNAL( changed(const TQColor&) ), TQ_SLOT( slotChangedLeftColor(const TQColor&) ));
46 connect(rightColorButton, TQ_SIGNAL( changed(const TQColor&) ), TQ_SLOT( slotChangedRightColor(const TQColor&) ));
47
48// intNumInputLeftOpacity->setRange( 0, 100, false);
49 connect(intNumInputLeftOpacity, TQ_SIGNAL( valueChanged(int) ), TQ_SLOT( slotChangedLeftOpacity(int) ));
50// intNumInputRightOpacity->setRange( 0, 100, false);
51 connect(intNumInputRightOpacity, TQ_SIGNAL( valueChanged(int) ), TQ_SLOT( slotChangedRightOpacity(int) ));
52
53}
54
55void KisAutogradient::activate()
56{
57 paramChanged();
58}
59
60void KisAutogradient::slotSelectedSegment(KisGradientSegment* segment)
61{
62 leftColorButton->setColor( segment->startColor().color() );
63 rightColorButton->setColor( segment->endColor().color() );
64 comboBoxColorInterpolationType->setCurrentItem( segment->colorInterpolation() );
65 comboBoxInterpolationType->setCurrentItem( segment->interpolation() );
66
67 int leftOpacity = tqRound(segment->startColor().alpha() * 100);
68 intNumInputLeftOpacity->setValue( leftOpacity );
69
70 int rightOpacity = tqRound(segment->endColor().alpha() * 100);
71 intNumInputRightOpacity->setValue( rightOpacity );
72
73 paramChanged();
74}
75
76void KisAutogradient::slotChangedSegment(KisGradientSegment*)
77{
78 paramChanged();
79}
80
81void KisAutogradient::slotChangedInterpolation(int type)
82{
83 KisGradientSegment* segment = gradientSlider->selectedSegment();
84 if(segment)
85 segment->setInterpolation( type );
86 gradientSlider->update();
87
88 paramChanged();
89}
90
91void KisAutogradient::slotChangedColorInterpolation(int type)
92{
93 KisGradientSegment* segment = gradientSlider->selectedSegment();
94 if(segment)
95 segment->setColorInterpolation( type );
96 gradientSlider->update();
97
98 paramChanged();
99}
100
101void KisAutogradient::slotChangedLeftColor( const TQColor& color)
102{
103 KisGradientSegment* segment = gradientSlider->selectedSegment();
104 if(segment)
105 segment->setStartColor( Color( color, segment->startColor().alpha() ) );
106 gradientSlider->update();
107
108 paramChanged();
109}
110
111void KisAutogradient::slotChangedRightColor( const TQColor& color)
112{
113 KisGradientSegment* segment = gradientSlider->selectedSegment();
114 if(segment)
115 segment->setEndColor( Color( color, segment->endColor().alpha() ) );
116 gradientSlider->repaint();
117
118 paramChanged();
119}
120
121void KisAutogradient::slotChangedLeftOpacity( int value )
122{
123 KisGradientSegment* segment = gradientSlider->selectedSegment();
124 if(segment)
125 segment->setStartColor( Color( segment->startColor().color(), (double)value / 100 ) );
126 gradientSlider->repaint(false);
127
128 paramChanged();
129}
130
131void KisAutogradient::slotChangedRightOpacity( int value )
132{
133 KisGradientSegment* segment = gradientSlider->selectedSegment();
134 if(segment)
135 segment->setEndColor( Color( segment->endColor().color(), (double)value / 100 ) );
136 gradientSlider->repaint(false);
137
138 paramChanged();
139}
140
141void KisAutogradient::paramChanged()
142{
143 m_autogradientResource->updatePreview ();
144 emit activatedResource( m_autogradientResource );
145}
146
147#include "kis_autogradient.moc"