[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/office/flake/lib
From:       Thomas Zander <zander () kde ! org>
Date:       2006-05-13 13:57:22
Message-ID: 1147528642.663213.28605.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 540457 by zander:

* Correct rotation to work for multiple shapes
* Make rotation un-doable


 M  +28 -0     KoCommand.cpp  
 M  +11 -0     KoCommand.h  
 M  +29 -1     KoShapeRotateStrategy.cpp  
 M  +3 -1      KoShapeRotateStrategy.h  


--- trunk/playground/office/flake/lib/KoCommand.cpp #540456:540457
@@ -29,3 +29,31 @@
 QString KoShapeMoveCommand::name () const {
     return "Move";
 }
+
+
+KoShapeRotateCommand::KoShapeRotateCommand(const KoSelectionSet &shapes, \
QList<double> &previousAngles, QList<double> &newAngles) +: \
m_previousAngles(previousAngles) +, m_newAngles(newAngles)
+{
+    m_shapes = shapes.toList();
+}
+
+void KoShapeRotateCommand::execute() {
+    for(int i=0; i < m_shapes.count(); i++) {
+        m_shapes.at(i)->repaint();
+        m_shapes.at(i)->rotate( m_newAngles.at(i) );
+        m_shapes.at(i)->repaint();
+    }
+}
+
+void KoShapeRotateCommand::unexecute() {
+    for(int i=0; i < m_shapes.count(); i++) {
+        m_shapes.at(i)->repaint();
+        m_shapes.at(i)->rotate( m_previousAngles.at(i) );
+        m_shapes.at(i)->repaint();
+    }
+}
+
+QString KoShapeRotateCommand::name () const {
+    return "Rotate";
+}
--- trunk/playground/office/flake/lib/KoCommand.h #540456:540457
@@ -51,4 +51,15 @@
     QList<QPointF> m_previousPositions, m_newPositions;
 };
 
+class KoShapeRotateCommand : public KCommand {
+public:
+    KoShapeRotateCommand(const KoSelectionSet &shapes, QList<double> \
&previousAngles, QList<double> &newAngles); +    void execute ();
+    void unexecute ();
+    QString name () const;
+private:
+    QList<KoShape*> m_shapes;
+    QList<double> m_previousAngles, m_newAngles;
+};
+
 #endif
--- trunk/playground/office/flake/lib/KoShapeRotateStrategy.cpp #540456:540457
@@ -22,6 +22,7 @@
 #include "KoCanvasBase.h"
 #include "KoGfxEvent.h"
 #include "KoShapeManager.h"
+#include "KoCommand.h"
 
 #include <QDebug>
 #include <QPointF>
@@ -38,6 +39,8 @@
         if(shape->isLocked())
             continue;
         m_selectedObjects << shape;
+        m_startPositions << shape->position();
+        m_initialAngles << shape->rotation();
         m_initialBoundingRect = m_initialBoundingRect.unite( shape->boundingBox() );
     }
 }
@@ -46,11 +49,23 @@
     QPointF center = m_initialBoundingRect.center();
     double angle = atan2( event->point.y() - center.y(), event->point.x() - \
center.x() ) -  atan2( m_start.y() - center.y(), m_start.x() - center.x() );
+    angle = angle / M_PI * 180;  // convert to degrees.
+    QMatrix matrix;
+    matrix.translate(center.x(), center.y());
+    matrix.rotate(angle);
 
+    int counter=0;
     foreach(KoShape *shape, m_selectedObjects) {
         shape->repaint();
-        shape->rotate(angle / M_PI * 180);
+        QPointF centerOfShape(shape->size().width()/2, shape->size().height()/2);
+        QPointF newCenter = matrix.map(m_startPositions[counter] + centerOfShape - \
center); +        shape->setPosition(newCenter - centerOfShape);
+        double totalAngle = m_initialAngles[counter] + angle;
+        while(totalAngle >= 360) totalAngle -= 360;
+        while(totalAngle <= -360) totalAngle += 360;
+        shape->rotate(totalAngle);
         shape->repaint();
+        counter++;
     }
 }
 
@@ -58,3 +73,16 @@
     SelectionDecorator decorator \
(m_canvas->shapeManager()->selection()->boundingBox(), KoInteractionTool::NoHandle, \
true, false);  decorator.paint(painter, converter);
 }
+
+KCommand* KoShapeRotateStrategy::createCommand() {
+    KMacroCommand *cmd = new KMacroCommand("Rotate");
+    QList<QPointF> newPositions;
+    QList<double> newAngles;
+    foreach(KoShape *shape, m_selectedObjects) {
+        newPositions << shape->position();
+        newAngles << shape->rotation();
+    }
+    cmd->addCommand(new KoShapeMoveCommand(m_selectedObjects, m_startPositions, \
newPositions)); +    cmd->addCommand(new KoShapeRotateCommand(m_selectedObjects, \
m_initialAngles, newAngles)); +    return cmd;
+}
--- trunk/playground/office/flake/lib/KoShapeRotateStrategy.h #540456:540457
@@ -40,13 +40,15 @@
     virtual ~KoShapeRotateStrategy() {}
 
     void handleMouseMove( KoGfxEvent *event );
-    KCommand* createCommand() { return 0; }
+    KCommand* createCommand();
     void finishInteraction() { }
     virtual void paint( QPainter &painter, KoViewConverter &converter);
 
 private:
     QRectF m_initialBoundingRect;
     QPointF m_start;
+    QList<QPointF> m_startPositions;
+    QList<double> m_initialAngles;
 };
 
 #endif /* KOSHAPEROTATESTRATEGY_H */


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic