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

0001 /*
0002    Copyright (c) 2006 Boudewijn Rempt (boud@valdyas.org)
0003    Copyright (C) 2007, 2009, 2010 Thomas Zander <zander@kde.org>
0004    Copyright (c) 2008 Carlos Licea <carlos.licea@kdemail.net>
0005 
0006    This library is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU Library General Public
0008    License as published by the Free Software Foundation; either
0009    version 2 of the License, or (at your option) any later version.
0010 
0011    This library is distributed in the hope that it will be useful,
0012    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014    Library General Public License for more details.
0015 
0016    You should have received a copy of the GNU Library General Public License
0017    along with this library; see the file COPYING.LIB.  If not, write to
0018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019    Boston, MA 02110-1301, USA.
0020  */
0021 #ifndef KO_DOCUMENTRESOURCEMANAGER_H
0022 #define KO_DOCUMENTRESOURCEMANAGER_H
0023 
0024 #include <QObject>
0025 
0026 #include "flake_export.h"
0027 
0028 class KoShape;
0029 class KUndo2Stack;
0030 class KoImageCollection;
0031 class KoDocumentBase;
0032 class KoShapeController;
0033 class KoColor;
0034 class KoUnit;
0035 
0036 class QVariant;
0037 class QSizeF;
0038 
0039 /**
0040  * The KoResourceManager contains a set of per-canvas <i>or</i> per-document
0041  * properties, like current foreground color, current background
0042  * color and more. All tools belonging to the current canvas are
0043  * notified when a Resource changes (is set).
0044  *
0045  * The properties come from the KoDocumentResourceManager::DocumentResource
0046  * See KoShapeController::resourceManager
0047  *
0048  * The manager can contain all sorts of variable types and there are accessors
0049  * for the most common ones.  All variables are always stored inside a QVariant
0050  * instance internally and you can always just use the resource() method to get
0051  * that directly.
0052  * The way to store arbitairy data objects that are stored as pointers you can use
0053  * the following code snippets;
0054  * @code
0055  *  QVariant variant;
0056  *  variant.setValue<void*>(textShapeData->document());
0057  *  resourceManager->setResource(KoText::CurrentTextDocument, variant);
0058  *  // and get it out again.
0059  *  QVariant var = resourceManager->resource(KoText::CurrentTextDocument);
0060  *  document = static_cast<QTextDocument*>(var.value<void*>());
0061  * @endcode
0062  */
0063 class FLAKE_EXPORT KoDocumentResourceManager : public QObject
0064 {
0065     Q_OBJECT
0066 
0067 public:
0068 
0069     /**
0070      * This enum holds identifiers to the resources that can be stored in here.
0071      */
0072 enum DocumentResource {
0073     UndoStack,              ///< The document-wide undo stack (KUndo2Stack)
0074     ImageCollection,        ///< The KoImageCollection for the document
0075     OdfDocument,            ///< The document this canvas shows (KoDocumentBase)
0076     PasteOffset,            ///< Application wide paste offset
0077     PasteAtCursor,          ///< Application wide paste at cursor setting
0078     HandleRadius,           ///< The handle radius used for drawing handles of any kind
0079     GrabSensitivity,        ///< The grab sensitivity used for grabbing handles of any kind
0080     MarkerCollection,       ///< The collection holding all markers
0081     ShapeController,       ///< The KoShapeController for the document
0082 
0083     KarbonStart = 1000,      ///< Base number for Karbon specific values.
0084     KexiStart = 2000,        ///< Base number for Kexi specific values.
0085     FlowStart = 3000,        ///< Base number for Flow specific values.
0086     PlanStart = 4000,        ///< Base number for Plan specific values.
0087     StageStart = 5000,       ///< Base number for Stage specific values.
0088     SheetsStart = 6000,      ///< Base number for Sheets specific values.
0089     WordsStart = 7000,       ///< Base number for Words specific values.
0090     KoPageAppStart = 8000,   ///< Base number for KoPageApp specific values.
0091     KoTextStart = 9000      ///< Base number for KoText specific values.
0092 };
0093 
0094 
0095     /**
0096      * Constructor.
0097      * @param parent the parent QObject, used for memory management.
0098      */
0099     explicit KoDocumentResourceManager(QObject *parent = 0);
0100     ~KoDocumentResourceManager() override;
0101 
0102     /**
0103      * Set a resource of any type.
0104      * @param key the integer key
0105      * @param value the new value for the key.
0106      * @see  KoDocumentResourceManager::DocumentResource
0107      */
0108     void setResource(int key, const QVariant &value);
0109 
0110     /**
0111      * Set a resource of type KoColor.
0112      * @param key the integer key
0113      * @param color the new value for the key.
0114      * @see  KoDocumentResourceManager::DocumentResource
0115      */
0116     void setResource(int key, const KoColor &color);
0117 
0118     /**
0119      * Set a resource of type KoShape*.
0120      * @param key the integer key
0121      * @param id the new value for the key.
0122      * @see  KoDocumentResourceManager::DocumentResource
0123      */
0124     void setResource(int key, KoShape *shape);
0125 
0126     /**
0127      * Set a resource of type KoUnit
0128      * @param key the integer key
0129      * @param id the new value for the key.
0130      * @see  KoDocumentResourceManager::DocumentResource
0131      */
0132     void setResource(int key, const KoUnit &unit);
0133 
0134     /**
0135      * Returns a qvariant containing the specified resource or a standard one if the
0136      * specified resource does not exist.
0137      * @param key the key
0138      * @see  KoDocumentResourceManager::DocumentResource
0139      */
0140     QVariant resource(int key) const;
0141 
0142     /**
0143      * Return the resource determined by param key as a boolean.
0144      * @param key the indentifying key for the resource
0145      * @see  KoDocumentResourceManager::DocumentResource
0146      */
0147     bool boolResource(int key) const;
0148 
0149     /**
0150      * Return the resource determined by param key as an integer.
0151      * @param key the indentifying key for the resource
0152      * @see  KoDocumentResourceManager::DocumentResource
0153      */
0154     int intResource(int key) const;
0155 
0156     /**
0157      * Return the resource determined by param key as a KoColor.
0158      * @param key the indentifying key for the resource
0159      * @see  KoDocumentResourceManager::DocumentResource
0160      */
0161     KoColor koColorResource(int key) const;
0162 
0163     /**
0164      * Return the resource determined by param key as a pointer to a KoShape.
0165      * @param key the indentifying key for the resource
0166      * @see  KoDocumentResourceManager::DocumentResource
0167      */
0168     KoShape *koShapeResource(int key) const;
0169 
0170     /**
0171      * Return the resource determined by param key as a QString .
0172      * @param key the indentifying key for the resource
0173      * @see  KoDocumentResourceManager::DocumentResource
0174      */
0175     QString stringResource(int key) const;
0176 
0177     /**
0178      * Return the resource determined by param key as a QSizeF.
0179      * @param key the indentifying key for the resource
0180      * @see  KoDocumentResourceManager::DocumentResource
0181      */
0182     QSizeF sizeResource(int key) const;
0183 
0184     /**
0185      * Return the resource determined by param key as a KoUnit.
0186      * @param key the indentifying key for the resource
0187      * @see  KoDocumentResourceManager::DocumentResource
0188      */
0189     KoUnit unitResource(int key) const;
0190 
0191     /**
0192      * Returns true if there is a resource set with the requested key.
0193      * @param key the indentifying key for the resource
0194      * @see  KoDocumentResourceManager::DocumentResource
0195      */
0196     bool hasResource(int key) const;
0197 
0198     /**
0199      * Remove the resource with @p key from the provider.
0200      * @param key the key that will be used to remove the resource
0201      * There will be a signal emitted with a variable that will return true on QVariable::isNull();
0202      * @see  KoDocumentResourceManager::DocumentResource
0203      */
0204     void clearResource(int key);
0205 
0206         /**
0207      * Tools that provide a handle for controlling the content that the tool can edit can
0208      * use this property to alter the radius that a circular handle should have on screen.
0209      * @param handleSize the radius in pixels.
0210      */
0211     void setHandleRadius(int handleSize);
0212     /// Returns the actual handle radius
0213     int handleRadius() const;
0214 
0215     /**
0216      * Tools that are used to grab handles or similar with the mouse
0217      * should use this value to determine if the mouse is near enough
0218      * @param grabSensitivity the grab sensitivity in pixels
0219      */
0220     void setGrabSensitivity(int grabSensitivity);
0221     /// Returns the actual grab sensitivity
0222     int grabSensitivity() const;
0223 
0224     /**
0225      * Offset used for pasting shapes to a document.
0226      */
0227     void setPasteOffset(qreal pasteOffset);
0228     /// Returns the current paste offset
0229     qreal pasteOffset() const;
0230 
0231     /**
0232      * Enables/disables pasting shape at cursor position
0233      */
0234     void enablePasteAtCursor(bool enable);
0235     /// Returns current state of paste at cursor setting
0236     bool pasteAtCursor() const;
0237 
0238     KUndo2Stack *undoStack() const;
0239     void setUndoStack(KUndo2Stack *undoStack);
0240 
0241     KoImageCollection *imageCollection() const;
0242     void setImageCollection(KoImageCollection *ic);
0243 
0244     KoDocumentBase *odfDocument() const;
0245     void setOdfDocument(KoDocumentBase *currentDocument);
0246 
0247     KoShapeController *shapeController() const;
0248     void setShapeController(KoShapeController *shapeController);
0249 
0250 Q_SIGNALS:
0251     /**
0252      * This signal is emitted every time a resource is set that is either
0253      * new or different from the previous set value.
0254      * @param key the indentifying key for the resource
0255      * @param value the variants new value.
0256      * @see KoDocumentResourceManager::DocumentResource
0257      */
0258     void resourceChanged(int key, const QVariant &value);
0259 
0260 private:
0261     KoDocumentResourceManager(const KoDocumentResourceManager&);
0262     KoDocumentResourceManager& operator=(const KoDocumentResourceManager&);
0263 
0264     class Private;
0265     Private *const d;
0266 };
0267 
0268 #endif