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

#include <kis_wdg_seexpr_presets_save.h>

+ Inheritance diagram for KisWdgSeExprPresetsSave:

Public Slots

void loadExistingThumbnail ()
 
void loadImageFromFile ()
 
void renderScriptToThumbnail ()
 
void savePreset ()
 
void setCurrentPreset (KisSeExprScriptSP resource)
 
void setCurrentRenderConfiguration (KisFilterConfigurationSP config)
 

Signals

void resourceSelected (KoResourceSP resource)
 

Public Member Functions

 KisWdgSeExprPresetsSave (QWidget *parent)
 
void showDialog ()
 
void useNewPresetDialog (bool show)
 determines if we should show the save as dialog (true) or save in the background (false)
 
virtual ~KisWdgSeExprPresetsSave ()
 
- Public Member Functions inherited from KisWdgSeExprSavePreset
 KisWdgSeExprSavePreset (QWidget *parent)
 

Private Attributes

KisFilterConfigurationSP m_currentConfiguration
 
KisSeExprScriptSP m_currentPreset
 
bool m_useNewPresetDialog {false}
 

Detailed Description

Definition at line 35 of file kis_wdg_seexpr_presets_save.h.

Constructor & Destructor Documentation

◆ KisWdgSeExprPresetsSave()

KisWdgSeExprPresetsSave::KisWdgSeExprPresetsSave ( QWidget * parent)

Definition at line 28 of file kis_wdg_seexpr_presets_save.cpp.

30 , m_currentPreset(nullptr)
31{
32 // we will default to reusing the previous preset thumbnail
33 // have that checked by default, hide the other elements, and load the last preset image
34 connect(loadExistingThumbnailButton, SIGNAL(clicked(bool)), this, SLOT(loadExistingThumbnail()));
35 connect(loadImageIntoThumbnailButton, SIGNAL(clicked(bool)), this, SLOT(loadImageFromFile()));
36 connect(loadRenderFromScriptButton, SIGNAL(clicked(bool)), this, SLOT(renderScriptToThumbnail()));
37 connect(clearPresetThumbnailButton, SIGNAL(clicked(bool)), presetThumbnailWidget, SLOT(clear()));
38
39 KGuiItem::assign(buttons->button(QDialogButtonBox::Save), KStandardGuiItem::save());
40 KGuiItem::assign(buttons->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
41
42 connect(buttons, SIGNAL(accepted()), this, SLOT(savePreset()));
43 connect(buttons, SIGNAL(rejected()), this, SLOT(close()));
44}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
QString buttons(const T &ev)
QAction * close(const QObject *recvr, const char *slot, QObject *parent)
QAction * clear(const QObject *recvr, const char *slot, QObject *parent)

References buttons(), connect(), loadExistingThumbnail(), loadImageFromFile(), renderScriptToThumbnail(), and savePreset().

◆ ~KisWdgSeExprPresetsSave()

KisWdgSeExprPresetsSave::~KisWdgSeExprPresetsSave ( )
virtual

Definition at line 46 of file kis_wdg_seexpr_presets_save.cpp.

47{
48}

Member Function Documentation

◆ loadExistingThumbnail

void KisWdgSeExprPresetsSave::loadExistingThumbnail ( )
slot

Definition at line 116 of file kis_wdg_seexpr_presets_save.cpp.

117{
118 presetThumbnailWidget->setPixmap(QPixmap::fromImage(m_currentPreset->image()));
119}

References m_currentPreset.

◆ loadImageFromFile

void KisWdgSeExprPresetsSave::loadImageFromFile ( )
slot

Definition at line 99 of file kis_wdg_seexpr_presets_save.cpp.

100{
101 // create a dialog to retrieve an image file.
102 KoFileDialog dialog(0, KoFileDialog::OpenFile, "OpenDocument");
104 dialog.setDefaultDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
105 QString filename = dialog.filename(); // the filename() returns the entire path & file name, not just the file name
106
107 if (!filename.isEmpty()) { // empty if "cancel" is pressed
108 // take that file and load it into the thumbnail are
109 const QImage imageToLoad(filename);
110
111 presetThumbnailWidget->clear(); // clear the background in case our new image has transparency
112 presetThumbnailWidget->setPixmap(QPixmap::fromImage(imageToLoad));
113 }
114}
static QStringList supportedMimeTypes(Direction direction)

References KisImportExportManager::Import, KoFileDialog::OpenFile, and KisImportExportManager::supportedMimeTypes().

◆ renderScriptToThumbnail

void KisWdgSeExprPresetsSave::renderScriptToThumbnail ( )
slot

Definition at line 121 of file kis_wdg_seexpr_presets_save.cpp.

122{
124 // TODO add some sort of progress marker?
127 src->setDefaultBounds(bounds);
128 src->setSupportsWraparoundMode(true);
129 KisFillPainter fillPainter(src);
130 fillPainter.fillRect(0, 0, 256, 256, m_currentConfiguration);
131
132 QImage thumbnail = src->convertToQImage(nullptr, 0, 0, 256, 256);
133 presetThumbnailWidget->setPixmap(QPixmap::fromImage(thumbnail));
134 }
135}
KisFilterConfigurationSP m_currentConfiguration
#define bounds(x, a, b)
The KisWrapAroundBoundsWrapper class wrapper around a KisDefaultBoundsBaseSP to enable wraparound....
static KoColorSpaceRegistry * instance()

References bounds, KisFillPainter::fillRect(), KoColorSpaceRegistry::instance(), and m_currentConfiguration.

◆ resourceSelected

void KisWdgSeExprPresetsSave::resourceSelected ( KoResourceSP resource)
signal

◆ savePreset

void KisWdgSeExprPresetsSave::savePreset ( )
slot

