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

#include <gamutmask_dock.h>

+ Inheritance diagram for GamutMaskDock:

Signals

void sigGamutMaskChanged (KoGamutMaskSP mask)
 
void sigGamutMaskPreviewUpdate ()
 
void sigGamutMaskSet (KoGamutMaskSP mask)
 
void sigGamutMaskUnset ()
 

Public Member Functions

 GamutMaskDock ()
 
QString observerName () override
 
void removingResource (KoGamutMaskSP resource) override
 
void resourceAdded (KoGamutMaskSP) override
 
void resourceChanged (KoGamutMaskSP resource) override
 
void setCanvas (KoCanvasBase *canvas) override
 
void setViewManager (KisViewManager *kisview) override
 
void unsetCanvas () override
 
void unsetResourceServer () override
 
 ~GamutMaskDock () override
 
- Public Member Functions inherited from KisMainwindowObserver
 KisMainwindowObserver ()
 
 ~KisMainwindowObserver () override
 
- Public Member Functions inherited from KoCanvasObserverBase
 KoCanvasObserverBase ()
 
KoCanvasBaseobservedCanvas () const
 
void setObservedCanvas (KoCanvasBase *canvas)
 
void unsetObservedCanvas ()
 
virtual ~KoCanvasObserverBase ()
 
- Public Member Functions inherited from KoResourceServerObserver< KoGamutMask >
virtual ~KoResourceServerObserver ()
 

Private Slots

void slotDocumentRemoved (QString filename)
 
void slotDocumentSaved ()
 
void slotGamutMaskCancelEdit ()
 
void slotGamutMaskCreateNew ()
 
void slotGamutMaskDelete ()
 
void slotGamutMaskDuplicate ()
 
void slotGamutMaskEdit ()
 
void slotGamutMaskPreview ()
 
void slotGamutMaskSave ()
 
void slotGamutMaskSelected (KoGamutMaskSP mask)
 
void slotViewChanged ()
 

Private Member Functions

void cancelMaskEdit ()
 
void closeMaskDocument ()
 
KoGamutMaskSP createMaskResource (KoGamutMaskSP sourceMask, QString newTitle)
 
void deleteMask ()
 
KisShapeLayerSP getShapeLayer ()
 
QList< KoShape * > getShapesFromLayer ()
 
int getUserFeedback (QString text, QString informativeText="", QMessageBox::StandardButtons buttons=QMessageBox::Yes|QMessageBox::No, QMessageBox::StandardButton defaultButton=QMessageBox::Yes, QMessageBox::Icon severity=QMessageBox::Warning)
 
bool openMaskEditor ()
 
QPair< QString, QFileInfo > resolveMaskTitle (QString suggestedTitle)
 
int saveOrCancel (QMessageBox::StandardButton defaultAction=QMessageBox::Save)
 
bool saveSelectedMaskResource ()
 
void selectMask (KoGamutMaskSP mask, bool notifyItemChooser=true)
 

Private Attributes

bool m_creatingNewMask {false}
 
GamutMaskChooserUIm_dockerUI {nullptr}
 
bool m_externalTemplateClose {false}
 
KisResourceItemChooserm_maskChooser {nullptr}
 
KisDocumentm_maskDocument {nullptr}
 
KisCanvasResourceProviderm_resourceProvider {nullptr}
 
KoGamutMaskSP m_selectedMask
 
bool m_selfClosingTemplate {false}
 
bool m_selfSelectingMask {false}
 
bool m_templatePrevSaved {false}
 
KisViewm_view {nullptr}
 

Additional Inherited Members

Detailed Description

Definition at line 30 of file gamutmask_dock.h.

Constructor & Destructor Documentation

◆ GamutMaskDock()

GamutMaskDock::GamutMaskDock ( )

Definition at line 55 of file gamutmask_dock.cpp.

