Krita Source Code Documentation
Loading...
Searching...
No Matches
KoToolFactoryBase Class Referenceabstract

#include <KoToolFactoryBase.h>

+ Inheritance diagram for KoToolFactoryBase:

Public Member Functions

QString activationShapeId () const
 
QList< QAction * > createActions (KisKActionCollection *actionCollection, KoToolManager *toolManager)
 
virtual KoToolBase * createTool (KoCanvasBase *canvas)=0
 
QString iconName () const
 
QString id () const
 
 KoToolFactoryBase (const QString &id)
 
int priority () const
 
 Private (const QString &i)
 
QString section () const
 
QKeySequence shortcut () const
 
QString toolName () const
 
QString toolTip () const
 
virtual ~KoToolFactoryBase ()
 

Public Attributes

QString activationId
 
QString iconName
 
const QString id
 
int priority
 
QString section
 
QKeySequence shortcut
 
QString toolName
 
QString tooltip
 

Protected Member Functions

virtual QList< QAction * > createActionsImpl (KoToolManager *toolManager)
 createActionsImpl should be reimplemented if the tool needs any actions. The actions should have a valid objectName().
 
void setActivationShapeId (const QString &activationShapeId)
 
void setIconName (const char *iconName)
 
void setIconName (const QString &iconName)
 
void setPriority (int newPriority)
 
void setSection (const QString &section)
 
void setShortcut (const QKeySequence &shortcut)
 
void setToolName (const QString &toolName)
 
void setToolTip (const QString &tooltip)
 

Private Attributes

Private *const d
 
- Private Attributes inherited from Private
KisCanvas2 * canvas
 
int displayedFrame
 
int intendedFrame
 

Additional Inherited Members

- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Detailed Description

A factory for KoToolBase objects.

The baseclass for all tool plugins. Each plugin that ships a KoToolBase should also ship a factory. That factory will extend this class and set variable data like a toolTip and icon in the constructor of that extending class.

