Krita Source Code Documentation
Loading...
Searching...
No Matches
KisGenericGradientEditor Class Reference

This is a generic gradient editor widget. More...

#include <KisGenericGradientEditor.h>

+ Inheritance diagram for KisGenericGradientEditor:

Public Slots

void setAddGradientButtonVisible (bool visible)
 Set if the add gradient button must be shown.
 
void setCanvasResourcesInterface (KoCanvasResourcesInterfaceSP newCanvasResourcesInterface)
 Set the canvas resources interface.
 
void setCompactGradientEditorMode (bool compact)
 Set if the internal gradient editor must use the compact mode.
 
void setCompactGradientPresetChooserMode (bool compact)
 Set if the gradient preset chooser must be shown without any controls other than the list view.
 
void setCompactMode (bool compact)
 Set if the editor must show a reduced ui.
 
void setConvertGradientButtonVisible (bool visible)
 Set if the convert gradient button must be shown.
 
void setGradient (KoAbstractGradientSP newGradient)
 Set the gradient.
 
void setGradientPresetChooserOptionsButtonVisible (bool visible)
 Set if the button for the gradient preset chooser options must be shown.
 
void setGradientPresetChooserVisible (bool visible)
 Set if the gradient preset chooser must be shown.
 
void setUpdateGradientButtonVisible (bool visible)
 Set if the update gradient button must be shown.
 
void setUseGradientPresetChooserPopUp (bool use)
 Set if the gradient preset chooser must be shown as a pop-up clicking a button or embedded in the widget ui.
 

Signals

void sigGradientChanged ()
 signal emitted when the gradient changes
 

Public Member Functions

KoCanvasResourcesInterfaceSP canvasResourcesInterface () const
 Get the current Canvas Resources Interface.
 
bool compactGradientEditorMode () const
 Tell if the internal gradient editor is using the compact mode.
 
bool compactGradientPresetChooserMode () const
 Tell if the gradient preset chooser is being shown without any controls other than the list view.
 
bool compactMode () const
 Tell if the compact mode is being used.
 
bool event (QEvent *e) override
 
KoAbstractGradientSP gradient () const
 Get the current gradient.
 
bool isAddGradientButtonVisible () const
 Tell if the add gradient button is being shown.
 
bool isConvertGradientButtonVisible () const
 Tell if the convert gradient button is being shown.
 
bool isGradientPresetChooserOptionsButtonVisible () const
 Tell if the button for the gradient preset chooser options is being shown.
 
bool isGradientPresetChooserVisible () const
 Tell if the gradient preset chooser is being shown.
 
bool isUpdateGradientButtonVisible () const
 Tell if the update gradient button is being shown.
 
 KisGenericGradientEditor (QWidget *parent=0)
 Construct a new KisGenericGradientEditor widget.
 
void loadUISettings (const QString &prefix=QString())
 Load the ui settings from the configuration.
 
QSize minimumSizeHint () const override
 
void saveUISettings (const QString &prefix=QString())
 Save the ui settings to the configuration.
 
QSize sizeHint () const override
 
void updateCachedSizeHint ()
 
bool useGradientPresetChooserPopUp () const
 Tell if the gradient preset chooser is being shown as a pop-up clicking a button or embedded in the widget ui.
 
 ~KisGenericGradientEditor () override
 

Public Attributes

QAction * actionCompactGradientPresetChooserMode
 
QAction * actionUseGradientPresetChooserPopUp
 
QPushButton * buttonAddGradient
 
QPushButton * buttonConvertGradient
 
QPushButton * buttonUpdateGradient
 
QSize cachedMinimumSizeHint
 
QSize cachedSizeHint
 
KoCanvasResourcesInterfaceSP canvasResourcesInterface
 
bool compactGradientEditorMode
 
bool compactGradientPresetChooserMode
 
bool compactMode
 
KoAbstractGradientSP gradient
 
bool isAddGradientButtonVisible
 
bool isConvertGradientButtonVisible
 
bool isGradientPresetChooserOptionsButtonVisible
 
bool isGradientPresetChooserVisible
 
bool isUpdateGradientButtonVisible
 
QLabel * labelConvertGradientWarning
 
KisGenericGradientEditorq
 
QToolButton * toolButtonGradientPresetChooser
 
KisPopupButtontoolButtonGradientPresetChooserOptions
 
bool useGradientPresetChooserPopUp
 
QWidget * widgetGradientEditor
 
KisGradientChooserwidgetGradientPresetChooser
 
QWidget * widgetToolButtonGradientPresetChooser
 

Private Slots

void on_buttonAddGradient_clicked ()
 
void on_buttonConvertGradient_clicked ()
 
void on_buttonUpdateGradient_clicked ()
 
void on_widgetGradientEditor_sigGradientChanged ()
 
void on_widgetGradientPresetChooser_resourceClicked (KoResourceSP resource)
 

Private Member Functions

void updateAddGradientButton ()
 
void updateConvertGradientButton ()
 
void updateGradientEditor ()
 
void updateGradientPresetChooser ()
 
void updateUpdateGradientButton ()
 
- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Private Attributes

QScopedPointer< Privatem_d
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Detailed Description

This is a generic gradient editor widget.

This widget makes use of other gradient related widgets and puts them together in one place to ease the edition of gradients.

It supports loading/saving from/to resources and conversion between the different types of gradients

Definition at line 36 of file KisGenericGradientEditor.cpp.

Constructor & Destructor Documentation

◆ KisGenericGradientEditor()

KisGenericGradientEditor::KisGenericGradientEditor ( QWidget * parent = 0)

Construct a new KisGenericGradientEditor widget.

Parameters
parentthe parent widget

Definition at line 102 of file KisGenericGradientEditor.cpp.