56 : QDockWidget(i18n("Gamut Masks"))
57{
59
60 m_dockerUI->bnMaskEditor->setIcon(KisIconUtils::loadIcon("document-edit"));
61 m_dockerUI->bnMaskDelete->setIcon(KisIconUtils::loadIcon("edit-delete"));
62 m_dockerUI->bnMaskNew->setIcon(KisIconUtils::loadIcon("list-add"));
63 m_dockerUI->bnMaskDuplicate->setIcon(KisIconUtils::loadIcon("duplicateitem"));
64
65 m_dockerUI->maskPropertiesBox->setVisible(false);
66 m_dockerUI->bnSaveMask->setIcon(KisIconUtils::loadIcon("document-save-16"));
67 m_dockerUI->bnCancelMaskEdit->setIcon(KisIconUtils::loadIcon("dialog-cancel"));
68 m_dockerUI->bnPreviewMask->setIcon(KisIconUtils::loadIcon("visible"));
69
70 QRegularExpression maskTitleRegex("^[-_\\(\\)\\sA-Za-z0-9]+$");
71 QRegularExpressionValidator* m_maskTitleValidator = new QRegularExpressionValidator(maskTitleRegex, this);
72 m_dockerUI->maskTitleEdit->setValidator(m_maskTitleValidator);
73
75 rServer->addObserver(this);
76
77 // gamut mask connections
78 connect(m_dockerUI->bnSaveMask , SIGNAL(clicked()) , SLOT(slotGamutMaskSave()));
79 connect(m_dockerUI->bnCancelMaskEdit , SIGNAL(clicked()) , SLOT(slotGamutMaskCancelEdit()));
80 connect(m_dockerUI->bnPreviewMask , SIGNAL(clicked()) , SLOT(slotGamutMaskPreview()));
81
82 connect(m_dockerUI->bnMaskEditor , SIGNAL(clicked()) , SLOT(slotGamutMaskEdit()));
83 connect(m_dockerUI->maskChooser, SIGNAL(sigGamutMaskSelected(KoGamutMaskSP)), SLOT(slotGamutMaskSelected(KoGamutMaskSP)));
84 connect(m_dockerUI->bnMaskNew , SIGNAL(clicked()) , SLOT(slotGamutMaskCreateNew()));
85 connect(m_dockerUI->bnMaskDelete , SIGNAL(clicked()) , SLOT(slotGamutMaskDelete()));
86 connect(m_dockerUI->bnMaskDuplicate , SIGNAL(clicked()) , SLOT(slotGamutMaskDuplicate()));
87
88 setWidget(m_dockerUI);
89}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void slotGamutMaskPreview()
GamutMaskChooserUI * m_dockerUI
void slotGamutMaskCreateNew()
void slotGamutMaskSelected(KoGamutMaskSP mask)
void slotGamutMaskCancelEdit()
void slotGamutMaskDuplicate()
void addObserver(ObserverType *observer)
QIcon loadIcon(const QString &name)
static KoResourceServerProvider * instance()
KoResourceServer< KoGamutMask > * gamutMaskServer

References KoResourceServer< T >::addObserver(), connect(), KoResourceServerProvider::gamutMaskServer, KoResourceServerProvider::instance(), KisIconUtils::loadIcon(), m_dockerUI, slotGamutMaskCancelEdit(), slotGamutMaskCreateNew(), slotGamutMaskDelete(), slotGamutMaskDuplicate(), slotGamutMaskEdit(), slotGamutMaskPreview(), slotGamutMaskSave(), and slotGamutMaskSelected().

◆ ~GamutMaskDock()

GamutMaskDock::~GamutMaskDock ( )
override

Member Function Documentation

◆ cancelMaskEdit()

void GamutMaskDock::cancelMaskEdit ( )
private

Definition at line 193 of file gamutmask_dock.cpp.

194{
195 if (m_creatingNewMask) {
196 deleteMask();
197 }
198
199 if (m_selectedMask) {
200 m_selectedMask->clearPreview();
201
204 }
205 }
206
208}
KoGamutMaskSP m_selectedMask
void sigGamutMaskChanged(KoGamutMaskSP mask)
KisCanvasResourceProvider * m_resourceProvider

References closeMaskDocument(), KisCanvasResourceProvider::currentGamutMask(), deleteMask(), m_creatingNewMask, m_resourceProvider, m_selectedMask, and sigGamutMaskChanged().

◆ closeMaskDocument()

void GamutMaskDock::closeMaskDocument ( )
private

Definition at line 372 of file gamutmask_dock.cpp.

373{
374 if (m_maskDocument) {
375
376 disconnect(m_view->viewManager(), SIGNAL(viewChanged()), this, SLOT(slotViewChanged()));
377 disconnect(m_maskDocument, SIGNAL(completed()), this, SLOT(slotDocumentSaved()));
378
379 // the template file is meant as temporary, if the user saved it, delete now
380 if (QFile::exists(m_maskDocument->localFilePath())) {
381 QFile::remove(m_maskDocument->localFilePath());
382 }
383
385 // set the document to not modified to bypass confirmation dialog
386 // the close is already confirmed
388
390 m_view->closeView();
391 m_view->deleteLater();
392
393 // set a flag that we are doing it ourselves, so the docker does not react to
394 // removing signal from KisPart
398 m_selfClosingTemplate = false;
399 }
400 }
401
402 m_dockerUI->maskPropertiesBox->setVisible(false);
403 m_dockerUI->editControlsBox->setVisible(true);
404 m_dockerUI->editControlsBox->setEnabled(true);
405
406 m_maskDocument = nullptr;
407 m_view = nullptr;
408 m_creatingNewMask = false;
409 m_templatePrevSaved = false;
410}
bool m_externalTemplateClose
KisDocument * m_maskDocument
bool m_selfClosingTemplate
QString localFilePath() const
void setModified(bool _mod)
bool closePath(bool promptToSave=true)
static KisPart * instance()
Definition KisPart.cpp:131
void removeView(KisView *view)
Definition KisPart.cpp:344
void removeDocument(KisDocument *document, bool deleteDocument=true)
Definition KisPart.cpp:248
void closeView()
Definition KisView.cpp:1441
KisViewManager * viewManager
Definition KisView.cpp:129

