forked from openkylin/ukui-menu
添加应用组件
This commit is contained in:
parent
240c1b04f8
commit
8bc2709564
|
@ -95,6 +95,7 @@ set(SOURCE_FILES
|
||||||
src/extension/extensions/recent-file-extension.cpp src/extension/extensions/recent-file-extension.h
|
src/extension/extensions/recent-file-extension.cpp src/extension/extensions/recent-file-extension.h
|
||||||
src/utils/app-page-header-utils.cpp src/utils/app-page-header-utils.h
|
src/utils/app-page-header-utils.cpp src/utils/app-page-header-utils.h
|
||||||
src/utils/power-button.cpp src/utils/power-button.h
|
src/utils/power-button.cpp src/utils/power-button.h
|
||||||
|
src/utils/app-manager.cpp src/utils/app-manager.h
|
||||||
)
|
)
|
||||||
|
|
||||||
# qrc文件
|
# qrc文件
|
||||||
|
|
|
@ -1,24 +1,39 @@
|
||||||
import QtQuick 2.0
|
import QtQuick 2.12
|
||||||
import QtQuick.Layouts 1.12
|
import QtQuick.Layouts 1.12
|
||||||
|
import QtQuick.Controls 2.5
|
||||||
|
import org.ukui.menu.core 1.0
|
||||||
|
|
||||||
Item {
|
StyleBackground {
|
||||||
RowLayout {
|
anchors.fill: parent
|
||||||
|
radius: 4
|
||||||
|
useStyleTransparent: false
|
||||||
|
alpha: control.containsPress ? 0.82 : control.containsMouse ? 0.55 : 0.00
|
||||||
|
ToolTip.visible: content.textTruncated && control.containsMouse
|
||||||
|
ToolTip.text: name
|
||||||
|
|
||||||
|
IconLabel {
|
||||||
|
id: content
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
Image {
|
iconHeight: 32; iconWidth: iconHeight
|
||||||
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
|
appName: name; appIcon: icon
|
||||||
Layout.preferredWidth: 32
|
display: Display.TextBesideIcon
|
||||||
Layout.preferredHeight: 32
|
spacing: 12
|
||||||
source: icon
|
}
|
||||||
|
MouseArea {
|
||||||
|
id: control
|
||||||
|
anchors.fill: parent
|
||||||
|
hoverEnabled: true
|
||||||
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||||
|
|
||||||
|
onPressed: {
|
||||||
|
if (mouse.button === Qt.RightButton) {
|
||||||
|
console.log("RightButtononPressed:",mouse.x,mouse.y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
onClicked: {
|
||||||
Text {
|
if (mouse.button === Qt.LeftButton) {
|
||||||
Layout.fillWidth: true
|
appListView.model.appClicked(index);
|
||||||
Layout.fillHeight: true
|
}
|
||||||
Layout.leftMargin: 5
|
|
||||||
|
|
||||||
horizontalAlignment: Qt.AlignLeft
|
|
||||||
verticalAlignment: Qt.AlignVCenter
|
|
||||||
text: name
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,14 +12,17 @@ Item {
|
||||||
property string appIcon: ""
|
property string appIcon: ""
|
||||||
// 上下布局spacing:0 左右布局spacing:12
|
// 上下布局spacing:0 左右布局spacing:12
|
||||||
property int spacing: 2
|
property int spacing: 2
|
||||||
|
property bool textTruncated: iconText.truncated
|
||||||
state: root.display
|
state: root.display
|
||||||
|
|
||||||
states: [
|
states: [
|
||||||
State {
|
State {
|
||||||
name: Display.TextBesideIcon
|
name: Display.TextBesideIcon
|
||||||
AnchorChanges {
|
PropertyChanges {
|
||||||
target: iconImage
|
target: iconImage
|
||||||
anchors.verticalCenter: root.verticalCenter
|
anchors.verticalCenter: root.verticalCenter
|
||||||
|
anchors.left: root.left
|
||||||
|
anchors.leftMargin: root.spacing
|
||||||
}
|
}
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: iconText
|
target: iconText
|
||||||
|
|
|
@ -18,32 +18,60 @@
|
||||||
|
|
||||||
import QtQuick 2.0
|
import QtQuick 2.0
|
||||||
import QtQml 2.12
|
import QtQml 2.12
|
||||||
|
import QtQuick.Controls 2.5
|
||||||
|
import QtQuick.Layouts 1.12
|
||||||
import AppControls2 1.0 as AppControls2
|
import AppControls2 1.0 as AppControls2
|
||||||
import org.ukui.menu.core 1.0
|
import org.ukui.menu.core 1.0
|
||||||
|
|
||||||
ListView {
|
Item {
|
||||||
property string title: ""
|
property string title: ""
|
||||||
model: modelManager.getAppModel()
|
|
||||||
delegate: Component {
|
MouseArea {
|
||||||
Loader {
|
id: appListArea
|
||||||
width: ListView.view ? ListView.view.width : 0
|
hoverEnabled: true
|
||||||
height: 40
|
anchors.fill: parent
|
||||||
property int index: model.index
|
|
||||||
property int type: model.type
|
RowLayout {
|
||||||
property string name: model.name
|
anchors.fill: parent
|
||||||
property string icon: model.icon
|
spacing: 0
|
||||||
sourceComponent: {
|
|
||||||
if (type === DataType.Normal) {
|
ListView {
|
||||||
return appItem;
|
id: appListView
|
||||||
}
|
spacing: 4
|
||||||
if (type === DataType.Folder) {
|
Layout.fillHeight: true
|
||||||
return folderItem;
|
Layout.fillWidth: true
|
||||||
}
|
ScrollBar.vertical: appListScrollBar
|
||||||
if (type === DataType.Label) {
|
model: modelManager.getAppModel()
|
||||||
return labelItem;
|
|
||||||
|
delegate: Component {
|
||||||
|
Loader {
|
||||||
|
width: ListView.view ? ListView.view.width : 0
|
||||||
|
height: 40
|
||||||
|
property int index: model.index
|
||||||
|
property int type: model.type
|
||||||
|
property string name: model.name
|
||||||
|
property string icon: model.icon
|
||||||
|
sourceComponent: {
|
||||||
|
if (type === DataType.Normal) {
|
||||||
|
return appItem;
|
||||||
|
}
|
||||||
|
if (type === DataType.Folder) {
|
||||||
|
return folderItem;
|
||||||
|
}
|
||||||
|
if (type === DataType.Label) {
|
||||||
|
return labelItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AppControls2.ScrollBar {
|
||||||
|
id: appListScrollBar
|
||||||
|
Layout.fillHeight: true
|
||||||
|
Layout.preferredWidth: 14
|
||||||
|
visible: appListArea.containsMouse
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,3 +90,4 @@ ListView {
|
||||||
AppControls2.FolderItem {}
|
AppControls2.FolderItem {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import QtQuick 2.0
|
import QtQuick 2.12
|
||||||
import QtQuick.Layouts 1.12
|
import QtQuick.Layouts 1.12
|
||||||
|
import QtQuick.Controls 2.5
|
||||||
import AppControls2 1.0 as AppControls2
|
import AppControls2 1.0 as AppControls2
|
||||||
import org.ukui.menu.core 1.0
|
import org.ukui.menu.core 1.0
|
||||||
|
|
||||||
|
@ -37,11 +37,10 @@ AppControls2.StyleBackground {
|
||||||
}
|
}
|
||||||
|
|
||||||
AppList {
|
AppList {
|
||||||
id: appList
|
clip: true
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
Layout.leftMargin: 16
|
Layout.leftMargin: 4
|
||||||
clip: true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "model.h"
|
#include "model.h"
|
||||||
|
#include "app-manager.h"
|
||||||
#include "data-provider-manager.h"
|
#include "data-provider-manager.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
@ -92,4 +93,13 @@ QVariantList AppModel::folderApps(const QString &folderName)
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AppModel::appClicked(const int &index)
|
||||||
|
{
|
||||||
|
if (index < 0 || index >= m_apps.size()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AppManager::instance()->launchApp(m_apps.at(index).id());
|
||||||
|
}
|
||||||
|
|
||||||
} // UkuiMenu
|
} // UkuiMenu
|
||||||
|
|
|
@ -37,6 +37,7 @@ public:
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
Q_INVOKABLE QVariantList folderApps(const QString &folderName);
|
Q_INVOKABLE QVariantList folderApps(const QString &folderName);
|
||||||
|
Q_INVOKABLE void appClicked(const int &index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVector<DataEntity> m_apps;
|
QVector<DataEntity> m_apps;
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2023, KylinSoft Co., Ltd.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "app-manager.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QDBusReply>
|
||||||
|
#include <QDBusInterface>
|
||||||
|
|
||||||
|
#define KYLIN_APP_MANAGER_NAME "com.kylin.AppManager"
|
||||||
|
#define KYLIN_APP_MANAGER_PATH "/com/kylin/AppManager"
|
||||||
|
#define KYLIN_APP_MANAGER_INTERFACE "com.kylin.AppManager"
|
||||||
|
|
||||||
|
namespace UkuiMenu {
|
||||||
|
AppManager *AppManager::instance()
|
||||||
|
{
|
||||||
|
static AppManager instance(nullptr);
|
||||||
|
return &instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
AppManager::AppManager(QObject *parent) : QObject(parent)
|
||||||
|
{
|
||||||
|
m_appManagerDbusInterface = new QDBusInterface(KYLIN_APP_MANAGER_NAME,
|
||||||
|
KYLIN_APP_MANAGER_PATH,
|
||||||
|
KYLIN_APP_MANAGER_INTERFACE,
|
||||||
|
QDBusConnection::sessionBus());
|
||||||
|
if (!m_appManagerDbusInterface) {
|
||||||
|
qWarning() << "appManager dbus does not exists.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AppManager::launchApp(const QString &desktopFile)
|
||||||
|
{
|
||||||
|
if (m_appManagerDbusInterface != nullptr) {
|
||||||
|
QDBusReply<bool> status = m_appManagerDbusInterface->call("LaunchApp", desktopFile);
|
||||||
|
return status;
|
||||||
|
} else {
|
||||||
|
qWarning() <<"LaunchApp is failed,return false";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // UkuiMenu
|
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2023, KylinSoft Co., Ltd.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef UKUI_MENU_APP_MANAGER_H
|
||||||
|
#define UKUI_MENU_APP_MANAGER_H
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class QDBusInterface;
|
||||||
|
|
||||||
|
namespace UkuiMenu {
|
||||||
|
|
||||||
|
class AppManager : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
static AppManager *instance();
|
||||||
|
AppManager(const AppManager &obj) = delete;
|
||||||
|
AppManager &operator = (const AppManager &obj) = delete;
|
||||||
|
|
||||||
|
bool launchApp(const QString &desktopFile);
|
||||||
|
|
||||||
|
private:
|
||||||
|
explicit AppManager(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QDBusInterface *m_appManagerDbusInterface = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // UkuiMenu
|
||||||
|
|
||||||
|
#endif //UKUI_MENU_APP_MANAGER_H
|
Loading…
Reference in New Issue