krita/ui
kis_autogradient.ccGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kis_autogradient.h"
00021 #include <QPainter>
00022 #include <QComboBox>
00023
00024 #include <kcolorbutton.h>
00025 #include <knuminput.h>
00026
00027 #include <KoColorSpace.h>
00028 #include <KoSegmentGradient.h>
00029
00030 #include "kis_autogradient_resource.h"
00031 #include "kis_debug.h"
00032
00033 #include "widgets/kis_gradient_slider_widget.h"
00034
00035
00036
00037 KisAutogradient::KisAutogradient(QWidget *parent, const char* name, const QString& caption) : QWidget(parent)
00038 {
00039 setObjectName(name);
00040 setupUi(this);
00041 setWindowTitle(caption);
00042 m_autogradientResource = new KisAutogradientResource();
00043 m_autogradientResource->createSegment(INTERP_LINEAR, COLOR_INTERP_RGB, 0.0, 1.0, 0.5, Qt::black, Qt::white);
00044 gradientSlider->setGradientResource(m_autogradientResource);
00045
00046 connect(gradientSlider, SIGNAL(sigSelectedSegment(KoGradientSegment*)), SLOT(slotSelectedSegment(KoGradientSegment*)));
00047 connect(gradientSlider, SIGNAL(sigChangedSegment(KoGradientSegment*)), SLOT(slotChangedSegment(KoGradientSegment*)));
00048 connect(comboBoxColorInterpolationType, SIGNAL(activated(int)), SLOT(slotChangedColorInterpolation(int)));
00049 connect(comboBoxInterpolationType, SIGNAL(activated(int)), SLOT(slotChangedInterpolation(int)));
00050 connect(leftColorButton, SIGNAL(changed(const QColor&)), SLOT(slotChangedLeftColor(const QColor&)));
00051 connect(rightColorButton, SIGNAL(changed(const QColor&)), SLOT(slotChangedRightColor(const QColor&)));
00052
00053 connect(intNumInputLeftOpacity, SIGNAL(valueChanged(int)), SLOT(slotChangedLeftOpacity(int)));
00054 connect(intNumInputRightOpacity, SIGNAL(valueChanged(int)), SLOT(slotChangedRightOpacity(int)));
00055
00056 }
00057
00058 void KisAutogradient::activate()
00059 {
00060 paramChanged();
00061 }
00062
00063 void KisAutogradient::slotSelectedSegment(KoGradientSegment* segment)
00064 {
00065 QColor startColor;
00066 QColor endColor;
00067
00068 segment->startColor().toQColor(&startColor);
00069 segment->endColor().toQColor(&endColor);
00070
00071 leftColorButton->setColor(startColor);
00072 rightColorButton->setColor(endColor);
00073 comboBoxColorInterpolationType->setCurrentIndex(segment->colorInterpolation());
00074 comboBoxInterpolationType->setCurrentIndex(segment->interpolation());
00075
00076 int leftOpacity = (startColor.alpha() * 100) / OPACITY_OPAQUE;
00077 intNumInputLeftOpacity->setValue(leftOpacity);
00078
00079 int rightOpacity = (endColor.alpha() * 100) / OPACITY_OPAQUE;
00080 intNumInputRightOpacity->setValue(rightOpacity);
00081
00082 paramChanged();
00083 }
00084
00085 void KisAutogradient::slotChangedSegment(KoGradientSegment*)
00086 {
00087 paramChanged();
00088 }
00089
00090 void KisAutogradient::slotChangedInterpolation(int type)
00091 {
00092 KoGradientSegment* segment = gradientSlider->selectedSegment();
00093 if (segment)
00094 segment->setInterpolation(type);
00095 gradientSlider->update();
00096
00097 paramChanged();
00098 }
00099
00100 void KisAutogradient::slotChangedColorInterpolation(int type)
00101 {
00102 KoGradientSegment* segment = gradientSlider->selectedSegment();
00103 if (segment)
00104 segment->setColorInterpolation(type);
00105 gradientSlider->update();
00106
00107 paramChanged();
00108 }
00109
00110 void KisAutogradient::slotChangedLeftColor(const QColor& color)
00111 {
00112 KoGradientSegment* segment = gradientSlider->selectedSegment();
00113 if (segment) {
00114 KoColor c(color, segment->startColor().colorSpace());
00115 c.setOpacity(segment->startColor().opacity());
00116 segment->setStartColor(c);
00117 }
00118 gradientSlider->update();
00119
00120 paramChanged();
00121 }
00122
00123 void KisAutogradient::slotChangedRightColor(const QColor& color)
00124 {
00125 KoGradientSegment* segment = gradientSlider->selectedSegment();
00126 if (segment) {
00127 QColor unused;
00128 KoColor c(color, segment->endColor().colorSpace());
00129 c.setOpacity(segment->endColor().opacity());
00130 segment->setEndColor(c);
00131 }
00132 gradientSlider->repaint();
00133
00134 paramChanged();
00135 }
00136
00137 void KisAutogradient::slotChangedLeftOpacity(int value)
00138 {
00139 KoGradientSegment* segment = gradientSlider->selectedSegment();
00140 if (segment) {
00141 KoColor c(segment->startColor().toQColor(), segment->startColor().colorSpace());
00142 c.setOpacity((value * OPACITY_OPAQUE) / 100);
00143 segment->setStartColor(c);
00144 }
00145 gradientSlider->repaint();
00146
00147 paramChanged();
00148 }
00149
00150 void KisAutogradient::slotChangedRightOpacity(int value)
00151 {
00152 KoGradientSegment* segment = gradientSlider->selectedSegment();
00153 if (segment) {
00154 KoColor c(segment->endColor().toQColor(), segment->endColor().colorSpace());
00155 c.setOpacity((value *OPACITY_OPAQUE) / 100);
00156 segment->setEndColor(c);
00157 }
00158 gradientSlider->repaint();
00159
00160 paramChanged();
00161 }
00162
00163 void KisAutogradient::paramChanged()
00164 {
00165 m_autogradientResource->updatePreview();
00166 emit activatedResource(m_autogradientResource);
00167 }
00168
00169 #include "kis_autogradient.moc"
|