103 : QWidget(parent)
104 , m_d(new Private)
105{
106 m_d->q = this;
107 m_d->gradient = nullptr;
108 m_d->canvasResourcesInterface = nullptr;
109 m_d->widgetGradientEditor = nullptr;
110
111 QVBoxLayout *layoutMain = new QVBoxLayout;
112 layoutMain->setContentsMargins(0, 0, 0, 0);
113 layoutMain->setSpacing(10);
114
115 QHBoxLayout *layoutButtons = new QHBoxLayout;
116 layoutButtons->setContentsMargins(0, 0, 0, 0);
117 layoutButtons->setSpacing(5);
118
119 m_d->buttonConvertGradient = new QPushButton(this);
120 m_d->labelConvertGradientWarning = new QLabel(this);
121 m_d->labelConvertGradientWarning->setPixmap(KisIconUtils::loadIcon("warning").pixmap(16, 16));
122 m_d->labelConvertGradientWarning->setToolTip(
123 i18nc(
124 "Warning text shown when converting from a segment gradient to a stop gradient",
125 "Converting a segment gradient to a stop gradient may cause loss of information"
126 )
127 );
128
129 m_d->widgetGradientPresetChooser = new KisGradientChooser(this);
130 m_d->widgetGradientPresetChooser->setNameLabelVisible(false);
131 m_d->widgetGradientPresetChooser->setEditOptionsVisible(false);
132
133 m_d->toolButtonGradientPresetChooser = new QToolButton(this);
134 m_d->toolButtonGradientPresetChooser->setText(
135 i18nc("Choose a preset gradient from the button popup", "Choose Gradient Preset")
136 );
137 m_d->toolButtonGradientPresetChooser->setPopupMode(QToolButton::InstantPopup);
138 m_d->widgetToolButtonGradientPresetChooser = new QWidget(this);
139 QVBoxLayout *layoutWidgetToolButtonGradientPresetChooser = new QVBoxLayout;
140 layoutWidgetToolButtonGradientPresetChooser->setContentsMargins(0, 0, 0, 0);
141 layoutWidgetToolButtonGradientPresetChooser->setSpacing(0);
142 m_d->widgetToolButtonGradientPresetChooser->setLayout(layoutWidgetToolButtonGradientPresetChooser);
143 QWidgetAction *widgetActionToolButtonGradientPresetChooser = new QWidgetAction(this);
144 widgetActionToolButtonGradientPresetChooser->setDefaultWidget(m_d->widgetToolButtonGradientPresetChooser);
145 m_d->toolButtonGradientPresetChooser->addAction(widgetActionToolButtonGradientPresetChooser);
146
147 m_d->buttonUpdateGradient = new QPushButton(this);
148 m_d->buttonUpdateGradient->setIcon(KisIconUtils::loadIcon("document-save"));
149 m_d->buttonUpdateGradient->setToolTip(
150 i18nc(
151 "Update the current gradient in the presets with the one in the generic gradient editor",
152 "Update the selected gradient preset with the current gradient"
153 )
154 );
155
156 m_d->buttonAddGradient = new QPushButton(this);
157 m_d->buttonAddGradient->setIcon(KisIconUtils::loadIcon("list-add"));
158 m_d->buttonAddGradient->setToolTip(
159 i18nc(
160 "Add the current gradient in the generic gradient editor to the presets",
161 "Add the current gradient to the presets"
162 )
163 );
164
165 m_d->toolButtonGradientPresetChooserOptions = new KisPopupButton(this);
166 m_d->toolButtonGradientPresetChooserOptions->setArrowVisible(false);
167 m_d->toolButtonGradientPresetChooserOptions->setAutoRaise(true);
168 m_d->toolButtonGradientPresetChooserOptions->setIcon(KisIconUtils::loadIcon("view-choose"));
169 m_d->actionUseGradientPresetChooserPopUp = new QAction(this);
170 m_d->actionUseGradientPresetChooserPopUp->setCheckable(true);
171 m_d->actionUseGradientPresetChooserPopUp->setText(
172 i18nc(
173 "Show the gradient preset chooser as a pop-up in a button or inline",
174 "Use a pop-up gradient preset chooser"
175 )
176 );
177 m_d->actionCompactGradientPresetChooserMode = new QAction(this);
178 m_d->actionCompactGradientPresetChooserMode->setCheckable(true);
179 m_d->actionCompactGradientPresetChooserMode->setText(
180 i18nc(
181 "Hide/show option widgets around the gradient preset chooser",
182 "Show compact gradient preset chooser"
183 )
184 );
185 QMenu *toolButtonGradientPresetChooserOptionsMenu = new QMenu;
186 toolButtonGradientPresetChooserOptionsMenu->addAction(m_d->actionUseGradientPresetChooserPopUp);
187 toolButtonGradientPresetChooserOptionsMenu->addAction(m_d->actionCompactGradientPresetChooserMode);
188 m_d->toolButtonGradientPresetChooserOptions->setPopupWidget(toolButtonGradientPresetChooserOptionsMenu);
189
190 layoutButtons->addWidget(m_d->buttonAddGradient, 0);
191 layoutButtons->addWidget(m_d->buttonUpdateGradient, 0);
192 layoutButtons->addWidget(m_d->buttonConvertGradient, 0);
193 layoutButtons->addWidget(m_d->labelConvertGradientWarning, 0);
194 layoutButtons->addStretch(1);
195 layoutButtons->addWidget(m_d->toolButtonGradientPresetChooser, 0);
196 layoutButtons->addWidget(m_d->toolButtonGradientPresetChooserOptions, 0);
197
198 layoutMain->addWidget(m_d->widgetGradientPresetChooser, 1);
199 layoutMain->addLayout(layoutButtons, 0);
200 layoutMain->addStretch();
201
202 setLayout(layoutMain);
203
204 m_d->compactMode = false;
205 m_d->isConvertGradientButtonVisible = true;
206 m_d->isUpdateGradientButtonVisible = true;
207 m_d->isAddGradientButtonVisible = true;
208 m_d->isGradientPresetChooserVisible = true;
209 m_d->isGradientPresetChooserOptionsButtonVisible = true;
210 m_d->useGradientPresetChooserPopUp = true;
211 m_d->compactGradientPresetChooserMode = false;
212 m_d->compactGradientEditorMode = false;
213
219
220 connect(
221 m_d->buttonConvertGradient,
222 SIGNAL(clicked()),
223 this,
225 );
226
227 connect(
228 m_d->buttonUpdateGradient,
229 SIGNAL(clicked()),
230 this,
232 );
233
234 connect(
235 m_d->buttonAddGradient,
236 SIGNAL(clicked()),
237 this,
239 );
240
241 connect(
242 m_d->widgetGradientPresetChooser,
243 SIGNAL(resourceClicked(KoResourceSP)),
244 this,
246 );
247
248 connect(
249 m_d->actionUseGradientPresetChooserPopUp,
250 SIGNAL(toggled(bool)),
251 this,
253 );
254
255 connect(
256 m_d->actionCompactGradientPresetChooserMode,
257 SIGNAL(toggled(bool)),
258 this,
260 );
261
262 m_d->updateCachedSizeHint();
263 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
264}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
QScopedPointer< Private > m_d
void setCompactGradientPresetChooserMode(bool compact)
Set if the gradient preset chooser must be shown without any controls other than the list view.
void setUseGradientPresetChooserPopUp(bool use)
Set if the gradient preset chooser must be shown as a pop-up clicking a button or embedded in the wid...
void on_widgetGradientPresetChooser_resourceClicked(KoResourceSP resource)
QIcon loadIcon(const QString &name)

