Warning, file /office/calligra/libs/flake/KoCanvasBase.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002 
0003    Copyright (C) 2006, 2010 Boudewijn Rempt <boud@valdyas.org>
0004    Copyright (C) 2006, 2010 Thomas Zander <zander@kde.org>
0005    Copyright (C) 2006 Thorsten Zachmann <zachmann@kde.org>
0006 
0007    This library is free software; you can redistribute it and/or
0008    modify it under the terms of the GNU Library General Public
0009    License as published by the Free Software Foundation; either
0010    version 2 of the License, or (at your option) any later version.
0011 
0012    This library is distributed in the hope that it will be useful,
0013    but WITHOUT ANY WARRANTY; without even the implied warranty of
0014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015    Library General Public License for more details.
0016 
0017    You should have received a copy of the GNU Library General Public License
0018    along with this library; see the file COPYING.LIB.  If not, write to
0019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020    Boston, MA 02110-1301, USA.
0021 */
0022 
0023 #ifndef KOCANVASBASE_H
0024 #define KOCANVASBASE_H
0025 
0026 #include <QPoint>
0027 
0028 #include "flake_export.h"
0029 
0030 class QGraphicsObject;
0031 class KUndo2Command;
0032 
0033 class KoUnit;
0034 class KoCanvasResourceManager;
0035 class KoShapeManager;
0036 class KoToolProxy;
0037 class KoViewConverter;
0038 class KoShapeController;
0039 class KoShapeBasedDocumentBase;
0040 class KoCanvasController;
0041 class KoShape;
0042 class KoSnapGuide;
0043 class KoGuidesData;
0044 
0045 class QWidget;
0046 class QCursor;
0047 class QObject;
0048 class QPointF;
0049 class QRectF;
0050 
0051 /**
0052  * KoCanvasBase is the interface actual application canvas classes
0053  * should implement. Flake tools know about the canvas, so they can
0054  * do things like scroll, redraw, set a cursor etc.
0055  */
0056 class FLAKE_EXPORT KoCanvasBase
0057 {
0058 
0059 public:
0060 
0061     /**
0062      * The constructor.
0063      * @param shapeBasedDocument the implementation of the shapeController that the
0064      *   application provides to allow shapes to be added in multiple views.
0065      */
0066     explicit KoCanvasBase(KoShapeBasedDocumentBase *shapeBasedDocument, KoCanvasResourceManager *sharedResourceManager = 0);
0067     virtual ~KoCanvasBase();
0068 
0069 public:
0070 
0071     /**
0072      * retrieve the grid size setting.
0073      * The grid spacing will be provided in pt.
0074      * @param horizontal a pointer to a qreal that will be filled with the horizontal grid-spacing
0075      * @param vertical a pointer to a qreal that will be filled with the vertical grid-spacing
0076      */
0077     virtual void gridSize(qreal *horizontal, qreal *vertical) const = 0;
0078 
0079     /**
0080      * return if snap to grid is enabled.
0081      * @return if snap to grid is enabled.
0082      */
0083     virtual bool snapToGrid() const = 0;
0084 
0085 
0086     /**
0087      * set the specified cursor on this canvas
0088      *
0089      * @param cursor the new cursor
0090      * @return the old cursor
0091      */
0092     virtual void setCursor(const QCursor &cursor) = 0;
0093 
0094     /**
0095      * Adds a command to the history. Call this for each @p command you create.
0096      * This will also execute the command.
0097      * This means, most of the application's code will look like
0098      *    MyCommand * cmd = new MyCommand( parameters );
0099      *    canvas.addCommand( cmd );
0100      *
0101      * Note that the command history takes ownership of the command, it will delete
0102      * it when the undo limit is reached, or when deleting the command history itself.
0103      * @param command the command to add
0104      */
0105     virtual void addCommand(KUndo2Command *command) = 0;
0106 
0107     /**
0108      * return the current shapeManager
0109      * @return the current shapeManager
0110      */
0111     virtual KoShapeManager *shapeManager() const = 0;
0112 
0113     /**
0114      * Tell the canvas to repaint the specified rectangle. The coordinates
0115      * are document coordinates, not view coordinates.
0116      */
0117     virtual void updateCanvas(const QRectF &rc) = 0;
0118 
0119     /**
0120      * Return the proxy to the active tool (determining which tool
0121      * is really, really active is hard when tablets are involved,
0122      * so leave that to others.
0123      */
0124     virtual KoToolProxy *toolProxy() const = 0;
0125 
0126     /**
0127      * Return the viewConverter for this view.
0128      * @return the viewConverter for this view.
0129      */
0130     virtual KoViewConverter *viewConverter() const = 0;
0131 
0132     /**
0133      * Convert a coordinate in pixels to pt.
0134      * @param viewPoint the point in the coordinate system of the widget, or window.
0135      */
0136     virtual QPointF viewToDocument(const QPointF &viewPoint) const;
0137 
0138     /**
0139      * Return the widget that will be added to the scrollArea.
0140      */
0141     virtual QWidget *canvasWidget() = 0;
0142 
0143     /**
0144      * Return the widget that will be added to the scrollArea.
0145      */
0146     virtual const QWidget *canvasWidget() const = 0;
0147 
0148     /**
0149      * Return the widget that will be added to the scrollArea.
0150      */
0151     virtual QGraphicsObject *canvasItem() { return 0; }
0152 
0153     /**
0154      * Return the widget that will be added to the scrollArea.
0155      */
0156     virtual const QGraphicsObject *canvasItem() const{ return 0; }
0157 
0158     /**
0159      * Return the unit of the current document for initialization of the widgets created
0160      * by the flake framework.
0161      * @see KoDocument::unit()
0162      */
0163     virtual KoUnit unit() const = 0;
0164 
0165     /**
0166      * Called when the user tries to move the argument shape to allow the application to limit the
0167      * users movement to stay within the document bounds.
0168      * An implementation can alter the parameter move to make sure that if the distance moved
0169      * is applied to the shape it will not become unreachable for the user.
0170      * The default implementation does not restrict movement.
0171      * @param shape the shape that will be moved soon.
0172      * @param move the distance the caller intends to move the shape.
0173      */
0174     virtual void clipToDocument(const KoShape *shape, QPointF &move) const;
0175 
0176     /**
0177      * Return the position of the document origin inside the canvas widget, in pixels.
0178      * By default the origin of the canvas widget and the position of the
0179      * document origin are coincident, thus an empty point is returned.
0180      */
0181     virtual QPoint documentOrigin() const {
0182         return QPoint(0, 0);
0183     }
0184 
0185     /**
0186      * This method should somehow call QWidget::updateMicroFocus() on the canvas widget.
0187      */
0188     virtual void updateInputMethodInfo() = 0;
0189 
0190     /**
0191      * disconnect the given QObject completely and utterly from any and all
0192      * connections it has to any QObject owned by the canvas. Do this in
0193      * the setCanvas of every KoCanvasObserver.
0194      */
0195     virtual void disconnectCanvasObserver(QObject *object);
0196 
0197     /**
0198      * Return a pointer to the resource manager associated with this
0199      * canvas. The resource manager contains per-canvas settings such
0200      * as current foreground and background color.
0201      * If instead of per-canvas resources you need per-document resources
0202      * you can by going via the shapeController instead;
0203      * @code
0204      *   canvasBase->shapeController()->resourceManager();
0205      * @endcode
0206      * @see KoShapeController::resourceManager()
0207      */
0208     KoCanvasResourceManager *resourceManager() const;
0209 
0210     /**
0211      * Return the shape controller for this canvas.
0212      * A shape controller is used to create or delete shapes and show the relevant dialogs to the user.
0213      */
0214     KoShapeController *shapeController() const;
0215 
0216     /**
0217      * Return the canvas controller for this canvas.
0218      */
0219     KoCanvasController *canvasController() const;
0220 
0221     /**
0222      * @brief Scrolls the content of the canvas so that the given rect is visible.
0223      *
0224      * The rect is to be specified in document coordinates.
0225      *
0226      * @param rect the rectangle to make visible
0227      */
0228     virtual void ensureVisible(const QRectF &rect);
0229 
0230     /**
0231      * Returns the snap guide of the canvas
0232      */
0233     KoSnapGuide *snapGuide() const;
0234 
0235     /**
0236      * This factory method creates a new widget for the user to change
0237      * the snapping guide policies object from snapGuide().
0238      */
0239     QWidget *createSnapGuideConfigWidget() const;
0240 
0241     /**
0242      * Returns the guides data.
0243      *
0244      * Applications that want to have guides should reimplement this
0245      * function and return the KOGuideData object.
0246      * The default implementation returns 0.
0247      *
0248      * @return pointer to the guide data or zero if there is none
0249      */
0250     virtual KoGuidesData *guidesData();
0251 
0252     /// called by KoCanvasController to set the controller that handles this canvas.
0253     void setCanvasController(KoCanvasController *controller);
0254 
0255 private:
0256     // we need a KoShapeBasedDocumentBase so that it can work
0257     KoCanvasBase();
0258 
0259     class Private;
0260     Private * const d;
0261 };
0262 
0263 #endif // KOCANVASBASE_H