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)
 
virtual KoToolBasecreateTool (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 toolTip () const
 
virtual ~KoToolFactoryBase ()
 

Public Attributes

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

Protected Member Functions

virtual QList< QAction * > createActionsImpl ()
 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 setToolTip (const QString &tooltip)
 

Private Slots

void activateTool ()
 

Private Attributes

Private *const d
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
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"));
         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 37 of file KoToolFactoryBase.cpp.

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

◆ ~KoToolFactoryBase()

KoToolFactoryBase::~KoToolFactoryBase ( )
virtual

Definition at line 42 of file KoToolFactoryBase.cpp.

43{
44 delete d;
45}

References d.

Member Function Documentation

◆ activateTool

void KoToolFactoryBase::activateTool ( )
privateslot

Definition at line 208 of file KoToolFactoryBase.cpp.

209{
210 KoToolManager::instance()->switchToolRequested(sender()->objectName());
211}
void switchToolRequested(const QString &id)
static KoToolManager * instance()
Return the toolmanager singleton.

References KoToolManager::instance(), and KoToolManager::switchToolRequested().

◆ 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 158 of file KoToolFactoryBase.cpp.

159{
160 return d->activationId;
161}

References d.

◆ createActions()

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

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 47 of file KoToolFactoryBase.cpp.

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

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

◆ createActionsImpl()

QList< QAction * > KoToolFactoryBase::createActionsImpl ( )
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, DefaultToolFactory, ToolReferenceImagesFactory, KarbonCalligraphyToolFactory, KisToolSelectPolygonalFactory, KisToolSelectMagneticFactory, SvgTextToolFactory, and KisToolTransformFactory.

Definition at line 203 of file KoToolFactoryBase.cpp.

204{
205 return QList<QAction *>();
206}

◆ 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 168 of file KoToolFactoryBase.cpp.

169{
170 d->activationId = activationShapeId;
171}
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 183 of file KoToolFactoryBase.cpp.

184{
185 d->iconName = QLatin1String(iconName);
186}

References d, and iconName.

◆ setIconName() [2/2]

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

Definition at line 188 of file KoToolFactoryBase.cpp.

189{
190 d->iconName = iconName;
191}

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 193 of file KoToolFactoryBase.cpp.

194{
195 d->priority = newPriority;
196}

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 178 of file KoToolFactoryBase.cpp.

179{
180 d->section = section;
181}

References d, and section.

◆ setShortcut()

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

Set the default shortcut for activation of this tool.

Definition at line 198 of file KoToolFactoryBase.cpp.

199{
200 d->shortcut = shortcut;
201}

References d, and shortcut.

◆ setToolTip()

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

Set the tooltip to be used for this tool

Parameters
tooltipthe tooltip

Definition at line 173 of file KoToolFactoryBase.cpp.

174{
175 d->tooltip = tooltip;
176}

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

◆ toolTip()

QString KoToolFactoryBase::toolTip ( ) const

return a translated tooltip Text

Returns
a translated tooltip Text

Definition at line 148 of file KoToolFactoryBase.cpp.

149{
150 return d->tooltip;
151}

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 188 of file KoToolFactoryBase.h.

◆ iconName

QString KoToolFactoryBase::iconName

Definition at line 31 of file KoToolFactoryBase.cpp.

◆ id

QString KoToolFactoryBase::id

Definition at line 32 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 33 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: