Warning, file /office/calligra/libs/flake/KoToolFactoryBase.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 * Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org> 0003 * Copyright (C) 2006 Thomas Zander <zander@kde.org> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Library General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Library General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Library General Public License 0016 * along with this library; see the file COPYING.LIB. If not, write to 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #ifndef KO_TOOL_FACTORY_H 0022 #define KO_TOOL_FACTORY_H 0023 0024 #include "flake_export.h" 0025 0026 #include <QString> 0027 0028 class KoCanvasBase; 0029 class KoToolBase; 0030 class QKeySequence; 0031 0032 /** 0033 * A factory for KoToolBase objects. 0034 * The baseclass for all tool plugins. Each plugin that ships a KoToolBase should also 0035 * ship a factory. That factory will extend this class and set variable data like 0036 * a toolTip and icon in the constructor of that extending class. 0037 * 0038 * An example usage would be:<pre> 0039 * class MyToolFactory : public KoToolFactoryBase { 0040 * public: 0041 * MyToolFactory(const QStringList&) 0042 * : KoToolFactoryBase("MyTool") { 0043 * setToolTip(i18n("Create object")); 0044 * setToolType("dynamic"); 0045 * setPriority(5); 0046 * } 0047 * ~MyToolFactory() {} 0048 * KoToolBase *createTool(KoCanvasBase *canvas); 0049 * }; 0050 * K_PLUGIN_FACTORY_WITH_JSON((MyToolFactoryFactory, "mytool.json", registerPlugin<MyToolFactory>();) 0051 * </pre> 0052 * 0053 */ 0054 class FLAKE_EXPORT KoToolFactoryBase 0055 { 0056 public: 0057 /** 0058 * Create the new factory 0059 * @param id a string that will be used internally for referencing the tool, for 0060 * example for use by the KoToolBase::activateTemporary. 0061 */ 0062 explicit KoToolFactoryBase(const QString &id); 0063 virtual ~KoToolFactoryBase(); 0064 0065 /** 0066 * Instantiate a new tool 0067 * @param canvas the canvas that the new tool will work on. Should be passed 0068 * to the constructor of the tool. 0069 * @return a new KoToolBase instance, or zero if the tool doesn't want to show up. 0070 */ 0071 virtual KoToolBase *createTool(KoCanvasBase *canvas) = 0; 0072 0073 /** 0074 * return the id for the tool this factory creates. 0075 * @return the id for the tool this factory creates. 0076 */ 0077 QString id() const; 0078 /** 0079 * Returns The priority of this tool in its section in the toolbox 0080 * @return The priority of this tool. 0081 */ 0082 int priority() const; 0083 /** 0084 * returns the type of tool, used to group tools in the toolbox 0085 * @return the type of tool 0086 */ 0087 QString toolType() const; 0088 /** 0089 * return a translated tooltip Text 0090 * @return a translated tooltip Text 0091 */ 0092 QString toolTip() const; 0093 /** 0094 * return the basename of the icon for this tool 0095 * @return the basename of the icon for this tool 0096 */ 0097 QString iconName() const; 0098 0099 /** 0100 * Return the id of the shape we can process. 0101 * This is the shape Id the tool we create is associated with. So a TextTool for a TextShape. 0102 * In combination with the toolType the following situations can occur; 0103 <table><tr><th>Type</th><th>shapeId</th><th>Result</th></tr> 0104 <tr> 0105 <td>'main'</td> 0106 <td>Foo</td> 0107 <td>Tool will always be visible, but only active when shape with shapeId 'Foo' is in the selection.</td></tr> 0108 <tr> 0109 <td>'main'</td> 0110 <td>''</td> 0111 <td>Tool will always be visible, but only active when at least one shape is selected</td></tr> 0112 <tr> 0113 <td>'main'</td> 0114 <td>'flake/always'</td> 0115 <td>Tool will always be visible and enabled.</td></tr> 0116 <tr> 0117 <td>'main'</td> 0118 <td>'flake/edit'</td> 0119 <td>Tool will be visible no matter which shape is selected (if any), but only 0120 be enabled when the current layer is editable.</td></tr> 0121 <tr> 0122 <td>'dynamic'</td> 0123 <td>Foo</td> 0124 <td>Tool will only be visible when shape with shapeId 'Foo' is in the selection.</td></tr> 0125 <tr> 0126 <td>'dynamic'</td> 0127 <td>''</td> 0128 <td>Tool will always be visible. We recommend you don't use this one.</td></tr> 0129 <tr> 0130 <td>"comma separated list of application names"</td> 0131 <td>see main type</td> 0132 <td>Similar to the 'main' item if the application name matches with the current application. Otherwise it's similar to 'dynamic', but segmented in its own section. If the list includes 'dynamic' it's even added to the dynamic section, when not matching the application name</td></tr> 0133 <tr> 0134 <td>'other'</td> 0135 <td>any</td> 0136 <td>similar to the 'dynamic' items, but segmented in its own section.</td></tr> 0137 <tr> 0138 <td>n/a</td> 0139 <td>/always</td> 0140 <td>An activation shape id ending with '/always' will make the tool always visible and enabled.</td></tr> 0141 </table> 0142 * @see KoShapeFactoryBase::shapeId() 0143 * @see setActivationShapeId() 0144 * @return the id of a shape, or an empty string for all shapes. 0145 */ 0146 QString activationShapeId() const; 0147 0148 /** 0149 * Return the default keyboard shortcut for activation of this tool (if 0150 * the shape this tool belongs to is active). 0151 * 0152 * @return the shortcut 0153 */ 0154 QKeySequence shortcut() const; 0155 0156 /** 0157 * Returns the main toolType 0158 * Each tool has a toolType which it uses to be grouped in the toolbox. 0159 * The predefined areas are main and dynamic. "main" tools are always 0160 * shown. 0161 * 0162 * @see toolType() 0163 * @see setToolType() 0164 */ 0165 static QString mainToolType() { 0166 return "main"; 0167 } 0168 /** 0169 * Returns the navigation toolType 0170 * Each tool has a toolType which it uses to be grouped in the toolbox. 0171 * The predefined areas are main and dynamic. "navigation" tools are always 0172 * shown and are for tools that change the settings of the canvas, zoom, pan... 0173 * 0174 * @see toolType() 0175 * @see setToolType() 0176 */ 0177 static QString navigationToolType() { 0178 return "navigation"; 0179 } 0180 /** 0181 * Returns the dynamic toolType 0182 * Each tool has a toolType which it uses to be grouped in the toolbox. 0183 * The predefined areas are main and dynamic. Dynamic tools are hidden 0184 * until the shape they belong to is activated. 0185 * 0186 * @see toolType() 0187 * @see setToolType() 0188 */ 0189 static QString dynamicToolType() { 0190 return "dynamic"; 0191 } 0192 0193 /** 0194 * Set the default shortcut for activation of this tool. 0195 */ 0196 void setShortcut(const QKeySequence & shortcut); 0197 0198 protected: 0199 /** 0200 * Set the tooltip to be used for this tool 0201 * @param tooltip the tooltip 0202 */ 0203 void setToolTip(const QString &tooltip); 0204 /** 0205 * Set the toolType. used to group tools in the toolbox 0206 * @param toolType the toolType 0207 */ 0208 void setToolType(const QString &toolType); 0209 /** 0210 * Set an icon to be used in the toolBox. 0211 * @param iconName the name of the icon per icon theme spec 0212 */ 0213 void setIconName(const QString &iconName); 0214 /** 0215 * Set the priority of this tool, as it is shown in the toolBox; lower number means 0216 * it will be show more to the front of the list. 0217 * @param newPriority the priority 0218 */ 0219 void setPriority(int newPriority); 0220 /** 0221 * Set the id of the shape we can process. 0222 * This is the Id, as passed to the constructor of a KoShapeFactoryBase, that the tool 0223 * we create is associated with. This means that if a KoTextShape is selected, then 0224 * all tools that have its id set here will be added to the dynamic part of the toolbox. 0225 * @param activationShapeId the Id of the shape 0226 * @see activationShapeId() 0227 */ 0228 void setActivationShapeId(const QString &activationShapeId); 0229 0230 0231 private: 0232 class Private; 0233 Private * const d; 0234 }; 0235 0236 #endif