diff --git a/libs/pigment/resources/KoSegmentGradient.h b/libs/pigment/resources/KoSegmentGradient.h index 873d206f00..24cfd50aad 100644 --- a/libs/pigment/resources/KoSegmentGradient.h +++ b/libs/pigment/resources/KoSegmentGradient.h @@ -1,474 +1,484 @@ /* Copyright (c) 2000 Matthias Elter 2004 Boudewijn Rempt 2004 Adrian Page 2004, 2007 Sven Langkamp 2017 Wolthera van Hövell tot Westerflier This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef KOSEGMENTGRADIENT_H #define KOSEGMENTGRADIENT_H #include #include #include #include #include "KoColor.h" #include enum { INTERP_LINEAR = 0, INTERP_CURVED, INTERP_SINE, INTERP_SPHERE_INCREASING, INTERP_SPHERE_DECREASING }; enum { COLOR_INTERP_RGB, COLOR_INTERP_HSV_CCW, COLOR_INTERP_HSV_CW }; //For saving to .ggr to match GIMP format, we also have Foreground (transparent) and Background (transparent) modes, currently unused... enum KoGradientSegmentEndpointType { COLOR_ENDPOINT, FOREGROUND_ENDPOINT, FOREGROUND_TRANSPARENT_ENDPOINT, BACKGROUND_ENDPOINT, BACKGROUND_TRANSPARENT_ENDPOINT }; struct KoGradientSegmentEndpoint { KoGradientSegmentEndpoint(qreal _off, KoColor _color, KoGradientSegmentEndpointType _type) : offset(_off), color(_color), type(_type) { } qreal offset; KoColor color; KoGradientSegmentEndpointType type; }; /// Write API docs here class KRITAPIGMENT_EXPORT KoGradientSegment { public: KoGradientSegment(int interpolationType, int colorInterpolationType, KoGradientSegmentEndpoint start, KoGradientSegmentEndpoint end, qreal middleOffset); // startOffset <= t <= endOffset void colorAt(KoColor&, qreal t) const; const KoColor& startColor() const; const KoColor& endColor() const; const KoGradientSegmentEndpointType startType() const; const KoGradientSegmentEndpointType endType() const; void setStartColor(const KoColor& color) { m_start.color = color; + if (m_start.type == FOREGROUND_TRANSPARENT_ENDPOINT || m_start.type == BACKGROUND_TRANSPARENT_ENDPOINT) { + m_start.color.setOpacity(quint8(0)); + } else if (m_start.type == FOREGROUND_ENDPOINT || m_start.type == BACKGROUND_ENDPOINT) { + m_start.color.setOpacity(quint8(255)); + } } void setEndColor(const KoColor& color) { m_end.color = color; + if (m_end.type == FOREGROUND_TRANSPARENT_ENDPOINT || m_end.type == BACKGROUND_TRANSPARENT_ENDPOINT) { + m_end.color.setOpacity(quint8(0)); + } else if (m_end.type == FOREGROUND_ENDPOINT || m_end.type == BACKGROUND_ENDPOINT) { + m_end.color.setOpacity(quint8(255)); + } } void setStartType(KoGradientSegmentEndpointType type); void setEndType(KoGradientSegmentEndpointType type); qreal startOffset() const; qreal middleOffset() const; qreal endOffset() const; void setStartOffset(qreal t); void setMiddleOffset(qreal t); void setEndOffset(qreal t); void setVariableColors(const KoColor& foreground, const KoColor& background); bool hasVariableColors(); qreal length() { return m_length; } int interpolation() const; int colorInterpolation() const; void setInterpolation(int interpolationType); void setColorInterpolation(int colorInterpolationType); void mirrorSegment(); bool isValid() const; protected: class ColorInterpolationStrategy { public: ColorInterpolationStrategy() {} virtual ~ColorInterpolationStrategy() {} virtual void colorAt(KoColor& dst, qreal t, const KoColor& start, const KoColor& end) const = 0; virtual int type() const = 0; }; class RGBColorInterpolationStrategy : public ColorInterpolationStrategy { public: static RGBColorInterpolationStrategy *instance(); void colorAt(KoColor& dst, qreal t, const KoColor& start, const KoColor& end) const override; int type() const override { return COLOR_INTERP_RGB; } private: RGBColorInterpolationStrategy(); static RGBColorInterpolationStrategy *m_instance; const KoColorSpace * const m_colorSpace; }; class HSVCWColorInterpolationStrategy : public ColorInterpolationStrategy { public: static HSVCWColorInterpolationStrategy *instance(); void colorAt(KoColor& dst, qreal t, const KoColor& start, const KoColor& end) const override; int type() const override { return COLOR_INTERP_HSV_CW; } private: HSVCWColorInterpolationStrategy(); static HSVCWColorInterpolationStrategy *m_instance; const KoColorSpace * const m_colorSpace; }; class HSVCCWColorInterpolationStrategy : public ColorInterpolationStrategy { public: static HSVCCWColorInterpolationStrategy *instance(); void colorAt(KoColor& dst, qreal t, const KoColor& start, const KoColor& end) const override; int type() const override { return COLOR_INTERP_HSV_CCW; } private: HSVCCWColorInterpolationStrategy(); static HSVCCWColorInterpolationStrategy *m_instance; const KoColorSpace * const m_colorSpace; }; class InterpolationStrategy { public: InterpolationStrategy() {} virtual ~InterpolationStrategy() {} virtual qreal valueAt(qreal t, qreal middle) const = 0; virtual int type() const = 0; }; class LinearInterpolationStrategy : public InterpolationStrategy { public: static LinearInterpolationStrategy *instance(); qreal valueAt(qreal t, qreal middle) const override; int type() const override { return INTERP_LINEAR; } // This does the actual calculation and is made // static as an optimization for the other // strategies that need this for their own calculation. static qreal calcValueAt(qreal t, qreal middle); private: LinearInterpolationStrategy() {} static LinearInterpolationStrategy *m_instance; }; class CurvedInterpolationStrategy : public InterpolationStrategy { public: static CurvedInterpolationStrategy *instance(); qreal valueAt(qreal t, qreal middle) const override; int type() const override { return INTERP_CURVED; } private: CurvedInterpolationStrategy(); static CurvedInterpolationStrategy *m_instance; qreal m_logHalf; }; class SphereIncreasingInterpolationStrategy : public InterpolationStrategy { public: static SphereIncreasingInterpolationStrategy *instance(); qreal valueAt(qreal t, qreal middle) const override; int type() const override { return INTERP_SPHERE_INCREASING; } private: SphereIncreasingInterpolationStrategy() {} static SphereIncreasingInterpolationStrategy *m_instance; }; class SphereDecreasingInterpolationStrategy : public InterpolationStrategy { public: static SphereDecreasingInterpolationStrategy *instance(); qreal valueAt(qreal t, qreal middle) const override; int type() const override { return INTERP_SPHERE_DECREASING; } private: SphereDecreasingInterpolationStrategy() {} static SphereDecreasingInterpolationStrategy *m_instance; }; class SineInterpolationStrategy : public InterpolationStrategy { public: static SineInterpolationStrategy *instance(); qreal valueAt(qreal t, qreal middle) const override; int type() const override { return INTERP_SINE; } private: SineInterpolationStrategy() {} static SineInterpolationStrategy *m_instance; }; private: InterpolationStrategy *m_interpolator; ColorInterpolationStrategy *m_colorInterpolator; qreal m_middleOffset; qreal m_length; qreal m_middleT; KoGradientSegmentEndpoint m_start, m_end; bool m_hasVariableColors = false; }; /** * KoSegmentGradient stores a segment based gradients like Gimp gradients */ class KRITAPIGMENT_EXPORT KoSegmentGradient : public KoAbstractGradient { public: explicit KoSegmentGradient(const QString &file = QString()); ~KoSegmentGradient() override; KoSegmentGradient(const KoSegmentGradient &rhs); KoSegmentGradient &operator=(const KoSegmentGradient &rhs) = delete; KoResourceSP clone() const override; bool loadFromDevice(QIODevice *dev, KisResourcesInterfaceSP resourcesInterface) override; bool saveToDevice(QIODevice* dev) const override; QPair resourceType() const override { return QPair(ResourceType::Gradients, ResourceSubType::SegmentedGradients); } /// reimplemented void colorAt(KoColor& dst, qreal t) const override; /// reimplemented bool hasVariableColors() const override; /// reimplemented void setVariableColors(const KoColor& foreground, const KoColor& background) override; /** * Returns the segment at a given position * @param t position inside the gradient, with 0 <= t <= 1 * @return the segment the position, 0 if no segment is found */ KoGradientSegment *segmentAt(qreal t) const; /// reimplemented QGradient* toQGradient() const override; /// reimplemented QString defaultFileExtension() const override; /** * @brief toXML * convert the gradient to xml. */ void toXML(QDomDocument& doc, QDomElement& gradientElt) const; /** * @brief fromXML * get a segment gradient from xml. * @return gradient */ static KoSegmentGradient fromXML(const QDomElement& elt); /** * a gradient colour picker can consist of one or more segments. * A segment has two end points - each colour in the gradient * colour picker represents a segment end point. * @param interpolation * @param colorInterpolation * @param startOffset * @param endOffset * @param middleOffset * @param left * @param right * @param leftType * @param rightType * @return void */ void createSegment(int interpolation, int colorInterpolation, double startOffset, double endOffset, double middleOffset, const QColor & leftColor, const QColor & rightColor, KoGradientSegmentEndpointType leftType = COLOR_ENDPOINT, KoGradientSegmentEndpointType rightType = COLOR_ENDPOINT); /** * gets a list of end points of the segments in the gradient * colour picker. If two colours, one segment then two end * points, and if three colours, then two segments with four * endpoints. * @return a list of double values */ const QList getHandlePositions() const; /** * gets a list of middle points of the segments in the gradient * colour picker. * @return a list of double values */ const QList getMiddleHandlePositions() const; /** * Moves the StartOffset of the specified segment to the * specified value and corrects the endoffset of the previous * segment. If the segment is the first Segment the startoffset * will be set to 0.0 . The offset will maximally be moved till * the middle of the current or the previous segment. This is * useful if someone clicks to move the handler for a segment, * to set the half the segment to the right and half the segment * to the left of the handler. * @param segment the segment for which to move the relative * offset within the gradient colour picker. * @param t the new startoff position for the segment * @return void */ void moveSegmentStartOffset(KoGradientSegment* segment, double t); /** * Moves the endoffset of the specified segment to the specified * value and corrects the startoffset of the following segment. * If the segment is the last segment the endoffset will be set * to 1.0 . The offset will maximally be moved till the middle * of the current or the following segment. This is useful if * someone moves the segment handler in the gradient colour * picker, and needs the segment to move with it. Sets the end * position of the segment to the correct new position. * @param segment the segment for which to move the relative * end position within the gradient colour picker. * @param t the new end position for the segment * @return void */ void moveSegmentEndOffset(KoGradientSegment* segment, double t); /** * moves the Middle of the specified segment to the specified * value. The offset will maximally be moved till the endoffset * or startoffset of the segment. This sets the middle of the * segment to the same position as the handler of the gradient * colour picker. * @param segment the segment for which to move the relative * middle position within the gradient colour picker. * @param t the new middle position for the segment * @return void */ void moveSegmentMiddleOffset(KoGradientSegment* segment, double t); /** * splits the specified segment into two equal parts * @param segment the segment to split * @return void */ void splitSegment(KoGradientSegment* segment); /** * duplicate the specified segment * @param segment the segment to duplicate * @return void */ void duplicateSegment(KoGradientSegment* segment); /** * create a segment horizontally reversed to the specified one. * @param segment the segment to reverse * @return void */ void mirrorSegment(KoGradientSegment* segment); /** * removes the specific segment from the gradient colour picker. * @param segment the segment to remove * @return the segment which will be at the place of the old * segment. 0 if the segment is not in the gradient or it is * not possible to remove the segment. */ KoGradientSegment* removeSegment(KoGradientSegment* segment); /** * checks if it's possible to remove a segment (at least two * segments in the gradient) * @return true if it's possible to remove an segment */ bool removeSegmentPossible() const; const QList& segments() const; protected: inline void pushSegment(KoGradientSegment* segment) { m_segments.push_back(segment); } QList m_segments; private: bool init(); }; typedef QSharedPointer KoSegmentGradientSP; #endif // KOSEGMENTGRADIENT_H diff --git a/libs/ui/forms/wdgautogradient.ui b/libs/ui/forms/wdgautogradient.ui index 491c8a9d17..cf600f7cd7 100644 --- a/libs/ui/forms/wdgautogradient.ui +++ b/libs/ui/forms/wdgautogradient.ui @@ -1,445 +1,473 @@ KisWdgAutogradient 0 0 500 250 500 250 Name: 0 1 Qt::ClickFocus - - + + Sans Serif 9 50 false false false false - Right: + Left: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + 0 0 0 30 Sans Serif 9 50 false false false false Qt::ClickFocus - - - - - 0 - 0 - - - - - Sans Serif - 9 - 50 - false - false - false - false - - - - Qt::ClickFocus - - - 100 - - - 100 - - - - - - - - Sans Serif - 9 - 50 - false - false - false - false - - + + - Opacity: + Color + + + true + + leftBtnGroup + - - + + Sans Serif 9 50 false false false false - Left: + Right: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + - Foreground + Color + + + true - leftBtnGroup + rightBtnGroup Foreground rightBtnGroup - - + + 0 0 0 30 Sans Serif 9 50 false false false false Qt::ClickFocus - - + + Sans Serif 9 50 false false false false - Segment Color + Opacity: Background leftBtnGroup - - - - Color + + + + + 0 + 0 + - - true + + + Sans Serif + 9 + 50 + false + false + false + false + + + + Qt::ClickFocus + + + 100 + + + 100 + + + + + + + Foreground leftBtnGroup - - + + + + + Sans Serif + 9 + 50 + false + false + false + false + + - Color + Segment Color - - true + + + + + + Background rightBtnGroup - - + + - + 0 0 Sans Serif 9 50 false false false false Qt::ClickFocus 100 100 - - + + - Background + Transparent + + + + + + + Transparent + + + + + + + Transparent + + + + + + + Transparent - - rightBtnGroup - 0 0 0 0 Qt::Horizontal 40 20 Sans Serif 9 50 false false false false Qt::ClickFocus Linear Curved Sine Sphere Inc. Sphere Dec. Sans Serif 9 50 false false false false Qt::ClickFocus RGB HSV CW HSV CCW KisColorButton QPushButton
kis_color_button.h
KisIntParseSpinBox QSpinBox
kis_int_parse_spin_box.h
KisGradientSliderWidget
KisGradientSliderWidget.h
diff --git a/libs/ui/kis_autogradient.cc b/libs/ui/kis_autogradient.cc index ccbe961bc8..e6ceaac593 100644 --- a/libs/ui/kis_autogradient.cc +++ b/libs/ui/kis_autogradient.cc @@ -1,255 +1,342 @@ /* * Copyright (c) 2004 Cyrille Berger * 2004 Sven Langkamp * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kis_autogradient.h" #include #include #include #include #include #include #include "kis_debug.h" #include "KisGradientSliderWidget.h" /****************************** KisAutogradient ******************************/ KisAutogradientEditor::KisAutogradientEditor(KoSegmentGradientSP gradient, QWidget *parent, const char* name, const QString& caption, KoColor fgColor, KoColor bgColor) : QWidget(parent) , m_autogradientResource(gradient) , m_fgColor(fgColor) , m_bgColor(bgColor) { setObjectName(name); setupUi(this); setWindowTitle(caption); gradientSlider->setGradientResource(m_autogradientResource); nameedit->setText(gradient->name()); KoGradientSegment* segment = gradientSlider->selectedSegment(); if (segment) { slotSelectedSegment(segment); } connect(nameedit, SIGNAL(editingFinished()), this, SLOT(slotChangedName())); connect(gradientSlider, SIGNAL(sigSelectedSegment(KoGradientSegment*)), SLOT(slotSelectedSegment(KoGradientSegment*))); connect(gradientSlider, SIGNAL(sigChangedSegment(KoGradientSegment*)), SLOT(slotChangedSegment(KoGradientSegment*))); connect(comboBoxColorInterpolationType, SIGNAL(activated(int)), SLOT(slotChangedColorInterpolation(int))); connect(comboBoxInterpolationType, SIGNAL(activated(int)), SLOT(slotChangedInterpolation(int))); connect(leftColorButton, SIGNAL(changed(KoColor)), SLOT(slotChangedLeftColor(KoColor))); connect(rightColorButton, SIGNAL(changed(KoColor)), SLOT(slotChangedRightColor(KoColor))); connect(intNumInputLeftOpacity, SIGNAL(valueChanged(int)), SLOT(slotChangedLeftOpacity(int))); connect(intNumInputRightOpacity, SIGNAL(valueChanged(int)), SLOT(slotChangedRightOpacity(int))); connect(leftBtnGroup, SIGNAL(buttonToggled(QAbstractButton*, bool)), this, SLOT(slotChangedLeftType(QAbstractButton*, bool))); connect(rightBtnGroup, SIGNAL(buttonToggled(QAbstractButton*, bool)), this, SLOT(slotChangedRightType(QAbstractButton*, bool))); + + connect(leftForegroundTransparent, SIGNAL(toggled(bool)), this, SLOT(slotChangedLeftTypeTransparent(bool))); + connect(leftBackgroundTransparent, SIGNAL(toggled(bool)), this, SLOT(slotChangedLeftTypeTransparent(bool))); + connect(rightForegroundTransparent, SIGNAL(toggled(bool)), this, SLOT(slotChangedRightTypeTransparent(bool))); + connect(rightBackgroundTransparent, SIGNAL(toggled(bool)), this, SLOT(slotChangedRightTypeTransparent(bool))); } void KisAutogradientEditor::activate() { paramChanged(); } void KisAutogradientEditor::slotSelectedSegment(KoGradientSegment* segment) { leftColorButton->setColor(segment->startColor()); rightColorButton->setColor(segment->endColor()); comboBoxColorInterpolationType->setCurrentIndex(segment->colorInterpolation()); comboBoxInterpolationType->setCurrentIndex(segment->interpolation()); int leftOpacity = segment->startColor().opacityF(); intNumInputLeftOpacity->setValue(leftOpacity * 100); intNumInputLeftOpacity->setSuffix(i18n(" %")); int rightOpacity = segment->endColor().opacityF(); intNumInputRightOpacity->setValue(rightOpacity * 100); intNumInputRightOpacity->setSuffix(i18n(" %")); KoGradientSegmentEndpointType leftType = segment->startType(); KoGradientSegmentEndpointType rightType = segment->endType(); switch (leftType) { case COLOR_ENDPOINT: leftColorRadioButton->setChecked(true); break; - case FOREGROUND_ENDPOINT: case FOREGROUND_TRANSPARENT_ENDPOINT: + leftForegroundTransparent->setChecked(true); + case FOREGROUND_ENDPOINT: leftForegroundRadioButton->setChecked(true); break; - case BACKGROUND_ENDPOINT: case BACKGROUND_TRANSPARENT_ENDPOINT: + leftBackgroundTransparent->setChecked(true); + case BACKGROUND_ENDPOINT: leftBackgroundRadioButton->setChecked(true); break; } switch (rightType) { case COLOR_ENDPOINT: rightColorRadioButton->setChecked(true); break; - case FOREGROUND_ENDPOINT: case FOREGROUND_TRANSPARENT_ENDPOINT: + rightForegroundTransparent->setChecked(true); + case FOREGROUND_ENDPOINT: rightForegroundRadioButton->setChecked(true); break; - case BACKGROUND_ENDPOINT: case BACKGROUND_TRANSPARENT_ENDPOINT: + rightBackgroundTransparent->setChecked(true); + case BACKGROUND_ENDPOINT: rightBackgroundRadioButton->setChecked(true); break; } paramChanged(); } void KisAutogradientEditor::slotChangedSegment(KoGradientSegment*) { paramChanged(); } void KisAutogradientEditor::slotChangedInterpolation(int type) { KoGradientSegment* segment = gradientSlider->selectedSegment(); if (segment) segment->setInterpolation(type); gradientSlider->update(); paramChanged(); } void KisAutogradientEditor::slotChangedColorInterpolation(int type) { KoGradientSegment* segment = gradientSlider->selectedSegment(); if (segment) segment->setColorInterpolation(type); gradientSlider->update(); paramChanged(); } void KisAutogradientEditor::slotChangedLeftColor(const KoColor& color) { KoGradientSegment* segment = gradientSlider->selectedSegment(); if (segment) { KoColor c(color, segment->startColor().colorSpace()); c.setOpacity(segment->startColor().opacityU8()); segment->setStartColor(c); } gradientSlider->update(); paramChanged(); } void KisAutogradientEditor::slotChangedRightColor(const KoColor& color) { KoGradientSegment* segment = gradientSlider->selectedSegment(); if (segment) { KoColor c(color, segment->endColor().colorSpace()); c.setOpacity(segment->endColor().opacityU8()); segment->setEndColor(c); } gradientSlider->repaint(); paramChanged(); } void KisAutogradientEditor::slotChangedLeftOpacity(int value) { KoGradientSegment* segment = gradientSlider->selectedSegment(); if (segment) { KoColor c(segment->startColor(), segment->startColor().colorSpace()); c.setOpacity(qreal(value) / qreal(100.0)); segment->setStartColor(c); } gradientSlider->repaint(); paramChanged(); } void KisAutogradientEditor::slotChangedRightOpacity(int value) { KoGradientSegment* segment = gradientSlider->selectedSegment(); if (segment) { KoColor c(segment->endColor(), segment->endColor().colorSpace()); c.setOpacity(quint8((value *OPACITY_OPAQUE_U8) / 100)); segment->setEndColor(c); } gradientSlider->repaint(); paramChanged(); } void KisAutogradientEditor::slotChangedLeftType(QAbstractButton* button, bool checked) { if (!checked) { //Radio buttons, so we only care about the one that was checked, not the one unchecked return; } KoGradientSegmentEndpointType type; KoColor color; const KoColorSpace* colorSpace = m_autogradientResource->colorSpace(); if (button == leftForegroundRadioButton) { - type = FOREGROUND_ENDPOINT; color = KoColor(m_fgColor, colorSpace); - } - else if (button == leftBackgroundRadioButton) { - type = BACKGROUND_ENDPOINT; + leftForegroundTransparent->setEnabled(true); + if (leftForegroundTransparent->isChecked()) { + type = FOREGROUND_TRANSPARENT_ENDPOINT; + } else { + type = FOREGROUND_ENDPOINT; + } + } else if (button == leftBackgroundRadioButton) { color = KoColor(m_bgColor, colorSpace); + leftBackgroundTransparent->setEnabled(true); + if (leftBackgroundTransparent->isChecked()) { + type = BACKGROUND_TRANSPARENT_ENDPOINT; + } else { + type = BACKGROUND_ENDPOINT; + } } else { type = COLOR_ENDPOINT; + leftForegroundTransparent->setEnabled(false); + leftBackgroundTransparent->setEnabled(false); color = KoColor(leftColorButton->color(), colorSpace); } KoGradientSegment* segment = gradientSlider->selectedSegment(); if (segment) { segment->setStartType(type); } slotChangedLeftColor(color); } void KisAutogradientEditor::slotChangedRightType(QAbstractButton* button, bool checked) { if (!checked) { //Radio buttons, so we only care about the one that was checked, not the one unchecked return; } KoGradientSegmentEndpointType type; KoColor color; const KoColorSpace* colorSpace = m_autogradientResource->colorSpace(); if (button == rightForegroundRadioButton) { - type = FOREGROUND_ENDPOINT; color = KoColor(m_fgColor, colorSpace); - } - else if (button == rightBackgroundRadioButton) { - type = BACKGROUND_ENDPOINT; + rightForegroundTransparent->setEnabled(true); + if (rightForegroundTransparent->isChecked()) { + type = FOREGROUND_TRANSPARENT_ENDPOINT; + } else { + type = FOREGROUND_ENDPOINT; + } + } else if (button == rightBackgroundRadioButton) { color = KoColor(m_bgColor, colorSpace); + rightBackgroundTransparent->setEnabled(true); + if (rightBackgroundTransparent->isChecked()) { + type = BACKGROUND_TRANSPARENT_ENDPOINT; + } else { + type = BACKGROUND_ENDPOINT; + } } else { type = COLOR_ENDPOINT; + rightForegroundTransparent->setEnabled(false); + rightBackgroundTransparent->setEnabled(false); color = KoColor(rightColorButton->color(), colorSpace); } KoGradientSegment* segment = gradientSlider->selectedSegment(); if (segment) { segment->setEndType(type); } slotChangedRightColor(color); } +void KisAutogradientEditor::slotChangedLeftTypeTransparent(bool checked) +{ + if (leftColorRadioButton->isChecked()) { //shouldn't be able to check/uncheck in this state, but just in case + return; + } + + KoGradientSegmentEndpointType type; + if (leftForegroundRadioButton->isChecked()) { + if (checked) { + type = FOREGROUND_TRANSPARENT_ENDPOINT; + } else { + type = FOREGROUND_ENDPOINT; + } + } else { + if (checked) { + type = FOREGROUND_TRANSPARENT_ENDPOINT; + } else { + type = FOREGROUND_ENDPOINT; + } + } + + KoGradientSegment* segment = gradientSlider->selectedSegment(); + if (segment) { + segment->setStartType(type); + slotChangedLeftColor(segment->startColor()); + } +} + +void KisAutogradientEditor::slotChangedRightTypeTransparent(bool checked) +{ + if (rightColorRadioButton->isChecked()) { //shouldn't be able to check/uncheck in this state, but just in case + return; + } + + KoGradientSegmentEndpointType type; + if (rightForegroundRadioButton->isChecked()) { + if (checked) { + type = FOREGROUND_TRANSPARENT_ENDPOINT; + } else { + type = FOREGROUND_ENDPOINT; + } + } else { + if (checked) { + type = FOREGROUND_TRANSPARENT_ENDPOINT; + } else { + type = FOREGROUND_ENDPOINT; + } + } + + KoGradientSegment* segment = gradientSlider->selectedSegment(); + if (segment) { + segment->setEndType(type); + slotChangedRightColor(segment->endColor()); + } +} + void KisAutogradientEditor::slotChangedName() { m_autogradientResource->setName(nameedit->text()); } void KisAutogradientEditor::paramChanged() { m_autogradientResource->updatePreview(); } diff --git a/libs/ui/kis_autogradient.h b/libs/ui/kis_autogradient.h index dd75cd4dab..ff3eb7b04b 100644 --- a/libs/ui/kis_autogradient.h +++ b/libs/ui/kis_autogradient.h @@ -1,57 +1,59 @@ /* * Copyright (c) 2004 Cyrille Berger * 2004 Sven Langkamp * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _KIS_AUTOGRADIENT_H_ #define _KIS_AUTOGRADIENT_H_ #include "ui_wdgautogradient.h" class KoGradientSegment; #include class KisAutogradientEditor : public QWidget, public Ui::KisWdgAutogradient { Q_OBJECT public: KisAutogradientEditor(KoSegmentGradientSP gradient, QWidget *parent, const char* name, const QString& caption, KoColor fgColor, KoColor bgColor); void activate(); private: KoSegmentGradientSP m_autogradientResource; KoColor m_fgColor; KoColor m_bgColor; private Q_SLOTS: void slotSelectedSegment(KoGradientSegment* segment); void slotChangedSegment(KoGradientSegment* segment); void slotChangedInterpolation(int type); void slotChangedColorInterpolation(int type); void slotChangedLeftColor(const KoColor& color); void slotChangedRightColor(const KoColor& color); void slotChangedLeftOpacity(int value); void slotChangedRightOpacity(int value); void slotChangedLeftType(QAbstractButton* button, bool checked); void slotChangedRightType(QAbstractButton* button, bool checked); + void slotChangedLeftTypeTransparent(bool checked); + void slotChangedRightTypeTransparent(bool checked); void slotChangedName(); void paramChanged(); }; #endif