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 */
51class MAUIKIT_EXPORT MauiApp : public QObject
52{
53 Q_OBJECT
54 // QML_SINGLETON
55 QML_NAMED_ELEMENT(App)
56 QML_ATTACHED(MauiApp)
57 QML_UNCREATABLE("Cannot be created MauiApp")
58 Q_DISABLE_COPY(MauiApp)
59
60 /**
61 * The information metadata about the application.
62 * See the KAboutData documentation for more details.
63 * @note This is the information parsed for feeding the ApplicationWindow's about dialog.
64 */
65 Q_PROPERTY(KAboutData about READ getAbout CONSTANT FINAL)
66
67 /**
68 * The URL to the image asset for the application icon.
69 */
70 Q_PROPERTY(QString iconName READ getIconName WRITE setIconName NOTIFY iconNameChanged)
71
72 /**
73 * An URL link to the application donation page.
74 */
75 Q_PROPERTY(QString donationPage READ getDonationPage WRITE setDonationPage NOTIFY donationPageChanged)
76
77 /**
78 * The formatted MauiKit string version.
79 */
80 Q_PROPERTY(QString mauikitVersion READ getMauikitVersion CONSTANT FINAL)
81
82 Q_PROPERTY(QObject *rootComponent READ rootComponent WRITE setRootComponent NOTIFY rootComponentChanged)
83
84public:
85 /**
86 * @private
87 */
88 MauiApp(QObject *parent = nullptr);
89 /**
90 * @brief Retrieves information of the MauiKit framework wrapped into a KAboutComponent object.
91 */
92 static KAboutComponent aboutMauiKit();
93
94 /**
95 * @private
96 */
97 static MauiApp *qmlAttachedProperties(QObject *object);
98
99 /**
100 * @brief Retrieves the single instance of MauiApp.
101 */
102 static MauiApp *instance();
103
104 /**
105 * @private
106 */
107 static QObject * qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine) {
108 Q_UNUSED(scriptEngine);
109
110 auto instance = MauiApp::instance();
111 // if(engine)
112 // instance->setRootComponent(engine->rootContext().contextObject());
113 // C++ and QML instance they are the same instance
114 return instance;
115 }
116
117 /**
118 * @brief The formatted MauiKit version string
119 */
120 static QString getMauikitVersion();
121
122 /**
123 * @brief The file URL to the application icon
124 */
125 QString getIconName() const;
126
127 /**
128 * @brief Set the file URL to the application icon.
129 * Usually it is a self contained URL
130 */
131 void setIconName(const QString &value);
132
133 /**
134 * @brief Donation web page link
135 * @return URL link
136 */
137 QString getDonationPage() const;
138
139 /**
140 * @brief Set the donation web page link
141 * @param value the URL link
142 */
143 void setDonationPage(const QString &value);
144
145 /**
146 * @brief Gather information about this module.
147 * @return
148 */
149 KAboutData getAbout() const;
150
151 /**
152 * @brief Define the root element of the Maui Application.
153 * Usually the root element is expected to be a QWindow derived element.
154 * @see ApplicationWindow
155 */
156 Q_INVOKABLE void setRootComponent(QObject *item);
157 QObject * rootComponent();
158
159 /**
160 * @brief Requests to display the about dialog.
161 * @note This will only work if the root component is a Maui ApplicationWindow
162 */
163 Q_INVOKABLE void aboutDialog();
164
165
166private:
167 QObject *m_rootComponent = nullptr;
168
169 QString m_iconName;
170 QString m_donationPage;
171
172 static void setDefaultMauiStyle();
173
175 void iconNameChanged();
176 void donationPageChanged();
177 void currentIconThemeChanged(QString currentIconTheme);
178 void rootComponentChanged();
179};
180
181QML_DECLARE_TYPEINFO(MauiApp, QML_HAS_ATTACHED_PROPERTIES)
182
The MauiApp class The MauiApp is a global singleton instance, can be accessed from QML as an attached...
Definition mauiapp.h:52
static MauiApp * instance()
Retrieves the single instance of MauiApp.
Definition mauiapp.cpp:144
Q_SIGNALSQ_SIGNALS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:56:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.