References connect(), KisIconUtils::loadIcon(), m_d, on_buttonAddGradient_clicked(), on_buttonConvertGradient_clicked(), on_buttonUpdateGradient_clicked(), on_widgetGradientPresetChooser_resourceClicked(), setCompactGradientPresetChooserMode(), setUseGradientPresetChooserPopUp(), updateAddGradientButton(), updateConvertGradientButton(), updateGradientEditor(), updateGradientPresetChooser(), and updateUpdateGradientButton().

◆ ~KisGenericGradientEditor()

KisGenericGradientEditor::~KisGenericGradientEditor ( )
override

Definition at line 266 of file KisGenericGradientEditor.cpp.

267{}

Member Function Documentation

◆ canvasResourcesInterface()

KoCanvasResourcesInterfaceSP KisGenericGradientEditor::canvasResourcesInterface ( ) const

Get the current Canvas Resources Interface.

Returns
The current Canvas Resources Interface
See also
setCanvasResourcesInterface(KoCanvasResourcesInterfaceSP)

◆ compactGradientEditorMode()

bool KisGenericGradientEditor::compactGradientEditorMode ( ) const

Tell if the internal gradient editor is using the compact mode.

Returns
true if the internal gradient editor is using the compact mode, false otherwise
See also
setCompactGradientEditorMode(bool)

◆ compactGradientPresetChooserMode()

bool KisGenericGradientEditor::compactGradientPresetChooserMode ( ) const

Tell if the gradient preset chooser is being shown without any controls other than the list view.

Returns
true if the gradient preset chooser is being shown without any controls other than the list view, false otherwise
See also
setCompactGradientPresetChooserMode(bool)

◆ compactMode()

bool KisGenericGradientEditor::compactMode ( ) const

Tell if the compact mode is being used.

Returns
true if the compact mode is being used, false otherwise
See also
setCompactMode(bool)

◆ event()

bool KisGenericGradientEditor::event ( QEvent * e)
override

Definition at line 511 of file KisGenericGradientEditor.cpp.

512{
513 if (e->type() == QEvent::StyleChange || e->type() == QEvent::FontChange) {
514 m_d->updateCachedSizeHint();
515 }
516 return QWidget::event(e);
517}

References m_d.

◆ gradient()

KoAbstractGradientSP KisGenericGradientEditor::gradient ( ) const

Get the current gradient.

A clone is returned so that any changes in the returned gradient won't change the editor gradient and vice-versa

Returns
A clone of the current gradient
See also
setGradient(KoAbstractGradientSP)

◆ isAddGradientButtonVisible()

bool KisGenericGradientEditor::isAddGradientButtonVisible ( ) const

Tell if the add gradient button is being shown.

Returns
true if the add gradient button is being shown, false otherwise
See also
setAddGradientButtonVisible(bool)

◆ isConvertGradientButtonVisible()

bool KisGenericGradientEditor::isConvertGradientButtonVisible ( ) const

Tell if the convert gradient button is being shown.

Returns
true if the convert gradient button is being shown, false otherwise
See also
setConvertGradientButtonVisible(bool)

◆ isGradientPresetChooserOptionsButtonVisible()

bool KisGenericGradientEditor::isGradientPresetChooserOptionsButtonVisible ( ) const

Tell if the button for the gradient preset chooser options is being shown.

Returns
true if the button for the gradient preset chooser options is being shown, false otherwise
See also
setGradientPresetChooserOptionsButtonVisible(bool)

◆ isGradientPresetChooserVisible()

bool KisGenericGradientEditor::isGradientPresetChooserVisible ( ) const

Tell if the gradient preset chooser is being shown.

Returns
true if the gradient preset chooser is being shown, false otherwise
See also
setGradientPresetChooserVisible(bool)

◆ isUpdateGradientButtonVisible()

bool KisGenericGradientEditor::isUpdateGradientButtonVisible ( ) const

Tell if the update gradient button is being shown.

Returns
true if the update gradient button is being shown, false otherwise
See also
setUpdateGradientButtonVisible(bool)

◆ loadUISettings()

void KisGenericGradientEditor::loadUISettings ( const QString & prefix = QString())