References KisDocument::closePath(), KisView::closeView(), KisPart::instance(), KisDocument::localFilePath(), m_creatingNewMask, m_dockerUI, m_externalTemplateClose, m_maskDocument, m_selfClosingTemplate, m_templatePrevSaved, m_view, KisPart::removeDocument(), KisPart::removeView(), KisDocument::setModified(), slotDocumentSaved(), slotViewChanged(), and KisView::viewManager.

◆ createMaskResource()

KoGamutMaskSP GamutMaskDock::createMaskResource ( KoGamutMaskSP sourceMask,
QString newTitle )
private

Definition at line 337 of file gamutmask_dock.cpp.

338{
339 m_creatingNewMask = true;
340
341 KoGamutMaskSP newMask;
342 if (sourceMask) {
343 newMask = KoGamutMaskSP(new KoGamutMask(sourceMask.data()));
344 newMask->setVersion(-1);
345 newMask->setResourceId(-1);
346 newMask->setImage(sourceMask->image());
347 } else {
348 newMask = KoGamutMaskSP(new KoGamutMask());
349
350 QString defaultPreviewPath = ":/gamutmasks/empty_mask_preview.png";
351 KIS_SAFE_ASSERT_RECOVER_NOOP(!(defaultPreviewPath.isEmpty() || defaultPreviewPath.isNull() || !QFile::exists(defaultPreviewPath)));
352
353 newMask->setImage(QImage(defaultPreviewPath, "PNG"));
354 }
355
357
358 QString saveLocation = rServer->saveLocation();
359 QString name = newTitle;
360
361 QFileInfo fileInfo(saveLocation + "/" + name + newMask->defaultFileExtension());
362
363 newMask->setTitle(name);
364 newMask->setFilename(fileInfo.fileName());
365 newMask->setValid(true);
366
367 // don't save just yet; saving will happen when the user presses Save button on editing
368
369 return newMask;
370}
QSharedPointer< KoGamutMask > KoGamutMaskSP
Definition KoGamutMask.h:98
The resource type for gamut masks used by the artistic color selector.
Definition KoGamutMask.h:44
QString saveLocation()
Returns path where to save user defined and imported resources to.
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130
const char * name(StandardAction id)

References KoResourceServerProvider::gamutMaskServer, KoResourceServerProvider::instance(), KIS_SAFE_ASSERT_RECOVER_NOOP, m_creatingNewMask, and KoResourceServer< T >::saveLocation().

◆ deleteMask()

void GamutMaskDock::deleteMask ( )
private

Definition at line 278 of file gamutmask_dock.cpp.

279{
281 QModelIndex idx = model.indexForResource(m_selectedMask);
282 if (idx.isValid()) {
283 model.setResourceInactive(idx);
284 }
285 m_selectedMask = nullptr;
286}
The KisResourceModel class provides the main access to resources. It is possible to filter the resour...
const QString GamutMasks

References ResourceType::GamutMasks, KisResourceModel::indexForResource(), m_selectedMask, and KisAbstractResourceModel::setResourceInactive().

◆ getShapeLayer()

KisShapeLayerSP GamutMaskDock::getShapeLayer ( )
private

Definition at line 433 of file gamutmask_dock.cpp.

434{
436 return KisShapeLayerSP(dynamic_cast<KisShapeLayer*>(node.data()));
437}
KisImageSP image
KisGroupLayerSP rootLayer() const
KisSharedPtr< KisShapeLayer > KisShapeLayerSP
Definition kis_types.h:125
KisNodeSP findNodeByName(KisNodeSP root, const QString &name)

References KisSharedPtr< T >::data(), KisLayerUtils::findNodeByName(), KisDocument::image, m_maskDocument, and KisImage::rootLayer().

◆ getShapesFromLayer()

QList< KoShape * > GamutMaskDock::getShapesFromLayer ( )
private

Definition at line 412 of file gamutmask_dock.cpp.

