F:/KPlato/koffice/libs/flake/KoShapeMoveStrategy.cpp

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002 
00003    Copyright (C) 2006 Thorsten Zachmann <zachmann@kde.org>
00004    Copyright (C) 2006 Thomas Zander <zander@kde.org>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include "KoShapeMoveStrategy.h"
00023 
00024 #include <QPainter>
00025 #include <QMouseEvent>
00026 
00027 #include "KoCanvasBase.h"
00028 #include "KoShapeManager.h"
00029 #include "KoSelection.h"
00030 #include "KoPointerEvent.h"
00031 #include "KoCommand.h"
00032 #include "kcommand.h"
00033 #include "KoInteractionTool.h"
00034 
00035 KoShapeMoveStrategy::KoShapeMoveStrategy( KoTool *tool, KoCanvasBase *canvas, const QPointF &clicked)
00036 : KoInteractionStrategy(tool, canvas)
00037 , m_initialTopLeft(99999, 99999)
00038 , m_start(clicked)
00039 {
00040     KoSelectionSet selectedShapes = canvas->shapeManager()->selection()->selectedShapes(KoFlake::TopLevelSelection);
00041     QRectF boundingRect;
00042     foreach(KoShape *shape, selectedShapes) {
00043         if(shape->isLocked())
00044             continue;
00045         m_selectedShapes << shape;
00046         m_previousPositions << shape->position();
00047         m_newPositions << shape->position();
00048         boundingRect = boundingRect.unite( shape->boundingRect() );
00049     }
00050     m_initialTopLeft = boundingRect.topLeft();
00051     m_initialSelectionPosition = canvas->shapeManager()->selection()->position();
00052 }
00053 
00054 void KoShapeMoveStrategy::handleMouseMove(const QPointF &point, Qt::KeyboardModifiers modifiers) {
00055     m_diff = point - m_start;
00056     if(m_canvas->snapToGrid() && (modifiers & Qt::ShiftModifier) == 0) {
00057         QPointF newPos = m_initialTopLeft + m_diff;
00058         applyGrid(newPos);
00059         m_diff = newPos - m_initialTopLeft;
00060     }
00061     if(modifiers & (Qt::AltModifier | Qt::ControlModifier)) {
00062         // keep x or y position unchanged
00063         if(qAbs(m_diff.x()) < qAbs(m_diff.y()))
00064             m_diff.setX(0);
00065         else
00066             m_diff.setY(0);
00067     }
00068 
00069     int i=0;
00070     foreach(KoShape *shape, m_selectedShapes) {
00071         QPointF newPos (m_previousPositions.at(i) + m_diff);
00072         m_newPositions[i] = newPos;
00073         shape->repaint();
00074         shape->setPosition(newPos);
00075         shape->repaint();
00076         i++;
00077     }
00078     m_canvas->shapeManager()->selection()->setPosition(m_initialSelectionPosition + m_diff);
00079 }
00080 
00081 KCommand* KoShapeMoveStrategy::createCommand() {
00082     if(m_diff.x() == 0 && m_diff.y() == 0)
00083         return 0;
00084     return new KoShapeMoveCommand(m_selectedShapes, m_previousPositions, m_newPositions);
00085 }
00086 
00087 void KoShapeMoveStrategy::paint( QPainter &painter, KoViewConverter &converter) {
00088     SelectionDecorator decorator (KoFlake::NoHandle, false, false);
00089     decorator.setSelection(m_canvas->shapeManager()->selection());
00090     decorator.paint(painter, converter);
00091 }

Généré le Wed Nov 22 23:41:00 2006 pour KPlato par  doxygen 1.5.1-p1