Load the ui settings from the configuration.

Parameters
prefixstring prepended to the settings names
See also
saveUISettings(const QString &)

Definition at line 269 of file KisGenericGradientEditor.cpp.

270{
271 KConfigGroup configGroup(KSharedConfig::openConfig(), "GenericGradientEditor");
272 const QString pfx = prefix.isEmpty() ? QString("global/") : prefix + "/";
273
274 m_d->useGradientPresetChooserPopUp = configGroup.readEntry(pfx + "useGradientPresetChooserPopUp", m_d->useGradientPresetChooserPopUp);
275 m_d->compactGradientPresetChooserMode = configGroup.readEntry(pfx + "compactGradientPresetChooserMode", m_d->compactGradientPresetChooserMode);
276
278}

References m_d, and updateGradientPresetChooser().

◆ minimumSizeHint()

QSize KisGenericGradientEditor::minimumSizeHint ( ) const
override

Definition at line 506 of file KisGenericGradientEditor.cpp.

507{
508 return m_d->cachedMinimumSizeHint;
509}

References m_d.

◆ on_buttonAddGradient_clicked

void KisGenericGradientEditor::on_buttonAddGradient_clicked ( )
privateslot

Definition at line 639 of file KisGenericGradientEditor.cpp.

640{
641 qDebug() << m_d->gradient << m_d->gradient->valid() << m_d->gradient->name();
642
643 if (!m_d->gradient || !m_d->gradient->valid() || m_d->gradient->name().isEmpty()) {
644 return;
645 }
646
647 m_d->gradient->updatePreview();
650}
The KisResourceModel class provides the main access to resources. It is possible to filter the resour...
static bool addResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource, QString storageLocation="")
const QString Gradients

References KisResourceUserOperations::addResourceWithUserInput(), ResourceType::Gradients, and m_d.

◆ on_buttonConvertGradient_clicked

void KisGenericGradientEditor::on_buttonConvertGradient_clicked ( )
privateslot

Definition at line 612 of file KisGenericGradientEditor.cpp.

613{
614 if (m_d->gradient.dynamicCast<KoStopGradient>()) {
616 }
617 else if (m_d->gradient.dynamicCast<KoSegmentGradient>()) {
619 }
620}
void setGradient(KoAbstractGradientSP newGradient)
Set the gradient.
KoStopGradientSP toStopGradient(const QGradientStops &gradient)
Convert a QGradientStop list to a KoStopGradientSP.
KoSegmentGradientSP toSegmentGradient(const QGradientStops &gradient)
Convert a QGradientStop list to a krita segment gradient.

References m_d, setGradient(), KisGradientConversion::toSegmentGradient(), and KisGradientConversion::toStopGradient().

◆ on_buttonUpdateGradient_clicked

void KisGenericGradientEditor::on_buttonUpdateGradient_clicked ( )
privateslot

Definition at line 622 of file KisGenericGradientEditor.cpp.

623{
624 if (!m_d->gradient || !m_d->gradient->valid() || !(m_d->gradient->resourceId() > -1)) {
625 return;
626 }
627
628 KoResourceSP selectedGradient = m_d->widgetGradientPresetChooser->currentResource();
629 if (!selectedGradient ||
630 !(m_d->gradient->resourceId() == selectedGradient->resourceId()) ||
631 selectedGradient->permanent()) {
632 return;
633 }
634
635 m_d->gradient->updatePreview();
637}
static bool updateResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource)

References m_d, and KisResourceUserOperations::updateResourceWithUserInput().

◆ on_widgetGradientEditor_sigGradientChanged

void KisGenericGradientEditor::on_widgetGradientEditor_sigGradientChanged ( )
privateslot

Definition at line 657 of file KisGenericGradientEditor.cpp.

658{
661 Q_EMIT sigGradientChanged();
662}
void sigGradientChanged()
signal emitted when the gradient changes

References sigGradientChanged(), updateAddGradientButton(), and updateUpdateGradientButton().

◆ on_widgetGradientPresetChooser_resourceClicked

void KisGenericGradientEditor::on_widgetGradientPresetChooser_resourceClicked ( KoResourceSP resource)
privateslot

Definition at line 652 of file KisGenericGradientEditor.cpp.

653{
654 setGradient(resource.dynamicCast<KoAbstractGradient>());
655}

References setGradient().

◆ saveUISettings()

void KisGenericGradientEditor::saveUISettings ( const QString & prefix = QString())

Save the ui settings to the configuration.

Parameters
prefixstring prepended to the settings names
See also
loadUISettings(const QString &)

Definition at line 280 of file KisGenericGradientEditor.cpp.

281{
282 KConfigGroup configGroup(KSharedConfig::openConfig(), "GenericGradientEditor");
283 const QString pfx = prefix.isEmpty() ? QString("global/") : prefix + "/";
284
285 configGroup.writeEntry(pfx + "useGradientPresetChooserPopUp", m_d->useGradientPresetChooserPopUp);
286 configGroup.writeEntry(pfx + "compactGradientPresetChooserMode", m_d->compactGradientPresetChooserMode);
287}

References m_d.

◆ setAddGradientButtonVisible

void KisGenericGradientEditor::setAddGradientButtonVisible ( bool visible)
slot

Set if the add gradient button must be shown.

Parameters
visibletrue if the add gradient button must be shown, false otherwise
See also
isAddGradientButtonVisible()

Definition at line 460 of file KisGenericGradientEditor.cpp.

461{
462 m_d->isAddGradientButtonVisible = visible;
464}

References m_d, and updateAddGradientButton().

◆ setCanvasResourcesInterface

void KisGenericGradientEditor::setCanvasResourcesInterface ( KoCanvasResourcesInterfaceSP newCanvasResourcesInterface)
slot

Set the canvas resources interface.

the canvas resources interface is used to get the current foreground and background colors

