From 8bc2709564eed1c708d5b323f5748b191f526eea Mon Sep 17 00:00:00 2001 From: qiqi Date: Mon, 20 Feb 2023 17:23:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BA=94=E7=94=A8=E7=BB=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 1 + qml/AppControls2/AppItem.qml | 49 +++++++++++++++--------- qml/AppControls2/IconLabel.qml | 5 ++- qml/AppUI/AppList.qml | 69 ++++++++++++++++++++++++---------- qml/AppUI/AppPage.qml | 9 ++--- src/model/model.cpp | 10 +++++ src/model/model.h | 1 + src/utils/app-manager.cpp | 58 ++++++++++++++++++++++++++++ src/utils/app-manager.h | 46 +++++++++++++++++++++++ 9 files changed, 205 insertions(+), 43 deletions(-) create mode 100644 src/utils/app-manager.cpp create mode 100644 src/utils/app-manager.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d7c71a6..3245a23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,6 +95,7 @@ set(SOURCE_FILES 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/power-button.cpp src/utils/power-button.h + src/utils/app-manager.cpp src/utils/app-manager.h ) # qrc文件 diff --git a/qml/AppControls2/AppItem.qml b/qml/AppControls2/AppItem.qml index 3952343..cc399e9 100644 --- a/qml/AppControls2/AppItem.qml +++ b/qml/AppControls2/AppItem.qml @@ -1,24 +1,39 @@ -import QtQuick 2.0 +import QtQuick 2.12 import QtQuick.Layouts 1.12 +import QtQuick.Controls 2.5 +import org.ukui.menu.core 1.0 -Item { - RowLayout { +StyleBackground { + 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 - Image { - Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter - Layout.preferredWidth: 32 - Layout.preferredHeight: 32 - source: icon + iconHeight: 32; iconWidth: iconHeight + appName: name; appIcon: icon + display: Display.TextBesideIcon + spacing: 12 + } + 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); + } } - - Text { - Layout.fillWidth: true - Layout.fillHeight: true - Layout.leftMargin: 5 - - horizontalAlignment: Qt.AlignLeft - verticalAlignment: Qt.AlignVCenter - text: name + onClicked: { + if (mouse.button === Qt.LeftButton) { + appListView.model.appClicked(index); + } } } } diff --git a/qml/AppControls2/IconLabel.qml b/qml/AppControls2/IconLabel.qml index 3de9772..701d5bc 100644 --- a/qml/AppControls2/IconLabel.qml +++ b/qml/AppControls2/IconLabel.qml @@ -12,14 +12,17 @@ Item { property string appIcon: "" // 上下布局spacing:0 左右布局spacing:12 property int spacing: 2 + property bool textTruncated: iconText.truncated state: root.display states: [ State { name: Display.TextBesideIcon - AnchorChanges { + PropertyChanges { target: iconImage anchors.verticalCenter: root.verticalCenter + anchors.left: root.left + anchors.leftMargin: root.spacing } PropertyChanges { target: iconText diff --git a/qml/AppUI/AppList.qml b/qml/AppUI/AppList.qml index 7f7436b..d597685 100644 --- a/qml/AppUI/AppList.qml +++ b/qml/AppUI/AppList.qml @@ -18,32 +18,60 @@ import QtQuick 2.0 import QtQml 2.12 - +import QtQuick.Controls 2.5 +import QtQuick.Layouts 1.12 import AppControls2 1.0 as AppControls2 import org.ukui.menu.core 1.0 -ListView { +Item { property string title: "" - model: modelManager.getAppModel() - 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; + + MouseArea { + id: appListArea + hoverEnabled: true + anchors.fill: parent + + RowLayout { + anchors.fill: parent + spacing: 0 + + ListView { + id: appListView + spacing: 4 + Layout.fillHeight: true + Layout.fillWidth: true + ScrollBar.vertical: appListScrollBar + model: modelManager.getAppModel() + + 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 {} } } + diff --git a/qml/AppUI/AppPage.qml b/qml/AppUI/AppPage.qml index 4cd8818..fc148ab 100644 --- a/qml/AppUI/AppPage.qml +++ b/qml/AppUI/AppPage.qml @@ -16,9 +16,9 @@ * */ -import QtQuick 2.0 +import QtQuick 2.12 import QtQuick.Layouts 1.12 - +import QtQuick.Controls 2.5 import AppControls2 1.0 as AppControls2 import org.ukui.menu.core 1.0 @@ -37,11 +37,10 @@ AppControls2.StyleBackground { } AppList { - id: appList + clip: true Layout.fillWidth: true Layout.fillHeight: true - Layout.leftMargin: 16 - clip: true + Layout.leftMargin: 4 } } } diff --git a/src/model/model.cpp b/src/model/model.cpp index 6ee5ffa..ab8fff9 100644 --- a/src/model/model.cpp +++ b/src/model/model.cpp @@ -17,6 +17,7 @@ */ #include "model.h" +#include "app-manager.h" #include "data-provider-manager.h" #include @@ -92,4 +93,13 @@ QVariantList AppModel::folderApps(const QString &folderName) 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 diff --git a/src/model/model.h b/src/model/model.h index 6e501e7..36de9e4 100644 --- a/src/model/model.h +++ b/src/model/model.h @@ -37,6 +37,7 @@ public: QHash roleNames() const override; Q_INVOKABLE QVariantList folderApps(const QString &folderName); + Q_INVOKABLE void appClicked(const int &index); private: QVector m_apps; diff --git a/src/utils/app-manager.cpp b/src/utils/app-manager.cpp new file mode 100644 index 0000000..8f46ce8 --- /dev/null +++ b/src/utils/app-manager.cpp @@ -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 . + * + */ + +#include "app-manager.h" + +#include +#include +#include + +#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 status = m_appManagerDbusInterface->call("LaunchApp", desktopFile); + return status; + } else { + qWarning() <<"LaunchApp is failed,return false"; + return false; + } +} + +} // UkuiMenu \ No newline at end of file diff --git a/src/utils/app-manager.h b/src/utils/app-manager.h new file mode 100644 index 0000000..437bff8 --- /dev/null +++ b/src/utils/app-manager.h @@ -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 . + * + */ + +#ifndef UKUI_MENU_APP_MANAGER_H +#define UKUI_MENU_APP_MANAGER_H +#include + +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