kcm/decoration: Port to ecm_add_qml_module and declarative type registration

This makes the types visible to QML tooling
This commit is contained in:
Nicolas Fella 2024-03-23 12:38:57 +01:00 committed by Vlad Zahorodnii
parent c8e0568022
commit 9e9da67fc0
11 changed files with 45 additions and 72 deletions

View file

@ -1,17 +1,18 @@
set(plugin_SRCS
ecm_add_qml_module(kdecorationprivatedeclarative URI org.kde.kwin.private.kdecoration DEPENDENCIES QtCore QtQuick GENERATE_PLUGIN_SOURCE)
target_sources(kdecorationprivatedeclarative PRIVATE
previewbutton.cpp
previewbridge.cpp
previewclient.cpp
previewitem.cpp
previewsettings.cpp
plugin.cpp
buttonsmodel.cpp
../../../decorations/decorationpalette.cpp
../../../decorations/decorations_logging.cpp
types.h
)
add_library(kdecorationprivatedeclarative SHARED ${plugin_SRCS})
target_link_libraries(kdecorationprivatedeclarative
target_link_libraries(kdecorationprivatedeclarative PRIVATE
KDecoration2::KDecoration
KDecoration2::KDecoration2Private
Qt::DBus
@ -22,5 +23,4 @@ target_link_libraries(kdecorationprivatedeclarative
KF6::Service
)
install(TARGETS kdecorationprivatedeclarative DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/kwin/private/kdecoration )
install(FILES qmldir DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/kwin/private/kdecoration )
ecm_finalize_qml_module(kdecorationprivatedeclarative)

View file

@ -8,6 +8,8 @@
#include <KDecoration2/DecorationButton>
#include <QAbstractListModel>
#include <QQmlEngine>
namespace KDecoration2
{
@ -18,6 +20,7 @@ class PreviewBridge;
class ButtonsModel : public QAbstractListModel
{
Q_OBJECT
QML_ELEMENT
public:
explicit ButtonsModel(const QList<DecorationButtonType> &buttons, QObject *parent = nullptr);
explicit ButtonsModel(QObject *parent = nullptr);

View file

@ -1,39 +0,0 @@
/*
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include "plugin.h"
#include "buttonsmodel.h"
#include "previewbridge.h"
#include "previewbutton.h"
#include "previewclient.h"
#include "previewitem.h"
#include "previewsettings.h"
#include <KDecoration2/Decoration>
#include <KDecoration2/DecorationShadow>
namespace KDecoration2
{
namespace Preview
{
void Plugin::registerTypes(const char *uri)
{
Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.kwin.private.kdecoration"));
qmlRegisterType<KDecoration2::Preview::BridgeItem>(uri, 1, 0, "Bridge");
qmlRegisterType<KDecoration2::Preview::Settings>(uri, 1, 0, "Settings");
qmlRegisterType<KDecoration2::Preview::PreviewItem>(uri, 1, 0, "Decoration");
qmlRegisterType<KDecoration2::Preview::PreviewButtonItem>(uri, 1, 0, "Button");
qmlRegisterType<KDecoration2::Preview::ButtonsModel>(uri, 1, 0, "ButtonsModel");
qmlRegisterAnonymousType<KDecoration2::Preview::PreviewClient>(uri, 1);
qmlRegisterAnonymousType<KDecoration2::Decoration>(uri, 1);
qmlRegisterAnonymousType<KDecoration2::DecorationShadow>(uri, 1);
qmlRegisterAnonymousType<KDecoration2::Preview::PreviewBridge>(uri, 1);
}
}
}
#include "moc_plugin.cpp"

View file

@ -1,24 +0,0 @@
/*
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#pragma once
#include <QQmlExtensionPlugin>
namespace KDecoration2
{
namespace Preview
{
class Plugin : public QQmlExtensionPlugin
{
Q_PLUGIN_METADATA(IID "org.kde.kdecoration2")
Q_OBJECT
public:
void registerTypes(const char *uri) override;
};
}
}

View file

@ -10,6 +10,7 @@
#include <QList>
#include <QPointer>
#include <QQmlEngine>
class QQuickItem;
@ -24,9 +25,11 @@ class PreviewClient;
class PreviewItem;
class PreviewSettings;
class PreviewBridge : public DecorationBridge
class PreviewBridge : public KDecoration2::DecorationBridge
{
Q_OBJECT
QML_ANONYMOUS
Q_PROPERTY(QString plugin READ plugin WRITE setPlugin NOTIFY pluginChanged)
Q_PROPERTY(QString theme READ theme WRITE setTheme NOTIFY themeChanged)
Q_PROPERTY(QString kcmoduleName READ kcmoduleName WRITE setKcmoduleName NOTIFY kcmoduleNameChanged)
@ -85,6 +88,7 @@ private:
class BridgeItem : public QObject
{
Q_OBJECT
QML_NAMED_ELEMENT(Bridge)
Q_PROPERTY(QString plugin READ plugin WRITE setPlugin NOTIFY pluginChanged)
Q_PROPERTY(QString theme READ theme WRITE setTheme NOTIFY themeChanged)
Q_PROPERTY(QString kcmoduleName READ kcmoduleName WRITE setKcmoduleName NOTIFY kcmoduleNameChanged)

View file

@ -22,6 +22,7 @@ class Settings;
class PreviewButtonItem : public QQuickPaintedItem
{
Q_OBJECT
QML_NAMED_ELEMENT(Button)
Q_PROPERTY(KDecoration2::Preview::PreviewBridge *bridge READ bridge WRITE setBridge NOTIFY bridgeChanged)
Q_PROPERTY(KDecoration2::Preview::Settings *settings READ settings WRITE setSettings NOTIFY settingsChanged)
Q_PROPERTY(int type READ typeAsInt WRITE setType NOTIFY typeChanged)

View file

@ -10,6 +10,7 @@
#include <KDecoration2/Private/DecoratedClientPrivate>
#include <QObject>
#include <QPalette>
#include <QQmlEngine>
class QAbstractItemModel;
@ -20,6 +21,7 @@ namespace Preview
class PreviewClient : public QObject, public ApplicationMenuEnabledDecoratedClientPrivate
{
Q_OBJECT
QML_ANONYMOUS
Q_PROPERTY(KDecoration2::Decoration *decoration READ decoration CONSTANT)
Q_PROPERTY(QString caption READ caption WRITE setCaption NOTIFY captionChanged)
Q_PROPERTY(QIcon icon READ icon WRITE setIcon NOTIFY iconChanged)

View file

@ -23,6 +23,7 @@ class Settings;
class PreviewItem : public QQuickPaintedItem
{
Q_OBJECT
QML_NAMED_ELEMENT(Decoration)
Q_PROPERTY(KDecoration2::Decoration *decoration READ decoration NOTIFY decorationChanged)
Q_PROPERTY(KDecoration2::Preview::PreviewBridge *bridge READ bridge WRITE setBridge NOTIFY bridgeChanged)
Q_PROPERTY(KDecoration2::Preview::Settings *settings READ settings WRITE setSettings NOTIFY settingsChanged)

View file

@ -10,6 +10,7 @@
#include <QAbstractListModel>
#include <QObject>
#include <QPointer>
#include <QQmlEngine>
namespace KDecoration2
{
@ -116,6 +117,7 @@ private:
class Settings : public QObject
{
Q_OBJECT
QML_ELEMENT
Q_PROPERTY(KDecoration2::Preview::PreviewBridge *bridge READ bridge WRITE setBridge NOTIFY bridgeChanged)
Q_PROPERTY(KDecoration2::DecorationSettings *settings READ settingsPointer NOTIFY settingsChanged)
Q_PROPERTY(int borderSizesIndex READ borderSizesIndex WRITE setBorderSizesIndex NOTIFY borderSizesIndexChanged)

View file

@ -1,2 +0,0 @@
module org.kde.kwin.private.kdecoration
plugin kdecorationprivatedeclarative

View file

@ -0,0 +1,25 @@
/*
SPDX-FileCopyrightText: 2024 Nicolas Fella <nicolas.fella@gmx.de>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#pragma once
#include <QQmlEngine>
#include <KDecoration2/Decoration>
#include <KDecoration2/DecorationShadow>
struct DecorationForeign
{
Q_GADGET
QML_ANONYMOUS
QML_FOREIGN(KDecoration2::Decoration)
};
struct DecorationShadowForeign
{
Q_GADGET
QML_ANONYMOUS
QML_FOREIGN(KDecoration2::DecorationShadow)
};