An example usage would be:

   class MyToolFactory : public KoToolFactoryBase {
   public:
     MyToolFactory(const QStringList&)
         : KoToolFactoryBase("MyTool") {
         setToolTip(i18n("Create object"));
         setToolName(i18n("Create Object Tool"));
         setSection("main");
         setPriority(5);
     }
     ~MyToolFactory() {}
     KoToolBase *createTool(KoCanvasBase *canvas);
   };
   K_PLUGIN_FACTORY_WITH_JSON((MyToolFactoryFactory, "mytool.json", registerPlugin<MyToolFactory>();)

Definition at line 19 of file KoToolFactoryBase.cpp.

Constructor & Destructor Documentation

◆ KoToolFactoryBase()

KoToolFactoryBase::KoToolFactoryBase ( const QString & id)
explicit

Create the new factory

Parameters
ida string that will be used internally for referencing the tool

Definition at line 38 of file KoToolFactoryBase.cpp.

39 : d(new Private(id))
40{
41}

◆ ~KoToolFactoryBase()

KoToolFactoryBase::~KoToolFactoryBase ( )
virtual

Definition at line 43 of file KoToolFactoryBase.cpp.

44{
45 delete d;
46}

References d.

Member Function Documentation

◆ activationShapeId()

QString KoToolFactoryBase::activationShapeId ( ) const

Return the id of the shape we can process. This is the shape Id the tool we create is associated with. So a TextTool for a TextShape.

See also
KoShapeFactoryBase::shapeId()
setActivationShapeId()
Returns
the id of a shape, or an empty string for all shapes.

Definition at line 164 of file KoToolFactoryBase.cpp.

165{
166 return d->activationId;
167}

References d.

◆ createActions()

QList< QAction * > KoToolFactoryBase::createActions ( KisKActionCollection * actionCollection,
KoToolManager * toolManager )

Create the actions for this tool. Actions are unique per window, not per tool instance; tool instances are unique per view/canvas.

Definition at line 48 of file KoToolFactoryBase.cpp.

49{
50 QList<QAction *> toolActions;
51
53 QList<QAction*> actions = createActionsImpl(toolManager);
54 QAction *action = actionRegistry->makeQAction(id(), this);
55 actionCollection->addAction(id(), action);
56 connect(action, &QAction::triggered, toolManager, [toolId = id(), toolManager] () {
57 toolManager->switchToolRequested(toolId);
58 });
59
60 Q_FOREACH(QAction *action, actions) {
61 if (action->objectName().isEmpty()) {
62 qWarning() << "Tool" << id() << "tries to add an action without a name";
63 continue;
64 }
65 QAction *existingAction = actionCollection->action(action->objectName());
66 if (existingAction) {
67 delete action;
68 action = existingAction;
69 }
70
71 QStringList tools;
72 if (action->property("tool_action").isValid()) {
73 tools = action->property("tool_action").toStringList();
74 }
75 tools << id();
76 action->setProperty("tool_action", tools);
77 if (!existingAction) {
78 actionCollection->addAction(action->objectName(), action);
79 }
80 toolActions << action;
81 }
82
83 // Enable this to easily generate action files for tools
84 #if 0
85 if (toolActions.size() > 0) {
86
87 QDomDocument doc;
88 QDomElement e = doc.createElement("Actions");
89 e.setAttribute("name", id);
90 e.setAttribute("version", "2");
91 doc.appendChild(e);
92
93 Q_FOREACH (QAction *action, toolActions) {
94 QDomElement a = doc.createElement("Action");
95 a.setAttribute("name", action->objectName());
96
97 // But seriously, XML is the worst format ever designed
98 auto addElement = [&](QString title, QString content) {
99 QDomElement newNode = doc.createElement(title);
100 QDomText newText = doc.createTextNode(content);
101 newNode.appendChild(newText);
102 a.appendChild(newNode);
103 };
104
105 addElement("icon", action->icon().name());
106 addElement("text", action->text());
107 addElement("whatsThis" , action->whatsThis());
108 addElement("toolTip" , action->toolTip());
109 addElement("iconText" , action->iconText());
110 addElement("shortcut" , action->shortcut().toString());
111 addElement("isCheckable" , QString((action->isChecked() ? "true" : "false")));
112 addElement("statusTip", action->statusTip());
113 e.appendChild(a);
114 }
115 QFile f(id()z + ".action");
116 f.open(QFile::WriteOnly);
117 f.write(doc.toString().toUtf8());
118 f.close();
119
120 }
121
122 else {
123 debugFlake << "Tool" << id() << "has no actions";
124 }
125#endif
126
127// qDebug() << "Generated actions for tool factory" << id();
128// Q_FOREACH(QAction *action, toolActions) {
129// qDebug() << "\taction:" << action->objectName() << "shortcut" << action->shortcuts() << "tools" << action->property("tool_action").toStringList();
130// }
131 return toolActions;
132}
#define debugFlake
Definition FlakeDebug.h:15
QAction * makeQAction(const QString &name, QObject *parent=0)
static KisActionRegistry * instance()
Q_INVOKABLE QAction * addAction(const QString &name, QAction *action)
QAction * action(int index) const
virtual QList< QAction * > createActionsImpl(KoToolManager *toolManager)
createActionsImpl should be reimplemented if the tool needs any actions. The actions should have a va...
void switchToolRequested(const QString &id)

References KisKActionCollection::action(), KisKActionCollection::addAction(), createActionsImpl(), debugFlake, id, KisActionRegistry::instance(), KisActionRegistry::makeQAction(), and KoToolManager::switchToolRequested().

◆ createActionsImpl()

QList< QAction * > KoToolFactoryBase::createActionsImpl ( KoToolManager * toolManager)
protectedvirtual

createActionsImpl should be reimplemented if the tool needs any actions. The actions should have a valid objectName().

Returns
the list of actions this tool wishes to be available.

Reimplemented in KoPathToolFactory, KisSelectionToolFactoryBase, KisToolPolyLineFactoryBase, KisToolPaintFactoryBase, KisToolBrushFactory, KisToolMoveFactory, KisToolPanFactory, DefaultToolFactory, ToolReferenceImagesFactory, KarbonCalligraphyToolFactory, KisToolSelectPolygonalFactory, KisToolSelectMagneticFactory, SvgTextToolFactory, and KisToolTransformFactory.

Definition at line 214 of file KoToolFactoryBase.cpp.

215{
216 Q_UNUSED(toolManager);
217 return QList<QAction *>();
218}

◆ createTool()

◆ iconName()

QString KoToolFactoryBase::iconName ( ) const

return the basename of the icon for this tool

Returns
the basename of the icon for this tool

◆ id()

QString KoToolFactoryBase::id ( ) const

return the id for the tool this factory creates.

Returns
the id for the tool this factory creates.

◆ priority()

int KoToolFactoryBase::priority ( ) const

Returns The priority of this tool in its section in the toolbox

Returns
The priority of this tool.

◆ Private()

KoToolFactoryBase::Private ( const QString & i)
inline

Definition at line 22 of file KoToolFactoryBase.cpp.

23 : priority(100),
24 id(i)
25 {
26 }

◆ section()

QString KoToolFactoryBase::section ( ) const

returns the section used to group tools in the toolbox

Returns
the section

◆ setActivationShapeId()

void KoToolFactoryBase::setActivationShapeId ( const QString & activationShapeId)
protected

Set the id of the shape we can process. This is the Id, as passed to the constructor of a KoShapeFactoryBase, that the tool we create is associated with. This means that if a KoTextShape is selected, then all tools that have its id set here will be added to the dynamic part of the toolbox.

Parameters
activationShapeIdthe Id of the shape
See also
activationShapeId()

Definition at line 174 of file KoToolFactoryBase.cpp.

175{
176 d->activationId = activationShapeId;
177}
QString activationShapeId() const

References activationShapeId(), and d.

◆ setIconName() [1/2]

void KoToolFactoryBase::setIconName ( const char * iconName)
protected

Set an icon to be used in the toolBox.

Parameters
iconNamethe basename (without extension) of the icon

Definition at line 194 of file KoToolFactoryBase.cpp.

195{
196 d->iconName = QLatin1String(iconName);
197}

References d, and iconName.

◆ setIconName() [2/2]

void KoToolFactoryBase::setIconName ( const QString & iconName)
protected

Definition at line 199 of file KoToolFactoryBase.cpp.

200{
201 d->iconName = iconName;
202}

References d, and iconName.

◆ setPriority()

void KoToolFactoryBase::setPriority ( int newPriority)
protected

Set the priority of this tool, as it is shown in the toolBox; lower number means it will be show more to the front of the list.

Parameters
newPrioritythe priority

Definition at line 204 of file KoToolFactoryBase.cpp.

205{
206 d->priority = newPriority;
207}

References d.

◆ setSection()

void KoToolFactoryBase::setSection ( const QString & section)
protected

Set the section used to group tools in the toolbox

Parameters
sectionthe section

Definition at line 189 of file KoToolFactoryBase.cpp.

190{
191 d->section = section;
192}

References d, and section.

◆ setShortcut()

void KoToolFactoryBase::setShortcut ( const QKeySequence & shortcut)
protected

Set the default shortcut for activation of this tool.

Definition at line 209 of file KoToolFactoryBase.cpp.

210{
211 d->shortcut = shortcut;
212}

References d, and shortcut.

◆ setToolName()

void KoToolFactoryBase::setToolName ( const QString & toolName)
protected

Set the tool name to be used for this tool

Parameters
toolNamethe tool name

Definition at line 184 of file KoToolFactoryBase.cpp.

185{
186 d->toolName = toolName;
187}

References d, and toolName.

◆ setToolTip()

void KoToolFactoryBase::setToolTip ( const QString & tooltip)
protected

Set the tooltip to be used for this tool

Parameters
tooltipthe tooltip

Definition at line 179 of file KoToolFactoryBase.cpp.

180{
181 d->tooltip = tooltip;
182}

References d, and tooltip.

◆ shortcut()

QKeySequence KoToolFactoryBase::shortcut ( ) const

Return the default keyboard shortcut for activation of this tool (if the shape this tool belongs to is active).

See KoToolManager for use.

Returns
the shortcut

◆ toolName()

QString KoToolFactoryBase::toolName ( ) const

return the translated tool name

Returns
the translated tool name

◆ toolTip()

QString KoToolFactoryBase::toolTip ( ) const

return a translated tooltip Text

Returns
a translated tooltip Text

Definition at line 149 of file KoToolFactoryBase.cpp.

150{
151 return d->tooltip;
152}

References d.

Member Data Documentation

◆ activationId

QString KoToolFactoryBase::activationId

Definition at line 30 of file KoToolFactoryBase.cpp.

◆ d

Private* const KoToolFactoryBase::d
private

Definition at line 199 of file KoToolFactoryBase.h.

◆ iconName

QString KoToolFactoryBase::iconName

Definition at line 31 of file KoToolFactoryBase.cpp.

◆ id

QString KoToolFactoryBase::id

Definition at line 33 of file KoToolFactoryBase.cpp.

◆ priority

int KoToolFactoryBase::priority

Definition at line 27 of file KoToolFactoryBase.cpp.

◆ section

QString KoToolFactoryBase::section

Definition at line 28 of file KoToolFactoryBase.cpp.

◆ shortcut

QKeySequence KoToolFactoryBase::shortcut

Definition at line 34 of file KoToolFactoryBase.cpp.

◆ toolName

QString KoToolFactoryBase::toolName

Definition at line 32 of file KoToolFactoryBase.cpp.

◆ tooltip

QString KoToolFactoryBase::tooltip

Definition at line 29 of file KoToolFactoryBase.cpp.


The documentation for this class was generated from the following files: