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 20a25823 authored by Thomas Zander's avatar Thomas Zander

Since KoShape::rotate() is now relative it occurred to me that, really,

the name of the method kind of makes sense for something thats relative.
Otherwise it would be setRotation().
But this makes the other transformation methods a bit weird since they
too look relative. And now we can't say anymore that everything is absolute.
So, rename the KoShape::scale and KoShape::shear() and KoShape::resize() to
setScale(), setShear() and setSize()

svn path=/trunk/koffice/; revision=690296
parent 95923e79
......@@ -234,7 +234,7 @@ void KisToolSelectElliptical::mouseReleaseEvent(KoPointerEvent *e)
KoShapeFactory *rectFactory = KoShapeRegistry::instance()->value("KoEllipseShape");
if(rectFactory) {
shape = rectFactory->createDefaultShape();
shape->resize(documentRect.size());
shape->setSize(documentRect.size());
shape->setPosition(documentRect.topLeft());
}
else {
......
......@@ -233,7 +233,7 @@ void KisToolSelectRectangular::mouseReleaseEvent(KoPointerEvent *e)
KoShapeFactory *rectFactory = KoShapeRegistry::instance()->value("KoRectangleShape");
if(rectFactory) {
shape = rectFactory->createDefaultShape();
shape->resize(documentRect.size());
shape->setSize(documentRect.size());
shape->setPosition(documentRect.topLeft());
}
else {
......
......@@ -72,7 +72,7 @@ QUndoCommand* KoCreateShapeStrategy::createCommand() {
// if the user has dragged when creating the shape,
// resize the shape to the dragged size
if(newSize.width() > 1.0 && newSize.height() > 1.0)
shape->resize(newSize);
shape->setSize(newSize);
QUndoCommand * cmd = parent->m_canvas->shapeController()->addShape( shape );
if ( cmd )
......
......@@ -112,7 +112,7 @@ void KoParameterShape::paintHandle( QPainter & painter, const KoViewConverter &
painter.drawPolygon( poly );
}
void KoParameterShape::resize( const QSizeF &newSize )
void KoParameterShape::setSize( const QSizeF &newSize )
{
QSizeF oldSize = size();
QMatrix matrix( newSize.width() / oldSize.width(), 0, 0, newSize.height() / oldSize.height(), 0, 0 );
......@@ -122,7 +122,7 @@ void KoParameterShape::resize( const QSizeF &newSize )
m_handles[i] = matrix.map( m_handles[i] );
}
KoPathShape::resize( newSize );
KoPathShape::setSize( newSize );
}
QPointF KoParameterShape::normalize()
......
......@@ -93,7 +93,7 @@ public:
*/
virtual void paintHandle( QPainter & painter, const KoViewConverter & converter, int handleId, int handleRadius );
virtual void resize( const QSizeF &size );
virtual void setSize( const QSizeF &size );
/**
* @brief Check if object is a parametric shape
......
......@@ -449,16 +449,16 @@ QPointF KoPathShape::position() const
return KoShape::position();
}
void KoPathShape::resize( const QSizeF &newSize )
void KoPathShape::setSize( const QSizeF &newSize )
{
QSizeF oldSize = size();
double zoomX = newSize.width() / oldSize.width();
double zoomY = newSize.height() / oldSize.height();
QMatrix matrix( zoomX, 0, 0, zoomY, 0, 0 );
//qDebug() << "resize" << zoomX << "," << zoomY << "," << newSize;
//qDebug() << "setSize" << zoomX << "," << zoomY << "," << newSize;
map( matrix );
KoShape::resize( newSize );
KoShape::setSize( newSize );
}
KoPathPoint * KoPathShape::moveTo( const QPointF &p )
......
......@@ -92,7 +92,7 @@ public:
virtual QRectF boundingRect() const;
virtual QSizeF size() const;
virtual QPointF position() const;
virtual void resize( const QSizeF &size );
virtual void setSize( const QSizeF &size );
// reimplemented
virtual void saveOdf( KoShapeSavingContext & context ) const;
......
......@@ -145,7 +145,7 @@ void KoSelection::requestSelectionChangedEvent() {
void KoSelection::selectionChangedEvent() {
d->eventTriggered = false;
scale(1,1);
setScale(1,1);
//just as well use the oppertunity to update the size and position
updateSizeAndPosition();
emit selectionChanged();
......@@ -172,7 +172,7 @@ void KoSelection::updateSizeAndPosition()
{
QRectF bb = sizeRect();
QMatrix matrix = transformationMatrix(0);
resize( bb.size() );
setSize( bb.size() );
QPointF p = matrix.map(bb.topLeft() + matrix.inverted().map( position()) );
setPosition( p );
}
......
......@@ -145,7 +145,7 @@ void KoShape::paintDecorations(QPainter &painter, const KoViewConverter &convert
}*/
}
void KoShape::scale( double sx, double sy )
void KoShape::setScale( double sx, double sy )
{
QPointF pos = position();
QMatrix scaleMatrix;
......@@ -171,7 +171,7 @@ void KoShape::rotate( double angle )
d->shapeChanged(RotationChanged);
}
void KoShape::shear( double sx, double sy )
void KoShape::setShear( double sx, double sy )
{
QPointF pos = position();
QMatrix shearMatrix;
......@@ -184,7 +184,7 @@ void KoShape::shear( double sx, double sy )
d->shapeChanged(ShearChanged);
}
void KoShape::resize( const QSizeF &newSize )
void KoShape::setSize( const QSizeF &newSize )
{
QSizeF s( size() );
if(s == newSize)
......@@ -438,12 +438,13 @@ KoInsets KoShape::borderInsets() const {
double KoShape::scaleX() const {
return 0.0;
}
double KoShape::scaleY() const {
return 0.0;
}
double KoShape::rotation() const {
// try to extract the rotation angle out of the local matrix
// try to extract the rotation angle out of the local matrix
// if it is a pure rotation matrix
// check if the matrix has shearing mixed in
......
......@@ -85,10 +85,10 @@ public:
/// Used by shapeChanged() to select which change was made
enum ChangeType {
PositionChanged, ///< used after a setPosition()
RotationChanged, ///< used after a rotate()
ScaleChanged, ///< used after a scale()
ShearChanged, ///< used after a shear()
SizeChanged, ///< used after a resize()
RotationChanged, ///< used after a setRotation()
ScaleChanged, ///< used after a setScale()
ShearChanged, ///< used after a setShear()
SizeChanged, ///< used after a setSize()
ParentChanged, ///< used after a setParent()
CollisionDetected ///< used when another shape moved in our boundingrect
};
......@@ -138,8 +138,6 @@ public:
* @param element element which represents the shape in odf
*
* @return false if loading failed
*
* TODO make it pure virtual
*/
virtual bool loadOdf( const KoXmlElement & element, KoShapeLoadingContext &context ) = 0;
......@@ -165,7 +163,7 @@ public:
* @param sx scale in x direction
* @param sy scale in y direction
*/
void scale( double sx, double sy );
void setScale( double sx, double sy );
/**
* Return the current scaling adjustment over the X axis.
......@@ -178,11 +176,11 @@ public:
KDE_DEPRECATED double scaleY() const;
/**
* @brief Rotate the shape
* @brief Rotate the shape (relative)
*
* The shape will be rotated using the center of the shape using the size()
* The shape will be rotated from the current rotation using the center of the shape using the size()
*
* @param angle set the rotation angle of the shape in degrees
* @param angle change the angle of rotation increasing it with 'angle' degrees
*/
void rotate( double angle );
......@@ -200,7 +198,7 @@ public:
* @param sx shear in x direction
* @param sy shear in y direction
*/
void shear( double sx, double sy );
void setShear( double sx, double sy );
/**
* Return the current horizontal shearing angle for this shape.
......@@ -223,7 +221,7 @@ public:
* Easiest example of this difference is that using this method will not distort the
* size of pattern-fills and borders.
*/
virtual void resize( const QSizeF &size );
virtual void setSize( const QSizeF &size );
/**
* @brief Get the size of the shape in pt.
......
......@@ -43,7 +43,7 @@ bool KoShapeGroup::hitTest( const QPointF &position ) const {
void KoShapeGroup::childCountChanged() {
QRectF br = boundingRect();
setPosition( br.topLeft() );
resize( br.size() );
setSize( br.size() );
}
void KoShapeGroup::saveOdf( KoShapeSavingContext & context ) const {
......
......@@ -191,7 +191,7 @@ void KoShapeResizeStrategy::handleMouseMove(const QPointF &point, Qt::KeyboardMo
QSizeF size( scaleX * m_startSizes[i].width(), scaleY * m_startSizes[i].height() );
// apply the transformation
shape->resize( size );
shape->setSize( size );
// apply the rest of the transformation without the resizing part
shape->applyTransformation( scaleMatrix.inverted() * resizeMatrix );
shape->applyTransformation( mirrorMatrix );
......
......@@ -78,7 +78,7 @@ void KoShapeGroupCommand::redo () {
}
}
m_container->setPosition( bound.topLeft() );
m_container->resize( bound.size() );
m_container->setSize( bound.size() );
}
QMatrix groupTransform = m_container->transformationMatrix(0).inverted();
......
......@@ -43,7 +43,7 @@ void KoShapeShearCommand::redo() {
QUndoCommand::redo();
for(int i=0; i < m_shapes.count(); i++) {
m_shapes.at(i)->repaint();
m_shapes.at(i)->shear( m_newShearXs.at(i), m_newShearYs.at(i));
m_shapes.at(i)->setShear( m_newShearXs.at(i), m_newShearYs.at(i));
m_shapes.at(i)->repaint();
}
}
......@@ -52,7 +52,7 @@ void KoShapeShearCommand::undo() {
QUndoCommand::undo();
for(int i=0; i < m_shapes.count(); i++) {
m_shapes.at(i)->repaint();
m_shapes.at(i)->shear( m_previousShearXs.at(i), m_previousShearYs.at(i) );
m_shapes.at(i)->setShear( m_previousShearXs.at(i), m_previousShearYs.at(i) );
m_shapes.at(i)->repaint();
}
}
......@@ -50,7 +50,7 @@ void KoShapeSizeCommand::redo () {
int i=0;
foreach(KoShape *shape, d->shapes) {
shape->repaint();
shape->resize(d->newSizes[i++]);
shape->setSize(d->newSizes[i++]);
shape->repaint();
}
}
......@@ -60,7 +60,7 @@ void KoShapeSizeCommand::undo () {
int i=0;
foreach(KoShape *shape, d->shapes) {
shape->repaint();
shape->resize(d->previousSizes[i++]);
shape->setSize(d->previousSizes[i++]);
shape->repaint();
}
}
......@@ -3,18 +3,34 @@
#include "MockShapes.h"
#include <QPointF>
TestPosition::TestPosition()
: shape1(0),
shape2(0),
childShape1(0),
childShape2(0),
container(0),
container2(0)
{
}
void TestPosition::init() {
delete container;
delete container2;
delete shape1;
delete shape2;
delete childShape1;
delete childShape2;
void TestPosition::initTestCase() {
shape1 = new MockShape();
shape1->setPosition(QPointF(50, 50));
shape1->resize(QSize(50, 50));
shape1->setSize(QSize(50, 50));
shape2 = new MockShape();
shape2->setPosition(QPointF(20, 20));
shape2->resize(QSize(50, 50));
shape2->setSize(QSize(50, 50));
childShape1 = new MockShape();
childShape1->setPosition(QPointF(20, 20));
childShape1->resize(QSize(50, 50));
childShape1->setSize(QSize(50, 50));
container = new MockContainer();
container->setPosition(QPointF(100, 100));
container->addChild(childShape1);
......@@ -22,23 +38,14 @@ void TestPosition::initTestCase() {
childShape2 = new MockShape();
childShape2->setPosition(QPointF(25, 25));
childShape2->resize(QSizeF(10, 15));
childShape2->setSize(QSizeF(10, 15));
container2 = new MockContainer();
container2->setPosition(QPointF(100, 200));
container2->resize(QSizeF(100, 100));
container2->setSize(QSizeF(100, 100));
container2->rotate(90);
container2->addChild(childShape2);
}
void TestPosition::cleanupTestCase() {
delete container;
delete container2;
delete shape1;
delete shape2;
delete childShape1;
delete childShape2;
}
void TestPosition::testBasePosition() {
// internal consistency tests.
QCOMPARE(shape1->position(), QPointF(50,50) );
......@@ -123,11 +130,11 @@ void TestPosition::testSetAndGetRotation() {
shape1->rotate(180);
QCOMPARE(shape1->rotation(), 180.0);
shape1->rotate(2);
QCOMPARE(shape1->rotation(), 2.0);
QCOMPARE(shape1->rotation(), 182.0);
shape1->rotate(4);
QCOMPARE(shape1->rotation(), 4.0);
QCOMPARE(shape1->rotation(), 186.0);
shape1->rotate(358);
QCOMPARE(shape1->rotation(), 358.0);
QCOMPARE(shape1->rotation(), 184.0);
}
QTEST_MAIN(TestPosition)
......
......@@ -9,9 +9,11 @@ class KoShapeContainer;
class TestPosition : public QObject
{
Q_OBJECT
public:
TestPosition();
private slots:
void initTestCase();
void cleanupTestCase();
void init(); // will be called before each testfunction is executed.
// tests
void testBasePosition();
......
......@@ -13,7 +13,7 @@ void TestShapeAt::test() {
MockCanvas canvas;
KoShapeManager manager(&canvas);
shape1.setPosition(QPointF(100, 100));
shape1.resize(QSizeF(50, 50));
shape1.setSize(QSizeF(50, 50));
shape1.setZIndex(0);
manager.add(&shape1);
......@@ -25,7 +25,7 @@ void TestShapeAt::test() {
QVERIFY(manager.shapeAt(QPointF(100, 100), KoFlake::NextUnselected) != 0 );
shape2.setPosition(QPointF(80, 80));
shape2.resize(QSizeF(50, 50));
shape2.setSize(QSizeF(50, 50));
shape2.setZIndex(1);
manager.add(&shape2);
......@@ -47,7 +47,7 @@ void TestShapeAt::test() {
QCOMPARE(manager.shapeAt(QPointF(105, 105), KoFlake::NextUnselected), &shape1);
shape3.setPosition(QPointF(120, 80));
shape3.resize(QSizeF(50, 50));
shape3.setSize(QSizeF(50, 50));
shape3.setZIndex(2);
manager.add(&shape3);
......
......@@ -66,7 +66,7 @@ void KoShapeGeometry::updateShape() {
QPointF pos(widget.left->value(), widget.top->value());
m_shape->setAbsolutePosition(pos);
QSizeF size(widget.width->value(), widget.height->value());
m_shape->resize(size);
m_shape->setSize(size);
m_shape->repaint();
}
......@@ -85,7 +85,7 @@ void KoShapeGeometry::save() {
void KoShapeGeometry::cancel() {
m_shape->setAbsolutePosition(mOriginalPosition);
m_shape->resize(mOriginalSize);
m_shape->setSize(mOriginalSize);
}
KAction *KoShapeGeometry::createAction() {
......
......@@ -22,7 +22,7 @@ void TestDocumentLayout::initTestCase() {
void TestDocumentLayout::initForNewTest(const QString &initText) {
// this leaks memory like mad, but who cares ;)
shape1 = new MockTextShape();
shape1->resize(QSizeF(200, 1000));
shape1->setSize(QSizeF(200, 1000));
// this leaks memory like mad, but who cares ;)
doc = shape1->layout->document();
......
......@@ -24,7 +24,7 @@
IconShape::IconShape(const QString &icon) {
m_icon = KIcon(icon).pixmap(22);
resize(m_icon.size());
setSize(m_icon.size());
}
void IconShape::paint(QPainter &painter, const KoViewConverter &converter) {
......
......@@ -59,7 +59,7 @@ ShapeSelector::~ShapeSelector() {
}
void ShapeSelector::loadShapeTypes() {
m_mainFolder->resize(m_canvas->size());
m_mainFolder->setSize(m_canvas->size());
foreach(QString id, KoShapeRegistry::instance()->keys()) {
KoShapeFactory *factory = KoShapeRegistry::instance()->value(id);
......@@ -117,7 +117,7 @@ void ShapeSelector::add(KoShape *shape) {
}
void ShapeSelector::setSize(const QSize &size) {
m_mainFolder->resize(QSizeF(size));
m_mainFolder->setSize(QSizeF(size));
}
#include "ShapeSelector.moc"
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