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

#include <KisDlgSavePreset.h>

+ Inheritance diagram for KisPresetSaveWidget:

Public Slots

void loadExistingThumbnail ()
 
void loadImageFromFile ()
 
void loadImageFromLibrary ()
 
void loadScratchpadThumbnail ()
 
void savePreset ()
 

Signals

void resourceSelected (KoResourceSP resource)
 

Public Member Functions

 KisPresetSaveWidget (QWidget *parent)
 
void saveScratchPadThumbnailArea (const QImage image)
 
void scratchPadSetup (KisCanvasResourceProvider *resourceProvider)
 
void setFavoriteResourceManager (KisFavoriteResourceManager *favManager)
 
void showDialog ()
 
void useNewBrushDialog (bool show)
 determines if we should show the save as dialog (true) or save in the background (false)
 
virtual ~KisPresetSaveWidget ()
 
- Public Member Functions inherited from KisPaintOpPresetSaveDialog
 KisPaintOpPresetSaveDialog (QWidget *parent)
 

Public Attributes

KisCanvasResourceProviderm_resourceProvider {0}
 

Private Attributes

KisFavoriteResourceManagerm_favoriteResourceManager {0}
 
bool m_useNewBrushDialog {false}
 
QImage scratchPadThumbnailArea
 

Detailed Description

Definition at line 27 of file KisDlgSavePreset.h.

Constructor & Destructor Documentation

◆ KisPresetSaveWidget()

KisPresetSaveWidget::KisPresetSaveWidget ( QWidget * parent)

Definition at line 26 of file KisDlgSavePreset.cpp.

