添加文件夹组内重命名

This commit is contained in:
gjq 2023-04-04 09:33:06 +08:00 committed by hewenfei
parent 80d92c01c4
commit 38f3673a7d
4 changed files with 92 additions and 5 deletions

View File

@ -16,7 +16,7 @@
* *
*/ */
import QtQuick 2.0 import QtQuick 2.12
import QtQuick.Layouts 1.12 import QtQuick.Layouts 1.12
import QtQuick.Controls 2.5 import QtQuick.Controls 2.5
import AppControls2 1.0 as AppControls2 import AppControls2 1.0 as AppControls2
@ -104,8 +104,10 @@ SwipeView {
RowLayout { RowLayout {
anchors.fill: parent anchors.fill: parent
anchors.leftMargin: 12 anchors.leftMargin: 12
anchors.rightMargin: 30
spacing: 2
Image { ThemeIcon {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
Layout.maximumWidth: 16 Layout.maximumWidth: 16
@ -117,11 +119,86 @@ SwipeView {
onClicked: folderPageLoader.hideFolderPage(); onClicked: folderPageLoader.hideFolderPage();
} }
} }
Text {
AppControls2.StyleBackground {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: 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
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
text: title 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;
}
}
} }
} }
} }

View File

@ -258,10 +258,14 @@ void AppFolderHelper::renameFolder(const int &folderId, const QString &folderNam
if (!m_folders.contains(folderId)) { if (!m_folders.contains(folderId)) {
return; return;
} }
if (m_folders[folderId].name == folderName) {
return;
}
m_folders[folderId].name = folderName; m_folders[folderId].name = folderName;
} }
Q_EMIT folderDataChanged(folderId); Q_EMIT folderDataChanged(folderId);
forceSync();
} }
QList<Folder> AppFolderHelper::folderData() QList<Folder> AppFolderHelper::folderData()

View File

@ -46,6 +46,11 @@ void FolderModel::setFolderId(const QString &folderId)
loadFolderData(id); loadFolderData(id);
} }
void FolderModel::renameFolder(const QString &folderName)
{
AppFolderHelper::instance()->renameFolder(m_folderId, folderName);
}
void FolderModel::loadFolderData(int id) void FolderModel::loadFolderData(int id)
{ {
Folder folder; Folder folder;

View File

@ -30,6 +30,7 @@ class FolderModel : public QAbstractListModel
public: public:
explicit FolderModel(QObject *parent = nullptr); explicit FolderModel(QObject *parent = nullptr);
Q_INVOKABLE void setFolderId(const QString &folderId); Q_INVOKABLE void setFolderId(const QString &folderId);
Q_INVOKABLE void renameFolder(const QString &folderName);
int rowCount(const QModelIndex &parent) const override; int rowCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override; QVariant data(const QModelIndex &index, int role) const override;