Commit 77ec68fc authored by Sven Langkamp's avatar Sven Langkamp

fixed some problems with inverted selections and setDirty

svn path=/trunk/koffice/; revision=689060
parent fcbd59dc
......@@ -213,6 +213,7 @@ QVector<QPolygon> KisPixelSelection::outline()
QTime t;
t.start();
quint8 defaultPixel = *(m_datamanager->defaultPixel());
QRect selectionExtent = exactBounds();
qint32 xOffset = selectionExtent.x();
qint32 yOffset = selectionExtent.y();
......@@ -232,7 +233,7 @@ QVector<QPolygon> KisPixelSelection::outline()
for (qint32 y = 0; y < height; y++) {
for (qint32 x = 0; x < width; x++) {
if(buffer[y*width+x]== MIN_SELECTED)
if(buffer[y*width+x]== defaultPixel)
continue;
EdgeType startEdge = TopEdge;
......@@ -280,20 +281,21 @@ QVector<QPolygon> KisPixelSelection::outline()
bool KisPixelSelection::isOutlineEdge(EdgeType edge, qint32 x, qint32 y, quint8* buffer, qint32 bufWidth, qint32 bufHeight)
bool KisPixelSelection::isOutlineEdge(EdgeType edge, qint32 x, qint32 y, quint8* buffer, qint32 bufWidth, qint32 bufHeight )
{
if(buffer[y*bufWidth+x] == MIN_SELECTED)
quint8 defaultPixel = *(m_datamanager->defaultPixel());
if(buffer[y*bufWidth+x] == defaultPixel)
return false;
switch(edge){
case LeftEdge:
return x == 0 || buffer[y*bufWidth+(x - 1)] == MIN_SELECTED;
return x == 0 || buffer[y*bufWidth+(x - 1)] == defaultPixel;
case TopEdge:
return y == 0 || buffer[(y - 1)*bufWidth+x] == MIN_SELECTED;
return y == 0 || buffer[(y - 1)*bufWidth+x] == defaultPixel;
case RightEdge:
return x == bufWidth -1 || buffer[y*bufWidth+(x + 1)] == MIN_SELECTED;
return x == bufWidth -1 || buffer[y*bufWidth+(x + 1)] == defaultPixel;
case BottomEdge:
return y == bufHeight -1 || buffer[(y + 1)*bufWidth+x] == MIN_SELECTED;
return y == bufHeight -1 || buffer[(y + 1)*bufWidth+x] == defaultPixel;
}
return false;
}
......@@ -372,6 +374,6 @@ void KisPixelSelection::renderToProjection(KisSelection* projection)
{
KisPainter painter(projection);
QRect r = selectedExactRect();
painter.bitBlt(r.x(), r.y(), COMPOSITE_OVER, KisPaintDeviceSP(this), r.x(), r.y(), r.width(), r.height());
painter.bitBlt(r.x(), r.y(), COMPOSITE_COPY, KisPaintDeviceSP(this), r.x(), r.y(), r.width(), r.height());
painter.end();
}
......@@ -262,6 +262,9 @@ void KisSelection::updateProjection()
{
clear();
if(m_hasPixelSelection) {
quint8 defPixel = *(m_pixelSelection->dataManager()->defaultPixel());
m_datamanager->setDefaultPixel(&defPixel);
m_pixelSelection->renderToProjection(this);
}
if(m_hasShapeSelection) {
......
......@@ -64,7 +64,9 @@ void KisSelectionTest::testInvertSelection()
pixelSelection->invert();
QCOMPARE( dev->pixelSelection()->selected(100,100), MAX_SELECTED);
QCOMPARE( dev->pixelSelection()->selected(22,22), MAX_SELECTED);
QCOMPARE( dev->selection()->selected(100,100), MAX_SELECTED);
QCOMPARE( dev->selection()->selected(22,22), MAX_SELECTED);
QCOMPARE( dev->selection()->selected(10,10), MIN_SELECTED);
}
......
......@@ -587,9 +587,9 @@ void KisSelectionManager::selectAll()
if (img->undo()) t = new KisSelectedTransaction(i18n("Select All"), dev);
Q_CHECK_PTR(t);
dev->selection()->clear();
dev->selection()->invert();
dev->setDirty();
dev->pixelSelection()->clear();
dev->pixelSelection()->invert();
dev->setDirty(img->bounds());
dev->emitSelectionChanged();
if (img->undo())
......@@ -613,7 +613,7 @@ void KisSelectionManager::deselect()
} else {
dev->deselect();
}
dev->setDirty();
dev->setDirty(img->bounds());
dev->emitSelectionChanged();
if (img->undo())
......@@ -638,7 +638,7 @@ void KisSelectionManager::clear()
}
dev->clearSelection();
dev->setDirty();
dev->setDirty(img->bounds());
dev->emitSelectionChanged();
if (img->undo()) img->undoAdapter()->addCommand(t);
......@@ -710,7 +710,7 @@ void KisSelectionManager::reselect()
Q_CHECK_PTR(t);
dev->reselect(); // sets hasSelection=true
dev->setDirty();
dev->setDirty(img->bounds());
dev->emitSelectionChanged();
if (img->undo())
......@@ -727,7 +727,7 @@ void KisSelectionManager::invert()
if (!dev) return;
if (dev->hasSelection()) {
KisSelectionSP s = dev->selection();
KisPixelSelectionSP s = dev->pixelSelection();
KisSelectedTransaction * t = 0;
if (img->undo())
......@@ -737,7 +737,7 @@ void KisSelectionManager::invert()
}
s->invert();
dev->setDirty();
dev->setDirty(img->bounds());
dev->emitSelectionChanged();
if (t) {
......@@ -784,7 +784,7 @@ void KisSelectionManager::feather()
return;
}
KisSelectionSP selection = dev->selection();
KisPixelSelectionSP selection = dev->pixelSelection();
KisSelectedTransaction * t = 0;
if (img->undo()) t = new KisSelectedTransaction(i18n("Feather..."), dev);
Q_CHECK_PTR(t);
......@@ -819,7 +819,7 @@ void KisSelectionManager::feather()
painter.applyMatrix(k, rect.x(), rect.y(), rect.width(), rect.height(), BORDER_AVOID);
painter.end();
dev->setDirty();
dev->setDirty(img->bounds());
dev->emitSelectionChanged();
if (img->undo())
......@@ -858,7 +858,7 @@ void KisSelectionManager::grow (qint32 xradius, qint32 yradius)
if (!dev) return;
if (!dev->hasSelection()) return;
KisSelectionSP selection = dev->selection();
KisPixelSelectionSP selection = dev->pixelSelection();
//determine the layerSize
QRect layerSize = dev->exactBounds();
......@@ -991,7 +991,7 @@ void KisSelectionManager::grow (qint32 xradius, qint32 yradius)
delete[] buf;
delete[] out;
dev->setDirty();
dev->setDirty(img->bounds());
dev->emitSelectionChanged();
if (t) {
......@@ -1009,7 +1009,7 @@ void KisSelectionManager::shrink (qint32 xradius, qint32 yradius, bool edge_lock
if (!dev) return;
if (!dev->hasSelection()) return;
KisSelectionSP selection = dev->selection();
KisPixelSelectionSP selection = dev->pixelSelection();
//determine the layerSize
QRect layerSize = dev->exactBounds();
......@@ -1158,7 +1158,7 @@ void KisSelectionManager::shrink (qint32 xradius, qint32 yradius, bool edge_lock
delete[] buf;
delete[] out;
dev->setDirty();
dev->setDirty(img->bounds());
dev->emitSelectionChanged();
}
......@@ -1173,7 +1173,7 @@ void KisSelectionManager::smooth()
if (!dev) return;
if (!dev->hasSelection()) return;
KisSelectionSP selection = dev->selection();
KisPixelSelectionSP selection = dev->pixelSelection();
//determine the layerSize
QRect layerSize = dev->exactBounds();
......@@ -1227,7 +1227,7 @@ void KisSelectionManager::smooth()
delete[] out;
dev->setDirty();
dev->setDirty(img->bounds());
dev->emitSelectionChanged();
}
......
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