Warning, file /office/calligra/libs/flake/KoCanvasResourceManager.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 "KoCanvasResourceManager.h"
0023 
0024 #include <QVariant>
0025 #include <FlakeDebug.h>
0026 
0027 #include "KoShape.h"
0028 #include "KoShapeStroke.h"
0029 #include "KoResourceManager_p.h"
0030 #include <KoColorSpaceRegistry.h>
0031 
0032 class Q_DECL_HIDDEN KoCanvasResourceManager::Private
0033 {
0034 public:
0035     KoResourceManager manager;
0036 };
0037 
0038 KoCanvasResourceManager::KoCanvasResourceManager(QObject *parent)
0039         : QObject(parent),
0040         d(new Private())
0041 {
0042     const KoColorSpace* cs = KoColorSpaceRegistry::instance()->rgb8();
0043     setForegroundColor(KoColor(Qt::black, cs));
0044     setBackgroundColor(KoColor(Qt::white, cs));
0045     setResource(ApplicationSpeciality, NoSpecial);
0046 }
0047 
0048 KoCanvasResourceManager::~KoCanvasResourceManager()
0049 {
0050     delete d;
0051 }
0052 
0053 void KoCanvasResourceManager::setResource(int key, const QVariant &value)
0054 {
0055     d->manager.setResource(key, value);
0056     emit canvasResourceChanged(key, value);
0057 }
0058 
0059 QVariant KoCanvasResourceManager::resource(int key) const
0060 {
0061     return d->manager.resource(key);
0062 }
0063 
0064 void KoCanvasResourceManager::setResource(int key, const KoColor &color)
0065 {
0066     QVariant v;
0067     v.setValue(color);
0068     setResource(key, v);
0069 }
0070 
0071 void KoCanvasResourceManager::setResource(int key, KoShape *shape)
0072 {
0073     QVariant v;
0074     v.setValue(shape);
0075     setResource(key, v);
0076 }
0077 
0078 void KoCanvasResourceManager::setResource(int key, const KoUnit &unit)
0079 {
0080     QVariant v;
0081     v.setValue(unit);
0082     setResource(key, v);
0083 }
0084 
0085 KoColor KoCanvasResourceManager::koColorResource(int key) const
0086 {
0087     return d->manager.koColorResource(key);
0088 }
0089 
0090 void KoCanvasResourceManager::setForegroundColor(const KoColor &color)
0091 {
0092     setResource(ForegroundColor, color);
0093 }
0094 
0095 KoColor KoCanvasResourceManager::foregroundColor() const
0096 {
0097     return koColorResource(ForegroundColor);
0098 }
0099 
0100 void KoCanvasResourceManager::setBackgroundColor(const KoColor &color)
0101 {
0102     setResource(BackgroundColor, color);
0103 }
0104 
0105 KoColor KoCanvasResourceManager::backgroundColor() const
0106 {
0107     return koColorResource(BackgroundColor);
0108 }
0109 
0110 KoShape *KoCanvasResourceManager::koShapeResource(int key) const
0111 {
0112     return d->manager.koShapeResource(key);
0113 }
0114 
0115 KoUnit KoCanvasResourceManager::unitResource(int key) const
0116 {
0117     return resource(key).value<KoUnit>();
0118 }
0119 
0120 
0121 void KoCanvasResourceManager::setActiveStroke(const KoShapeStroke &stroke)
0122 {
0123     QVariant v;
0124     v.setValue(stroke);
0125     setResource(ActiveStroke, v);
0126 }
0127 
0128 KoShapeStroke KoCanvasResourceManager::activeStroke() const
0129 {
0130     if (!d->manager.hasResource(ActiveStroke)) {
0131         KoShapeStroke empty;
0132         return empty;
0133     }
0134     return resource(ActiveStroke).value<KoShapeStroke>();
0135 }
0136 
0137 bool KoCanvasResourceManager::boolResource(int key) const
0138 {
0139     return d->manager.boolResource(key);
0140 }
0141 
0142 int KoCanvasResourceManager::intResource(int key) const
0143 {
0144     return d->manager.intResource(key);
0145 }
0146 
0147 QString KoCanvasResourceManager::stringResource(int key) const
0148 {
0149     return d->manager.stringResource(key);
0150 }
0151 
0152 QSizeF KoCanvasResourceManager::sizeResource(int key) const
0153 {
0154     return d->manager.sizeResource(key);
0155 }
0156 
0157 bool KoCanvasResourceManager::hasResource(int key) const
0158 {
0159     return d->manager.hasResource(key);
0160 }
0161 
0162 void KoCanvasResourceManager::clearResource(int key)
0163 {
0164     d->manager.clearResource(key);
0165     QVariant empty;
0166     emit canvasResourceChanged(key, empty);
0167 }