diff --git a/qml/AppControls2/AppItem.qml b/qml/AppControls2/AppItem.qml index b71d5f2..7eadc34 100644 --- a/qml/AppControls2/AppItem.qml +++ b/qml/AppControls2/AppItem.qml @@ -5,6 +5,7 @@ import org.ukui.menu.core 1.0 MouseArea { id: control + property bool isSelect: false hoverEnabled: true states: State { when: control.activeFocus @@ -18,7 +19,7 @@ MouseArea { anchors.fill: parent radius: 4 useStyleTransparent: false - alpha: control.containsPress ? 0.82 : control.containsMouse ? 0.55 : 0.00 + alpha: isSelect ? 1.00 : control.containsPress ? 0.82 : control.containsMouse ? 0.55 : 0.00 ToolTip.visible: content.textTruncated && control.containsMouse ToolTip.text: name diff --git a/qml/AppControls2/FolderItem.qml b/qml/AppControls2/FolderItem.qml index 5f9f45b..92c7dc7 100644 --- a/qml/AppControls2/FolderItem.qml +++ b/qml/AppControls2/FolderItem.qml @@ -8,6 +8,7 @@ MouseArea { id: control property bool editStatus: false property bool truncate: false + property bool isSelect: false hoverEnabled: true ToolTip.visible: editStatus && truncate && control.containsMouse ToolTip.text: name @@ -23,7 +24,7 @@ MouseArea { anchors.fill: parent radius: 4 useStyleTransparent: false - alpha: control.containsPress ? 0.82 : control.containsMouse ? 0.55 : 0.00 + alpha: isSelect ? 0.55 : control.containsPress ? 0.82 : control.containsMouse ? 0.55 : 0.00 RowLayout { anchors.fill: parent diff --git a/qml/AppUI/AppList.qml b/qml/AppUI/AppList.qml index 6766ff4..20439f2 100644 --- a/qml/AppUI/AppList.qml +++ b/qml/AppUI/AppList.qml @@ -16,7 +16,7 @@ * */ -import QtQuick 2.0 +import QtQuick 2.15 import QtQml 2.12 import QtQuick.Controls 2.5 import QtQuick.Layouts 1.12 @@ -25,6 +25,7 @@ import org.ukui.menu.core 1.0 Item { property string title: "" + property string idSelect: "" signal labelItemClicked() signal openFolderPageSignal(string folderId, string folderName); @@ -43,9 +44,10 @@ Item { model: modelManager.getAppModel() delegate: Component { Loader { - width: ListView.view ? ListView.view.width : 0 - height: 40 + id: loaderView focus: true + width: ListView.view ? ListView.view.width : 0 + height: appListView.itemHeight property int index: model.index property int type: model.type property string id: model.id @@ -55,13 +57,13 @@ Item { property bool recentInstall: model.recentInstall sourceComponent: { if (type === DataType.Normal) { - return appItem; + return appItemComponent; } if (type === DataType.Folder) { - return folderItem; + return folderItemComponent; } if (type === DataType.Label) { - return labelItem; + return labelItemComponent; } } } @@ -69,21 +71,48 @@ Item { } Component { - id: appItem - AppControls2.AppItem { - focus: true - acceptedButtons: Qt.LeftButton | Qt.RightButton - onClicked: { - if (mouse.button === Qt.RightButton) { - appListView.model.openMenu(index); - return; - } - if (mouse.button === Qt.LeftButton) { - appManager.launchApp(id); - if (recentInstall) { - appManager.appLaunched(id); + id: appItemComponent + Item { + id: appItemBase + AppControls2.AppItem { + id: appItem + focus: true + width: appListView.view ? appListView.view.width : 0 + height: appListView.itemHeight + acceptedButtons: Qt.LeftButton | Qt.RightButton + Drag.active: drag.active + Drag.hotSpot.x: width / 2 + Drag.hotSpot.y: height / 2 + onClicked: { + if (mouse.button === Qt.RightButton) { + appListView.model.openMenu(index); + return; } - return; + if (mouse.button === Qt.LeftButton) { + appManager.launchApp(id); + if (recentInstall) { + appManager.appLaunched(id); + } + return; + } + } + onPressAndHold: { + if (mouse.button === Qt.LeftButton) { + x = appItem.mapToItem(appListView,0,0).x; + y = appItem.mapToItem(appListView,0,0).y; + drag.target = appItem; + appItem.parent = appListView; + appItem.isSelect = true; + } + } + onReleased: { + idSelect = id; + Drag.drop(); + drag.target = null; + appItem.parent = appItemBase; + x = 0; + y = 0; + appItem.isSelect = false; } } Keys.onPressed: { @@ -98,43 +127,59 @@ Item { } Component { - id: labelItem + id: labelItemComponent AppControls2.LabelItem { - focus: true + focus: true; onClicked: labelItemClicked(); } } Component { - id: folderItem - AppControls2.FolderItem { - focus: true - acceptedButtons: Qt.LeftButton | Qt.RightButton - onClicked: { - if (mouse.button === Qt.RightButton) { - appListView.model.openMenu(index); - return; - } - if (mouse.button === Qt.LeftButton) { - openFolderPageSignal(id, name); - return; + id: folderItemComponent + DropArea { + onEntered: { + folderItem.isSelect = true; + } + onExited: { + folderItem.isSelect = false; + } + onDropped: { + folderItem.isSelect = false; + if (id !== idSelect) { + appListView.model.addAppToFolder(idSelect, id); } } - Keys.onPressed: { - if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) { - openFolderPageSignal(id, name); + AppControls2.FolderItem { + id: folderItem + focus: true + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton + onClicked: { + if (mouse.button === Qt.RightButton) { + appListView.model.openMenu(index); + return; + } + if (mouse.button === Qt.LeftButton) { + openFolderPageSignal(id, name); + return; + } + } + Keys.onPressed: { + if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) { + openFolderPageSignal(id, name); + } + } + Component.onCompleted: { + appListView.model.renameText.connect(toEditText); + } + Component.onDestruction: { + appListView.model.renameText.disconnect(toEditText); } - } - Component.onCompleted: { - appListView.model.renameText.connect(toEditText); - } - Component.onDestruction: { - appListView.model.renameText.disconnect(toEditText); - } - function toEditText(idOfIndex){ - if (id === idOfIndex) { - editStatus = true; + function toEditText(idOfIndex){ + if (id === idOfIndex) { + editStatus = true; + } } } } diff --git a/qml/AppUI/AppListView.qml b/qml/AppUI/AppListView.qml index 9495d99..05dd6a6 100644 --- a/qml/AppUI/AppListView.qml +++ b/qml/AppUI/AppListView.qml @@ -29,6 +29,7 @@ MouseArea { property alias model: listView.model property alias delegate: listView.delegate property alias listFocus: listView.focus + property int itemHeight: 40 hoverEnabled: true clip: true onContainsMouseChanged: listView.focus = false @@ -49,6 +50,7 @@ MouseArea { ListView { id: listView + cacheBuffer: itemHeight * listView.count spacing: 4 Layout.fillHeight: true Layout.fillWidth: true diff --git a/qml/extensions/FavoriteExtension.qml b/qml/extensions/FavoriteExtension.qml index 4680ac8..663a841 100644 --- a/qml/extensions/FavoriteExtension.qml +++ b/qml/extensions/FavoriteExtension.qml @@ -49,7 +49,6 @@ UkuiMenuExtension { anchors.leftMargin: 16 anchors.topMargin: 12 anchors.bottomMargin: 6 - clip: true cellWidth: itemHeight + spacing; cellHeight: cellWidth property int exchangedStartIndex: 0 property int spacing: 4 diff --git a/src/appdata/app-folder-helper.cpp b/src/appdata/app-folder-helper.cpp index 16ec4f2..5ab3bf5 100644 --- a/src/appdata/app-folder-helper.cpp +++ b/src/appdata/app-folder-helper.cpp @@ -211,6 +211,30 @@ void AppFolderHelper::addAppToNewFolder(const QString &appId, const QString &fol Q_EMIT folderAdded(folder.id); } +void AppFolderHelper::addAppsToNewFolder(const QString &appIdA, const QString &appIdB, const QString &folderName) +{ + if (appIdA.isEmpty() || appIdB.isEmpty()) { + return; + } + + // TODO: max越界处理 + int max = m_folders.isEmpty() ? -1 : m_folders.lastKey(); + QString name = folderName; + if (name.isEmpty()) { + name = tr("New Folder %1").arg(m_folders.size() + 1); + } + + Folder folder; + folder.id = ++max; + folder.name = name; + folder.apps.append(appIdA); + folder.apps.append(appIdB); + + insertFolder(folder); + Q_EMIT folderAdded(folder.id); + forceSync(); +} + void AppFolderHelper::removeAppFromFolder(const QString &appId, const int &folderId) { if (appId.isEmpty()) { diff --git a/src/appdata/app-folder-helper.h b/src/appdata/app-folder-helper.h index 8bddb5d..2c3502d 100644 --- a/src/appdata/app-folder-helper.h +++ b/src/appdata/app-folder-helper.h @@ -74,6 +74,7 @@ public: void addAppToFolder(const QString& appId, const int& folderId); void addAppToNewFolder(const QString& appId, const QString& folderName); + void addAppsToNewFolder(const QString& appIdA, const QString& appIdB, const QString& folderName); void removeAppFromFolder(const QString& appId, const int& folderId); bool deleteFolder(const int& folderId); void renameFolder(const int& folderId, const QString& folderName); diff --git a/src/model/app-model.cpp b/src/model/app-model.cpp index 4e3ae88..cfea11e 100644 --- a/src/model/app-model.cpp +++ b/src/model/app-model.cpp @@ -189,10 +189,11 @@ void AppModel::insertData(QVector &data, int index) void AppModel::openMenu(const int &index) { - QModelIndex modelIndex = createIndex(index, 0, nullptr); - if (modelIndex.isValid()) { - MenuManager::instance()->showMenu(modelIndex.data(DataEntity::Id).toString()); + if (index < 0 || index >= m_apps.size()) { + return; } + + MenuManager::instance()->showMenu(m_apps.at(index)); } void AppModel::renameFolder(const QString &index, const QString &folderName) @@ -200,6 +201,16 @@ void AppModel::renameFolder(const QString &index, const QString &folderName) AppFolderHelper::instance()->renameFolder(index.toInt(), folderName); } +void AppModel::addAppsToFolder(const QString &appIdA, const QString &appIdB, const QString &folderName) +{ + AppFolderHelper::instance()->addAppsToNewFolder(appIdA, appIdB, folderName); +} + +void AppModel::addAppToFolder(const QString &appId, const QString &folderId) +{ + AppFolderHelper::instance()->addAppToFolder(appId, folderId.toInt()); +} + QVariantList AppModel::getApps(int start, int end) { if (start < 0 || start >= m_apps.size() || end < 0 || end > m_apps.size()) { diff --git a/src/model/app-model.h b/src/model/app-model.h index 7299730..e91b755 100644 --- a/src/model/app-model.h +++ b/src/model/app-model.h @@ -43,6 +43,8 @@ public: Q_INVOKABLE void appClicked(const int &index); Q_INVOKABLE void openMenu(const int &index); Q_INVOKABLE void renameFolder(const QString &index, const QString &folderName); + Q_INVOKABLE void addAppsToFolder(const QString &appIdA, const QString &appIdB, const QString &folderName); + Q_INVOKABLE void addAppToFolder(const QString &appId, const QString &folderId); public Q_SLOTS: void toRenameFolder(QString id);