From 38343851e3fd38e7aff4928b9ad1568b12717c98 Mon Sep 17 00:00:00 2001 From: gjq Date: Fri, 7 Apr 2023 10:00:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qml/AppControls2/FolderItem.qml | 101 ++++++++++++++++++-- qml/AppUI/AppList.qml | 12 +++ qml/AppUI/AppPageContent.qml | 153 +++++++++++++++++------------- src/appdata/app-folder-helper.cpp | 10 +- src/model/app-model.cpp | 11 +++ src/model/app-model.h | 7 ++ 6 files changed, 218 insertions(+), 76 deletions(-) diff --git a/qml/AppControls2/FolderItem.qml b/qml/AppControls2/FolderItem.qml index cf61a1a..869f4be 100644 --- a/qml/AppControls2/FolderItem.qml +++ b/qml/AppControls2/FolderItem.qml @@ -1,13 +1,15 @@ 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 MouseArea { id: control + property bool editStatus: false hoverEnabled: true - // ToolTip.visible: content.textTruncated && control.containsMouse - // ToolTip.text: name + ToolTip.visible: textShow.truncated && textShow.visible && control.containsMouse + ToolTip.text: name StyleBackground { anchors.fill: parent @@ -19,6 +21,7 @@ MouseArea { anchors.fill: parent anchors.leftMargin: 12 spacing: 12 + FolderIcon { rows: 2; columns: 2 spacing: 2; padding: 2 @@ -28,14 +31,98 @@ MouseArea { Layout.preferredHeight: 32 } - Text { + Item { + id: renameArea Layout.fillWidth: true Layout.fillHeight: true - verticalAlignment: Text.AlignVCenter - horizontalAlignment: Text.AlignLeft - elide: Text.ElideRight - text: name + + StyleText { + id: textShow + anchors.fill: parent + visible: !control.editStatus + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignLeft + elide: Text.ElideRight + text: name + } + + AppControls2.StyleBackground { + anchors.fill: parent + radius: 6 + useStyleTransparent: false + alpha: textChange.activeFocus ? 0.04 : 0 + paletteRole: Palette.Text + border.width: 2 + borderAlpha: textChange.activeFocus ? 1 : 0 + borderColor: Palette.Highlight + + TextInput { + id: textChange + text: name + visible: control.editStatus + focus: false + clip: true + anchors.left: parent.left + anchors.leftMargin: 8 + anchors.right: buttonMouseArea.left + anchors.rightMargin: 8 + anchors.verticalCenter: parent.verticalCenter + activeFocusOnPress: false + verticalAlignment: Text.AlignVCenter + selectByMouse: true + maximumLength: 14 + + onEditingFinished: { + modelManager.getAppModel().renameFolder(id, text); + control.editStatus = false; + } + + function updateTextInputColor() { + color = themePalette.paletteColor(Palette.Text); + selectionColor = themePalette.paletteColor(Palette.Highlight); + } + + Component.onCompleted: { + updateTextInputColor(); + themePalette.styleColorChanged.connect(updateTextInputColor); + } + + Component.onDestruction: themePalette.styleColorChanged.disconnect(updateTextInputColor); + } + + MouseArea { + id: buttonMouseArea + hoverEnabled: true + width: 16; height: width + anchors.right: parent.right + anchors.rightMargin: 10 + anchors.verticalCenter: parent.verticalCenter + visible: textChange.activeFocus + + ThemeIcon { + anchors.centerIn: parent + width: 16; height: width + source: "image://appicon/edit-clear-symbolic" + } + + onClicked: { + textChange.text = name; + control.editStatus = false; + } + } + + } + } } } + onEditStatusChanged: { + if (editStatus) { + textChange.forceActiveFocus(); + textChange.focus = true; + } + else { + textChange.focus = false + } + } } diff --git a/qml/AppUI/AppList.qml b/qml/AppUI/AppList.qml index 0c574f2..58398b7 100644 --- a/qml/AppUI/AppList.qml +++ b/qml/AppUI/AppList.qml @@ -98,6 +98,18 @@ Item { return; } } + Component.onCompleted: { + appListView.model.renameText.connect(toEditText); + } + Component.onDestruction: { + appListView.model.renameText.disconnect(toEditText); + } + + function toEditText(idOfIndex){ + if (id === idOfIndex) { + editStatus = true; + } + } } } } diff --git a/qml/AppUI/AppPageContent.qml b/qml/AppUI/AppPageContent.qml index b59bbc5..d805d9b 100644 --- a/qml/AppUI/AppPageContent.qml +++ b/qml/AppUI/AppPageContent.qml @@ -123,83 +123,106 @@ SwipeView { } } - AppControls2.StyleBackground { + Item { + id: contain + property bool editStatus: false Layout.fillWidth: true Layout.fillHeight: true - radius: 6 - alpha: folderText.activeFocus ? 0.04 : 0 - useStyleTransparent: false - paletteRole: Palette.Text - border.width: 2 - borderAlpha: folderText.activeFocus ? 1 : 0 - borderColor: Palette.Highlight - - TextInput { - id: folderText - clip: true - font.pixelSize: 14 - focus: false - anchors.left: parent.left - anchors.leftMargin: 8 - anchors.right: buttonMouseArea.left - anchors.rightMargin: 8 - anchors.verticalCenter: parent.verticalCenter - activeFocusOnPress: false + AppControls2.StyleText { + id: textShow + visible: !contain.editStatus + anchors.fill: parent verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignLeft + elide: Text.ElideRight text: title - selectByMouse: true - maximumLength: 14 - - onEditingFinished: { - modelManager.getFolderModel().renameFolder(text); - folderText.focus = false; - folderText.z = 0; - } - - function updateTextInputColor() { - color = themePalette.paletteColor(Palette.Text); - selectionColor = themePalette.paletteColor(Palette.Highlight); - } - - Component.onCompleted: { - updateTextInputColor(); - themePalette.styleColorChanged.connect(updateTextInputColor); - } - - Component.onDestruction: themePalette.styleColorChanged.disconnect(updateTextInputColor); - } - MouseArea { - id: textArea - anchors.fill: folderText - onDoubleClicked: { - forceActiveFocus(); - folderText.focus = true; - folderText.z = 2; + AppControls2.StyleBackground { + anchors.fill: parent + radius: 6 + useStyleTransparent: false + alpha: textEdit.activeFocus ? 0.04 : 0 + paletteRole: Palette.Text + border.width: 2 + borderAlpha: textEdit.activeFocus ? 1 : 0 + borderColor: Palette.Highlight + + TextInput { + id: textEdit + visible: contain.editStatus + clip: true + focus: false + anchors.left: parent.left + anchors.leftMargin: 8 + anchors.right: buttonMouseArea.left + anchors.rightMargin: 8 + anchors.verticalCenter: parent.verticalCenter + activeFocusOnPress: false + verticalAlignment: Text.AlignVCenter + text: title + selectByMouse: true + maximumLength: 14 + + onEditingFinished: { + modelManager.getFolderModel().renameFolder(text); + textShow.text = text; + contain.editStatus = false; + } + + function updateTextInputColor() { + color = themePalette.paletteColor(Palette.Text); + selectionColor = themePalette.paletteColor(Palette.Highlight); + } + + Component.onCompleted: { + updateTextInputColor(); + themePalette.styleColorChanged.connect(updateTextInputColor); + } + + Component.onDestruction: themePalette.styleColorChanged.disconnect(updateTextInputColor); + } - } - MouseArea { - id: buttonMouseArea - hoverEnabled: true - width: 16; height: width - anchors.right: parent.right - anchors.rightMargin: 10 - anchors.verticalCenter: parent.verticalCenter - visible: folderText.activeFocus + MouseArea { + id: textArea + anchors.fill: textEdit + onDoubleClicked: { + contain.editStatus = true; + } + } - ThemeIcon { - anchors.centerIn: parent + MouseArea { + id: buttonMouseArea + hoverEnabled: true width: 16; height: width - source: "image://appicon/edit-clear-symbolic" - } + anchors.right: parent.right + anchors.rightMargin: 10 + anchors.verticalCenter: parent.verticalCenter + visible: textEdit.activeFocus - onClicked: { - folderText.text = title; - folderText.focus = false; - folderText.z = 0; + ThemeIcon { + anchors.centerIn: parent + width: 16; height: width + source: "image://appicon/edit-clear-symbolic" + } + + onClicked: { + textEdit.text = title; + contain.editStatus = false; + } + } + } + onEditStatusChanged: { + if (editStatus) { + textEdit.z = 2; + textEdit.forceActiveFocus(); + textEdit.focus = true; + } + else { + textEdit.z = 0; + textEdit.focus = false; } } } diff --git a/src/appdata/app-folder-helper.cpp b/src/appdata/app-folder-helper.cpp index a219729..16ec4f2 100644 --- a/src/appdata/app-folder-helper.cpp +++ b/src/appdata/app-folder-helper.cpp @@ -19,6 +19,8 @@ #include "app-folder-helper.h" #include "menu-manager.h" #include "app-data-manager.h" +#include "model-manager.h" +#include "app-model.h" #include #include @@ -109,10 +111,10 @@ void FolderMenuProvider::folderMenuForNormal(QObject *parent, const QString &app void FolderMenuProvider::folderMenuForFolder(QObject *parent, const QString &folderId, QList &list) { -// list << new QAction(QObject::tr("Rename"), parent); -// QObject::connect(list.last(), &QAction::triggered, parent, [folderId] { -// AppFolderHelper::instance()->renameFolder(folderId.toInt(), "new name"); -// }); + list << new QAction(QObject::tr("Rename"), parent); + QObject::connect(list.last(), &QAction::triggered, parent, [folderId] { + ModelManager::instance()->getAppModel()->toRenameFolder(folderId); + }); list << new QAction(QObject::tr("Dissolve folder"), parent); QObject::connect(list.last(), &QAction::triggered, parent, [folderId] { diff --git a/src/model/app-model.cpp b/src/model/app-model.cpp index 8fe9995..0f8bbb2 100644 --- a/src/model/app-model.cpp +++ b/src/model/app-model.cpp @@ -19,6 +19,7 @@ #include "app-model.h" #include "app-manager.h" #include "menu-manager.h" +#include "app-folder-helper.h" #include #include @@ -110,6 +111,11 @@ void AppModel::reloadPluginData() resetModel(data); } +void AppModel::toRenameFolder(QString id) +{ + Q_EMIT renameText(id); +} + void AppModel::onPluginDataChanged(QVector data, DataUpdateMode::Mode mode, quint32 index) { switch (mode) { @@ -180,6 +186,11 @@ void AppModel::openMenu(const int &index) MenuManager::instance()->showMenu(m_apps.at(index)); } +void AppModel::renameFolder(const QString &index, const QString &folderName) +{ + AppFolderHelper::instance()->renameFolder(index.toInt(), folderName); +} + 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 db3d393..2b882fd 100644 --- a/src/model/app-model.h +++ b/src/model/app-model.h @@ -42,6 +42,10 @@ public: Q_INVOKABLE QVariantList folderApps(const QString &folderName); Q_INVOKABLE void appClicked(const int &index); Q_INVOKABLE void openMenu(const int &index); + Q_INVOKABLE void renameFolder(const QString &index, const QString &folderName); + +public Q_SLOTS: + void toRenameFolder(QString id); private Q_SLOTS: void onPluginDataChanged(QVector data, DataUpdateMode::Mode mode, quint32 index); @@ -55,6 +59,9 @@ private: private: QVector m_apps; + +Q_SIGNALS: + Q_INVOKABLE void renameText(QString id); }; } // UkuiMenu