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

#include <kis_action_registry.h>

+ Inheritance diagram for KisActionRegistry:

Classes

struct  ActionCategory
 

Signals

void shortcutsUpdated ()
 

Public Member Functions

ActionInfoItem & actionInfo (const QString &name)
 
void applyShortcutScheme (const KConfigBase *config=0)
 
ActionCategory fetchActionCategory (const QString &name) const
 
QString getActionProperty (const QString &name, const QString &property)
 
bool hasAction (const QString &name) const
 
 KisActionRegistry ()
 
void loadActionFiles ()
 
void loadCustomShortcuts ()
 
void loadCustomShortcuts (QString filename=QStringLiteral("kritashortcutsrc"))
 
void loadShortcutScheme (const QString &schemeName)
 loadShortcutScheme
 
QAction * makeQAction (const QString &name, QObject *parent=0)
 
void notifySettingsUpdated ()
 
 Private (KisActionRegistry *_q)
 
bool propertizeAction (const QString &name, QAction *a)
 
QList< QString > registeredShortcutIds () const
 
bool sanityCheckPropertized (const QString &name)
 
void settingsPageSaved ()
 
void updateShortcut (const QString &name, QAction *ac)
 
 ~KisActionRegistry ()
 

Static Public Member Functions

static KisActionRegistryinstance ()
 

Public Attributes

QMap< QString, ActionInfoItem > actionInfoList
 
KisActionRegistryq
 
QSet< QString > sanityPropertizedShortcuts
 

Private Attributes

const QScopedPointer< Privated
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Additional Inherited Members

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

Detailed Description

KisActionRegistry is intended to manage the global action configuration data for Krita. The data come from four sources:

  • .action files, containing static action configuration data in XML format,
  • .rc configuration files, originally from XMLGUI and now in WidgetUtils,
  • kritashortcutsrc, containing temporary shortcut configuration, and
  • .shortcuts scheme files providing sets of default shortcuts, also from XMLGUI

This class can be used as a factory by calling makeQAction. It can be used to add standard properties such as default shortcuts and default tooltip to an existing action with propertizeAction. If you have a custom action class which needs to add other properties, you can use propertizeAction to add any sort of data you wish to the .action configuration file.

This class is also in charge of displaying the shortcut configuration dialog. The interplay between this class, KisKActionCollection, KisShortcutsEditor and so on can be complex, and is sometimes synchronized by file I/O by reading and writing the configuration files mentioned above.

It is a global static. Grab an instance().

Definition at line 146 of file kis_action_registry.cpp.

Constructor & Destructor Documentation

◆ KisActionRegistry()

KisActionRegistry::KisActionRegistry ( )

Constructor. Please don't touch!

Definition at line 186 of file kis_action_registry.cpp.

187 : d(new KisActionRegistry::Private(this))
188{
189 KConfigGroup cg = KSharedConfig::openConfig()->group("Shortcut Schemes");
190 QString schemeName = cg.readEntry("Current Scheme", "Default");
191 QString schemeFileName = KisKShortcutSchemesHelper::schemeFileLocations().value(schemeName);
192 if (!QFileInfo(schemeFileName).exists()) {
193 schemeName = "Default";
194 }
195 loadShortcutScheme(schemeName);
197}
void loadShortcutScheme(const QString &schemeName)
loadShortcutScheme
const QScopedPointer< Private > d
Private(KisActionRegistry *_q)
static QHash< QString, QString > schemeFileLocations()

References loadCustomShortcuts(), loadShortcutScheme(), and KisKShortcutSchemesHelper::schemeFileLocations().

◆ ~KisActionRegistry()

KisActionRegistry::~KisActionRegistry ( )

Definition at line 199 of file kis_action_registry.cpp.

200{
201}

Member Function Documentation

◆ actionInfo()

ActionInfoItem & KisActionRegistry::actionInfo ( const QString & name)
inline

Definition at line 158 of file kis_action_registry.cpp.

158 {
159 if (!actionInfoList.contains(name)) {
160 dbgAction << "Tried to look up info for unknown action" << name;
161 }
162 return actionInfoList[name];
163 }
QMap< QString, ActionInfoItem > actionInfoList
#define dbgAction
Definition kis_debug.h:58
const char * name(StandardAction id)

References dbgAction.

◆ applyShortcutScheme()

void KisActionRegistry::applyShortcutScheme ( const KConfigBase * config = 0)

Definition at line 261 of file kis_action_registry.cpp.