413{
414 KisShapeLayerSP shapeLayer = getShapeLayer();
415
416 // create a deep copy of the shapes to save in the mask,
417 // otherwise they vanish when the template closes
418 QList<KoShape*> newShapes;
419
420 if (shapeLayer) {
421 for (KoShape* sh: shapeLayer->shapes()) {
422 KoShape* newShape = sh->cloneShape();
423 KoShapeStrokeSP border(new KoShapeStroke(0.5f, Qt::white));
424 newShape->setStroke(border);
425 newShape->setBackground(QSharedPointer<KoColorBackground>(new KoColorBackground(QColor(255,255,255,0))));
426 newShapes.append(newShape);
427 }
428 }
429
430 return newShapes;
431}
KisShapeLayerSP getShapeLayer()
A simple solid color shape background.
virtual void setStroke(KoShapeStrokeModelSP stroke)
Definition KoShape.cpp:1081
virtual void setBackground(QSharedPointer< KoShapeBackground > background)
Definition KoShape.cpp:918
virtual KoShape * cloneShape() const
creates a deep copy of the shape or shape's subtree
Definition KoShape.cpp:200

References KoShape::cloneShape(), getShapeLayer(), KoShape::setBackground(), KoShape::setStroke(), and KoShapeContainer::shapes().

◆ getUserFeedback()

int GamutMaskDock::getUserFeedback ( QString text,
QString informativeText = "",
QMessageBox::StandardButtons buttons = QMessageBox::Yes | QMessageBox::No,
QMessageBox::StandardButton defaultButton = QMessageBox::Yes,
QMessageBox::Icon severity = QMessageBox::Warning )
private

Definition at line 288 of file gamutmask_dock.cpp.

291{
292 QMessageBox msgBox;
293 msgBox.setWindowTitle(i18nc("@title:window", "Krita"));
294 msgBox.setText(QString("<p><b>%1</b></p>").arg(text));
295 msgBox.setInformativeText(informativeText);
296 msgBox.setStandardButtons(buttons);
297 msgBox.setDefaultButton(defaultButton);
298 msgBox.setIcon(severity);
299 int res = msgBox.exec();
300
301 return res;
302}
QString buttons(const T &ev)

References buttons().

◆ observerName()

QString GamutMaskDock::observerName ( )
inlineoverridevirtual

Reimplemented from KoCanvasObserverBase.

Definition at line 37 of file gamutmask_dock.h.

37{ return "GamutMaskDock"; }

◆ openMaskEditor()

bool GamutMaskDock::openMaskEditor ( )
private

Definition at line 118 of file gamutmask_dock.cpp.

119{
120 if (!m_selectedMask) {
121 return false;
122 }
123
124 // find the template resource first, so we can abort the action early on
125 QString maskTemplateFile = ":/gamutmasks/GamutMaskTemplate.kra";
126 if (maskTemplateFile.isEmpty() || maskTemplateFile.isNull() || !QFile::exists(maskTemplateFile)) {
127 dbgPlugins << "GamutMaskDock::openMaskEditor(): maskTemplateFile (" << maskTemplateFile << ") was not found on the system";
128 getUserFeedback(i18n("Could not open gamut mask for editing."),
129 i18n("The editor template was not found."),
130 QMessageBox::Ok, QMessageBox::Ok, QMessageBox::Critical);
131 return false;
132 }
133
134 m_dockerUI->maskChooser->setEnabled(false);
135 m_dockerUI->maskPropertiesBox->setVisible(true);
136 m_dockerUI->maskPropertiesBox->setEnabled(true);
137 m_dockerUI->editControlsBox->setEnabled(false);
138 m_dockerUI->editControlsBox->setVisible(false);
139
140 m_dockerUI->maskTitleEdit->setText(m_selectedMask->title());
141 m_dockerUI->maskDescriptionEdit->setPlainText(m_selectedMask->description());
142
146
147 // template document needs a proper autogenerated filename,
148 // to avoid collision with other documents,
149 // otherwise bugs happen when slotDocumentRemoved is called
150 // (e.g. user closes another view, the template stays open, but the edit operation is canceled)
152 QString maskPath =
153 QString("%1%2%3_%4.kra")
154 .arg(QDir::tempPath(), "/", "GamutMaskTemplate", QString::number(std::time(nullptr)));
155 m_maskDocument->setPath(maskPath);
157
158 KisShapeLayerSP shapeLayer = getShapeLayer();
159
160 // pass only copies of shapes to the layer,
161 // so the originals don't disappear from the mask later
162 for (KoShape *shape: m_selectedMask->koShapes()) {
163 KoShape* newShape = shape->cloneShape();
164 newShape->setStroke(KoShapeStrokeModelSP());
165 newShape->setBackground(QSharedPointer<KoColorBackground>(new KoColorBackground(QColor(255,255,255))));
166 shapeLayer->addShape(newShape);
167 }
168
170
171 // set document as active
173 KIS_ASSERT(mainWindow);
174
177
178 for(KisView *view: KisPart::instance()->views()) {
179 if (view->document() == m_maskDocument) {
180 view->activateWindow();
181 break;
182 }
183 }
184
185 connect(m_view->viewManager(), SIGNAL(viewChanged()), this, SLOT(slotViewChanged()));
186 connect(m_maskDocument, SIGNAL(completed()), this, SLOT(slotDocumentSaved()));
187
188 m_dockerUI->maskChooser->setEnabled(true);
189
190 return true;
191}
QSharedPointer< KoShapeStrokeModel > KoShapeStrokeModelSP
PythonPluginManager * instance
int getUserFeedback(QString text, QString informativeText="", QMessageBox::StandardButtons buttons=QMessageBox::Yes|QMessageBox::No, QMessageBox::StandardButton defaultButton=QMessageBox::Yes, QMessageBox::Icon severity=QMessageBox::Warning)
void setPath(const QString &path)
void setLocalFilePath(const QString &localFilePath)
void setPreActivatedNode(KisNodeSP activatedNode)
void setInfiniteAutoSaveInterval()
bool openPath(const QString &path, OpenFlags flags=None)
openPath Open a Path
Main window for Krita.
KisView * addViewAndNotifyLoadingCompleted(KisDocument *document, QMdiSubWindow *subWindow=0)
void addDocument(KisDocument *document, bool notify=true)
Definition KisPart.cpp:211
KisMainWindow * currentMainwindow() const
Definition KisPart.cpp:483
KisDocument * createDocument() const
Definition KisPart.cpp:230
void addShape(KoShape *shape)
#define KIS_ASSERT(cond)
Definition kis_assert.h:33
#define dbgPlugins
Definition kis_debug.h:51

