16#include "config-xmlgui.h"
22#include <kconfiggroup.h>
23#include <ksharedconfig.h>
26#include <QDomDocument>
28#include <QGuiApplication>
38#if defined(KCONFIG_BEFORE_5_24)
39# define authorizeAction authorizeKAction
120 return this->findChildren<KisKActionCategory *>();
126 if (c->
text() == name) {
149 if (!name.isEmpty()) {
181 qWarning() <<
"this does not work on a KisKActionCollection containing actions!";
184 if (!cName.isEmpty()) {
206 if (!QGuiApplication::applicationDisplayName().
isEmpty()) {
207 return QGuiApplication::applicationDisplayName();
209 return QCoreApplication::applicationName();
226 if (!
action->actionGroup()) {
234 QSet<QActionGroup *> set;
236 if (
action->actionGroup()) {
237 set.insert(
action->actionGroup());
253 const QString objectName =
action->objectName();
254 QString indexName = name;
256 if (indexName.isEmpty()) {
258 indexName = objectName;
262 action->setObjectName(indexName);
267 if (indexName.isEmpty()) {
268 QTextStream(&indexName) << (
void *)
action;
270 action->setObjectName(indexName);
275 Q_ASSERT(!
action->objectName().isEmpty());
293 if (oldIndex != -1) {
303 widget->addAction(
action);
306 connect(
action, SIGNAL(destroyed(QObject*)), SLOT(_k_actionDestroyed(QObject*)));
342 widget->removeAction(
action);
357 const QObject *receiver,
const char *member)
366 action->setObjectName(name);
373 QAction *a =
new QAction(
this);
374 if (receiver && member) {
375 connect(a, SIGNAL(triggered(
bool)), receiver, member);
383 return shortcuts.isEmpty() ? QKeySequence() : shortcuts.first();
398 action->setShortcuts(shortcuts);
399 action->setProperty(
"defaultShortcuts", QVariant::fromValue(shortcuts));
405 const QVariant
value =
action->property(
"isShortcutConfigurable");
406 return value.isValid() ?
value.toBool() :
true;
411 action->setProperty(
"isShortcutConfigurable", configurable);
428 for (QMap<QString, QAction *>::ConstIterator it =
d->
actionByName.constBegin();
430 actionRegistry->updateShortcut(it.key(), it.value());
438 ar->loadCustomShortcuts();
440 for (QMap<QString, QAction *>::ConstIterator it =
d->
actionByName.constBegin();
442 QAction *
action = it.value();
448 QString actionName = it.key();
449 ar->updateShortcut(actionName,
action);
459 if (!kxmlguiClient || kxmlguiClient->
xmlFile().isEmpty()) {
464 QString attrShortcut = QStringLiteral(
"shortcut");
469 doc.setContent(sXml);
477 for (QMap<QString, QAction *>::ConstIterator it =
actionByName.constBegin();
479 QAction *action = it.value();
484 QString actionName = it.key();
488 if (actionName.startsWith(QLatin1String(
"unnamed-"))) {
489 qCritical() <<
"Skipped writing shortcut for action " << actionName <<
"(" << action->text() <<
")!";
498 if (act_elem.isNull()) {
502 if (bSameAsDefault) {
503 act_elem.removeAttribute(attrShortcut);
504 if (act_elem.attributes().count() == 1) {
505 elem.removeChild(act_elem);
508 act_elem.setAttribute(attrShortcut, QKeySequence::listToString(action->shortcuts()));
519 QAction *oneAction)
const
529 KConfigGroup cg(KSharedConfig::openConfig(),
configGroup());
536 writeActions.append(oneAction);
541 for (QMap<QString, QAction *>::ConstIterator it =
d->
actionByName.constBegin();
544 QAction *
action = it.value();
549 QString actionName = it.key();
553 if (actionName.startsWith(QLatin1String(
"unnamed-"))) {
554 qCritical() <<
"Skipped saving shortcut for action without name " \
561 bool bConfigHasAction = !config->readEntry(actionName, QString()).isEmpty();
565 KConfigGroup::WriteConfigFlags flags = KConfigGroup::Persistent;
567 if (writeScheme || !bSameAsDefault) {
570 QString s = QKeySequence::listToString(
action->shortcuts());
572 s = QStringLiteral(
"none");
574 config->writeEntry(actionName, s, flags);
575 }
else if (bConfigHasAction) {
578 config->deleteEntry(actionName, flags);
588 QAction *
action = qobject_cast<QAction *>(sender());
601 QAction *
action = qobject_cast<QAction *>(sender());
619 if (signal.methodSignature() ==
"actionHighlighted(QAction*)" ||
620 signal.methodSignature() ==
"actionHovered(QAction*)") {
628 }
else if (signal.methodSignature() ==
"actionTriggered(QAction*)") {
637 QObject::connectNotify(signal);
648 if (!widget->actions().contains(
action)) {
649 widget->addAction(
action);
660 connect(widget, SIGNAL(destroyed(QObject*)),
this, SLOT(_k_associatedWidgetDestroyed(QObject*)));
667 widget->removeAction(
action);
671 disconnect(widget, SIGNAL(destroyed(QObject*)),
this, SLOT(_k_associatedWidgetDestroyed(QObject*)));
682 const auto indexOf = [&](
const QObject *action,
int from = 0) ->
int {
683 for (
int i = from; i <
actions.size(); i++) {
691 int index = indexOf(action);
699 Q_ASSERT(indexOf(action, index + 1) == -1);
702 const QString name = action->objectName();
729 widget->removeAction(
action);
740#include "moc_kactioncollection.cpp"
float value(const T *src, size_t ch)
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
static KisActionRegistry * instance()
void unlistAction(QAction *action)
QAction * addAction(const QString &name, QAction *action)
KisKActionCollectionPrivate()
bool writeKisKXMLGUIConfigFile()
const KisKXMLGUIClient * m_parentGUIClient
void _k_actionDestroyed(QObject *obj)
QString m_componentDisplayName
QAction * unlistAction(QObject *)
QMap< QString, QAction * > actionByName
void _k_associatedWidgetDestroyed(QObject *obj)
void setComponentForAction(QAction *action)
QList< QAction * > actions
static QList< KisKActionCollection * > s_allCollections
QList< QWidget * > associatedWidgets
A container for a set of QAction objects.
bool isShortcutsConfigurable(QAction *action) const
Q_INVOKABLE void setDefaultShortcuts(QAction *action, const QList< QKeySequence > &shortcuts)
void inserted(QAction *action)
QList< QKeySequence > defaultShortcuts(QAction *action) const
void setComponentDisplayName(const QString &displayName)
QAction * takeAction(QAction *action)
QT_MOC_COMPAT void actionHighlighted(QAction *action)
QList< KisKActionCategory * > categories() const
QString componentName() const
void setConfigGroup(const QString &group)
QList< QWidget * > associatedWidgets() const
void setDefaultShortcut(QAction *action, const QKeySequence &shortcut)
Q_INVOKABLE QAction * addAction(const QString &name, QAction *action)
const QList< QAction * > actionsWithoutGroup() const
const QList< QActionGroup * > actionGroups() const
QString componentDisplayName() const
const KisKXMLGUIClient * parentGUIClient() const
virtual void slotActionTriggered()
KisKActionCollection(QObject *parent, const QString &cName=QString())
KisKActionCategory * getCategory(const QString &categoryName)
void associateWidget(QWidget *widget) const
class KisKActionCollectionPrivate *const d
void addActions(const QList< QAction * > &actions)
QKeySequence defaultShortcut(QAction *action) const
void removeAssociatedWidget(QWidget *widget)
static const QList< KisKActionCollection * > & allCollections()
void writeSettings(KConfigGroup *config=0, bool writeScheme=false, QAction *oneAction=0) const
Q_INVOKABLE QAction * addCategorizedAction(const QString &name, QAction *action, const QString &categoryName)
void setComponentName(const QString &componentName)
void clearAssociatedWidgets()
void setShortcutsConfigurable(QAction *action, bool configurable)
~KisKActionCollection() override
void actionTriggered(QAction *action)
QAction * action(int index) const
void connectNotify(const QMetaMethod &signal) override
Overridden to perform connections when someone wants to know whether an action was highlighted or tri...
void removeAction(QAction *action)
QList< QAction * > actions() const
virtual QT_MOC_COMPAT void slotActionHighlighted()
void addAssociatedWidget(QWidget *widget)
void actionHovered(QAction *action)
virtual QString xmlFile() const
virtual QString localXMLFile() const
static QDomElement actionPropertiesElement(QDomDocument &doc)
static bool saveConfigFile(const QDomDocument &doc, const QString &filename, const QString &componentName=QString())
static QString readConfigFile(const QString &filename, const QString &componentName=QString())
static QDomElement findActionByName(QDomElement &elem, const QString &sName, bool create)
QAction * create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent)