Commit ed4fd8e4 authored by Thomas Zander's avatar Thomas Zander

Import Flake into koffice

I'm hoping I can find someone else to create cmake stuff :)

svn path=/trunk/koffice/; revision=544705
parent 6d22cf24
/* This file is part of the KDE project
Copyright (C) 2006 Boudewijn Rempt <boud@valdyas.org>
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 KOCANVASBASE_H
#define KOCANVASBASE_H
#include <QPointF>
#include <QPoint>
#include <QRectF>
#include <QRect>
class KoSelection;
class KCommand;
class KoShapeManager;
class KoTool;
class KoViewConverter;
/**
* KoCanvasBase is the interface actual application canvas classes
* should implement. Flake tools know about the canvas, so they can
* do things like scroll, redraw, set a cursor etc.
*/
class KoCanvasBase {
public:
KoCanvasBase() {};
virtual ~KoCanvasBase() {};
public:
/**
* retrieve the grid size setting.
* The grid spacing will be provided in pt.
* @param horizontal a pointer to a double that will be filled with the horizontal grid-spacing
* @param vertical a pointer to a double that will be filled with the vertical grid-spacing
*/
virtual void gridSize(double *horizontal, double *vertical) const = 0;
/**
* return if snap to grid is enabled.
* @return if snap to grid is enabled.
*/
virtual bool snapToGrid() const = 0;
/**
* Adds a command to the history. Call this for each @p command you create.
* Unless you set @p execute to false, this will also execute the command.
* This means, most of the application's code will look like
* MyCommand * cmd = new MyCommand( parameters );
* canvas.addCommand( cmd );
*
* Note that the command history takes ownership of the command, it will delete
* it when the undo limit is reached, or when deleting the command history itself.
* @param command the command to add
* @param execute if true, the commands execute method will be called
*/
virtual void addCommand(KCommand *command, bool execute = true) = 0;
/**
* return the current shapeManager
* @return the current shapeManager
*/
virtual KoShapeManager *shapeManager() const = 0;
/**
* Tell the canvas repaint the specified rectangle. The coordinates
* are document coordinates, not view coordinates.
*/
virtual void updateCanvas(const QRectF& rc) = 0;
/**
* Return the curently active tool, or 0 if non active.
* @return the curently active tool, or 0 if non active.
*/
virtual KoTool* activeTool() = 0;
/**
* Return the viewConverter for this view.
* @return the viewConverter for this view.
*/
virtual KoViewConverter *viewConverter() = 0;
#if 0
/* The next list of methods are naming taken from Krita, which means they have allready been
toughened by time. So, if you ever need a method in this interface; please uncomment the
respective one here for good naming conventions. It will probably save you time in
implementing some of the methods in the different KOffice apps as well ;)
*/
virtual KoSelection * currentSelection() const 0;
/**
* @return the value of the horizontal scrollbar.
*/
virtual qint32 horizontalScrollbarValue() const 0;
/**
* @return the value of the vertical scrollbar
*/
virtual qint32 verticalScrollbarValue() const 0;
/**
* Sets the horizontal and vertical scrollbars to the specified values
*
* @param x the value the horizontal scrollbar is set to
* @param y the value the vertical scrollbar is set to
*/
virtual void scrollTo(qint32 x, qint32 y) 0;
/**
* Tell all of the canvas to repaint itself.
*/
virtual void updateCanvas() 0;
/**
* Tell the canvas to repaint the rectangle defined by x, y, w and h.
* The coordinates are document coordinates.
*/
virtual void updateCanvas(qint32 x, qint32 y, qint32 w, qint32 h) 0;
/**
* Increase the zoomlevel one step
*/
virtual void zoomIn() 0;
/**
Increase the zoomlevel one step and make sure that x,y is the center
point of the view.
@param x The x coordinate of the visible point in document
coordinates
@param y the y coordinate of the visible point in document
coordinates
*/
virtual void zoomIn(qint32 x, qint32 y) 0;
/**
* Decrease the zoomlevel one step
*/
virtual void zoomOut() 0;
/**
* Decrease the zoomlevel one step and make sure that x,y is the center point of the view.
*
* @param x the x coordinate of the visible point in document coordinates
* @param y the y coordinate of the visible point in document coordinates
*/
virtual void zoomOut(qint32 x, qint32 y) 0;
/**
* To centre the view on the given point with the given zoom factor.
*
* @param x the x coordinate of the center point in document coordinates
* @param y the y coordinate of the center point in document coordinates
* @param zf the zoomfactor
*/
virtual void zoomAroundPoint(double x, double y, double zf) 0;
/**
* Make the rect defined by x, y, w and h visible, zooming in or
* out as necessary. The view will be centered around the center point
* of the specified rect.
*/
virtual void zoomTo(qint32 x, qint32 y, qint32 w, qint32 h) 0;
/**
* Make the rect defined by x, y, w and h visible, zooming in or
* out as necessary. The view will be centered around the center point
* of the specified rect.
*/
virtual void zoomTo(const QRect& r) 0;
/**
* Make the rect defined by x, y, w and h visible, zooming in or
* out as necessary. The view will be centered around the center point
* of the specified rect.
*/
virtual void zoomTo(const QRectF& r) 0;
/**
* Conversion functions from view coordinates to document coordinates
*
* You can get the rectangle of the document that's visible using the
* viewToWindow() functions (KoCanvasBase). E.g.
* viewToWindow(QRect(0, 0, canvasWidth, canvasHeight)).
*
* Here, the view is the canvas widget in the view widget, and the window
* is the window on the document.
*/
virtual QPoint viewToWindow(const QPoint& pt) 0;
virtual QPointF viewToWindow(const QPointF& pt) 0;
virtual QRect viewToWindow(const QRect& rc) 0;
virtual QRectF viewToWindow(const QRectF& rc) 0;
virtual void viewToWindow(qint32 *x, qint32 *y) 0;
/**
* Conversion functions from document coordinates to view coordinates
*/
virtual QPoint windowToView(const QPoint& pt) 0;
virtual QPointF windowToView(const QPointF& pt) 0;
virtual QRect windowToView(const QRect& rc) 0;
virtual QRectF windowToView(const QRectF& rc) 0;
virtual void windowToView(qint32 *x, qint32 *y) 0;
/**
* Set the cursor shown when the pointer is over the canvas widget to
* the specified cursor.
*
* @param cursor the new cursor
* @return the old cursor
*/
virtual QCursor setCanvasCursor(const QCursor & cursor) 0;
/**
* Set the active input device to the specified input device, This
* could be a mouse, a stylus, an eraser or any other pointing input
* device.
*
* @param inputDevice the new input device
*/
virtual void setInputDevice(KoInputDevice inputDevice) 0;
/**
* @return the current input device, such as a mouse or a stylus
*/
virtual KoInputDevice currentInputDevice() const 0;
#endif
};
#endif
#include "KoCommand.h"
#include "KoShape.h"
#include "KoShapeGroup.h"
#include "KoShapeContainer.h"
#include "KoShapeControllerInterface.h"
#include <QString>
KoShapeMoveCommand::KoShapeMoveCommand(const KoSelectionSet &shapes, QList<QPointF> &previousPositions, QList<QPointF> &newPositions)
: m_previousPositions(previousPositions)
, m_newPositions(newPositions)
{
m_shapes = shapes.toList();
Q_ASSERT(m_shapes.count() == m_previousPositions.count());
Q_ASSERT(m_shapes.count() == m_newPositions.count());
}
void KoShapeMoveCommand::execute() {
for(int i=0; i < m_shapes.count(); i++) {
m_shapes.at(i)->repaint();
m_shapes.at(i)->setPosition( m_newPositions.at(i) );
m_shapes.at(i)->repaint();
}
}
void KoShapeMoveCommand::unexecute() {
for(int i=0; i < m_shapes.count(); i++) {
m_shapes.at(i)->repaint();
m_shapes.at(i)->setPosition( m_previousPositions.at(i) );
m_shapes.at(i)->repaint();
}
}
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();
Q_ASSERT(m_shapes.count() == m_previousAngles.count());
Q_ASSERT(m_shapes.count() == m_newAngles.count());
}
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";
}
KoShapeSizeCommand::KoShapeSizeCommand(const KoSelectionSet &shapes, QList<QSizeF> &previousSizes, QList<QSizeF> &newSizes)
: m_previousSizes(previousSizes)
, m_newSizes(newSizes)
{
m_shapes = shapes.toList();
Q_ASSERT(m_shapes.count() == m_previousSizes.count());
Q_ASSERT(m_shapes.count() == m_newSizes.count());
}
void KoShapeSizeCommand::execute () {
int i=0;
foreach(KoShape *shape, m_shapes) {
shape->repaint();
shape->resize(m_newSizes[i++]);
shape->repaint();
}
}
void KoShapeSizeCommand::unexecute () {
int i=0;
foreach(KoShape *shape, m_shapes) {
shape->repaint();
shape->resize(m_previousSizes[i++]);
shape->repaint();
}
}
QString KoShapeSizeCommand::name () const {
}
KoGroupShapesCommand::KoGroupShapesCommand(KoShapeContainer *container, QList<KoShape *> shapes, QList<bool> clipped)
: m_shapes(shapes)
, m_clipped(clipped)
, m_container(container)
{
Q_ASSERT(m_clipped.count() == m_shapes.count());
}
KoGroupShapesCommand::KoGroupShapesCommand(KoShapeGroup *container, QList<KoShape *> shapes)
: m_shapes(shapes)
, m_container(container)
{
for(int i=m_shapes.count(); i > 0; i--)
m_clipped.append(false);
}
KoGroupShapesCommand::KoGroupShapesCommand() {
}
void KoGroupShapesCommand::execute () {
foreach(KoShape *shape, m_shapes) {
m_container->addChild(shape);
shape->setPosition(shape->position() - m_container->position());
}
}
void KoGroupShapesCommand::unexecute () {
foreach(KoShape *shape, m_shapes) {
m_container->removeChild(shape);
shape->setPosition(shape->position() + m_container->position());
}
}
QString KoGroupShapesCommand::name () const {
return "Group Shapes";
}
KoUngroupShapesCommand::KoUngroupShapesCommand(KoShapeContainer *container, QList<KoShape *> shapes)
: KoGroupShapesCommand()
{
m_shapes = shapes;
m_container = container;
foreach(KoShape *shape, m_shapes) {
m_clipped.append( m_container->childClipped(shape) );
}
}
void KoUngroupShapesCommand::execute () {
KoGroupShapesCommand::unexecute();
}
void KoUngroupShapesCommand::unexecute () {
KoGroupShapesCommand::execute();
}
QString KoUngroupShapesCommand::name () const {
return "Ungroup shapes";
}
KoShapeCreateCommand::KoShapeCreateCommand( KoShapeControllerInterface *controller, KoShape *shape )
: m_controller( controller )
, m_shape( shape )
, m_deleteShape( true )
{
}
KoShapeCreateCommand::~KoShapeCreateCommand() {
if( m_shape && m_deleteShape )
delete m_shape;
}
void KoShapeCreateCommand::execute () {
if( ! m_shape || ! m_controller )
return;
m_controller->addShape( m_shape );
m_deleteShape = false;
}
void KoShapeCreateCommand::unexecute () {
if( ! m_shape || ! m_controller )
return;
m_controller->removeShape( m_shape );
m_deleteShape = true;
}
QString KoShapeCreateCommand::name () const {
return "Create shape";
}
/* 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 KOCommand_h
#define KOCommand_h
#include <kcommand.h>
#include <KoSelection.h>
#include <QList>
#include <QPointF>
class KoShape;
class KoShapeGroup;
class KoShapeContainer;
class KoShapeControllerInterface;
class QString;
/// The undo / redo command for shape moving.
class KoShapeMoveCommand : public KCommand {
public:
/**
* Constructor.
* @param shapes the set of objects that are moved.
* @param previousPositions the known set of previous positions for each of the objects.
* this list naturally must have the same amount of items as the shapes set.
* @param newPositions the new positions for the shapes.
* this list naturally must have the same amount of items as the shapes set.
*/
KoShapeMoveCommand(const KoSelectionSet &shapes, QList<QPointF> &previousPositions, QList<QPointF> &newPositions);
void execute ();
void unexecute ();
QString name () const;
private:
QList<KoShape*> m_shapes;
QList<QPointF> m_previousPositions, m_newPositions;
};
/// The undo / redo command for shape rotating.
class KoShapeRotateCommand : public KCommand {
public:
/**
* Comand to rotate a selection of shapes. Note that it just alters the rotated
* property of those shapes, and nothing more.
* @param shapes all the shapes that should be rotated
* @param previousAngles a list with the same amount of items as shapes with the
* old rotation angles
* @param newAngles a list with the same amount of items as shapes with the new angles.
*/
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;
};
/// The undo / redo command for shape sizing.
class KoShapeSizeCommand : public KCommand {
public:
KoShapeSizeCommand(const KoSelectionSet &shapes, QList<QSizeF> &previousSizes, QList<QSizeF> &newSizes);
void execute ();
void unexecute ();
QString name () const;
private:
QList<KoShape*> m_shapes;
QList<QSizeF> m_previousSizes, m_newSizes;
};
/// The undo / redo command for grouping shapes
class KoGroupShapesCommand : public KCommand {
public:
/**
* Command to group a set of shapes into a predefined container.
* @param container the container to group the shapes under.
* @param shapes a list of all the shapes that should be grouped.
* @param clipped a list of the same length as the shapes list with one bool for each shape.
* See KoShapeContainer::childClipped()
*/
KoGroupShapesCommand(KoShapeContainer *container, QList<KoShape *> shapes, QList<bool> clipped);
/**
* Command to group a set of shapes into a predefined container.
* Convenience constructor since KoShapeGroup does not allow clipping.
* @param container the group to group the shapes under.
* @param shapes a list of all the shapes that should be grouped.
*/
KoGroupShapesCommand(KoShapeGroup *container, QList<KoShape *> shapes);
virtual ~KoGroupShapesCommand() { };
virtual void execute ();
virtual void unexecute ();
virtual QString name () const;
protected:
KoGroupShapesCommand(); ///< protected constructor for child classes
QList<KoShape*> m_shapes; ///<list of shapes to be grouped
QList<bool> m_clipped; ///< list of booleas to specify the shape of the same index to eb clipped
KoShapeContainer *m_container; ///< the container where the grouping should be for.
};
/// The undo / redo command for ungrouping shapes
class KoUngroupShapesCommand : public KoGroupShapesCommand {
public:
/**
* Command to ungroup a set of shapes from one parent container.
* @param container the group to ungroup the shapes from.
* @param shapes a list of all the shapes that should be ungrouped.
*/
KoUngroupShapesCommand(KoShapeContainer *container, QList<KoShape *> shapes);
void execute ();
void unexecute ();
QString name () const;
};
/// The undo / redo command for creating shapes
class KoShapeCreateCommand : public KCommand {
public:
KoShapeCreateCommand( KoShapeControllerInterface *controller, KoShape *shape );
virtual ~KoShapeCreateCommand();
void execute ();
void unexecute ();
virtual QString name () const;
protected:
KoShapeControllerInterface *m_controller;
KoShape *m_shape;
bool m_deleteShape;
};
#endif
/* 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.
*/
/**
* \mainpage
* The Flake library is a low level library for all kinds of graphical content
* to be placed on any KOffice canvas. This includes a line to text-areas or
* even movies. Just as important, this library will include tools to manipulate
* the graphical content. At least at the level of Flake objects. This goes from
* moving/rotating the object to a basis for complex brushes for a paint program.
* <p>Use KoShape as a base object for any application-specific graphical
* content, and extend KoShapeContainer for objects that can contain others.
* <p>KoShape is the base class for all flake objects. Flake objects extend it
* to allow themselves to be manipulated by the KoTool s. The content of such an
* object is independent and based on the model of the data this object represents.
*/
/**
* Flake reference
*/
class KoFlake {
public:
/// the selection type for KoSelection::selectedObjects()
enum SelectionType {
FullSelection,
StrippedSelection
};
/// Enum determining which handle is meant, used in KoInteractionTool
enum SelectionHandle {
TopMiddleHandle,
TopRightHandle,
RightMiddleHandle,
BottomRightHandle,
BottomMiddleHandle,
BottomLeftHandle,
LeftMiddleHandle,
TopLeftHandle,
NoHandle
};
private:
KoFlake();
};
/* This file is part of the KDE project
Copyright (C) 2006 Thorsten Zachmann <zachmann@kde.org>
Copyright (C) 2006 Casper Boemann Rasmussen <cbr@boemann.dk>
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 KOGFXEVENT_H
#define KOGFXEVENT_H
#include <QMouseEvent>
/**
* The event used in Flake to have both the original (canvas based) position as
* well as the normalized position.
*/
class KoGfxEvent
{
public:
/**
* Constructor.
* @param ev the mouse event that is the base of this event.
* @param pnt the zoomed pointed in the normal coordiante system.
*/
KoGfxEvent( QMouseEvent *ev, const QPointF &pnt )
: point( pnt )
, m_event( ev )
{}
/**
* For classes that are handed this event, you can choose to accept (default) this event.
* Acceptance signifies that you have handled this event and found it usefull, the effect
* of that will be that the event will not be handled to other event handlers.
*/
void accept() { m_event->accept(); }
/**
* For classes that are handed this event, you can choose to ignore this event.
* Ignoring this event means you have not handled it and want to allow other event
* handlers to try to handle it.
*/
void ignore() { m_event->ignore(); }
/**
* Return the modifiers.
*/
Qt::KeyboardModifiers modifiers () const { return m_event->modifiers(); }
/// return if the event has been accepted.
bool isAccepted () const { return m_event->isAccepted(); }
/// return if this event was spontaneous (see QMouseEvent::spontaneous())
bool spontaneous () const { return m_event->spontaneous(); }
/// return button pressed (see QMouseEvent::button());
Qt::MouseButton button () const { return m_event->button(); }
/// return buttons pressed (see QMouseEvent::buttons());
Qt::MouseButtons buttons () const { return m_event->buttons(); }
/// The point in normal space.
const QPointF &point;
private:
QMouseEvent *const m_event;
};
#endif /* KOGFXEVENT_H */
/* 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