References KisPart::addDocument(), KoShapeContainer::addShape(), KisMainWindow::addViewAndNotifyLoadingCompleted(), KoShape::cloneShape(), connect(), KisPart::createDocument(), KisPart::currentMainwindow(), dbgPlugins, KisDocument::DontAddToRecent, getShapeLayer(), getUserFeedback(), KisPart::instance(), KIS_ASSERT, m_dockerUI, m_maskDocument, m_selectedMask, m_view, KisDocument::openPath(), KoShape::setBackground(), KisDocument::setInfiniteAutoSaveInterval(), KisDocument::setLocalFilePath(), KisDocument::setPath(), KisDocument::setPreActivatedNode(), KoShape::setStroke(), slotDocumentSaved(), slotViewChanged(), KisView::viewManager, and KisPart::views.

◆ removingResource()

void GamutMaskDock::removingResource ( KoGamutMaskSP resource)
overridevirtual

Will be called by the resource server before a resource will be removed

Parameters
resourcethe resource which is going to be removed

Implements KoResourceServerObserver< KoGamutMask >.

Definition at line 513 of file gamutmask_dock.cpp.

514{
515 // if deleting previously set mask, notify selectors to unset their mask
516 if (resource == m_resourceProvider->currentGamutMask()) {
517 Q_EMIT sigGamutMaskUnset();
518 m_selectedMask = nullptr;
519 }
520}
void sigGamutMaskUnset()

References KisCanvasResourceProvider::currentGamutMask(), m_resourceProvider, m_selectedMask, and sigGamutMaskUnset().

◆ resolveMaskTitle()

QPair< QString, QFileInfo > GamutMaskDock::resolveMaskTitle ( QString suggestedTitle)
private

◆ resourceAdded()

void GamutMaskDock::resourceAdded ( KoGamutMaskSP resource)
inlineoverridevirtual

Will be called by the resource server after a resource is added

Parameters
resourcethe added resource

Implements KoResourceServerObserver< KoGamutMask >.

Definition at line 44 of file gamutmask_dock.h.

44{}

◆ resourceChanged()

void GamutMaskDock::resourceChanged ( KoGamutMaskSP resource)
overridevirtual

Will be called by the resource server when a resource is changed

Parameters
resourcethe resource which is going to be removed

Implements KoResourceServerObserver< KoGamutMask >.

Definition at line 522 of file gamutmask_dock.cpp.

523{
524 // if currently set mask has been changed, notify selectors
525 if (resource == m_resourceProvider->currentGamutMask()) {
526 selectMask(resource);
527 }
528}
void selectMask(KoGamutMaskSP mask, bool notifyItemChooser=true)

References KisCanvasResourceProvider::currentGamutMask(), m_resourceProvider, and selectMask().

◆ saveOrCancel()

int GamutMaskDock::saveOrCancel ( QMessageBox::StandardButton defaultAction = QMessageBox::Save)
private

Definition at line 304 of file gamutmask_dock.cpp.

305{
306 int response = 0;
307
308 if (m_maskDocument->isModified()) {
309 response = getUserFeedback(i18n("Gamut mask <b>'%1'</b> has been modified.", m_selectedMask->title()),
310 i18n("Do you want to save it?"),
311 QMessageBox::Cancel | QMessageBox::Close | QMessageBox::Save, defaultAction);
312
313 } else if (m_templatePrevSaved && defaultAction != QMessageBox::Close) {
314 response = QMessageBox::Save;
315
316 } else if (!m_templatePrevSaved) {
317 response = QMessageBox::Close;
318
319 } else {
320 response = defaultAction;
321 }
322
323 switch (response) {
324 case QMessageBox::Save : {
326 break;
327 }
328 case QMessageBox::Close : {
330 break;
331 }
332 }
333
334 return response;
335}
bool isModified() const

References cancelMaskEdit(), getUserFeedback(), KisDocument::isModified(), m_maskDocument, m_selectedMask, m_templatePrevSaved, and slotGamutMaskSave().

◆ saveSelectedMaskResource()

bool GamutMaskDock::saveSelectedMaskResource ( )
private

Definition at line 227 of file gamutmask_dock.cpp.

228{
230 return false;
231 }
232
233 bool maskSaved = false;
234
235 if (m_selectedMask) {
237
238 if (shapes.count() > 0) {
239 m_selectedMask->setMaskShapes(shapes);
240
241 m_selectedMask->setImage(
244 )
245 );
246
247 m_selectedMask->setDescription(m_dockerUI->maskDescriptionEdit->toPlainText());
248
249 m_selectedMask->clearPreview();
251 QModelIndex idx = model.indexForResourceId(m_selectedMask->resourceId());
252 bool r = true;
253 if (idx.isValid()) {
254 // don't add, only update
256 } else {
258 }
259
260 maskSaved = r;
261 } else {
262 getUserFeedback(i18n("Saving of gamut mask '%1' was aborted.", m_selectedMask->title()),
263 i18n("<p>The mask template is invalid.</p>"
264 "<p>Please check that:"
265 "<ul>"
266 "<li>your template contains a vector layer named 'maskShapesLayer'</li>"
267 "<li>there are one or more vector shapes on the 'maskShapesLayer'</li>"
268 "</ul></p>"
269 ),
270 QMessageBox::Ok, QMessageBox::Ok);
271 }
272 }
273
274
275 return maskSaved;
276}
QList< KoShape * > getShapesFromLayer()
QImage convertToQImage(qint32 x1, qint32 y1, qint32 width, qint32 height, const KoColorProfile *profile)
QRect bounds() const override
const KoColorProfile * profile() const
static bool addResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource, QString storageLocation="")
static bool updateResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource)

References KisResourceUserOperations::addResourceWithUserInput(), KisImage::bounds(), KisImage::convertToQImage(), ResourceType::GamutMasks, getShapesFromLayer(), getUserFeedback(), KisDocument::image, KisResourceModel::indexForResourceId(), m_dockerUI, m_maskDocument, m_selectedMask, KisImage::profile(), and KisResourceUserOperations::updateResourceWithUserInput().

◆ selectMask()

void GamutMaskDock::selectMask ( KoGamutMaskSP mask,
bool notifyItemChooser = true )
private

Definition at line 210 of file gamutmask_dock.cpp.

211{
212 if (!mask) {
213 return;
214 }
215
216 m_selectedMask = mask;
217
218 if (notifyItemChooser) {
219 m_selfSelectingMask = true;
220 m_dockerUI->maskChooser->setCurrentResource(m_selectedMask);
221 m_selfSelectingMask = false;
222 }
223
225}
void sigGamutMaskSet(KoGamutMaskSP mask)

References m_dockerUI, m_selectedMask, m_selfSelectingMask, and sigGamutMaskSet().

◆ setCanvas()

void GamutMaskDock::setCanvas ( KoCanvasBase * canvas)
overridevirtual

re-implement this method in your canvas observer. It will be called whenever a canvas becomes active. Note that you are responsible for not connecting more than one time to the signals of a canvas or any of the QObjects you can access through the canvas.

Implements KoCanvasObserverBase.

Definition at line 496 of file gamutmask_dock.cpp.

497{
498 setEnabled(canvas != 0);
499}

◆ setViewManager()

void GamutMaskDock::setViewManager ( KisViewManager * kisview)
overridevirtual

Implements KisMainwindowObserver.

Definition at line 97 of file gamutmask_dock.cpp.

98{
100
102
103 connect(this, SIGNAL(sigGamutMaskSet(KoGamutMaskSP)), m_resourceProvider, SLOT(slotGamutMaskActivated(KoGamutMaskSP)), Qt::UniqueConnection);
104 connect(this, SIGNAL(sigGamutMaskChanged(KoGamutMaskSP)), m_resourceProvider, SLOT(slotGamutMaskActivated(KoGamutMaskSP)), Qt::UniqueConnection);
105 connect(this, SIGNAL(sigGamutMaskUnset()), m_resourceProvider, SLOT(slotGamutMaskUnset()), Qt::UniqueConnection);
106 connect(this, SIGNAL(sigGamutMaskPreviewUpdate()), m_resourceProvider, SLOT(slotGamutMaskPreviewUpdate()), Qt::UniqueConnection);
107 connect(KisPart::instance(), SIGNAL(sigDocumentRemoved(QString)), this, SLOT(slotDocumentRemoved(QString)), Qt::UniqueConnection);
108}
void sigGamutMaskPreviewUpdate()
void slotDocumentRemoved(QString filename)
KisCanvasResourceProvider * canvasResourceProvider()

