Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_dlg_generator_layer.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2008 Boudewijn Rempt <boud@valdyas.org>
3 * SPDX-FileCopyrightText: 2020 L. E. Segovia <amy@amyspark.me>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7
9
10#include <QGroupBox>
11#include <QLayout>
12#include <QGridLayout>
13
14#include <klocalizedstring.h>
15#include <kstandardguiitem.h>
16
17#include <kis_config_widget.h>
19#include <kis_paint_device.h>
20#include <kis_transaction.h>
22#include <kis_generator_layer.h>
23#include <KisViewManager.h>
24#include <KisDocument.h>
26#include <kis_icon_utils.h>
27
28#define UPDATE_DELAY 100 /*ms */
29
30KisDlgGeneratorLayer::KisDlgGeneratorLayer(const QString & defaultName, KisViewManager *view, QWidget *parent, KisGeneratorLayerSP glayer = 0, const KisFilterConfigurationSP previousConfig = 0, const KisStrokeId stroke = KisStrokeId())
31 : QDialog(parent)
32 , layer(glayer)
33 , m_view(view)
34 , isEditing(layer && previousConfig)
35 , m_customName(false)
36 , m_freezeName(false)
37 , m_stroke(stroke)
38 , m_compressor(UPDATE_DELAY, KisSignalCompressor::FIRST_INACTIVE)
39{
40 if(isEditing){
41 setModal(false);
42 configBefore = previousConfig->cloneWithResourcesSnapshot();
43 }
44
45 dlgWidget.setupUi(this);
46 dlgWidget.wdgGenerator->initialize(m_view);
47 dlgWidget.btnBox->button(QDialogButtonBox::Ok)->setDefault(true);
48 KGuiItem::assign(dlgWidget.btnBox->button(QDialogButtonBox::Ok), KStandardGuiItem::ok());
49 KGuiItem::assign(dlgWidget.btnBox->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
50
51 dlgWidget.txtLayerName->setText( isEditing ? layer->name() : defaultName );
52 connect(dlgWidget.txtLayerName, SIGNAL(textChanged(QString)),
53 this, SLOT(slotNameChanged(QString)));
54 connect(dlgWidget.wdgGenerator, SIGNAL(previewConfiguration()), this, SLOT(previewGenerator()));
55 connect(&m_compressor, SIGNAL(timeout()), this, SLOT(slotDelayedPreviewGenerator()));
56
57 dlgWidget.filterGalleryToggle->setIcon(KisIconUtils::loadIcon("sidebaricon"));
58 dlgWidget.filterGalleryToggle->setChecked(true);
59 connect(dlgWidget.filterGalleryToggle, SIGNAL(toggled(bool)), dlgWidget.wdgGenerator, SLOT(showFilterGallery(bool)));
60
61 connect(dlgWidget.btnBox, SIGNAL(accepted()), this, SLOT(accept()));
62 connect(dlgWidget.btnBox, SIGNAL(rejected()), this, SLOT(reject()));
63 connect(this, SIGNAL(accepted()), this, SLOT(saveLayer()));
64 connect(this, SIGNAL(rejected()), this, SLOT(restoreLayer()));
65
66 if (layer && !isEditing) {
68 }
69
70 restoreGeometry(KisConfig(true).readEntry("generatordialog/geometry", QByteArray()));
71}
72
74{
75 /*
76 * Editing a layer should be using the show function with automatic deletion on close.
77 * Because of this, the action should be taken care of when the window is closed and
78 * the user has accepted the changes.
79 */
80 if (isEditing) {
82
84 Q_ASSERT(configAfter);
85 QString xmlBefore = configBefore->toXML();
86 QString xmlAfter = configAfter->toXML();
87
88 if (xmlBefore != xmlAfter) {
92 configAfter->cloneWithResourcesSnapshot());
93
95 m_view->document()->setModified(true);
96 }
97 } else {
99 layer->setFilter(configuration()->cloneWithResourcesSnapshot());
100 }
101}
102
104{
105 if (isEditing)
106 {
108 }
109}
110
112{
113 KisConfig(false).writeEntry("generatordialog/geometry", saveGeometry());
114}
115
117{
118 if (m_freezeName)
119 return;
120
121 m_customName = !text.isEmpty();
122 dlgWidget.btnBox->button(QDialogButtonBox::Ok)->setEnabled(m_customName);
123}
124
126{
127 if (!m_stroke.isNull()) {
128 if (m_updateCookie) {
130 } else {
131 layer->setFilterWithoutUpdate(configuration()->cloneWithResourcesSnapshot());
133 }
134 } else {
136 layer->setFilter(configuration()->cloneWithResourcesSnapshot());
137 }
138}
139
144
146{
147 dlgWidget.wdgGenerator->setConfiguration(config);
148 // hack! forcibly re-render the layer
150}
151
153{
154 return dlgWidget.wdgGenerator->configuration();
155}
156
158{
159 return dlgWidget.txtLayerName->text();
160}
161
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void writeEntry(const QString &name, const T &value)
Definition kis_config.h:779
KisFilterConfigurationSP configuration() const
void setConfiguration(const KisFilterConfigurationSP config)
KisThreadSafeSignalCompressor m_compressor
QWeakPointer< boost::none_t > m_updateCookie
Ui_WdgDlgGeneratorLayer dlgWidget
void slotNameChanged(const QString &)
KisDlgGeneratorLayer(const QString &defaultLayerName, KisViewManager *arg_view, QWidget *parent, KisGeneratorLayerSP glayer, const KisFilterConfigurationSP previousConfig, const KisStrokeId stroke)
KisFilterConfigurationSP configBefore
void setModified(bool _mod)
virtual void addCommand(KUndo2Command *cmd)=0
KisDocument * document() const
KisUndoAdapter * undoAdapter()
The undo adapter is used to add commands to the undo stack.
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75
#define UPDATE_DELAY
KisStrokeWSP KisStrokeId
Definition kis_types.h:272
QIcon loadIcon(const QString &name)
void setName(const QString &name)
QString name() const
void setFilterWithoutUpdate(KisFilterConfigurationSP filterConfig, bool checkCompareConfig=true)
QWeakPointer< boost::none_t > previewWithStroke(const KisStrokeId stroke)
void setFilter(KisFilterConfigurationSP filterConfig, bool checkCompareConfig=true) override