Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Scott Petrovic
Krita
Commits
c30ca18b
Commit
c30ca18b
authored
Jan 13, 2021
by
Halla Rempt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix activating tools with the tool action
(cherry picked from commit 7f4f7504a446af75e072ea283b149b9dcd693e27)
parent
febda59a
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
95 deletions
+40
-95
libs/flake/KoToolFactoryBase.cpp
libs/flake/KoToolFactoryBase.cpp
+11
-1
libs/flake/KoToolFactoryBase.h
libs/flake/KoToolFactoryBase.h
+8
-2
libs/flake/KoToolManager.cpp
libs/flake/KoToolManager.cpp
+21
-14
libs/flake/KoToolManager_p.cpp
libs/flake/KoToolManager_p.cpp
+0
-56
libs/flake/KoToolManager_p.h
libs/flake/KoToolManager_p.h
+0
-22
No files found.
libs/flake/KoToolFactoryBase.cpp
View file @
c30ca18b
...
...
@@ -10,6 +10,7 @@
#include <kactioncollection.h>
#include <kis_action_registry.h>
#include <KoToolManager.h>
#include <QKeySequence>
#include <QAction>
...
...
@@ -49,7 +50,11 @@ QList<QAction *> KoToolFactoryBase::createActions(KActionCollection *actionColle
KisActionRegistry
*
actionRegistry
=
KisActionRegistry
::
instance
();
QList
<
QAction
*>
actions
=
createActionsImpl
();
actions
<<
actionRegistry
->
makeQAction
(
id
());
QAction
*
action
=
actionRegistry
->
makeQAction
(
id
());
actionCollection
->
addAction
(
id
(),
action
);
connect
(
action
,
SIGNAL
(
triggered
()),
SLOT
(
activateTool
()));
//qDebug() << action << action->shortcut();
Q_FOREACH
(
QAction
*
action
,
actions
)
{
if
(
action
->
objectName
().
isEmpty
())
{
...
...
@@ -200,3 +205,8 @@ QList<QAction *> KoToolFactoryBase::createActionsImpl()
return
QList
<
QAction
*>
();
}
void
KoToolFactoryBase
::
activateTool
()
{
KoToolManager
::
instance
()
->
switchToolRequested
(
sender
()
->
objectName
());
}
libs/flake/KoToolFactoryBase.h
View file @
c30ca18b
...
...
@@ -12,6 +12,7 @@
#include <QString>
#include <QList>
#include <QObject>
class
KoCanvasBase
;
class
KoToolBase
;
...
...
@@ -42,8 +43,11 @@ class QAction;
</pre>
*/
class
KRITAFLAKE_EXPORT
KoToolFactoryBase
class
KRITAFLAKE_EXPORT
KoToolFactoryBase
:
public
QObject
{
Q_OBJECT
public:
/**
* Create the new factory
...
...
@@ -191,7 +195,6 @@ public:
protected:
/**
* Set the default shortcut for activation of this tool.
*/
...
...
@@ -241,6 +244,9 @@ protected:
*/
virtual
QList
<
QAction
*>
createActionsImpl
();
private
Q_SLOTS
:
void
activateTool
();
private:
class
Private
;
...
...
libs/flake/KoToolManager.cpp
View file @
c30ca18b
...
...
@@ -91,23 +91,30 @@ public:
QMap
<
QKeySequence
,
QStringList
>
shortcutMap
;
//
qDebug() << "................... activating tool" << activeToolId;
//
qDebug() << "................... activating tool" << activeToolId;
Q_FOREACH
(
QAction
*
action
,
windowActionCollection
->
actions
())
{
//qDebug() << "Action" << action->objectName() << "shortcuts" << action->shortcuts();
if
(
action
->
property
(
"tool_action"
).
isValid
())
{
QStringList
tools
=
action
->
property
(
"tool_action"
).
toStringList
();
//qDebug() << "\tassociated with" << tools;
if
(
tools
.
contains
(
activeToolId
))
{
if
(
KoToolRegistry
::
instance
()
->
keys
().
contains
(
action
->
objectName
()))
{
//qDebug() << "This action needs to be enabled!";
action
->
setEnabled
(
true
);
toolActions
<<
action
->
objectName
();
}
else
{
if
(
tools
.
contains
(
activeToolId
)
||
action
->
property
(
"always_enabled"
).
toBool
())
{
//qDebug() << "\t\tenabling";
action
->
setEnabled
(
true
);
toolActions
<<
action
->
objectName
();
}
else
{
//qDebug() << "\t\tDISabling";
action
->
setDisabled
(
true
);
}
}
}
else
{
globalActions
<<
action
->
objectName
();
}
...
...
@@ -236,14 +243,14 @@ void KoToolManager::registerToolActions(KActionCollection *ac, KoCanvasControlle
return
;
}
// Actions used to switch tools via shortcuts
Q_FOREACH
(
ToolHelper
*
th
,
d
->
tools
)
{
if
(
ac
->
action
(
th
->
id
()))
{
continue
;
}
ShortcutToolAction
*
action
=
th
->
createShortcutToolAction
(
ac
);
ac
->
addCategorizedAction
(
th
->
id
(),
action
,
"tool-shortcuts"
);
}
//
// Actions used to switch tools via shortcuts
//
Q_FOREACH (ToolHelper * th, d->tools) {
//
if (ac->action(th->id())) {
//
continue;
//
}
//
//
ShortcutToolAction* action = th->createShortcutToolAction(ac);
//
ac->addCategorizedAction(th->id(), action, "tool-shortcuts");
//
}
}
void
KoToolManager
::
addController
(
KoCanvasController
*
controller
)
...
...
libs/flake/KoToolManager_p.cpp
View file @
c30ca18b
...
...
@@ -30,12 +30,6 @@ ToolHelper::ToolHelper(KoToolFactoryBase *tool)
m_hasCustomShortcut
(
false
),
m_toolAction
(
0
)
{
// TODO: how to get an existing custom shortcut in the beginning here?
// Once the first ShortcutToolAction is added to the actionCollection,
// it will get any custom shortcut set by the actionCollection and
// by that trigger shortcutToolActionUpdated().
// But until then shortcut() will report a wrong shortcut and e.g. show
// that in the tooltips of the KoToolBox.
}
KoToolAction
*
ToolHelper
::
toolAction
()
...
...
@@ -84,25 +78,6 @@ void ToolHelper::activate()
emit
toolActivated
(
this
);
}
void
ToolHelper
::
shortcutToolActionUpdated
()
{
ShortcutToolAction
*
action
=
static_cast
<
ShortcutToolAction
*>
(
sender
());
// check if shortcut changed
const
QKeySequence
actionShortcut
=
action
->
shortcut
();
const
QKeySequence
currentShortcut
=
shortcut
();
if
(
actionShortcut
!=
currentShortcut
)
{
m_hasCustomShortcut
=
true
;
m_customShortcut
=
actionShortcut
;
if
(
m_toolAction
)
{
emit
m_toolAction
->
changed
();
}
// no need to forward the new shortcut to the other ShortcutToolAction objects,
// they are synchronized behind the scenes
// Thus they will also trigger this method, but due to them having
// the same shortcut not result in any further action.
}
}
KoToolBase
*
ToolHelper
::
createTool
(
KoCanvasBase
*
canvas
)
const
{
KoToolBase
*
tool
=
m_toolFactory
->
createTool
(
canvas
);
...
...
@@ -112,17 +87,6 @@ KoToolBase *ToolHelper::createTool(KoCanvasBase *canvas) const
return
tool
;
}
ShortcutToolAction
*
ToolHelper
::
createShortcutToolAction
(
QObject
*
parent
)
{
ShortcutToolAction
*
action
=
new
ShortcutToolAction
(
id
(),
text
(),
parent
);
KisActionRegistry
::
instance
()
->
propertizeAction
(
id
(),
action
);
connect
(
action
,
SIGNAL
(
changed
()),
SLOT
(
shortcutToolActionUpdated
()));
return
action
;
}
QString
ToolHelper
::
section
()
const
{
return
m_toolFactory
->
section
();
...
...
@@ -229,23 +193,3 @@ void Connector::selectionChanged()
{
emit
selectionChanged
(
m_shapeManager
->
selection
()
->
selectedShapes
());
}
// ************ ShortcutToolAction **********
ShortcutToolAction
::
ShortcutToolAction
(
const
QString
&
id
,
const
QString
&
name
,
QObject
*
parent
)
:
QAction
(
name
,
parent
)
,
m_toolID
(
id
)
{
connect
(
this
,
SIGNAL
(
triggered
(
bool
)),
this
,
SLOT
(
actionTriggered
()));
}
ShortcutToolAction
::~
ShortcutToolAction
()
{
}
void
ShortcutToolAction
::
actionTriggered
()
{
// todo: why not ToolHelper::activate(); and thus a slightly different behaviour?
// Answering the todo item: switchToolRequested
KoToolManager
::
instance
()
->
switchToolRequested
(
m_toolID
);
}
libs/flake/KoToolManager_p.h
View file @
c30ca18b
...
...
@@ -88,8 +88,6 @@ public:
bool
layerExplicitlyDisabled
;
};
class
ShortcutToolAction
;
/// \internal
class
ToolHelper
:
public
QObject
{
...
...
@@ -114,7 +112,6 @@ public:
/// wrapper around KoToolFactoryBase::priority();
int
priority
()
const
;
KoToolBase
*
createTool
(
KoCanvasBase
*
canvas
)
const
;
ShortcutToolAction
*
createShortcutToolAction
(
QObject
*
parent
);
/// unique id, >= 0
int
uniqueId
()
const
{
return
m_uniqueId
;
...
...
@@ -129,9 +126,6 @@ Q_SIGNALS:
/// Emitted when the tool should be activated, e.g. by pressing the tool's assigned button in the toolbox
void
toolActivated
(
ToolHelper
*
tool
);
private
Q_SLOTS
:
void
shortcutToolActionUpdated
();
private:
KoToolFactoryBase
*
const
m_toolFactory
;
const
int
m_uniqueId
;
...
...
@@ -158,20 +152,4 @@ private:
KoShapeManager
*
m_shapeManager
;
};
/// \internal
/// Helper class to provide a action for tool shortcuts
class
ShortcutToolAction
:
public
QAction
{
Q_OBJECT
public:
ShortcutToolAction
(
const
QString
&
id
,
const
QString
&
name
,
QObject
*
parent
);
~
ShortcutToolAction
()
override
;
private
Q_SLOTS
:
void
actionTriggered
();
private:
QString
m_toolID
;
};
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment