Commit f0bbb808 authored by Halla Rempt's avatar Halla Rempt
Browse files

Make the global selection a mask on the rootlayer

This way, the selection will be cropped, resized etc. together with
the other nodes. It will also make it possible in the future to use the
paint/fill/gradient/filter tools on the selection.

CCBUG:273260
parent 6f202ad5
......@@ -39,7 +39,7 @@ KisDeselectGlobalSelectionCommand::~KisDeselectGlobalSelectionCommand()
void KisDeselectGlobalSelectionCommand::redo()
{
m_oldDeselectedSelection = m_image->deselectedGlobalSelection();
m_image->setDeleselectedGlobalSelection(m_image->globalSelection());
m_image->setDeselectedGlobalSelection(m_image->globalSelection());
if (!m_newSelection) {
m_image->setGlobalSelection();
......@@ -55,7 +55,7 @@ void KisDeselectGlobalSelectionCommand::redo()
void KisDeselectGlobalSelectionCommand::undo()
{
m_image->setGlobalSelection(m_image->deselectedGlobalSelection());
m_image->setDeleselectedGlobalSelection(m_oldDeselectedSelection);
m_image->setDeselectedGlobalSelection(m_oldDeselectedSelection);
m_image->undoAdapter()->emitSelectionChanged();
}
......@@ -40,14 +40,14 @@ void KisReselectGlobalSelectionCommand::redo()
{
m_oldSelection = m_image->globalSelection();
m_image->setGlobalSelection(m_image->deselectedGlobalSelection());
m_image->setDeleselectedGlobalSelection(0);
m_image->setDeselectedGlobalSelection(0);
m_image->undoAdapter()->emitSelectionChanged();
}
void KisReselectGlobalSelectionCommand::undo()
{
m_image->setDeleselectedGlobalSelection(m_image->globalSelection());
m_image->setDeselectedGlobalSelection(m_image->globalSelection());
m_image->setGlobalSelection(m_oldSelection);
m_image->undoAdapter()->emitSelectionChanged();
......
......@@ -70,11 +70,6 @@ KisGroupLayer::~KisGroupLayer()
bool KisGroupLayer::allowAsChild(KisNodeSP node) const
{
if (node->inherits("KisMask") && !parent())
{
return false;
}
if (node->inherits("KisCloneLayer")) {
KisNodeSP source = qobject_cast<KisCloneLayer*>(node.data())->copyFrom();
if (source) {
......
......@@ -83,9 +83,9 @@
#ifdef SANITY_CHECKS
#define SANITY_CHECK_LOCKED(name) \
if(!locked()) qDebug() << "Locking policy failed:" << name \
<< "has been called without the image" \
"being locked";
if (!locked()) warnKrita() << "Locking policy failed:" << name \
<< "has been called without the image" \
"being locked";
#else
#define SANITY_CHECK_LOCKED(name)
#endif
......@@ -122,9 +122,6 @@ public:
vKisAnnotationSP annotations;
KisSelectionSP globalSelection;
KisSelectionSP deselectedGlobalSelection;
QAtomicInt disableUIUpdateSignals;
KisImageSignalRouter *signalRouter;
KisUpdateScheduler *scheduler;
......@@ -214,30 +211,62 @@ void KisImage::nodeChanged(KisNode* node)
KisSelectionSP KisImage::globalSelection() const
{
return m_d->globalSelection;
KisSelectionMaskSP selectionMask = m_d->rootLayer->selectionMask();
if (selectionMask) {
return selectionMask->selection();
}
else {
return 0;
}
}
void KisImage::setGlobalSelection(KisSelectionSP globalSelection)
{
if (globalSelection == 0)
m_d->globalSelection = new KisSelection(new KisDefaultBounds(this));
else
m_d->globalSelection = globalSelection;
KisSelectionMaskSP selectionMask = m_d->rootLayer->selectionMask();
if (!selectionMask) {
selectionMask = new KisSelectionMask(this);
selectionMask->setActive(true);
Q_ASSERT(addNode(selectionMask, m_d->rootLayer, 0));
}
if (globalSelection) {
selectionMask->setSelection(globalSelection);
}
else {
selectionMask->setSelection(new KisSelection(new KisDefaultBounds(this)));
}
Q_ASSERT(m_d->rootLayer->childCount() > 0);
Q_ASSERT(m_d->rootLayer->selectionMask());
}
void KisImage::removeGlobalSelection()
{
m_d->globalSelection = 0;
KisSelectionMaskSP selectionMask = m_d->rootLayer->selectionMask();
if (selectionMask) {
removeNode(selectionMask);
}
}
KisSelectionSP KisImage::deselectedGlobalSelection()
{
return m_d->deselectedGlobalSelection;
KisSelectionMaskSP selectionMask = m_d->rootLayer->selectionMask();
if (selectionMask) {
return selectionMask->deselectedSelection();
}
else {
return 0;
}
}
void KisImage::setDeleselectedGlobalSelection(KisSelectionSP selection)
void KisImage::setDeselectedGlobalSelection(KisSelectionSP selection)
{
m_d->deselectedGlobalSelection = selection;
KisSelectionMaskSP selectionMask = m_d->rootLayer->selectionMask();
if (!selectionMask) {
setGlobalSelection();
selectionMask = m_d->rootLayer->selectionMask();
}
Q_ASSERT(selectionMask);
selectionMask->setDeselectedSelection(selection);
}
KisBackgroundSP KisImage::backgroundPattern() const
......
......@@ -63,7 +63,13 @@ class MergeStrategy;
* meta information about the image. And it also provides some
* functions to manipulate the whole image.
*/
class KRITAIMAGE_EXPORT KisImage : public QObject, public KisStrokesFacade, public KisUpdatesFacade, public KisProjectionUpdateListener, public KisNodeFacade, public KisNodeGraphListener, public KisShared
class KRITAIMAGE_EXPORT KisImage : public QObject,
public KisStrokesFacade,
public KisUpdatesFacade,
public KisProjectionUpdateListener,
public KisNodeFacade,
public KisNodeGraphListener,
public KisShared
{
Q_OBJECT
......@@ -623,7 +629,7 @@ private:
/**
* Set deselected global selection
*/
void setDeleselectedGlobalSelection(KisSelectionSP selection);
void setDeselectedGlobalSelection(KisSelectionSP selection);
private:
class KisImagePrivate;
......
......@@ -283,12 +283,15 @@ KisSelectionMaskSP KisLayer::selectionMask() const
KisSelectionSP KisLayer::selection() const
{
if (selectionMask())
if (selectionMask()) {
return selectionMask()->selection();
else if (m_d->image.isValid())
}
else if (m_d->image.isValid()) {
return m_d->image->globalSelection();
else
}
else {
return 0;
}
}
///////////////////////////////////////////////////////////////////////
......
......@@ -94,12 +94,12 @@ void KisSelectionMask::accept(KisProcessingVisitor &visitor, KisUndoAdapter *und
return visitor.visit(this, undoAdapter);
}
KisSelectionSP KisSelectionMask::deleselectedSelection()
KisSelectionSP KisSelectionMask::deselectedSelection()
{
return m_d->deselectedSelection;
}
void KisSelectionMask::setDeleselectedSelection(KisSelectionSP selection)
void KisSelectionMask::setDeselectedSelection(KisSelectionSP selection)
{
m_d->deselectedSelection = selection;
}
......
......@@ -65,12 +65,12 @@ public:
/**
* @return the deselected selection or 0 if no selection was deselected
*/
KisSelectionSP deleselectedSelection();
KisSelectionSP deselectedSelection();
/**
* Set deselected selection
*/
void setDeleselectedSelection(KisSelectionSP selection);
void setDeselectedSelection(KisSelectionSP selection);
virtual KoDocumentSectionModel::PropertyList sectionModelProperties() const;
virtual void setSectionModelProperties(const KoDocumentSectionModel::PropertyList &properties);
......
......@@ -145,6 +145,10 @@ QModelIndex KisNodeModel::indexFromNode(const KisNodeSP node) const
//dbgUI << "KisNodeModel::indexFromNode " << node;
Q_ASSERT(node);
if (node->parent()) {
// Don't show the global selection mask if we don't show the root layer
if (!m_d->showRootLayer && !node->parent()->parent() && node->inherits("KisSelectionMask")) {
return QModelIndex();
}
int rowCount = node->parent()->childCount() - 1;
int index = node->parent()->index(node);
int row = rowCount - index;
......@@ -407,7 +411,7 @@ void KisNodeModel::beginRemoveNodes(KisNode * parent, int index)
beginRemoveRows(indexFromNode(parent), parent->childCount() - 1 - index, parent->childCount() - 1 - index);
}
void KisNodeModel::endRemoveNodes(KisNode *parent, int index)
void KisNodeModel::endRemoveNodes(KisNode */*parent*/, int /*index*/)
{
//dbgUI <<"KisNodeModel::endRemoveNodes";
endRemoveRows();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment