Krita Source Code Documentation
Loading...
Searching...
No Matches
CanvasData Class Reference

Public Member Functions

void activateToolActions ()
 
 CanvasData (KoCanvasController *cc, const KoInputDevice &id)
 
void deactivateToolActions ()
 
 ~CanvasData ()
 

Public Attributes

QString activationShapeId
 
KoToolBaseactiveTool
 
QString activeToolId
 
QHash< QString, KoToolBase * > allTools
 
KoCanvasController *const canvas
 
QStringList disabledGlobalActions
 
QLabel * dummyToolLabel
 
QWidget * dummyToolWidget
 
const KoInputDevice inputDevice
 
QList< KoToolBase * > mostRecentTools
 
QStringList toolActions
 

Detailed Description

Definition at line 57 of file KoToolManager.cpp.

Constructor & Destructor Documentation

◆ CanvasData()

CanvasData::CanvasData ( KoCanvasController * cc,
const KoInputDevice & id )
inline

Definition at line 60 of file KoToolManager.cpp.

61 : activeTool(0),
62 canvas(cc),
63 inputDevice(id),
66 {
67 }
const KoInputDevice inputDevice
QWidget * dummyToolWidget
KoToolBase * activeTool
QLabel * dummyToolLabel
KoCanvasController *const canvas

◆ ~CanvasData()

CanvasData::~CanvasData ( )
inline

Definition at line 69 of file KoToolManager.cpp.

70 {
71 // the dummy tool widget does not necessarily have a parent and we create it, so we delete it.
72 delete dummyToolWidget;
73 }

Member Function Documentation

◆ activateToolActions()

void CanvasData::activateToolActions ( )
inline

Definition at line 75 of file KoToolManager.cpp.

76 {
77 toolActions.clear();
79
80 KisKActionCollection *windowActionCollection = canvas->actionCollection();
81
82 if (!windowActionCollection) {
83 qWarning() << "We haven't got an action collection";
84 return;
85 }
86
87 QStringList globalActions;
88
89 QMap<QKeySequence, QStringList> shortcutMap;
90
91// qDebug() << "................... activating tool" << activeToolId;
92
93 Q_FOREACH(QAction *action, windowActionCollection->actions()) {
94
95 if (action->property("tool_action").isValid()) {
96 QStringList tools = action->property("tool_action").toStringList();
97
98 if (KoToolRegistry::instance()->keys().contains(action->objectName())) {
99 //qDebug() << "This action needs to be enabled!";
100 action->setEnabled(true);
101 toolActions << action->objectName();
102 }
103 else {
104 if (tools.contains(activeToolId) || action->property("always_enabled").toBool()) {
105 //qDebug() << "\t\tenabling";
106 action->setEnabled(true);
107 toolActions << action->objectName();
108 }
109 else {
110 //qDebug() << "\t\tDISabling";
111 action->setDisabled(true);
112 }
113 }
114 }
115 else {
116 globalActions << action->objectName();
117 }
118
119 Q_FOREACH(QKeySequence keySequence, action->shortcuts()) {
120 // After loading a custom shortcut profile, shortcuts can be defined as an empty string, which is not an empty shortcut
121 if (keySequence.toString() != "") {
122 if (shortcutMap.contains(keySequence)) {
123 shortcutMap[keySequence].append(action->objectName());
124 }
125 else {
126 shortcutMap[keySequence] = QStringList() << action->objectName();
127 }
128 }
129 }
130 }
131
132 // Make sure the tool's actions override the global actions that aren't associated with the tool.
133 Q_FOREACH(const QKeySequence &k, shortcutMap.keys()) {
134 if (shortcutMap[k].size() > 1) {
135 QStringList actions = shortcutMap[k];
136 //qDebug() << k << actions;
137 bool toolActionFound = false;
138 Q_FOREACH(const QString &action, actions) {
139 if (toolActions.contains(action)) {
140 toolActionFound = true;
141 }
142 }
143 Q_FOREACH(const QString &action, actions) {
144 if (toolActionFound && globalActions.contains(action)) {
145 //qDebug() << "\tdisabling global action" << action;
146 windowActionCollection->action(action)->setEnabled(false);
147 disabledGlobalActions << action;
148 }
149 }
150 //qDebug() << k << shortcutMap[k];
151 }
152 }
153
154 windowActionCollection->readSettings(); // The shortcuts might have been configured in the meantime.
155 }
QList< QString > QStringList
QStringList disabledGlobalActions
QString activeToolId
QStringList toolActions
A container for a set of QAction objects.
QAction * action(int index) const
QList< QAction * > actions() const
KisKActionCollection * actionCollection
static KoToolRegistry * instance()
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References KisKActionCollection::action(), KisKActionCollection::actions(), KoToolRegistry::instance(), and KisKActionCollection::readSettings().

◆ deactivateToolActions()

void CanvasData::deactivateToolActions ( )
inline

Definition at line 157 of file KoToolManager.cpp.

158 {
159 if (!activeTool)
160 return;
161
162 //qDebug() << "............... deactivating previous tool because activating" << activeToolId;
163
164 KisKActionCollection *windowActionCollection = canvas->actionCollection();
165
166 Q_FOREACH(const QString &action, toolActions) {
167 //qDebug() << "disabling" << action;
168 windowActionCollection->action(action)->setDisabled(true);
169 }
170 Q_FOREACH(const QString &action, disabledGlobalActions) {
171 //qDebug() << "enabling" << action;
172 windowActionCollection->action(action)->setEnabled(true);
173 }
174 }

References KisKActionCollection::action().

Member Data Documentation

◆ activationShapeId

QString CanvasData::activationShapeId

Definition at line 178 of file KoToolManager.cpp.

◆ activeTool

KoToolBase* CanvasData::activeTool

Definition at line 176 of file KoToolManager.cpp.

◆ activeToolId

QString CanvasData::activeToolId

Definition at line 177 of file KoToolManager.cpp.

◆ allTools

QHash<QString, KoToolBase*> CanvasData::allTools

Definition at line 179 of file KoToolManager.cpp.

◆ canvas

KoCanvasController* const CanvasData::canvas

Definition at line 181 of file KoToolManager.cpp.

◆ disabledGlobalActions

QStringList CanvasData::disabledGlobalActions

Definition at line 186 of file KoToolManager.cpp.

◆ dummyToolLabel

QLabel* CanvasData::dummyToolLabel

Definition at line 184 of file KoToolManager.cpp.

◆ dummyToolWidget

QWidget* CanvasData::dummyToolWidget

Definition at line 183 of file KoToolManager.cpp.

◆ inputDevice

const KoInputDevice CanvasData::inputDevice

Definition at line 182 of file KoToolManager.cpp.

◆ mostRecentTools

QList<KoToolBase*> CanvasData::mostRecentTools

Definition at line 180 of file KoToolManager.cpp.

◆ toolActions

QStringList CanvasData::toolActions

Definition at line 185 of file KoToolManager.cpp.


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