Parameters
newCanvasResourcesInterfacethe new canvas resources interface
See also
canvasResourcesInterface()

Definition at line 425 of file KisGenericGradientEditor.cpp.

426{
427 m_d->canvasResourcesInterface = newCanvasResourcesInterface;
428
429 if (dynamic_cast<KisStopGradientEditor*>(m_d->widgetGradientEditor)) {
430 dynamic_cast<KisStopGradientEditor*>(m_d->widgetGradientEditor)->setCanvasResourcesInterface(m_d->canvasResourcesInterface);
431 } else if (dynamic_cast<KisSegmentGradientEditor*>(m_d->widgetGradientEditor)) {
432 dynamic_cast<KisSegmentGradientEditor*>(m_d->widgetGradientEditor)->setCanvasResourcesInterface(m_d->canvasResourcesInterface);
433 }
434
435 m_d->widgetGradientPresetChooser->setCanvasResourcesInterface(newCanvasResourcesInterface);
436}
void setCanvasResourcesInterface(KoCanvasResourcesInterfaceSP newCanvasResourcesInterface)
Set the canvas resources interface.
void setCanvasResourcesInterface(KoCanvasResourcesInterfaceSP canvasResourcesInterface)

References m_d, KisSegmentGradientEditor::setCanvasResourcesInterface(), and setCanvasResourcesInterface().

◆ setCompactGradientEditorMode

void KisGenericGradientEditor::setCompactGradientEditorMode ( bool compact)
slot

Set if the internal gradient editor must use the compact mode.

Parameters
compacttrue if the internal gradient editor must use the compact mode, false otherwise
See also
compactGradientEditorMode()

Definition at line 493 of file KisGenericGradientEditor.cpp.

494{
495 m_d->compactGradientEditorMode = compact;
497 m_d->updateCachedSizeHint();
498}

References m_d, and updateGradientEditor().

◆ setCompactGradientPresetChooserMode

void KisGenericGradientEditor::setCompactGradientPresetChooserMode ( bool compact)
slot

Set if the gradient preset chooser must be shown without any controls other than the list view.

Parameters
compacttrue if the gradient preset chooser must be shown without any controls other than the list view, false otherwise
See also
compactGradientPresetChooserMode()

Definition at line 486 of file KisGenericGradientEditor.cpp.

487{
488 m_d->compactGradientPresetChooserMode = compact;
490 m_d->updateCachedSizeHint();
491}

References m_d, and updateGradientPresetChooser().

◆ setCompactMode

void KisGenericGradientEditor::setCompactMode ( bool compact)
slot

Set if the editor must show a reduced ui.

If the compact mode is set, only the gradient editors will be visible

Parameters
compacttrue if the compact mode must be used, false otherwise
See also
compactMode()

Definition at line 438 of file KisGenericGradientEditor.cpp.

439{
440 m_d->compactMode = compact;
441
446}

References m_d, updateAddGradientButton(), updateConvertGradientButton(), updateGradientPresetChooser(), and updateUpdateGradientButton().

◆ setConvertGradientButtonVisible

void KisGenericGradientEditor::setConvertGradientButtonVisible ( bool visible)
slot

Set if the convert gradient button must be shown.

Parameters
visibletrue if the convert gradient button must be shown, false otherwise
See also
isConvertGradientButtonVisible()

Definition at line 448 of file KisGenericGradientEditor.cpp.

449{
450 m_d->isConvertGradientButtonVisible = visible;
452}

References m_d, and updateConvertGradientButton().

◆ setGradient

void KisGenericGradientEditor::setGradient ( KoAbstractGradientSP newGradient)
slot

Set the gradient.

This editor makes a clone os the gradient passed so that any changes made in the editor won't change the passed gradient and vice-versa

Parameters
newGradientThe new gradient
See also
gradient()

Definition at line 347 of file KisGenericGradientEditor.cpp.

348{
349 if (newGradient == m_d->gradient) {
350 return;
351 }
352
353 if (!newGradient || !newGradient->valid()) {
354 if (m_d->widgetGradientEditor) {
355 layout()->removeWidget(m_d->widgetGradientEditor);
356 delete m_d->widgetGradientEditor;
357 m_d->widgetGradientEditor = nullptr;
358 }
359 m_d->gradient = nullptr;
364 return;
365 }
366
367 m_d->gradient = newGradient->clone().staticCast<KoAbstractGradient>();
368 if (m_d->canvasResourcesInterface) {
369 m_d->gradient->updateVariableColors(m_d->canvasResourcesInterface);
370 }
371
372 QWidget *newGradientEditorWidget = nullptr;
373 if (m_d->gradient.dynamicCast<KoStopGradient>()) {
374 if (dynamic_cast<KisStopGradientEditor*>(m_d->widgetGradientEditor)) {
375 dynamic_cast<KisStopGradientEditor*>(m_d->widgetGradientEditor)->setGradient(m_d->gradient.dynamicCast<KoStopGradient>());
376 } else {
377 newGradientEditorWidget =
378 new KisStopGradientEditor(m_d->gradient.dynamicCast<KoStopGradient>(), nullptr, "", "", m_d->canvasResourcesInterface);
379 }
380 } else if (m_d->gradient.dynamicCast<KoSegmentGradient>()) {
381 if (dynamic_cast<KisSegmentGradientEditor*>(m_d->widgetGradientEditor)) {
382 dynamic_cast<KisSegmentGradientEditor*>(m_d->widgetGradientEditor)->setGradient(m_d->gradient.dynamicCast<KoSegmentGradient>());
383 } else {
384 newGradientEditorWidget =
385 new KisSegmentGradientEditor(m_d->gradient.dynamicCast<KoSegmentGradient>(), nullptr, "", "", m_d->canvasResourcesInterface);
386 }
387 }
388
389 if (newGradientEditorWidget) {
390 QWidget *oldGradientEditorWidget = m_d->widgetGradientEditor;
391 m_d->widgetGradientEditor = newGradientEditorWidget;
392 m_d->widgetGradientEditor->layout()->setContentsMargins(0, 0, 0, 0);
393 m_d->widgetGradientEditor->setMinimumSize(0, 0);
394 m_d->widgetGradientEditor->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
395 if (dynamic_cast<KisStopGradientEditor*>(m_d->widgetGradientEditor)) {
396 dynamic_cast<KisStopGradientEditor*>(m_d->widgetGradientEditor)->setCompactMode(m_d->compactGradientPresetChooserMode);
397 } else {
398 dynamic_cast<KisSegmentGradientEditor*>(m_d->widgetGradientEditor)->setCompactMode(m_d->compactGradientPresetChooserMode);
399 }
400 if (oldGradientEditorWidget) {
401 setUpdatesEnabled(false);
402 layout()->replaceWidget(oldGradientEditorWidget, m_d->widgetGradientEditor);
403 dynamic_cast<QVBoxLayout*>(layout())->setStretchFactor(m_d->widgetGradientEditor, 0);
404 layout()->activate();
405 delete oldGradientEditorWidget;
406 setUpdatesEnabled(true);
407 } else {
408 dynamic_cast<QVBoxLayout*>(layout())->insertWidget(
409 m_d->useGradientPresetChooserPopUp ? 1 : 2,
411 0
412 );
413 }
414 connect(m_d->widgetGradientEditor, SIGNAL(sigGradientChanged()), this, SLOT(on_widgetGradientEditor_sigGradientChanged()));
419 }
420 m_d->updateCachedSizeHint();
421
422 Q_EMIT sigGradientChanged();
423}
void setCompactMode(bool compact)
Set if the editor must show a reduced ui.
virtual void updateVariableColors(KoCanvasResourcesInterfaceSP canvasResourcesInterface)