262{
263 // First, update the things in KisActionRegistry
264 d->actionInfoList.clear();
265 d->loadActionFiles();
266
267 if (config == 0) {
268 // Use default shortcut scheme. Simplest just to reload everything.
270 } else {
271 const auto schemeEntries = config->group(QStringLiteral("Shortcuts")).entryMap();
272 // Load info item for each shortcut, reset custom shortcuts
273 auto it = schemeEntries.constBegin();
274 while (it != schemeEntries.end()) {
275 ActionInfoItem &info = d->actionInfo(it.key());
276 info.setDefaultShortcuts(QKeySequence::listFromString(it.value()));
277 it++;
278 }
279 }
280}

References d, and loadCustomShortcuts().

◆ fetchActionCategory()

KisActionRegistry::ActionCategory KisActionRegistry::fetchActionCategory ( const QString & name) const

Definition at line 203 of file kis_action_registry.cpp.

204{
205 if (!d->actionInfoList.contains(name)) return ActionCategory();
206
207 const ActionInfoItem info = d->actionInfoList.value(name);
208 return ActionCategory(info.collectionName, info.categoryName);
209}

References d.

◆ getActionProperty()

QString KisActionRegistry::getActionProperty ( const QString & name,
const QString & property )
Returns
value property for an action name.

Allow flexible info structure for KisActions, etc.

Definition at line 356 of file kis_action_registry.cpp.

357{
358 ActionInfoItem info = d->actionInfo(name);
359 QDomElement actionXml = info.xmlData;
360 if (actionXml.text().isEmpty()) {
361 dbgAction << "getActionProperty: No XML data found for action" << name;
362 return QString();
363 }
364
365 return getChildContent(actionXml, property);
366
367}

References d, and dbgAction.

◆ hasAction()

bool KisActionRegistry::hasAction ( const QString & name) const
Returns
true if the given action exists

Definition at line 180 of file kis_action_registry.cpp.

181{
182 return d->actionInfoList.contains(name);
183}

References d.

◆ instance()

KisActionRegistry * KisActionRegistry::instance ( )
static

Definition at line 172 of file kis_action_registry.cpp.

173{
174 if (!s_instance.exists()) {
175 dbgRegistry << "initializing KoActionRegistry";
176 }
177 return s_instance;
178}
#define dbgRegistry
Definition kis_debug.h:47

References dbgRegistry.

◆ loadActionFiles()

void KisActionRegistry::loadActionFiles ( )

◆ loadCustomShortcuts() [1/2]

void KisActionRegistry::loadCustomShortcuts ( )

Reload custom shortcuts from kritashortcutsrc

Definition at line 216 of file kis_action_registry.cpp.

217{
218 d->loadCustomShortcuts();
219}

References d.

◆ loadCustomShortcuts() [2/2]

void KisActionRegistry::loadCustomShortcuts ( QString filename = QStringLiteral("kritashortcutsrc"))

◆ loadShortcutScheme()

void KisActionRegistry::loadShortcutScheme ( const QString & schemeName)

loadShortcutScheme

Parameters
schemeName

Definition at line 221 of file kis_action_registry.cpp.

222{
223 // Load scheme file
224 if (schemeName != QStringLiteral("Default")) {
225 QString schemeFileName = KisKShortcutSchemesHelper::schemeFileLocations().value(schemeName);
226 if (schemeFileName.isEmpty() || !QFileInfo(schemeFileName).exists()) {
228 return;
229 }
230 KConfig schemeConfig(schemeFileName, KConfig::SimpleConfig);
231 applyShortcutScheme(&schemeConfig);
232 } else {
233 // Apply default scheme, updating KisActionRegistry data
235 }
236}
void applyShortcutScheme(const KConfigBase *config=0)

References applyShortcutScheme(), and KisKShortcutSchemesHelper::schemeFileLocations().

◆ makeQAction()

QAction * KisActionRegistry::makeQAction ( const QString & name,
QObject * parent = 0 )

Produces a new QAction based on the .action data files.

N.B. this action will not be saved in the registry.

Definition at line 238 of file kis_action_registry.cpp.

239{
240 QAction * a = new QAction(parent);
241 if (!d->actionInfoList.contains(name)) {
242 qWarning() << "Warning: requested data for unknown action" << name;
243 a->setObjectName(name);
244 return a;
245 }
246
247 propertizeAction(name, a);
248 return a;
249}
bool propertizeAction(const QString &name, QAction *a)

References d, and propertizeAction().

◆ notifySettingsUpdated()

void KisActionRegistry::notifySettingsUpdated ( )

Call after settings are changed.

Definition at line 211 of file kis_action_registry.cpp.

212{
213 d->loadCustomShortcuts();
214}

References d.

◆ Private()

KisActionRegistry::Private ( KisActionRegistry * _q)
inline

Definition at line 150 of file kis_action_registry.cpp.

150: q(_q) {}
KisActionRegistry * q

◆ propertizeAction()

bool KisActionRegistry::propertizeAction ( const QString & name,
QAction * a )

Fills the standard QAction properties of an action.