Definition at line 137 of file kis_wdg_seexpr_presets_save.cpp.

138{
140
142 QModelIndex idx = model.indexForResourceId(m_currentPreset->resourceId());
143 bool r = true;
144
145 if (idx.isValid() && !m_useNewPresetDialog) {
146 // saving a preset that is replacing an existing one
147 const QString presetFileName = m_currentPreset->name().split(" ").join("_");
148#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
149 if (!presetThumbnailWidget->pixmap()->isNull()) {
150 m_currentPreset->setImage(presetThumbnailWidget->pixmap()->toImage());
151 }
152#else
153 if (!presetThumbnailWidget->pixmap().isNull()) {
154 m_currentPreset->setImage(presetThumbnailWidget->pixmap().toImage());
155 }
156#endif
157 m_currentPreset->setScript(m_currentConfiguration->getString("script"));
158 m_currentPreset->setFilename(presetFileName + m_currentPreset->defaultFileExtension());
159 m_currentPreset->setValid(true);
161 if (r) {
163 }
164 } else {
165 // Saving a completely new preset
166 // Clone the preset, otherwise the modifications will impact the existing resource
167 KisSeExprScriptSP newPreset = m_currentPreset->clone().dynamicCast<KisSeExprScript>();
168
169 if (newPreset) {
170 const QString presetFileName = newPresetNameTextField->text().split(" ").join("_");
171 newPreset->setName(newPresetNameTextField->text());
172 newPreset->setFilename(presetFileName + newPreset->defaultFileExtension());
173#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
174 if (!presetThumbnailWidget->pixmap()->isNull()) {
175 newPreset->setImage(presetThumbnailWidget->pixmap()->toImage());
176 }
177#else
178 if (!presetThumbnailWidget->pixmap().isNull()) {
179 newPreset->setImage(presetThumbnailWidget->pixmap().toImage());
180 }
181#endif
182 newPreset->setScript(m_currentConfiguration->getString("script"));
183 newPreset->setValid(true);
184
186
187 // trying to get brush preset to load after it is created
188 if (r) {
189 m_currentPreset = newPreset;
191 }
192 }
193 }
194
195 close(); // we are done... so close the save brush dialog
196}
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="")
static bool updateResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource)
void resourceSelected(KoResourceSP resource)
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75
const QString SeExprScripts

References KisResourceUserOperations::addResourceWithUserInput(), KisResourceModel::indexForResourceId(), KIS_ASSERT_RECOVER_RETURN, m_currentConfiguration, m_currentPreset, m_useNewPresetDialog, resourceSelected(), ResourceType::SeExprScripts, and KisResourceUserOperations::updateResourceWithUserInput().

◆ setCurrentPreset

void KisWdgSeExprPresetsSave::setCurrentPreset ( KisSeExprScriptSP resource)
slot

Definition at line 50 of file kis_wdg_seexpr_presets_save.cpp.

51{
52 m_currentPreset = resource;
53}

References m_currentPreset.

◆ setCurrentRenderConfiguration

void KisWdgSeExprPresetsSave::setCurrentRenderConfiguration ( KisFilterConfigurationSP config)
slot

Definition at line 55 of file kis_wdg_seexpr_presets_save.cpp.

56{
58}

References m_currentConfiguration.

◆ showDialog()

void KisWdgSeExprPresetsSave::showDialog ( )

Definition at line 60 of file kis_wdg_seexpr_presets_save.cpp.

61{
62 setModal(true);
63
64 // set the name of the current preset area.
66
67 // UI will look a bit different if we are saving a new preset
69 setWindowTitle(i18n("Save New SeExpr Preset"));
70
71 if (preset) {
72 // If the id is -1, this is a new preset that has never been saved, so it cannot be a copy
73 QString name = preset->name().replace("_", " ");
74 if (preset->resourceId() > -1) {
75 name = QString("%1 %2").arg(name, i18n("Copy"));
76 }
77 newPresetNameTextField->setText(name);
78 newPresetNameTextField->setReadOnly(false);
79 newPresetNameTextField->setEnabled(true);
80 }
81 } else {
82 setWindowTitle(i18n("Save SeExpr Preset"));
83
84 if (preset) {
85 const QString name(preset->name().replace("_", " "));
86 newPresetNameTextField->setText(name);
87 newPresetNameTextField->setReadOnly(true);
88 newPresetNameTextField->setEnabled(false);
89 }
90 }
91
92 if (preset) {
93 presetThumbnailWidget->setPixmap(QPixmap::fromImage(preset->image()));
94 }
95
96 open();
97}
QAction * open(const QObject *recvr, const char *slot, QObject *parent)
const char * name(StandardAction id)

References m_currentPreset, and m_useNewPresetDialog.

◆ useNewPresetDialog()

void KisWdgSeExprPresetsSave::useNewPresetDialog ( bool show)

determines if we should show the save as dialog (true) or save in the background (false)

Definition at line 198 of file kis_wdg_seexpr_presets_save.cpp.

199{
201}

References m_useNewPresetDialog.

Member Data Documentation

◆ m_currentConfiguration

KisFilterConfigurationSP KisWdgSeExprPresetsSave::m_currentConfiguration
private

Definition at line 63 of file kis_wdg_seexpr_presets_save.h.

◆ m_currentPreset

KisSeExprScriptSP KisWdgSeExprPresetsSave::m_currentPreset
private

Definition at line 62 of file kis_wdg_seexpr_presets_save.h.

◆ m_useNewPresetDialog

bool KisWdgSeExprPresetsSave::m_useNewPresetDialog {false}
private

Definition at line 61 of file kis_wdg_seexpr_presets_save.h.

61{false};

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