Commit a09e5840 authored by Thomas Zander's avatar Thomas Zander

New features on KoShape::setAbsolutePosition

svn path=/trunk/koffice/; revision=646474
parent b704c19e
......@@ -420,23 +420,15 @@ QPointF KoShape::absolutePosition(KoFlake::Position anchor) const {
QPointF point;
switch(anchor) {
case KoFlake::TopLeftCorner: break;
case KoFlake::TopRightCorner:
point = QPointF(size().width(), 0.0);
break;
case KoFlake::BottomLeftCorner:
point = QPointF(0.0, size().height());
break;
case KoFlake::BottomRightCorner:
point = QPointF(size().width(), size().height());
break;
case KoFlake::CenteredPositon:
point = QPointF(size().width() / 2.0, size().height() / 2.0);
break;
case KoFlake::TopRightCorner: point = QPointF(size().width(), 0.0); break;
case KoFlake::BottomLeftCorner: point = QPointF(0.0, size().height()); break;
case KoFlake::BottomRightCorner: point = QPointF(size().width(), size().height()); break;
case KoFlake::CenteredPositon: point = QPointF(size().width() / 2.0, size().height() / 2.0); break;
}
return d->matrix.map(point);
}
void KoShape::setAbsolutePosition(QPointF newPosition) {
void KoShape::setAbsolutePosition(QPointF newPosition, KoFlake::Position anchor) {
QPointF zero(0, 0);
QMatrix matrix;
// apply parents matrix to inherit any transformations done there.
......@@ -468,7 +460,16 @@ void KoShape::setAbsolutePosition(QPointF newPosition) {
matrix.shear( d->shearX, d->shearY );
matrix.scale( d->scaleX, d->scaleY );
QPointF vector2 = matrix.map( QPointF(size().width() / 2.0, size().height() / 2.0) );
QPointF point;
switch(anchor) {
case KoFlake::TopLeftCorner: break;
case KoFlake::TopRightCorner: point = QPointF(size().width(), 0.0); break;
case KoFlake::BottomLeftCorner: point = QPointF(0.0, size().height()); break;
case KoFlake::BottomRightCorner: point = QPointF(size().width(), size().height()); break;
case KoFlake::CenteredPositon: point = QPointF(size().width() / 2.0, size().height() / 2.0); break;
}
QPointF vector2 = matrix.map( point ); // QPointF(size().width() / 2.0, size().height() / 2.0) );
//kDebug(30006) << "vector1: " << vector1 << ", vector2: " << vector2 << endl;
setPosition(newPosition + vector1 - vector2);
......
......@@ -467,7 +467,7 @@ public:
shape-&gt;setAbsolutePosition(QPointF(0,0));</pre>
* @param newPosition the new absolute center of the shape.
*/
void setAbsolutePosition(QPointF newPosition);
void setAbsolutePosition(QPointF newPosition, KoFlake::Position anchor = KoFlake::CenteredPositon);
/**
* Move this shape from its current (absolute) position over a specified distance.
......
......@@ -60,6 +60,16 @@ void TestPosition::testAbsolutePosition() {
QCOMPARE(childShape2->absolutePosition(), QPointF(130, 232.5) );
container2->setClipping(childShape2, true);
QCOMPARE(childShape2->absolutePosition(), QPointF(167.5, 230) );
shape1->rotate(90);
shape1->setPosition(QPointF(10, 10));
QCOMPARE(shape1->absolutePosition(), QPointF(10 + 25, 10 + 25) );
QCOMPARE(shape1->absolutePosition(KoFlake::CenteredPositon), QPointF(10 + 25, 10 + 25) );
QCOMPARE(shape1->absolutePosition(KoFlake::TopLeftCorner), QPointF(10 + 50, 10) );
QCOMPARE(shape1->absolutePosition(KoFlake::BottomRightCorner), QPointF(10, 10 + 50) );
QCOMPARE(container2->absolutePosition(KoFlake::TopLeftCorner), QPointF(200, 200));
}
void TestPosition::testSetAbsolutePosition() {
......@@ -87,5 +97,27 @@ void TestPosition::testSetAbsolutePosition() {
QCOMPARE(childShape2->position(), QPointF(-200 - 5, 200 - 7.5) );
}
void TestPosition::testSetAbsolutePosition2() {
shape1->rotate(90);
shape1->setAbsolutePosition(QPointF(100, 100));
QCOMPARE(shape1->absolutePosition(), QPointF(100, 100));
shape1->setAbsolutePosition(QPointF(100, 100), KoFlake::TopLeftCorner);
QCOMPARE(shape1->absolutePosition(KoFlake::TopLeftCorner), QPointF(100, 100));
childShape1->setAbsolutePosition(QPointF(0, 0), KoFlake::BottomRightCorner);
QCOMPARE(childShape1->position(), QPointF(-150, -150) );
childShape1->setAbsolutePosition(QPointF(0, 0), KoFlake::BottomLeftCorner);
QCOMPARE(childShape1->position(), QPointF(-100, -150) );
childShape1->setAbsolutePosition(QPointF(0, 0), KoFlake::TopRightCorner);
QCOMPARE(childShape1->position(), QPointF(-150, -100) );
container2->setClipping(childShape2, true);
childShape2->setAbsolutePosition(QPointF(0, 0), KoFlake::TopLeftCorner);
QCOMPARE(childShape2->position(), QPointF(-200, 200) );
}
QTEST_MAIN(TestPosition)
#include "TestPosition.moc"
......@@ -19,6 +19,7 @@ private slots:
void testBasePosition();
void testAbsolutePosition();
void testSetAbsolutePosition();
void testSetAbsolutePosition2();
private:
void resetValues();
......
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