References connect(), m_d, on_widgetGradientEditor_sigGradientChanged(), setCompactMode(), setGradient(), sigGradientChanged(), updateAddGradientButton(), updateConvertGradientButton(), updateGradientEditor(), updateUpdateGradientButton(), and KoAbstractGradient::updateVariableColors().

◆ setGradientPresetChooserOptionsButtonVisible

void KisGenericGradientEditor::setGradientPresetChooserOptionsButtonVisible ( bool visible)
slot

Set if the button for the gradient preset chooser options must be shown.

Parameters
visibletrue if the button for the gradient preset chooser options must be shown, false otherwise
See also
isGradientPresetChooserOptionsButtonVisible()

Definition at line 473 of file KisGenericGradientEditor.cpp.

474{
475 m_d->isGradientPresetChooserOptionsButtonVisible = visible;
477}

References m_d, and updateGradientPresetChooser().

◆ setGradientPresetChooserVisible

void KisGenericGradientEditor::setGradientPresetChooserVisible ( bool visible)
slot

Set if the gradient preset chooser must be shown.

Parameters
visibletrue if the gradient preset chooser must be shown, false otherwise
See also
isSaveGradientButtonVisible()

Definition at line 466 of file KisGenericGradientEditor.cpp.

467{
468 m_d->isGradientPresetChooserVisible = visible;
470 m_d->updateCachedSizeHint();
471}

References m_d, and updateGradientPresetChooser().

◆ setUpdateGradientButtonVisible

void KisGenericGradientEditor::setUpdateGradientButtonVisible ( bool visible)
slot

Set if the update gradient button must be shown.

Parameters
visibletrue if the update gradient button must be shown, false otherwise
See also
isUpdateGradientButtonVisible()

Definition at line 454 of file KisGenericGradientEditor.cpp.

455{
456 m_d->isUpdateGradientButtonVisible = visible;
458}

References m_d, and updateUpdateGradientButton().

◆ setUseGradientPresetChooserPopUp

void KisGenericGradientEditor::setUseGradientPresetChooserPopUp ( bool use)
slot

Set if the gradient preset chooser must be shown as a pop-up clicking a button or embedded in the widget ui.

Parameters
usetrue if the gradient preset chooser must be shown as a pop-up, false otherwise
See also
useGradientPresetChooserPopUp()

Definition at line 479 of file KisGenericGradientEditor.cpp.

480{
481 m_d->useGradientPresetChooserPopUp = use;
483 m_d->updateCachedSizeHint();
484}

References m_d, and updateGradientPresetChooser().

◆ sigGradientChanged

void KisGenericGradientEditor::sigGradientChanged ( )
signal

signal emitted when the gradient changes

◆ sizeHint()

QSize KisGenericGradientEditor::sizeHint ( ) const
override

Definition at line 501 of file KisGenericGradientEditor.cpp.

502{
503 return m_d->cachedSizeHint;
504}

References m_d.

◆ updateAddGradientButton()

void KisGenericGradientEditor::updateAddGradientButton ( )
private

Definition at line 548 of file KisGenericGradientEditor.cpp.

549{
550 m_d->buttonAddGradient->setVisible(!m_d->compactMode && m_d->isAddGradientButtonVisible);
551 m_d->buttonAddGradient->setEnabled(m_d->gradient && !m_d->gradient->name().isEmpty());
552}

References m_d.

◆ updateCachedSizeHint()

void KisGenericGradientEditor::updateCachedSizeHint ( )
inline

Definition at line 67 of file KisGenericGradientEditor.cpp.