References KisViewManager::canvasResourceProvider(), connect(), KisCanvasResourceProvider::currentGamutMask(), KisPart::instance(), m_resourceProvider, selectMask(), sigGamutMaskChanged(), sigGamutMaskPreviewUpdate(), sigGamutMaskSet(), sigGamutMaskUnset(), and slotDocumentRemoved().

◆ sigGamutMaskChanged

void GamutMaskDock::sigGamutMaskChanged ( KoGamutMaskSP mask)
signal

◆ sigGamutMaskPreviewUpdate

void GamutMaskDock::sigGamutMaskPreviewUpdate ( )
signal

◆ sigGamutMaskSet

void GamutMaskDock::sigGamutMaskSet ( KoGamutMaskSP mask)
signal

◆ sigGamutMaskUnset

void GamutMaskDock::sigGamutMaskUnset ( )
signal

◆ slotDocumentRemoved

void GamutMaskDock::slotDocumentRemoved ( QString filename)
privateslot

Definition at line 570 of file gamutmask_dock.cpp.

571{
572 if (!m_maskDocument) {
573 return;
574 }
575
577
578 // we do not want to run this if it is we who close the file
580 // KisPart called, that a document will be removed
581 // if it's ours, cancel the mask edit operation
582 if (m_maskDocument->path() == filename) {
584 saveOrCancel();
585 }
586 }
587
589}
int saveOrCancel(QMessageBox::StandardButton defaultAction=QMessageBox::Save)
void waitForSavingToComplete()
QString path() const

References m_externalTemplateClose, m_maskDocument, m_selfClosingTemplate, KisDocument::path(), saveOrCancel(), and KisDocument::waitForSavingToComplete().

◆ slotDocumentSaved

void GamutMaskDock::slotDocumentSaved ( )
privateslot

Definition at line 604 of file gamutmask_dock.cpp.

605{
606 m_templatePrevSaved = true;
607}

References m_templatePrevSaved.

◆ slotGamutMaskCancelEdit

void GamutMaskDock::slotGamutMaskCancelEdit ( )
privateslot

Definition at line 463 of file gamutmask_dock.cpp.

464{
465 if (!m_selectedMask) {
466 return;
467 }
468
469 saveOrCancel(QMessageBox::Close);
470}

References m_selectedMask, and saveOrCancel().

◆ slotGamutMaskCreateNew

void GamutMaskDock::slotGamutMaskCreateNew ( )
privateslot

Definition at line 530 of file gamutmask_dock.cpp.

531{
532 KoGamutMaskSP newMask = createMaskResource(nullptr, "new mask");
533 selectMask(newMask);
534
535 bool editorOpened = openMaskEditor();
536 if (!editorOpened) {
537 deleteMask();
538 }
539}
KoGamutMaskSP createMaskResource(KoGamutMaskSP sourceMask, QString newTitle)

References createMaskResource(), deleteMask(), openMaskEditor(), and selectMask().

◆ slotGamutMaskDelete

void GamutMaskDock::slotGamutMaskDelete ( )
privateslot

Definition at line 556 of file gamutmask_dock.cpp.

557{
558 if (!m_selectedMask) {
559 return;
560 }
561
562 int res = getUserFeedback(i18n("Are you sure you want to delete mask <b>'%1'</b>?"
563 , m_selectedMask->title()));
564
565 if (res == QMessageBox::Yes) {
566 deleteMask();
567 }
568}

References deleteMask(), getUserFeedback(), and m_selectedMask.

◆ slotGamutMaskDuplicate

void GamutMaskDock::slotGamutMaskDuplicate ( )
privateslot

Definition at line 541 of file gamutmask_dock.cpp.

542{
543 if (!m_selectedMask) {
544 return;
545 }
546
547 KoGamutMaskSP newMask = createMaskResource(m_selectedMask, m_selectedMask->title() + QString(" (Copy)"));
548 selectMask(newMask);
549
550 bool editorOpened = openMaskEditor();
551 if (!editorOpened) {
552 deleteMask();
553 }
554}

References createMaskResource(), deleteMask(), m_selectedMask, openMaskEditor(), and selectMask().

◆ slotGamutMaskEdit

void GamutMaskDock::slotGamutMaskEdit ( )
privateslot

Definition at line 110 of file gamutmask_dock.cpp.

111{
112 if (!m_selectedMask) {
113 return;
114 }
116}

References m_selectedMask, and openMaskEditor().

◆ slotGamutMaskPreview

void GamutMaskDock::slotGamutMaskPreview ( )
privateslot

