Commit ac8af5ac authored by Thomas Zander's avatar Thomas Zander
Browse files

Introduce a new command to raise/lower shapes in the zIndex stack.

Also add actions in KWord for them.

svn path=/trunk/koffice/; revision=614778
parent ddad24f5
......@@ -56,6 +56,7 @@ set(flake_SRCS
commands/KoShapeShearCommand.cpp
commands/KoShapeSizeCommand.cpp
commands/KoUngroupShapesCommand.cpp
commands/KoShapeReorderCommand.cpp
)
kde4_automoc(${flake_SRCS})
......
......@@ -141,7 +141,7 @@ void KoShapeManager::paint( QPainter &painter, const KoViewConverter &converter,
painter.restore(); // for the matrix
}
#if 0
#ifdef KOFFICE_RTREE_DEBUG
// paint tree
double zx = 0;
double zy = 0;
......
/* This file is part of the KDE project
* Copyright (C) 2006 Thomas Zander <zander@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "KoShapeReorderCommand.h"
#include "KoShape.h"
#include "KoShapeManager.h"
#include <klocale.h>
#include <kdebug.h>
#include <limits.h>
KoShapeReorderCommand::KoShapeReorderCommand(const QList<KoShape*> &shapes, QList<int> &newIndexes)
: m_shapes(shapes)
, m_newIndexes(newIndexes)
{
Q_ASSERT(m_shapes.count() == m_newIndexes.count());
foreach(KoShape *shape, shapes)
m_previousIndexes.append(shape->zIndex());
}
void KoShapeReorderCommand::execute() {
for(int i=0; i < m_shapes.count(); i++) {
m_shapes.at(i)->repaint();
m_shapes.at(i)->setZIndex( m_newIndexes.at(i) );
m_shapes.at(i)->repaint();
}
}
void KoShapeReorderCommand::unexecute() {
for(int i=0; i < m_shapes.count(); i++) {
m_shapes.at(i)->repaint();
m_shapes.at(i)->setZIndex( m_previousIndexes.at(i) );
m_shapes.at(i)->repaint();
}
}
QString KoShapeReorderCommand::name () const {
return i18n( "Reorder shapes" );
}
// static
KoShapeReorderCommand *KoShapeReorderCommand::createCommand(const KoSelectionSet &shapes, KoShapeManager *manager, MoveShapeType move) {
QList<int> newIndexes;
QList<KoShape*> changedShapes;
foreach(KoShape *shape, shapes) {
// for each shape create a 'stack' and then move the shape up/down
// since two indexes can not collide we may need to change the zIndex of a number
// of other shapes in the stack as well.
QList<KoShape*> sortedShapes( manager->shapesAt(shape->boundingRect()) );
qSort(sortedShapes.begin(), sortedShapes.end(), KoShape::compareShapeZIndex);
if(move == BringToFront) {
KoShape *top = *(--sortedShapes.end());
if(shape != top) {
changedShapes.append(shape);
newIndexes.append(top->zIndex()+1);
}
}
else if(move == SendToBack) {
KoShape *bottom = (*sortedShapes.begin());
if(shape != bottom) {
changedShapes.append(shape);
newIndexes.append(bottom->zIndex()-1);
}
}
else {
QList<KoShape*>::Iterator iter = sortedShapes.begin();
while((*iter) != shape)
iter++;
if(move == RaiseShape) {
if(++iter == sortedShapes.end()) continue; // already at top
int newIndex = (*iter)->zIndex()+1;
changedShapes.append(shape);
newIndexes.append(newIndex);
++iter; // skip the one we want to get above.
while(iter != sortedShapes.end() && newIndex <= (*iter)->zIndex()) {
changedShapes.append(*iter);
newIndexes.append(++newIndex);
iter++;
}
}
else if(move == LowerShape) {
if(--iter == sortedShapes.begin()) continue; // already at bottom
int newIndex = (*iter)->zIndex()-1;
changedShapes.append(shape);
newIndexes.append(newIndex);
--iter; // skip the one we want to get below
while(iter != sortedShapes.begin() && newIndex >= (*iter)->zIndex()) {
changedShapes.append(*iter);
newIndexes.append(--newIndex);
iter--;
}
}
}
}
Q_ASSERT(changedShapes.count() == newIndexes.count());
return new KoShapeReorderCommand(changedShapes, newIndexes);
}
/* This file is part of the KDE project
* Copyright (C) 2006 Thomas Zander <zander@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KOSHAPEREORDEROMMAND_H
#define KOSHAPEREORDEROMMAND_H
#include "KoSelection.h"
#include <koffice_export.h>
#include <kcommand.h>
#include <QList>
class KoShape;
class KoShapeManager;
/// This command allows you to change the zIndex of a number of shapes.
class FLAKE_EXPORT KoShapeReorderCommand : public KCommand {
public:
/**
* Constructor.
* @param shapes the set of objects that are moved.
* @param newIndexes the new indexes for the shapes.
* this list naturally must have the same amount of items as the shapes set.
*/
KoShapeReorderCommand(const QList<KoShape*> &shapes, QList<int> &newIndexes);
enum MoveShapeType {
RaiseShape,
LowerShape,
BringToFront,
SendToBack
};
static KoShapeReorderCommand *createCommand(const KoSelectionSet &shapes, KoShapeManager *manager, MoveShapeType move);
/// execute the command
void execute ();
/// revert the actions done in execute
void unexecute ();
/// return the name of this command
QString name () const;
private:
QList<KoShape*> m_shapes;
QList<int> m_previousIndexes, m_newIndexes;
};
#endif
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