MauiKit Controls

mauiapp.h
1/*
2 * <one line to give the program's name and a brief idea of what it does.>
3 * Copyright (C) 2019 camilo <chiguitar@unal.edu.co>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21#include <QObject>
22#include <QQmlEngine>
23
24#include "mauikit_export.h"
25
26#include <KAboutData>
27
28class QQuickWindow;
29class QWindow;
30
31class Notify;
32class KAboutComponent;
33
34/**
35 * @brief The MauiApp class
36 * The MauiApp is a global singleton instance, can be accessed from QML as an attached property, so it can be used by importing `org.mauikit.controls`
37 *
38 * @warning It is needed that the first instance creation is made on the application main entry point before the QML engine creates the window surface, so the style and other parts are correctly loaded.
39 *
40 * Example:
41 * @code
42 * import org.mauikit.controls as Maui
43 *
44 * Maui.ApplicationWindow
45 * {
46 * title: Maui.App.about.name
47 * Maui.CSD.enabled: true
48 * }
49 * @endcode
50 *
51 * @section style Style
52 * By default MauiApp will set the style to "org.mauikit.style" after it has been instanciated, which is the most optimal and feature-rich style to be used with Maui applications. However this can be overriden by a custom one, by either setting the env variable `QT_QUICK_CONTROLS_STYLE` or by code:
53 *
54 * @code
55 * qputenv("QML_DISABLE_DISK_CACHE", "1"); // This is to workaround a bug causing the new style to not be picked up due to the cache of the default or previous one
56 QQuickStyle::setStyle("Imagine");
57 * @endcode
58 */
59class MAUIKIT_EXPORT MauiApp : public QObject
60{
62 // QML_SINGLETON
63 QML_NAMED_ELEMENT(App)
64 QML_ATTACHED(MauiApp)
65 QML_UNCREATABLE("Cannot be created MauiApp")
66 Q_DISABLE_COPY(MauiApp)
67
68 /**
69 * The information metadata about the application.
70 * See the KAboutData documentation for more details.
71 * @note This is the information parsed for feeding the ApplicationWindow's about dialog.
72 */
73 Q_PROPERTY(KAboutData about READ getAbout CONSTANT FINAL)
74
75 /**
76 * The URL to the image asset for the application icon.
77 */
78 Q_PROPERTY(QString iconName READ getIconName WRITE setIconName NOTIFY iconNameChanged)
79
80 /**
81 * An URL link to the application donation page.
82 */
83 Q_PROPERTY(QString donationPage READ getDonationPage WRITE setDonationPage NOTIFY donationPageChanged)
84
85 /**
86 * The formatted MauiKit string version.
87 */
89
90 /**
91 * The main and first Maui.ApplicationWindow to be instanciated.
92 */
93 Q_PROPERTY(QObject *rootComponent READ rootComponent WRITE setRootComponent NOTIFY rootComponentChanged)
94
95public:
96 /**
97 * @private
98 */
99 MauiApp(QObject *parent = nullptr);
100 /**
101 * @brief Retrieves information of the MauiKit framework wrapped into a KAboutComponent object.
102 */
104
105 /**
106 * @private
107 */
108 static MauiApp *qmlAttachedProperties(QObject *object);
109
110 /**
111 * @brief Retrieves the single instance of MauiApp.
112 */
113 static MauiApp *instance();
114
115 /**
116 * @private
117 */
118 static QObject * qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine) {
119 Q_UNUSED(scriptEngine);
120
122 // if(engine)
123 // instance->setRootComponent(engine->rootContext().contextObject());
124 // C++ and QML instance they are the same instance
125 return instance;
126 }
127
128 /**
129 * @brief The formatted MauiKit version string
130 */
131 static QString getMauikitVersion();
132
133 /**
134 * @brief The file URL to the application icon
135 */
136 QString getIconName() const;
137
138 /**
139 * @brief Set the file URL to the application icon.
140 * Usually it is a self contained URL
141 */
142 void setIconName(const QString &value);
143
144 /**
145 * @brief Donation web page link
146 * @return URL link
147 */
148 QString getDonationPage() const;
149
150 /**
151 * @brief Set the donation web page link
152 * @param value the URL link
153 */
154 void setDonationPage(const QString &value);
155
156 /**
157 * @brief Gather information about this module.
158 * @return
159 */
160 KAboutData getAbout() const;
161
162 /**
163 * @brief Define the root element of the Maui Application.
164 * Usually the root element is expected to be a QWindow derived element.
165 * @see ApplicationWindow
166 */
167 Q_INVOKABLE void setRootComponent(QObject *item);
168 QObject * rootComponent();
169
170 /**
171 * @brief Requests to display the about dialog.
172 * @note This will only work if the root component is a Maui ApplicationWindow
173 */
174 Q_INVOKABLE void aboutDialog();
175
176
177private:
178 QObject *m_rootComponent = nullptr;
179
180 QString m_iconName;
181 QString m_donationPage;
182
183 static void setDefaultMauiStyle();
184
185Q_SIGNALS:
186 void iconNameChanged();
187 void donationPageChanged();
188 void currentIconThemeChanged(QString currentIconTheme);
189 void rootComponentChanged();
190};
191
192QML_DECLARE_TYPEINFO(MauiApp, QML_HAS_ATTACHED_PROPERTIES)
193
The MauiApp class The MauiApp is a global singleton instance, can be accessed from QML as an attached...
Definition mauiapp.h:60
static KAboutComponent aboutMauiKit()
Retrieves information of the MauiKit framework wrapped into a KAboutComponent object.
Definition mauiapp.cpp:42
KAboutData about
The information metadata about the application.
Definition mauiapp.h:73
void setIconName(const QString &value)
Set the file URL to the application icon.
Definition mauiapp.cpp:95
QString getDonationPage() const
Donation web page link.
Definition mauiapp.cpp:104
QString iconName
The URL to the image asset for the application icon.
Definition mauiapp.h:78
QString mauikitVersion
The formatted MauiKit string version.
Definition mauiapp.h:88
static MauiApp * instance()
Retrieves the single instance of MauiApp.
Definition mauiapp.cpp:143
QString getIconName() const
The file URL to the application icon.
Definition mauiapp.cpp:90
KAboutData getAbout() const
Gather information about this module.
Definition mauiapp.cpp:118
QString donationPage
An URL link to the application donation page.
Definition mauiapp.h:83
Q_INVOKABLE void setRootComponent(QObject *item)
Define the root element of the Maui Application.
Definition mauiapp.cpp:148
void setDonationPage(const QString &value)
Set the donation web page link.
Definition mauiapp.cpp:109
QObject * rootComponent
The main and first Maui.ApplicationWindow to be instanciated.
Definition mauiapp.h:93
static QString getMauikitVersion()
The formatted MauiKit version string.
Definition mauiapp.cpp:85
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 18 2025 12:16:12 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.