Definition at line 472 of file gamutmask_dock.cpp.

473{
474 if (!m_selectedMask) {
475 return;
476 }
477
478 m_selectedMask->setPreviewMaskShapes(getShapesFromLayer());
480}

References getShapesFromLayer(), m_selectedMask, and sigGamutMaskPreviewUpdate().

◆ slotGamutMaskSave

void GamutMaskDock::slotGamutMaskSave ( )
privateslot

Definition at line 439 of file gamutmask_dock.cpp.

440{
442 return;
443 }
444
445 QString newTitle = m_dockerUI->maskTitleEdit->text();
446
447 if (m_selectedMask->title() != newTitle) {
448 // title has changed, rename
450
451 // delete old mask and select new
452 deleteMask();
453 selectMask(newMask);
454 }
455
456 bool maskSaved = saveSelectedMaskResource();
457 if (maskSaved) {
460 }
461}
bool saveSelectedMaskResource()

References closeMaskDocument(), createMaskResource(), deleteMask(), m_dockerUI, m_maskDocument, m_selectedMask, saveSelectedMaskResource(), selectMask(), and sigGamutMaskSet().

◆ slotGamutMaskSelected

void GamutMaskDock::slotGamutMaskSelected ( KoGamutMaskSP mask)
privateslot

Definition at line 482 of file gamutmask_dock.cpp.

483{
484 if (!m_selfSelectingMask) {
485 if (m_maskDocument) {
486 int res = saveOrCancel();
487 if (res == QMessageBox::Cancel) {
488 return;
489 }
490 }
491
492 selectMask(mask, false);
493 }
494}

References m_maskDocument, m_selfSelectingMask, saveOrCancel(), and selectMask().

◆ slotViewChanged

void GamutMaskDock::slotViewChanged ( )
privateslot

Definition at line 591 of file gamutmask_dock.cpp.

592{
593 if (!m_maskDocument || !m_view) {
594 return;
595 }
596
598 m_dockerUI->maskPropertiesBox->setEnabled(true);
599 } else {
600 m_dockerUI->maskPropertiesBox->setEnabled(false);
601 }
602}
KisDocument * document() const

References KisViewManager::document(), m_dockerUI, m_maskDocument, m_view, and KisView::viewManager.

◆ unsetCanvas()

void GamutMaskDock::unsetCanvas ( )
overridevirtual

Re-implement to notify the observer that its canvas is no longer among the living. The daisies, it is pushing up. This means you don't have to disconnect, it's dead.

The old canvas should be deleted already, so if you stored a pointer to it, don't touch!

Note that currently there is a bug where in certain specific circumstances unsetCanvas can be called when it shouldn't, see for example KWStatisticsDocker for a workaround for this problem.

Implements KoCanvasObserverBase.

Definition at line 501 of file gamutmask_dock.cpp.

502{
503 setEnabled(false);
504}

◆ unsetResourceServer()

Member Data Documentation

◆ m_creatingNewMask

bool GamutMaskDock::m_creatingNewMask {false}
private

Definition at line 93 of file gamutmask_dock.h.

93{false};

◆ m_dockerUI

GamutMaskChooserUI* GamutMaskDock::m_dockerUI {nullptr}
private

Definition at line 97 of file gamutmask_dock.h.

97{nullptr};

◆ m_externalTemplateClose

bool GamutMaskDock::m_externalTemplateClose {false}
private

Definition at line 92 of file gamutmask_dock.h.

92{false};

◆ m_maskChooser

KisResourceItemChooser* GamutMaskDock::m_maskChooser {nullptr}
private

Definition at line 98 of file gamutmask_dock.h.

98{nullptr};

◆ m_maskDocument

KisDocument* GamutMaskDock::m_maskDocument {nullptr}
private

Definition at line 102 of file gamutmask_dock.h.

102{nullptr};

◆ m_resourceProvider

KisCanvasResourceProvider* GamutMaskDock::m_resourceProvider {nullptr}
private

Definition at line 89 of file gamutmask_dock.h.

89{nullptr};

◆ m_selectedMask

KoGamutMaskSP GamutMaskDock::m_selectedMask
private

Definition at line 100 of file gamutmask_dock.h.

◆ m_selfClosingTemplate

bool GamutMaskDock::m_selfClosingTemplate {false}
private

Definition at line 91 of file gamutmask_dock.h.

91{false};

◆ m_selfSelectingMask

bool GamutMaskDock::m_selfSelectingMask {false}
private

Definition at line 95 of file gamutmask_dock.h.

95{false};

◆ m_templatePrevSaved

bool GamutMaskDock::m_templatePrevSaved {false}
private

Definition at line 94 of file gamutmask_dock.h.

94{false};

◆ m_view

KisView* GamutMaskDock::m_view {nullptr}
private

Definition at line 103 of file gamutmask_dock.h.

103{nullptr};

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