Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 6ae88957 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Fixed Deselect/Reselect to work in a "classic" way

Well, it might be probably a nice feature to be able to select the
previous selection, but the way it was done with "Reselect" might be
a bit complicated for everyday use. So just use a "classic" approach,
and take into account that it might be a cool feature to be able
continuously cycle through all the selection masks of the layer with
some hotkey.
parent 8be79671
......@@ -38,10 +38,11 @@ KisDeselectGlobalSelectionCommand::~KisDeselectGlobalSelectionCommand()
void KisDeselectGlobalSelectionCommand::redo()
{
m_oldSelection = m_image->globalSelection();
m_image->deselectGlobalSelection();
}
void KisDeselectGlobalSelectionCommand::undo()
{
m_image->reselectGlobalSelection();
m_image->setGlobalSelection(m_oldSelection);
}
......@@ -41,6 +41,7 @@ public:
private:
KisImageWSP m_image;
KisSelectionSP m_oldSelection;
};
#endif
......@@ -109,6 +109,7 @@ public:
const KoColorSpace * colorSpace;
KisSelectionSP deselectedGlobalSelection;
KisGroupLayerSP rootLayer; // The layers are contained in here
QList<KisLayer*> dirtyLayers; // for thumbnails
......@@ -224,43 +225,27 @@ void KisImage::setGlobalSelection(KisSelectionSP globalSelection)
Q_ASSERT(m_d->rootLayer->selectionMask());
}
m_d->deselectedGlobalSelection = 0;
m_d->legacyUndoAdapter->emitSelectionChanged();
}
void KisImage::deselectGlobalSelection()
{
KisSelectionMaskSP selectionMask = m_d->rootLayer->selectionMask();
if (selectionMask) {
selectionMask->setActive(false);
}
m_d->legacyUndoAdapter->emitSelectionChanged();
KisSelectionSP savedSelection = globalSelection();
setGlobalSelection(0);
m_d->deselectedGlobalSelection = savedSelection;
}
bool KisImage::canReselectGlobalSelection()
{
return deselectedMask();
return m_d->deselectedGlobalSelection;
}
void KisImage::reselectGlobalSelection()
{
KisSelectionMaskSP mask = deselectedMask();
if (mask) {
mask->setActive(true);
if(m_d->deselectedGlobalSelection) {
setGlobalSelection(m_d->deselectedGlobalSelection);
}
m_d->legacyUndoAdapter->emitSelectionChanged();
}
KisSelectionMaskSP KisImage::deselectedMask()
{
// Get a list of non-active masks
KoProperties properties;
properties.setProperty("active", false);
QList<KisNodeSP> masks = root()->childNodes(QStringList("KisSelectionMask"), properties);
return masks.size() > 0 ?
static_cast<KisSelectionMask*>(masks.last().data()) : 0;
}
KisBackgroundSP KisImage::backgroundPattern() const
......
......@@ -627,8 +627,6 @@ private:
*/
void reselectGlobalSelection();
KisSelectionMaskSP deselectedMask();
private:
class KisImagePrivate;
KisImagePrivate * const m_d;
......
......@@ -112,7 +112,7 @@ void KisImageTest::testGlobalSelection()
image->deselectGlobalSelection();
QCOMPARE(image->globalSelection(), KisSelectionSP(0));
QCOMPARE(image->canReselectGlobalSelection(), true);
QCOMPARE(image->root()->childCount(), 1U);
QCOMPARE(image->root()->childCount(), 0U);
image->reselectGlobalSelection();
QCOMPARE(image->globalSelection(), selection2);
......@@ -124,17 +124,12 @@ void KisImageTest::testGlobalSelection()
image->deselectGlobalSelection();
QCOMPARE(image->globalSelection(), KisSelectionSP(0));
QCOMPARE(image->canReselectGlobalSelection(), true);
QCOMPARE(image->root()->childCount(), 1U);
QCOMPARE(image->root()->childCount(), 0U);
image->setGlobalSelection(selection1);
QCOMPARE(image->globalSelection(), selection1);
QCOMPARE(image->canReselectGlobalSelection(), true);
QCOMPARE(image->root()->childCount(), 2U);
image->reselectGlobalSelection();
QCOMPARE(image->globalSelection(), selection2);
QCOMPARE(image->canReselectGlobalSelection(), true);
QCOMPARE(image->root()->childCount(), 2U);
QCOMPARE(image->canReselectGlobalSelection(), false);
QCOMPARE(image->root()->childCount(), 1U);
}
QTEST_KDEMAIN(KisImageTest, NoGUI)
......
Markdown is supported
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