Commit 97372d6e authored by Wolthera van Hövell's avatar Wolthera van Hövell 🛍

Make the custom pattern widget take the selection into account.

Now, if you have a selection, it'll use only that area to retreive the pattern from.

I was thinking of whether it needed an extra toggle, but both Scott and Boud thought it was implicit that having a selection means you want to use it.

This is my first time playing with selection code, so a glance would be nice.

Auditors: dkazakov
parent de26f01f
......@@ -36,6 +36,8 @@
#include "kis_image.h"
#include "kis_layer.h"
#include "kis_paint_device.h"
#include "kis_selection.h"
#include "kis_painter.h"
#include <kis_debug.h>
#include "kis_resource_server_provider.h"
......@@ -139,6 +141,7 @@ void KisCustomPattern::createPattern()
if (!m_view) return;
KisPaintDeviceSP dev;
KisPaintDeviceSP cache;
QString name;
KisImageWSP image = m_view->image();
if (!image) return;
......@@ -157,6 +160,21 @@ void KisCustomPattern::createPattern()
name = image->objectName();
}
if (!dev) return;
if(m_view->selection()) {
KisSelectionSP selection = m_view->selection();
QRect selectionRect = selection->selectedExactRect();
cache = dev->createCompositionSourceDevice();
KisPainter gc(cache);
gc.setSelection(selection);
gc.bitBlt(selectionRect.topLeft(), dev, selectionRect);
rc = selectionRect;
} else {
cache = dev;
}
if (!cache) return;
// warn when creating large patterns
QSize size = rc.size();
......@@ -167,7 +185,7 @@ void KisCustomPattern::createPattern()
}
QString dir = KoResourceServerProvider::instance()->patternServer()->saveLocation();
m_pattern = new KoPattern(dev->createThumbnail(size.width(), size.height(), rc, /*oversample*/ 1,
m_pattern = new KoPattern(cache->createThumbnail(size.width(), size.height(), rc, /*oversample*/ 1,
KoColorConversionTransformation::internalRenderingIntent(),
KoColorConversionTransformation::internalConversionFlags()), name, dir);
}
......
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