Returns
true if the action was loaded successfully.

Definition at line 312 of file kis_action_registry.cpp.

313{
314 if (!d->actionInfoList.contains(name)) {
315 warnAction << "propertizeAction: No XML data found for action" << name;
316 return false;
317 }
318
319 const ActionInfoItem info = d->actionInfo(name);
320
321 QDomElement actionXml = info.xmlData;
322 if (!actionXml.text().isEmpty()) {
323 // i18n requires converting format from QString.
324 auto getChildContent_i18n = [=](QString node){return quietlyTranslate(getChild(actionXml, node));};
325
326 // Note: the fields in the .action documents marked for translation are determined by extractrc.
327 QString icon = getChildContent(actionXml, "icon");
328 QString text = getChildContent_i18n("text");
329 QString whatsthis = getChildContent_i18n("whatsThis");
330 // tooltip is set in updateShortcut() because shortcut gets appended to the tooltip
331 //QString toolTip = getChildContent_i18n("toolTip");
332 QString statusTip = getChildContent_i18n("statusTip");
333 QString iconText = getChildContent_i18n("iconText");
334 bool isCheckable = getChildContent(actionXml, "isCheckable") == QString("true");
335
336 a->setObjectName(name); // This is helpful, should be added more places in Krita
337 if (!icon.isEmpty()) {
338 a->setIcon(KisIconUtils::loadIcon(icon.toLatin1()));
339 a->setProperty("iconName", QVariant::fromValue(icon)); // test
340 }
341 a->setText(text);
342 a->setObjectName(name);
343 a->setWhatsThis(whatsthis);
344
345 a->setStatusTip(statusTip);
346 a->setIconText(iconText);
347 a->setCheckable(isCheckable);
348 }
349
350 updateShortcut(name, a);
351 return true;
352}
void updateShortcut(const QString &name, QAction *ac)
#define warnAction
Definition kis_debug.h:100
QIcon loadIcon(const QString &name)

References d, KisIconUtils::loadIcon(), updateShortcut(), and warnAction.

◆ registeredShortcutIds()

QList< QString > KisActionRegistry::registeredShortcutIds ( ) const

Definition at line 307 of file kis_action_registry.cpp.

308{
309 return d->actionInfoList.keys();
310}

References d.

◆ sanityCheckPropertized()

bool KisActionRegistry::sanityCheckPropertized ( const QString & name)

Definition at line 302 of file kis_action_registry.cpp.

303{
304 return d->sanityPropertizedShortcuts.contains(name);
305}

References d.

◆ settingsPageSaved()

void KisActionRegistry::settingsPageSaved ( )

Called when "OK" button is pressed in settings dialog.

Definition at line 251 of file kis_action_registry.cpp.

252{
253 // For now, custom shortcuts are dealt with by writing to file and reloading.
255
256 // Announce UI should reload current shortcuts.
257 Q_EMIT shortcutsUpdated();
258}

References loadCustomShortcuts(), and shortcutsUpdated().

◆ shortcutsUpdated

void KisActionRegistry::shortcutsUpdated ( )
signal

◆ updateShortcut()

void KisActionRegistry::updateShortcut ( const QString & name,
QAction * ac )

Definition at line 282 of file kis_action_registry.cpp.

283{
284 const ActionInfoItem &info = d->actionInfo(name);
285 action->setShortcuts(info.effectiveShortcuts());
286 action->setProperty("defaultShortcuts", QVariant::fromValue(info.defaultShortcuts()));
287
288 d->sanityPropertizedShortcuts.insert(name);
289
290 // TODO: KisShortcutsEditor overwrites shortcuts as you edit them, so we cannot know here
291 // if the old shortcut is indeed "old" and must regenerate the tooltip unconditionally.
292
293 QString plainTip = quietlyTranslate(getChild(info.xmlData, "toolTip"));
294 if (action->shortcut().isEmpty()) {
295 action->setToolTip(plainTip);
296 } else {
297 //qDebug() << "action with shortcut:" << name << action->shortcut();
298 action->setToolTip(plainTip + " (" + action->shortcut().toString(QKeySequence::NativeText) + ")");
299 }
300}

References d.

Member Data Documentation

◆ actionInfoList

QMap<QString, ActionInfoItem> KisActionRegistry::actionInfoList

Definition at line 153 of file kis_action_registry.cpp.

◆ d

const QScopedPointer<Private> KisActionRegistry::d
private

Definition at line 136 of file kis_action_registry.h.

◆ q

KisActionRegistry* KisActionRegistry::q

Definition at line 165 of file kis_action_registry.cpp.

◆ sanityPropertizedShortcuts

QSet<QString> KisActionRegistry::sanityPropertizedShortcuts

Definition at line 166 of file kis_action_registry.cpp.


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