Warning, file /office/calligra/libs/flake/KoDocumentResourceManager.cpp 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, 2010 Thomas Zander <zander@kde.org> 0004 Copyright (c) 2008 Carlos Licea <carlos.licea@kdemail.net> 0005 Copyright (c) 2011 Jan Hambrecht <jaham@gmx.net> 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 #include "KoDocumentResourceManager.h" 0023 0024 #include <QVariant> 0025 #include <kundo2stack.h> 0026 #include <FlakeDebug.h> 0027 0028 #include "KoShape.h" 0029 #include "KoShapeController.h" 0030 #include "KoResourceManager_p.h" 0031 0032 class Q_DECL_HIDDEN KoDocumentResourceManager::Private 0033 { 0034 public: 0035 KoResourceManager manager; 0036 }; 0037 0038 KoDocumentResourceManager::KoDocumentResourceManager(QObject *parent) 0039 : QObject(parent), 0040 d(new Private()) 0041 { 0042 } 0043 0044 KoDocumentResourceManager::~KoDocumentResourceManager() 0045 { 0046 delete d; 0047 } 0048 0049 void KoDocumentResourceManager::setResource(int key, const QVariant &value) 0050 { 0051 d->manager.setResource(key, value); 0052 emit resourceChanged(key, value); 0053 } 0054 0055 QVariant KoDocumentResourceManager::resource(int key) const 0056 { 0057 return d->manager.resource(key); 0058 } 0059 0060 void KoDocumentResourceManager::setResource(int key, const KoColor &color) 0061 { 0062 QVariant v; 0063 v.setValue(color); 0064 setResource(key, v); 0065 } 0066 0067 void KoDocumentResourceManager::setResource(int key, KoShape *shape) 0068 { 0069 QVariant v; 0070 v.setValue(shape); 0071 setResource(key, v); 0072 } 0073 0074 void KoDocumentResourceManager::setResource(int key, const KoUnit &unit) 0075 { 0076 QVariant v; 0077 v.setValue(unit); 0078 setResource(key, v); 0079 } 0080 0081 KoColor KoDocumentResourceManager::koColorResource(int key) const 0082 { 0083 return d->manager.koColorResource(key); 0084 } 0085 0086 0087 bool KoDocumentResourceManager::boolResource(int key) const 0088 { 0089 return d->manager.boolResource(key); 0090 } 0091 0092 int KoDocumentResourceManager::intResource(int key) const 0093 { 0094 return d->manager.intResource(key); 0095 } 0096 0097 QString KoDocumentResourceManager::stringResource(int key) const 0098 { 0099 return d->manager.stringResource(key); 0100 } 0101 0102 QSizeF KoDocumentResourceManager::sizeResource(int key) const 0103 { 0104 return d->manager.sizeResource(key); 0105 } 0106 0107 bool KoDocumentResourceManager::hasResource(int key) const 0108 { 0109 return d->manager.hasResource(key); 0110 } 0111 0112 void KoDocumentResourceManager::clearResource(int key) 0113 { 0114 d->manager.clearResource(key); 0115 QVariant empty; 0116 emit resourceChanged(key, empty); 0117 } 0118 0119 KUndo2Stack *KoDocumentResourceManager::undoStack() const 0120 { 0121 if (!hasResource(UndoStack)) 0122 return 0; 0123 return static_cast<KUndo2Stack*>(resource(UndoStack).value<void*>()); 0124 } 0125 0126 void KoDocumentResourceManager::setHandleRadius(int handleRadius) 0127 { 0128 // do not allow arbitrary small handles 0129 if (handleRadius < 3) 0130 handleRadius = 3; 0131 setResource(HandleRadius, QVariant(handleRadius)); 0132 } 0133 0134 int KoDocumentResourceManager::handleRadius() const 0135 { 0136 if (hasResource(HandleRadius)) 0137 return intResource(HandleRadius); 0138 return 3; // default value. 0139 } 0140 void KoDocumentResourceManager::setGrabSensitivity(int grabSensitivity) 0141 { 0142 // do not allow arbitrary small grab sensitivity 0143 if (grabSensitivity < 3) 0144 grabSensitivity = 3; 0145 setResource(GrabSensitivity, QVariant(grabSensitivity)); 0146 } 0147 0148 int KoDocumentResourceManager::grabSensitivity() const 0149 { 0150 if (hasResource(GrabSensitivity)) 0151 return intResource(GrabSensitivity); 0152 return 3; // default value 0153 } 0154 0155 void KoDocumentResourceManager::setPasteOffset(qreal pasteOffset) 0156 { 0157 setResource(PasteOffset, QVariant(pasteOffset)); 0158 } 0159 0160 qreal KoDocumentResourceManager::pasteOffset() const 0161 { 0162 return resource(PasteOffset).toDouble(); 0163 } 0164 0165 void KoDocumentResourceManager::enablePasteAtCursor(bool enable) 0166 { 0167 setResource(PasteAtCursor, QVariant(enable)); 0168 } 0169 0170 bool KoDocumentResourceManager::pasteAtCursor() const 0171 { 0172 return resource(PasteAtCursor).toBool(); 0173 } 0174 0175 0176 void KoDocumentResourceManager::setUndoStack(KUndo2Stack *undoStack) 0177 { 0178 QVariant variant; 0179 variant.setValue<void*>(undoStack); 0180 setResource(UndoStack, variant); 0181 } 0182 0183 KoImageCollection *KoDocumentResourceManager::imageCollection() const 0184 { 0185 if (!hasResource(ImageCollection)) 0186 return 0; 0187 return static_cast<KoImageCollection*>(resource(ImageCollection).value<void*>()); 0188 } 0189 0190 void KoDocumentResourceManager::setImageCollection(KoImageCollection *ic) 0191 { 0192 QVariant variant; 0193 variant.setValue<void*>(ic); 0194 setResource(ImageCollection, variant); 0195 } 0196 0197 KoDocumentBase *KoDocumentResourceManager::odfDocument() const 0198 { 0199 if (!hasResource(OdfDocument)) 0200 return 0; 0201 return static_cast<KoDocumentBase*>(resource(OdfDocument).value<void*>()); 0202 } 0203 0204 void KoDocumentResourceManager::setOdfDocument(KoDocumentBase *currentDocument) 0205 { 0206 QVariant variant; 0207 variant.setValue<void*>(currentDocument); 0208 setResource(OdfDocument, variant); 0209 } 0210 0211 KoShapeController *KoDocumentResourceManager::shapeController() const 0212 { 0213 if (!hasResource(ShapeController)) 0214 return 0; 0215 return resource(ShapeController).value<KoShapeController *>(); 0216 } 0217 0218 void KoDocumentResourceManager::setShapeController(KoShapeController *shapeController) 0219 { 0220 QVariant variant; 0221 variant.setValue<KoShapeController *>(shapeController); 0222 setResource(ShapeController, variant); 0223 }