28{
29 // this is setting the area we will "capture" for saving the brush preset. It can potentially be a different
30 // area that the entire scratchpad
31 brushPresetThumbnailWidget->setCutoutOverlayRect(QRect(0, 0, brushPresetThumbnailWidget->height(), brushPresetThumbnailWidget->width()));
32
33
34 // we will default to reusing the previous preset thumbnail
35 // have that checked by default, hide the other elements, and load the last preset image
36 connect(clearBrushPresetThumbnailButton, SIGNAL(clicked(bool)), brushPresetThumbnailWidget, SLOT(fillDefault()));
37 connect(loadImageIntoThumbnailButton, SIGNAL(clicked(bool)), this, SLOT(loadImageFromFile()));
38
39 connect(loadScratchPadThumbnailButton, SIGNAL(clicked(bool)), this, SLOT(loadScratchpadThumbnail()));
40 connect(loadExistingThumbnailButton, SIGNAL(clicked(bool)), this, SLOT(loadExistingThumbnail()));
41 connect(loadIconLibraryThumbnailButton, SIGNAL(clicked(bool)), this, SLOT(loadImageFromLibrary()));
42
43 KGuiItem::assign(buttons->button(QDialogButtonBox::Save), KStandardGuiItem::save());
44 KGuiItem::assign(buttons->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
45 connect(buttons, SIGNAL(accepted()), this, SLOT(savePreset()));
46 connect(buttons, SIGNAL(rejected()), this, SLOT(close()));
47}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
KisPaintOpPresetSaveDialog(QWidget *parent)
QString buttons(const T &ev)
QAction * close(const QObject *recvr, const char *slot, QObject *parent)

References buttons(), connect(), loadExistingThumbnail(), loadImageFromFile(), loadImageFromLibrary(), loadScratchpadThumbnail(), and savePreset().

◆ ~KisPresetSaveWidget()

KisPresetSaveWidget::~KisPresetSaveWidget ( )
virtual

Definition at line 49 of file KisDlgSavePreset.cpp.

50{
51
52}

Member Function Documentation

◆ loadExistingThumbnail

void KisPresetSaveWidget::loadExistingThumbnail ( )
slot

Definition at line 124 of file KisDlgSavePreset.cpp.

125{
126 brushPresetThumbnailWidget->paintPresetImage();
127}

◆ loadImageFromFile

void KisPresetSaveWidget::loadImageFromFile ( )
slot

Definition at line 100 of file KisDlgSavePreset.cpp.

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

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

◆ loadImageFromLibrary

void KisPresetSaveWidget::loadImageFromLibrary ( )
slot

Definition at line 129 of file KisDlgSavePreset.cpp.

130{
131 //add dialog code here.
132 QDialog dialog;
133 dialog.setWindowTitle(i18n("Preset Icon Library"));
134 QVBoxLayout *layout = new QVBoxLayout(&dialog);
135
137 layout->addWidget(libWidget);
138 QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
139 KGuiItem::assign(buttons->button(QDialogButtonBox::Ok), KStandardGuiItem::ok());
140 KGuiItem::assign(buttons->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
141 connect(buttons, SIGNAL(accepted()), &dialog, SLOT(accept()));
142 connect(buttons, SIGNAL(rejected()), &dialog, SLOT(reject()));
143 layout->addWidget(buttons);
144
145 //if dialog accepted, get image.
146 if (dialog.exec() == QDialog::Accepted) {
147
148 QImage presetImage = libWidget->getImage();
149 brushPresetThumbnailWidget->paintCustomImage(presetImage);
150 }
151}

References buttons(), connect(), and KisPaintopPresetIconLibrary::getImage().

◆ loadScratchpadThumbnail

void KisPresetSaveWidget::loadScratchpadThumbnail ( )
slot

Definition at line 119 of file KisDlgSavePreset.cpp.

120{
121 brushPresetThumbnailWidget->paintCustomImage(scratchPadThumbnailArea);
122}

References scratchPadThumbnailArea.

◆ resourceSelected

void KisPresetSaveWidget::resourceSelected ( KoResourceSP resource)
signal

◆ savePreset

void KisPresetSaveWidget::savePreset ( )
slot

Definition at line 158 of file KisDlgSavePreset.cpp.

159{
161 if (!curPreset) {
162 return;
163 }
164
165 // if we are saving a new brush, use what we type in for the input
166 QString presetFileName = m_useNewBrushDialog ? newBrushNameTexField->text() : curPreset->name();
167 // We don't want dots or spaces in the filenames
168 presetFileName = presetFileName.replace(' ', '_').replace('.', '_');
169 QString extension = curPreset->defaultFileExtension();
170
171 // Ensure the filename has the corresponding extension
172 if (!presetFileName.endsWith(extension)) {
173 presetFileName.append(extension);
174 }
175
176 bool success = true;
177
179 KisPaintOpPresetSP newPreset = curPreset->clone().dynamicCast<KisPaintOpPreset>();
180 newPreset->setResourceId(-1); // so it won't confuse anything into overwriting
181 newPreset->setFilename(presetFileName);
182 newPreset->setName(m_useNewBrushDialog ? newBrushNameTexField->text() : curPreset->name());
183 newPreset->setImage(brushPresetThumbnailWidget->cutoutOverlay());
184 newPreset->setValid(true);
185 newPreset->setStorageLocation("");
187 success = false;
188 }
189
190 // trying to get brush preset to load after it is created
191 if (success) Q_EMIT resourceSelected(newPreset);
192
193 }
194 else { // saving a preset that is replacing an existing one
195 curPreset->setName(m_useNewBrushDialog ? newBrushNameTexField->text() : curPreset->name());
196 curPreset->setImage(brushPresetThumbnailWidget->cutoutOverlay());
197 // Ensure it has the updated name (for mypaint serialization) -- BUG 445282
198 curPreset->setFilename(presetFileName);
199
201 success = false;
202 }
203
204 // this helps updating the thumbnail in the big label in the editor
205 if (success) Q_EMIT resourceSelected(curPreset);
206 }
207
208
209 // // HACK ALERT! the server does not notify the observers
210 // // automatically, so we need to call the update manually!
211 // rServer->tagCategoryMembersChanged();
212 if (success) {
214 close(); // we are done... so close the save brush dialog
215 }
216
217}
KisPaintOpPresetSP currentPreset() const
KisFavoriteResourceManager * m_favoriteResourceManager
void resourceSelected(KoResourceSP resource)
KisCanvasResourceProvider * m_resourceProvider
static bool addResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource, QString storageLocation="")
static bool updateResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource)
const char * name(StandardAction id)