68 {
69 static bool editorWidthHintComputed = false;
70 static int editorWidthHint;
71 static int editorMinimumWidthHint;
72 if (!editorWidthHintComputed) {
73 KisStopGradientEditor stopGradientEditor(nullptr);
74 KisSegmentGradientEditor segmentGradientEditor(nullptr);
75 editorWidthHint = qMax(stopGradientEditor.sizeHint().width(), segmentGradientEditor.sizeHint().width());
76 editorMinimumWidthHint = qMax(stopGradientEditor.minimumSizeHint().width(), segmentGradientEditor.minimumSizeHint().width());
77 editorWidthHintComputed = true;
78 }
79
80 const bool presetChooserHidden = useGradientPresetChooserPopUp || !isGradientPresetChooserVisible;
81
82 cachedSizeHint = QSize(
83 qMax(widgetGradientPresetChooser->sizeHint().width(), editorWidthHint),
84
85 (presetChooserHidden ? 0 : widgetGradientPresetChooser->minimumHeight()) +
88 (presetChooserHidden ? 15 : 25) // spacing
89 );
90
92 qMax(widgetGradientPresetChooser->minimumSizeHint().width(), editorMinimumWidthHint),
93
94 (presetChooserHidden ? 0 : widgetGradientPresetChooser->minimumHeight()) +
97 (presetChooserHidden ? 15 : 25) // spacing
98 );
99 }
QSize minimumSizeHint() const override
KisGradientChooser * widgetGradientPresetChooser

◆ updateConvertGradientButton()

void KisGenericGradientEditor::updateConvertGradientButton ( )
private

Definition at line 519 of file KisGenericGradientEditor.cpp.

520{
521 bool isSegmentGradient = dynamic_cast<KisSegmentGradientEditor*>(m_d->widgetGradientEditor);
522
523 m_d->buttonConvertGradient->setVisible(!m_d->compactMode && m_d->isConvertGradientButtonVisible);
524 m_d->labelConvertGradientWarning->setVisible(!m_d->compactMode && m_d->isConvertGradientButtonVisible && isSegmentGradient);
525
526 m_d->buttonConvertGradient->setText(
527 m_d->gradient
528 ? isSegmentGradient
529 ? i18nc("Convert the segment gradient to a stop gradient", "Convert to Stop Gradient")
530 : i18nc("Convert the stop gradient to a segment gradient", "Convert to Segment Gradient")
531 : i18nc("A gradient wasn't set in the generic gradient editor", "No Gradient Set")
532 );
533
534 m_d->buttonConvertGradient->setEnabled(!m_d->gradient.isNull());
535}

References m_d.

◆ updateGradientEditor()

void KisGenericGradientEditor::updateGradientEditor ( )
private

Definition at line 602 of file KisGenericGradientEditor.cpp.

603{
604 if (dynamic_cast<KisStopGradientEditor*>(m_d->widgetGradientEditor)) {
605 dynamic_cast<KisStopGradientEditor*>(m_d->widgetGradientEditor)->setCompactMode(m_d->compactGradientEditorMode);
606 }
607 else if (dynamic_cast<KisSegmentGradientEditor*>(m_d->widgetGradientEditor)) {
608 dynamic_cast<KisSegmentGradientEditor*>(m_d->widgetGradientEditor)->setCompactMode(m_d->compactGradientEditorMode);
609 }
610}

References m_d, and setCompactMode().

◆ updateGradientPresetChooser()

void KisGenericGradientEditor::updateGradientPresetChooser ( )
private

Definition at line 554 of file KisGenericGradientEditor.cpp.

555{
556 m_d->widgetGradientPresetChooser->resourceItemChooser()->showImportExportBtns(!m_d->compactGradientPresetChooserMode);
557 m_d->widgetGradientPresetChooser->resourceItemChooser()->showStorageBtn(!m_d->compactGradientPresetChooserMode);
558 m_d->widgetGradientPresetChooser->resourceItemChooser()->showTaggingBar(!m_d->compactGradientPresetChooserMode);
559 m_d->widgetGradientPresetChooser->resourceItemChooser()->showViewModeBtn(!m_d->compactGradientPresetChooserMode);
560
561 {
562 int margin = !m_d->useGradientPresetChooserPopUp || m_d->compactGradientPresetChooserMode ? 0 : 10;
563 m_d->widgetGradientPresetChooser->setContentsMargins(margin, margin, margin, margin);
564
565 if (m_d->useGradientPresetChooserPopUp) {
566 if (!m_d->widgetToolButtonGradientPresetChooser->children().contains(m_d->widgetGradientPresetChooser)) {
567 layout()->removeWidget(m_d->widgetGradientPresetChooser);
568 m_d->widgetToolButtonGradientPresetChooser->layout()->addWidget(m_d->widgetGradientPresetChooser);
569 }
570 m_d->widgetGradientPresetChooser->setMinimumSize(
571 m_d->compactGradientPresetChooserMode ? 300 : 320,
573 );
574 m_d->widgetGradientPresetChooser->adjustSize();
575 } else {
576 if (!children().contains(m_d->widgetGradientPresetChooser)) {
577 m_d->widgetToolButtonGradientPresetChooser->layout()->removeWidget(m_d->widgetGradientPresetChooser);
578 static_cast<QVBoxLayout*>(layout())->insertWidget(0, m_d->widgetGradientPresetChooser, 1);
579 }
580 m_d->widgetGradientPresetChooser->setMinimumSize(
581 0,
582 m_d->compactGradientPresetChooserMode ? 100 : 200
583 );
584 m_d->widgetGradientPresetChooser->show();
585 }
586 }
587
588 m_d->toolButtonGradientPresetChooser->setVisible(
589 !m_d->compactMode &&
590 m_d->isGradientPresetChooserVisible &&
591 m_d->useGradientPresetChooserPopUp
592 );
593 m_d->toolButtonGradientPresetChooserOptions->setVisible(
594 !m_d->compactMode &&
595 m_d->isGradientPresetChooserVisible &&
596 m_d->isGradientPresetChooserOptionsButtonVisible
597 );
598 m_d->actionUseGradientPresetChooserPopUp->setChecked(m_d->useGradientPresetChooserPopUp);
599 m_d->actionCompactGradientPresetChooserMode->setChecked(m_d->compactGradientPresetChooserMode);
600}

