Commit bad6973a authored by Dmitry Kazakov's avatar Dmitry Kazakov

Make KisPaintDevice offset API more consistent

1) Rename move() into moveTo()
2) Add offset() method
parent 4e83cf20
......@@ -1046,25 +1046,30 @@ KisDefaultBoundsBaseSP KisPaintDevice::defaultBounds() const
return m_d->defaultBounds;
}
void KisPaintDevice::move(const QPoint &pt)
void KisPaintDevice::moveTo(const QPoint &pt)
{
m_d->currentStrategy()->move(pt);
m_d->cache()->invalidate();
}
void KisPaintDevice::move(qint32 x, qint32 y)
QPoint KisPaintDevice::offset() const
{
move(QPoint(x, y));
return QPoint(x(), y());
}
void KisPaintDevice::moveTo(qint32 x, qint32 y)
{
moveTo(QPoint(x, y));
}
void KisPaintDevice::setX(qint32 x)
{
move(QPoint(x, m_d->y()));
moveTo(QPoint(x, m_d->y()));
}
void KisPaintDevice::setY(qint32 y)
{
move(QPoint(m_d->x(), y));
moveTo(QPoint(m_d->x(), y));
}
qint32 KisPaintDevice::x() const
......
......@@ -146,12 +146,17 @@ public:
/**
* Moves the device to these new coordinates (so no incremental move or so)
*/
void move(qint32 x, qint32 y);
void moveTo(qint32 x, qint32 y);
/**
* Convenience method for the above.
*/
virtual void move(const QPoint& pt);
virtual void moveTo(const QPoint& pt);
/**
* Return an X,Y offset of the device in a convenient form
*/
QPoint offset() const;
/**
* The X offset of the paint device
......
......@@ -295,7 +295,7 @@ void KisPixelSelection::invert()
m_d->invalidateThumbnailImage();
}
void KisPixelSelection::move(const QPoint &pt)
void KisPixelSelection::moveTo(const QPoint &pt)
{
const int lod = defaultBounds()->currentLevelOfDetail();
const QPoint lod0Point = !lod ? pt :
......@@ -315,7 +315,7 @@ void KisPixelSelection::move(const QPoint &pt)
m_d->lod0CachesOffset = lod0Point;
KisPaintDevice::move(pt);
KisPaintDevice::moveTo(pt);
}
bool KisPixelSelection::isTotallyUnselected(const QRect & r) const
......
......@@ -109,8 +109,8 @@ public:
/**
* Overridden from KisPaintDevice to handle outline cache moves
*/
void move(const QPoint& pt);
using KisPaintDevice::move;
void moveTo(const QPoint& pt);
using KisPaintDevice::moveTo;
bool isEmpty() const;
QPainterPath outlineCache() const;
......
......@@ -128,7 +128,7 @@ void KisTransactionData::Private::moveDevice(const QPoint newOffset)
if (transactionFrameId >= 0) {
device->framesInterface()->setFrameOffset(transactionFrameId, newOffset);
} else {
device->move(newOffset);
device->moveTo(newOffset);
}
}
......
......@@ -132,7 +132,7 @@ QRect KisTransformWorker::rotateRight90(KisPaintDeviceSP dev,
int portion)
{
QRect r = rotateWithTf(90, dev, boundRect, progressUpdater, portion);
dev->move(dev->x() - 1, dev->y());
dev->moveTo(dev->x() - 1, dev->y());
return QRect(- r.top() - r.height(), r.x(), r.height(), r.width());
}
......@@ -142,7 +142,7 @@ QRect KisTransformWorker::rotateLeft90(KisPaintDeviceSP dev,
int portion)
{
QRect r = rotateWithTf(270, dev, boundRect, progressUpdater, portion);
dev->move(dev->x(), dev->y() - 1);
dev->moveTo(dev->x(), dev->y() - 1);
return QRect(r.top(), - r.x() - r.width(), r.height(), r.width());
}
......@@ -152,7 +152,7 @@ QRect KisTransformWorker::rotate180(KisPaintDeviceSP dev,
int portion)
{
QRect r = rotateWithTf(180, dev, boundRect, progressUpdater, portion);
dev->move(dev->x() - 1, dev->y() -1);
dev->moveTo(dev->x() - 1, dev->y() -1);
return QRect(- r.x() - r.width(), - r.top() - r.height(), r.width(), r.height());
}
......@@ -279,11 +279,11 @@ bool KisTransformWorker::runPartial(const QRect &processRect)
} else if (xShearPresent) {
transformPass <KisHLineIteratorSP>(m_dev.data(), m_dev.data(), xscale, m_xshear, dx, m_filter, portion);
m_boundRect.translate(0, dy);
m_dev->move(m_dev->x(), m_dev->y() + dy);
m_dev->moveTo(m_dev->x(), m_dev->y() + dy);
} else if (yShearPresent) {
transformPass <KisVLineIteratorSP>(m_dev.data(), m_dev.data(), yscale, m_yshear, dy, m_filter, portion);
m_boundRect.translate(dx, 0);
m_dev->move(m_dev->x() + dx, m_dev->y());
m_dev->moveTo(m_dev->x() + dx, m_dev->y());
}
yscale = 1.;
......@@ -332,7 +332,7 @@ bool KisTransformWorker::runPartial(const QRect &processRect)
if (simpleTranslation) {
m_boundRect.translate(xtranslate, ytranslate);
m_dev->move(m_dev->x() + xtranslate, m_dev->y() + ytranslate);
m_dev->moveTo(m_dev->x() + xtranslate, m_dev->y() + ytranslate);
} else {
QTransform SC = QTransform::fromScale(xscale, yscale);
QTransform R; R.rotateRadians(rotation);
......
......@@ -246,7 +246,7 @@ void KisWarpTransformWorker::run()
if (m_origPoint.size() == 1) {
QPointF translate(QPointF(m_dev->x(), m_dev->y()) + m_transfPoint[0] - m_origPoint[0]);
m_dev->move(translate.toPoint());
m_dev->moveTo(translate.toPoint());
return;
}
......
......@@ -143,7 +143,7 @@ void KisPaintDeviceTest::testGeometry()
QCOMPARE(dev->exactBounds(), QRect(0, 0, 512, 512));
QCOMPARE(dev->extent(), QRect(0, 0, 512, 512));
dev->move(10, 10);
dev->moveTo(10, 10);
QCOMPARE(dev->exactBounds(), QRect(10, 10, 512, 512));
QCOMPARE(dev->extent(), QRect(10, 10, 512, 512));
......@@ -270,7 +270,7 @@ void KisPaintDeviceTest::testColorSpaceConversion()
const KoColorSpace* dstCs = KoColorSpaceRegistry::instance()->lab16();
KisPaintDeviceSP dev = new KisPaintDevice(srcCs);
dev->convertFromQImage(image, 0);
dev->move(10, 10); // Unalign with tile boundaries
dev->moveTo(10, 10); // Unalign with tile boundaries
KUndo2Command* cmd = dev->convertTo(dstCs);
QCOMPARE(dev->exactBounds(), QRect(10, 10, image.width(), image.height()));
......@@ -342,7 +342,7 @@ void KisPaintDeviceTest::testFastBitBlt()
QFAIL(QString("Failed to create identical image, first different pixel: %1,%2 \n").arg(errpoint.x()).arg(errpoint.y()).toLatin1());
}
srcDev->move(10,10);
srcDev->moveTo(10,10);
QVERIFY(!dstDev->fastBitBltPossible(srcDev));
}
......@@ -353,11 +353,11 @@ void KisPaintDeviceTest::testMakeClone()
const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
KisPaintDeviceSP srcDev = new KisPaintDevice(cs);
srcDev->convertFromQImage(image, 0);
srcDev->move(10,10);
srcDev->moveTo(10,10);
const KoColorSpace * weirdCS = KoColorSpaceRegistry::instance()->lab16();
KisPaintDeviceSP dstDev = new KisPaintDevice(weirdCS);
dstDev->move(1000,1000);
dstDev->moveTo(1000,1000);
QVERIFY(!dstDev->fastBitBltPossible(srcDev));
......@@ -439,7 +439,7 @@ void KisPaintDeviceTest::testCaching()
QImage thumb2 = dev->createThumbnail(50, 50);
QRect exactBounds2 = dev->exactBounds();
dev->move(10, 10);
dev->moveTo(10, 10);
QImage thumb3 = dev->createThumbnail(50, 50);
QRect exactBounds3 = dev->exactBounds();
......@@ -1297,7 +1297,7 @@ void KisPaintDeviceTest::testMoveWrapAround()
//dev->convertToQImage(0, rc.x(), rc.y(), rc.width(), rc.height()).save("move0.png");
QCOMPARE(dev->exactBounds(), QRect(3,3,16,16));
dev->move(QPoint(10,10));
dev->moveTo(QPoint(10,10));
QCOMPARE(dev->exactBounds(), QRect(8,8,6,6));
//dev->convertToQImage(0, rc.x(), rc.y(), rc.width(), rc.height()).save("move1.png");
......
......@@ -131,14 +131,14 @@ void KisTransactionTest::testDeviceMove()
QCOMPARE(dev->y(), 0);
KisTransaction t1(kundo2_noi18n("move1"), dev, 0);
dev->move(10,20);
dev->moveTo(10,20);
t1.commit(&undoAdapter);
QCOMPARE(dev->x(), 10);
QCOMPARE(dev->y(), 20);
KisTransaction t2(kundo2_noi18n("move2"), dev, 0);
dev->move(7,11);
dev->moveTo(7,11);
t2.commit(&undoAdapter);
QCOMPARE(dev->x(), 7);
......@@ -265,7 +265,7 @@ void KisTransactionTest::testUndoWithUnswitchedFrames()
{
KisTransaction transaction(kundo2_noi18n("third_move"), dev, 0);
dev->move(17,17);
dev->moveTo(17,17);
transaction.commit(&undoAdapter);
......
......@@ -266,14 +266,14 @@ void KisKraSaverTest::testRoundTripAnimation()
image->animationInterface()->switchCurrentTimeAsync(10);
image->waitForDone();
layer1->paintDevice()->fill(QRect(200, 50, 10, 10), KoColor(Qt::black, cs));
layer1->paintDevice()->move(25, 15);
layer1->paintDevice()->moveTo(25, 15);
layer1->paintDevice()->setDefaultPixel(KoColor(Qt::green, cs).data());
rasterChannel->addKeyframe(20, &parentCommand);
image->animationInterface()->switchCurrentTimeAsync(20);
image->waitForDone();
layer1->paintDevice()->fill(QRect(150, 200, 30, 30), KoColor(Qt::black, cs));
layer1->paintDevice()->move(100, 50);
layer1->paintDevice()->moveTo(100, 50);
layer1->paintDevice()->setDefaultPixel(KoColor(Qt::blue, cs).data());
QScopedPointer<KisDocument> doc(KisPart::instance()->createDocument());
......
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