AbstractKirigamiApplication Class

The main container for your actions. More...

Header: #include <AbstractKirigamiApplication>
Inherits: QObject

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.StatefulApplication as StatefulApplication

StatefulApplication.StatefulWindow {
    id: root

    application: MyKoolApp {}

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

{}

Member Function Documentation

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

Default constructor of AbstractKirigamiApplication

[virtual noexcept] AbstractKirigamiApplication::~AbstractKirigamiApplication()

Default destructor of AbstractKirigamiApplication

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

Get the named action. 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] QList<KirigamiActionCollection *> AbstractKirigamiApplication::actionCollections() const

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

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.

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.