Warning, file /office/calligra/libs/flake/KoCanvasResourceManager.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, 2011 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_CANVASRESOURCEMANAGER_H 0022 #define KO_CANVASRESOURCEMANAGER_H 0023 0024 #include <QObject> 0025 0026 #include "flake_export.h" 0027 0028 class KoShape; 0029 class KoShapeStroke; 0030 class KoColor; 0031 class KoUnit; 0032 0033 class QVariant; 0034 class QSizeF; 0035 0036 /** 0037 * The KoCanvasResourceManager contains a set of per-canvas 0038 * properties, like current foreground color, current background 0039 * color and more. All tools belonging to the current canvas are 0040 * notified when a Resource changes (is set). 0041 * 0042 * The manager can contain all sorts of variable types and there are accessors 0043 * for the most common ones. All variables are always stored inside a QVariant 0044 * instance internally and you can always just use the resource() method to get 0045 * that directly. 0046 * The way to store arbitairy data objects that are stored as pointers you can use 0047 * the following code snippets; 0048 * @code 0049 * QVariant variant; 0050 * variant.setValue<void*>(textShapeData->document()); 0051 * resourceManager->setResource(KoText::CurrentTextDocument, variant); 0052 * // and get it out again. 0053 * QVariant var = resourceManager->resource(KoText::CurrentTextDocument); 0054 * document = static_cast<QTextDocument*>(var.value<void*>()); 0055 * @endcode 0056 */ 0057 class FLAKE_EXPORT KoCanvasResourceManager : public QObject 0058 { 0059 Q_OBJECT 0060 0061 public: 0062 0063 /** 0064 * This enum holds identifiers to the resources that can be stored in here. 0065 */ 0066 enum CanvasResource { 0067 ForegroundColor, ///< The active forground color selected for this canvas. 0068 BackgroundColor, ///< The active background color selected for this canvas. 0069 ActiveStroke, ///< The active stroke selected for this canvas 0070 PageSize, ///< The size of the (current) page in postscript points. 0071 Unit, ///< The unit of this canvas 0072 CurrentPage, ///< The current page number 0073 ActiveStyleType, ///< the actual active style type see KoFlake::StyleType for valid values 0074 ActiveRange, ///< The area where the rulers should show white 0075 ShowTextShapeOutlines, ///< Paint of text shape outlines ? 0076 ShowFormattingCharacters, ///< Paint of formatting characters ? 0077 ShowTableBorders, ///< Paint of table borders (when not really there) ? 0078 ShowSectionBounds, ///< Paint of sections bounds ? 0079 ShowInlineObjectVisualization, ///< paint a different background for inline objects 0080 ApplicationSpeciality, ///< Special features and limitations of the application 0081 KarbonStart = 1000, ///< Base number for Karbon specific values. 0082 KexiStart = 2000, ///< Base number for Kexi specific values. 0083 FlowStart = 3000, ///< Base number for Flow specific values. 0084 PlanStart = 4000, ///< Base number for Plan specific values. 0085 StageStart = 5000, ///< Base number for Stage specific values. 0086 SheetsStart = 6000, ///< Base number for Sheets specific values. 0087 WordsStart = 7000, ///< Base number for Words specific values. 0088 KoPageAppStart = 8000 ///< Base number for KoPageApp specific values. 0089 }; 0090 0091 enum ApplicationSpecial { 0092 NoSpecial = 0, 0093 NoAdvancedText = 1 0094 }; 0095 0096 /** 0097 * Constructor. 0098 * @param parent the parent QObject, used for memory management. 0099 */ 0100 explicit KoCanvasResourceManager(QObject *parent = 0); 0101 ~KoCanvasResourceManager() override; 0102 0103 public Q_SLOTS: 0104 /** 0105 * Set a resource of any type. 0106 * @param key the integer key 0107 * @param value the new value for the key. 0108 * @see KoCanvasResourceManager::CanvasResource 0109 */ 0110 void setResource(int key, const QVariant &value); 0111 0112 /** 0113 * Set a resource of type KoColor. 0114 * @param key the integer key 0115 * @param color the new value for the key. 0116 * @see KoCanvasResourceManager::CanvasResource 0117 */ 0118 void setResource(int key, const KoColor &color); 0119 0120 /** 0121 * Set a resource of type KoShape*. 0122 * @param key the integer key 0123 * @param id the new value for the key. 0124 * @see KoCanvasResourceManager::CanvasResource 0125 */ 0126 void setResource(int key, KoShape *shape); 0127 0128 /** 0129 * Set a resource of type KoUnit 0130 * @param key the integer key 0131 * @param id the new value for the key. 0132 * @see KoCanvasResourceManager::CanvasResource 0133 */ 0134 void setResource(int key, const KoUnit &unit); 0135 0136 public: 0137 /** 0138 * Returns a qvariant containing the specified resource or a standard one if the 0139 * specified resource does not exist. 0140 * @param key the key 0141 * @see KoCanvasResourceManager::CanvasResource 0142 */ 0143 QVariant resource(int key) const; 0144 0145 /** 0146 * Set the foregroundColor resource. 0147 * @param color the new foreground color 0148 */ 0149 void setForegroundColor(const KoColor &color); 0150 0151 /** 0152 * Return the foregroundColor 0153 */ 0154 KoColor foregroundColor() const; 0155 0156 /** 0157 * Set the backgroundColor resource. 0158 * @param color the new background color 0159 */ 0160 void setBackgroundColor(const KoColor &color); 0161 /** 0162 * Return the backgroundColor 0163 */ 0164 KoColor backgroundColor() const; 0165 0166 /// Sets the stroke resource 0167 void setActiveStroke(const KoShapeStroke &stroke); 0168 0169 /// Returns the stroke resource 0170 KoShapeStroke activeStroke() const; 0171 0172 /** 0173 * Return the resource determined by param key as a boolean. 0174 * @param key the indentifying key for the resource 0175 * @see KoCanvasResourceManager::CanvasResource 0176 */ 0177 bool boolResource(int key) const; 0178 0179 /** 0180 * Return the resource determined by param key as an integer. 0181 * @param key the indentifying key for the resource 0182 * @see KoCanvasResourceManager::CanvasResource 0183 */ 0184 int intResource(int key) const; 0185 0186 /** 0187 * Return the resource determined by param key as a KoColor. 0188 * @param key the indentifying key for the resource 0189 * @see KoCanvasResourceManager::CanvasResource 0190 */ 0191 KoColor koColorResource(int key) const; 0192 0193 /** 0194 * Return the resource determined by param key as a pointer to a KoShape. 0195 * @param key the indentifying key for the resource 0196 * @see KoCanvasResourceManager::CanvasResource 0197 */ 0198 KoShape *koShapeResource(int key) const; 0199 0200 /** 0201 * Return the resource determined by param key as a QString . 0202 * @param key the indentifying key for the resource 0203 * @see KoCanvasResourceManager::CanvasResource 0204 */ 0205 QString stringResource(int key) const; 0206 0207 /** 0208 * Return the resource determined by param key as a QSizeF. 0209 * @param key the indentifying key for the resource 0210 * @see KoCanvasResourceManager::CanvasResource 0211 */ 0212 QSizeF sizeResource(int key) const; 0213 0214 /** 0215 * Return the resource determined by param key as a KoUnit. 0216 * @param key the indentifying key for the resource 0217 * @see KoCanvasResourceManager::CanvasResource 0218 */ 0219 KoUnit unitResource(int key) const; 0220 0221 /** 0222 * Returns true if there is a resource set with the requested key. 0223 * @param key the indentifying key for the resource 0224 * @see KoCanvasResourceManager::CanvasResource 0225 */ 0226 bool hasResource(int key) const; 0227 0228 /** 0229 * Remove the resource with @p key from the provider. 0230 * @param key the key that will be used to remove the resource 0231 * There will be a signal emitted with a variable that will return true on QVariable::isNull(); 0232 * @see KoCanvasResourceManager::CanvasResource 0233 */ 0234 void clearResource(int key); 0235 0236 Q_SIGNALS: 0237 /** 0238 * This signal is emitted every time a resource is set that is either 0239 * new or different from the previous set value. 0240 * @param key the indentifying key for the resource 0241 * @param value the variants new value. 0242 * @see KoCanvasResourceManager::CanvasResource 0243 */ 0244 void canvasResourceChanged(int key, const QVariant &value); 0245 0246 private: 0247 KoCanvasResourceManager(const KoCanvasResourceManager&); 0248 KoCanvasResourceManager& operator=(const KoCanvasResourceManager&); 0249 0250 class Private; 0251 Private *const d; 0252 }; 0253 0254 #endif