References KisResourceUserOperations::addResourceWithUserInput(), KisCanvasResourceProvider::currentPreset(), m_favoriteResourceManager, m_resourceProvider, m_useNewBrushDialog, resourceSelected(), KisFavoriteResourceManager::updateFavoritePresets(), and KisResourceUserOperations::updateResourceWithUserInput().

◆ saveScratchPadThumbnailArea()

void KisPresetSaveWidget::saveScratchPadThumbnailArea ( const QImage image)

Definition at line 221 of file KisDlgSavePreset.cpp.

222{
224}

References scratchPadThumbnailArea.

◆ scratchPadSetup()

void KisPresetSaveWidget::scratchPadSetup ( KisCanvasResourceProvider * resourceProvider)

Definition at line 54 of file KisDlgSavePreset.cpp.

55{
56 m_resourceProvider = resourceProvider;
57
58 brushPresetThumbnailWidget->setupScratchPad(m_resourceProvider, Qt::white);
59}

References m_resourceProvider.

◆ setFavoriteResourceManager()

void KisPresetSaveWidget::setFavoriteResourceManager ( KisFavoriteResourceManager * favManager)

Definition at line 153 of file KisDlgSavePreset.cpp.

154{
155 m_favoriteResourceManager = favManager;
156}

References m_favoriteResourceManager.

◆ showDialog()

void KisPresetSaveWidget::showDialog ( )

Definition at line 61 of file KisDlgSavePreset.cpp.

62{
63 setModal(true);
64
65 // set the name of the current brush preset area.
67
68 // UI will look a bit different if we are saving a new brush
70 setWindowTitle(i18n("Save New Brush Preset"));
71 newBrushNameTexField->setVisible(true);
72 clearBrushPresetThumbnailButton->setVisible(true);
73 loadImageIntoThumbnailButton->setVisible(true);
74 currentBrushNameLabel->setVisible(false);
75
76 // If the id is -1, this is a new preset that has never been saved, so it cannot be a copy
77 QString name = preset->name();
78 if (preset && preset->resourceId() > -1) {
79 name.append(" ").append(i18n("Copy"));
80 }
81 newBrushNameTexField->setText(name);
82
83
84 } else {
85 setWindowTitle(i18n("Save Brush Preset"));
86
87 if (preset) {
88 currentBrushNameLabel->setText(preset->name());
89 }
90
91 newBrushNameTexField->setVisible(false);
92 currentBrushNameLabel->setVisible(true);
93 }
94
95 brushPresetThumbnailWidget->paintPresetImage();
96
97 open();
98}
QAction * open(const QObject *recvr, const char *slot, QObject *parent)

References KisCanvasResourceProvider::currentPreset(), m_resourceProvider, and m_useNewBrushDialog.

◆ useNewBrushDialog()

void KisPresetSaveWidget::useNewBrushDialog ( bool show)

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

Definition at line 227 of file KisDlgSavePreset.cpp.

228{
229 m_useNewBrushDialog = show;
230}

References m_useNewBrushDialog.

Member Data Documentation

◆ m_favoriteResourceManager

KisFavoriteResourceManager* KisPresetSaveWidget::m_favoriteResourceManager {0}
private

Definition at line 61 of file KisDlgSavePreset.h.

61{0};

◆ m_resourceProvider

KisCanvasResourceProvider* KisPresetSaveWidget::m_resourceProvider {0}

Definition at line 42 of file KisDlgSavePreset.h.

42{0};

◆ m_useNewBrushDialog

bool KisPresetSaveWidget::m_useNewBrushDialog {false}
private

Definition at line 60 of file KisDlgSavePreset.h.

60{false};

◆ scratchPadThumbnailArea

QImage KisPresetSaveWidget::scratchPadThumbnailArea
private

Definition at line 62 of file KisDlgSavePreset.h.


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