References m_d.

◆ updateUpdateGradientButton()

void KisGenericGradientEditor::updateUpdateGradientButton ( )
private

Definition at line 537 of file KisGenericGradientEditor.cpp.

538{
539 m_d->buttonUpdateGradient->setVisible(!m_d->compactMode && m_d->isUpdateGradientButtonVisible);
540 KoResourceSP selectedGradient = m_d->widgetGradientPresetChooser->currentResource();
541 m_d->buttonUpdateGradient->setEnabled(
542 m_d->gradient && selectedGradient &&
543 m_d->gradient->resourceId() == selectedGradient->resourceId() &&
544 !selectedGradient->permanent()
545 );
546}

References m_d.

◆ useGradientPresetChooserPopUp()

bool KisGenericGradientEditor::useGradientPresetChooserPopUp ( ) const

Tell if the gradient preset chooser is being shown as a pop-up clicking a button or embedded in the widget ui.

Returns
true if the gradient preset chooser is being shown as a pop-up, false otherwise
See also
setGradientPresetChooserVisible(bool)

Member Data Documentation

◆ actionCompactGradientPresetChooserMode

QAction* KisGenericGradientEditor::actionCompactGradientPresetChooserMode

Definition at line 52 of file KisGenericGradientEditor.cpp.

◆ actionUseGradientPresetChooserPopUp

QAction* KisGenericGradientEditor::actionUseGradientPresetChooserPopUp

Definition at line 51 of file KisGenericGradientEditor.cpp.

◆ buttonAddGradient

QPushButton* KisGenericGradientEditor::buttonAddGradient

Definition at line 45 of file KisGenericGradientEditor.cpp.

◆ buttonConvertGradient

QPushButton* KisGenericGradientEditor::buttonConvertGradient

Definition at line 43 of file KisGenericGradientEditor.cpp.

◆ buttonUpdateGradient

QPushButton* KisGenericGradientEditor::buttonUpdateGradient

Definition at line 44 of file KisGenericGradientEditor.cpp.

◆ cachedMinimumSizeHint

QSize KisGenericGradientEditor::cachedMinimumSizeHint

Definition at line 65 of file KisGenericGradientEditor.cpp.

◆ cachedSizeHint

QSize KisGenericGradientEditor::cachedSizeHint

Definition at line 65 of file KisGenericGradientEditor.cpp.

◆ canvasResourcesInterface

KoCanvasResourcesInterfaceSP KisGenericGradientEditor::canvasResourcesInterface

Definition at line 40 of file KisGenericGradientEditor.cpp.

◆ compactGradientEditorMode

bool KisGenericGradientEditor::compactGradientEditorMode

Definition at line 63 of file KisGenericGradientEditor.cpp.

◆ compactGradientPresetChooserMode

bool KisGenericGradientEditor::compactGradientPresetChooserMode

Definition at line 62 of file KisGenericGradientEditor.cpp.

◆ compactMode

bool KisGenericGradientEditor::compactMode

Definition at line 55 of file KisGenericGradientEditor.cpp.

◆ gradient

KoAbstractGradientSP KisGenericGradientEditor::gradient

Definition at line 39 of file KisGenericGradientEditor.cpp.

◆ isAddGradientButtonVisible

bool KisGenericGradientEditor::isAddGradientButtonVisible

Definition at line 58 of file KisGenericGradientEditor.cpp.

◆ isConvertGradientButtonVisible

bool KisGenericGradientEditor::isConvertGradientButtonVisible

Definition at line 56 of file KisGenericGradientEditor.cpp.

◆ isGradientPresetChooserOptionsButtonVisible

bool KisGenericGradientEditor::isGradientPresetChooserOptionsButtonVisible

Definition at line 60 of file KisGenericGradientEditor.cpp.

◆ isGradientPresetChooserVisible

bool KisGenericGradientEditor::isGradientPresetChooserVisible

Definition at line 59 of file KisGenericGradientEditor.cpp.

◆ isUpdateGradientButtonVisible

bool KisGenericGradientEditor::isUpdateGradientButtonVisible

Definition at line 57 of file KisGenericGradientEditor.cpp.

◆ labelConvertGradientWarning

QLabel* KisGenericGradientEditor::labelConvertGradientWarning

Definition at line 46 of file KisGenericGradientEditor.cpp.

◆ m_d

QScopedPointer<Private> KisGenericGradientEditor::m_d
private

Definition at line 219 of file KisGenericGradientEditor.h.

◆ q

KisGenericGradientEditor* KisGenericGradientEditor::q

Definition at line 42 of file KisGenericGradientEditor.cpp.

◆ toolButtonGradientPresetChooser

QToolButton* KisGenericGradientEditor::toolButtonGradientPresetChooser

Definition at line 48 of file KisGenericGradientEditor.cpp.

◆ toolButtonGradientPresetChooserOptions

KisPopupButton* KisGenericGradientEditor::toolButtonGradientPresetChooserOptions

Definition at line 50 of file KisGenericGradientEditor.cpp.

◆ useGradientPresetChooserPopUp

bool KisGenericGradientEditor::useGradientPresetChooserPopUp

Definition at line 61 of file KisGenericGradientEditor.cpp.

◆ widgetGradientEditor

QWidget* KisGenericGradientEditor::widgetGradientEditor

Definition at line 53 of file KisGenericGradientEditor.cpp.

◆ widgetGradientPresetChooser

KisGradientChooser* KisGenericGradientEditor::widgetGradientPresetChooser

Definition at line 47 of file KisGenericGradientEditor.cpp.

◆ widgetToolButtonGradientPresetChooser

QWidget* KisGenericGradientEditor::widgetToolButtonGradientPresetChooser

Definition at line 49 of file KisGenericGradientEditor.cpp.


The documentation for this class was generated from the following files: