添加应用组件
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/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文件
|
||||
|
|
|
@ -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
|
||||
Image {
|
||||
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
|
||||
Layout.preferredWidth: 32
|
||||
Layout.preferredHeight: 32
|
||||
source: icon
|
||||
}
|
||||
radius: 4
|
||||
useStyleTransparent: false
|
||||
alpha: control.containsPress ? 0.82 : control.containsMouse ? 0.55 : 0.00
|
||||
ToolTip.visible: content.textTruncated && control.containsMouse
|
||||
ToolTip.text: name
|
||||
|
||||
Text {
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
Layout.leftMargin: 5
|
||||
IconLabel {
|
||||
id: content
|
||||
anchors.fill: parent
|
||||
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
|
||||
|
||||
horizontalAlignment: Qt.AlignLeft
|
||||
verticalAlignment: Qt.AlignVCenter
|
||||
text: name
|
||||
onPressed: {
|
||||
if (mouse.button === Qt.RightButton) {
|
||||
console.log("RightButtononPressed:",mouse.x,mouse.y);
|
||||
}
|
||||
}
|
||||
onClicked: {
|
||||
if (mouse.button === Qt.LeftButton) {
|
||||
appListView.model.appClicked(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -18,13 +18,31 @@
|
|||
|
||||
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: ""
|
||||
|
||||
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
|
||||
|
@ -46,6 +64,16 @@ ListView {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AppControls2.ScrollBar {
|
||||
id: appListScrollBar
|
||||
Layout.fillHeight: true
|
||||
Layout.preferredWidth: 14
|
||||
visible: appListArea.containsMouse
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: appItem
|
||||
|
@ -62,3 +90,4 @@ ListView {
|
|||
AppControls2.FolderItem {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "model.h"
|
||||
#include "app-manager.h"
|
||||
#include "data-provider-manager.h"
|
||||
|
||||
#include <QObject>
|
||||
|
@ -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
|
||||
|
|
|
@ -37,6 +37,7 @@ public:
|
|||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
Q_INVOKABLE QVariantList folderApps(const QString &folderName);
|
||||
Q_INVOKABLE void appClicked(const int &index);
|
||||
|
||||
private:
|
||||
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