diff --git a/qml/AppUI/AppPageContent.qml b/qml/AppUI/AppPageContent.qml index 4e27feb..667b375 100644 --- a/qml/AppUI/AppPageContent.qml +++ b/qml/AppUI/AppPageContent.qml @@ -16,7 +16,7 @@ * */ -import QtQuick 2.0 +import QtQuick 2.12 import QtQuick.Layouts 1.12 import QtQuick.Controls 2.5 import AppControls2 1.0 as AppControls2 @@ -104,8 +104,10 @@ SwipeView { RowLayout { anchors.fill: parent anchors.leftMargin: 12 + anchors.rightMargin: 30 + spacing: 2 - Image { + ThemeIcon { Layout.fillWidth: true Layout.fillHeight: true Layout.maximumWidth: 16 @@ -117,11 +119,86 @@ SwipeView { onClicked: folderPageLoader.hideFolderPage(); } } - Text { + + AppControls2.StyleBackground { Layout.fillWidth: true Layout.fillHeight: true - verticalAlignment: Text.AlignVCenter - text: title + + 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 + verticalAlignment: Text.AlignVCenter + 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; + } + } + + MouseArea { + id: buttonMouseArea + hoverEnabled: true + width: 16; height: width + anchors.right: parent.right + anchors.rightMargin: 10 + anchors.verticalCenter: parent.verticalCenter + visible: folderText.activeFocus + + ThemeIcon { + anchors.centerIn: parent + width: 16; height: width + source: "image://appicon/edit-clear-symbolic" + } + + onClicked: { + folderText.text = title; + folderText.focus = false; + folderText.z = 0; + } + } } } } diff --git a/src/appdata/app-folder-helper.cpp b/src/appdata/app-folder-helper.cpp index bfdf71e..a219729 100644 --- a/src/appdata/app-folder-helper.cpp +++ b/src/appdata/app-folder-helper.cpp @@ -258,10 +258,14 @@ void AppFolderHelper::renameFolder(const int &folderId, const QString &folderNam if (!m_folders.contains(folderId)) { return; } + if (m_folders[folderId].name == folderName) { + return; + } m_folders[folderId].name = folderName; } Q_EMIT folderDataChanged(folderId); + forceSync(); } QList AppFolderHelper::folderData() diff --git a/src/model/folder-model.cpp b/src/model/folder-model.cpp index b9f1c65..c5f6cbb 100644 --- a/src/model/folder-model.cpp +++ b/src/model/folder-model.cpp @@ -46,6 +46,11 @@ void FolderModel::setFolderId(const QString &folderId) loadFolderData(id); } +void FolderModel::renameFolder(const QString &folderName) +{ + AppFolderHelper::instance()->renameFolder(m_folderId, folderName); +} + void FolderModel::loadFolderData(int id) { Folder folder; diff --git a/src/model/folder-model.h b/src/model/folder-model.h index 9a0f52b..a6b03fa 100644 --- a/src/model/folder-model.h +++ b/src/model/folder-model.h @@ -30,6 +30,7 @@ class FolderModel : public QAbstractListModel public: explicit FolderModel(QObject *parent = nullptr); Q_INVOKABLE void setFolderId(const QString &folderId); + Q_INVOKABLE void renameFolder(const QString &folderName); int rowCount(const QModelIndex &parent) const override; QVariant data(const QModelIndex &index, int role) const override;