diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 7a31d2249..6c540b39b 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -5,6 +5,7 @@ find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core Gui Quick) add_subdirectory(applet-example) +add_subdirectory(applet-widget-example) add_subdirectory(applet-example-data) add_subdirectory(containment-example) add_subdirectory(panel-example) diff --git a/example/applet-widget-example/CMakeLists.txt b/example/applet-widget-example/CMakeLists.txt new file mode 100644 index 000000000..2876a7b51 --- /dev/null +++ b/example/applet-widget-example/CMakeLists.txt @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +# +# SPDX-License-Identifier: GPL-3.0-or-later + +find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Widgets) +find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Widget) + +add_library(ds-example-applet-widget SHARED + exampleapplet.h + exampleapplet.cpp +) + +target_link_libraries(ds-example-applet-widget PRIVATE + dde-shell-frame + Qt${QT_VERSION_MAJOR}::Widgets + Dtk${DTK_VERSION_MAJOR}::Widget +) + +ds_install_package(PACKAGE org.deepin.ds.example.applet-widget TARGET ds-example-applet-widget) diff --git a/example/applet-widget-example/exampleapplet.cpp b/example/applet-widget-example/exampleapplet.cpp new file mode 100644 index 000000000..d8358fe7c --- /dev/null +++ b/example/applet-widget-example/exampleapplet.cpp @@ -0,0 +1,41 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "exampleapplet.h" + +#include "pluginfactory.h" + +#include +#include +#include + +#include +#include + +DGUI_USE_NAMESPACE +DWIDGET_USE_NAMESPACE + +WidgetExampleApplet::WidgetExampleApplet(QObject *parent) + : DApplet(parent) +{ +} + +bool WidgetExampleApplet::init() +{ + auto widget = new QWidget(); + DPlatformWindowHandle handle(widget); + widget->setFixedSize(QSize(200, 200)); + auto layout = new QVBoxLayout(widget); + auto btn = new DIconButton(); + btn->setIcon(DIconTheme::findQIcon("deepin-home")); + btn->setIconSize(QSize(36, 36)); + layout->addWidget(btn); + widget->show(); + + return DApplet::init(); +} + +D_APPLET_CLASS(WidgetExampleApplet) + +#include "exampleapplet.moc" diff --git a/example/applet-widget-example/exampleapplet.h b/example/applet-widget-example/exampleapplet.h new file mode 100644 index 000000000..4c505eb94 --- /dev/null +++ b/example/applet-widget-example/exampleapplet.h @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include "applet.h" + +DS_USE_NAMESPACE + +class WidgetExampleApplet : public DApplet +{ + Q_OBJECT +public: + explicit WidgetExampleApplet(QObject *parent = nullptr); + + virtual bool init() override; +}; diff --git a/example/applet-widget-example/package/metadata.json b/example/applet-widget-example/package/metadata.json new file mode 100644 index 000000000..875fe0a4a --- /dev/null +++ b/example/applet-widget-example/package/metadata.json @@ -0,0 +1,7 @@ +{ + "Plugin": { + "Version": "1.0", + "Id": "org.deepin.ds.example.applet-widget", + "Parent": "org.deepin.ds.example.containment" + } +}