AbstractKirigamiApplication Class

The main container for your actions. More...

Header: #include <AbstractKirigamiApplication>
Inherits: QObject

Properties

Public Functions

AbstractKirigamiApplication(QObject *parent = nullptr)
virtual ~AbstractKirigamiApplication()
QAction *action(const QString &actionName)
virtual QList<KirigamiActionCollection *> actionCollections() const
QObject *configurationView() const
KirigamiActionCollection *mainCollection() const
void setConfigurationView(QObject *configurationView)

Signals

Protected Functions

void readSettings()
virtual void setupActions()

Detailed Description

AbstractKirigamiApplication is a class that needs to be inherited in your application.

It allows to expose the various actions of your application to the QML frontend. Depending on the complexitiy of the application, you can either reimplement setupActions only and put all your actions inside the mainCollection, or, if you want to organize your actions in multiple collections, you can also expose the custom collections by overwriting actionCollections.

class MyKoolApp : public AbstractKirigamiApplication
{
    Q_OBJECT
    QML_ELEMENT

 public:
    explicit MyKoolApp(QObject *parent = nullptr);

    void setupActions() override;
};

MyKoolApp::MyKoolApp(QObject *parent)
    : AbstractKirigamiApplication(parent)
{
     setupActions();
}

void MyKoolApp::setupActions()
{
    AbstractKirigamiApplication::setupActions();

    auto actionName = QLatin1String("add_notebook");
    if (KAuthorized::authorizeAction(actionName)) {
        auto action = mainCollection()->addAction(actionName, this, &MyKoolApp::newNotebook);
        action->setText(i18nc("@action:inmenu", "New Notebook"));
        action->setIcon(QIcon::fromTheme(QStringLiteral("list-add-symbolic")));
        mainCollection()->addAction(action->objectName(), action);
        mainCollection()->setDefaultShortcut(action, QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_N));
    }
}

The application object then need to be assigned to the application property in a StatefulWindow.

import org.kde.kirigamiaddons.actions as KirigamiActions

KirigamiActions.StatefulWindow {
    id: root

    application: MyKoolApp {}

    KirigamiActions.Action {
        actionName: 'add_notebook'
        application: root.application
    }
}

{}

Property Documentation

configurationView : QObject*

This property holds the configurationView of the application

When set, AbstractKirigamiApplication will setup a "options_configure" action that will open the configurationView when triggered.

Access functions:

QObject *configurationView() const
void setConfigurationView(QObject *configurationView)

Notifier signal:

Member Function Documentation

[explicit] AbstractKirigamiApplication::AbstractKirigamiApplication(QObject *parent = nullptr)

Default constructor of AbstractKirigamiApplication parent the parent object

[virtual noexcept] AbstractKirigamiApplication::~AbstractKirigamiApplication()

Default destructor of AbstractKirigamiApplication

[invokable] QAction *AbstractKirigamiApplication::action(const QString &actionName)

Get the named action. actionName the name of the action to look up. Returns nullptr is not such action is defined.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

[virtual invokable] QList<KirigamiActionCollection *> AbstractKirigamiApplication::actionCollections() const

Return the list of KirigamiActionCollection setup in your application. Overwrite this method if you are using custom collections.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

[signal] void AbstractKirigamiApplication::actionCollectionsChanged()

Emitted when an action collection is assigned to this application.

QObject *AbstractKirigamiApplication::configurationView() const

Getter for the configurationView property.

Note: Getter function for property configurationView.

See also setConfigurationView().

[signal] void AbstractKirigamiApplication::configurationViewChanged()

Changed signal for the configurationView property.

Note: Notifier signal for property configurationView.

KirigamiActionCollection *AbstractKirigamiApplication::mainCollection() const

Return the main action collection.

[protected] void AbstractKirigamiApplication::readSettings()

Read the configured settings for the action.

void AbstractKirigamiApplication::setConfigurationView(QObject *configurationView)

Setter for the configurationView property. configurationView the new configuration view.

Note: Setter function for property configurationView.

See also configurationView().

[virtual protected] void AbstractKirigamiApplication::setupActions()

Entry points to declare your actions.

Don't forget to call the parent implementation to get the following actions setup for you:

  • CommandBar
  • About page for your application
  • About page for KDE

Once the actions are setup, call readSettings to read the configured shortcuts.