Multiple optimizations
This commit is contained in:
parent
72db8fceb4
commit
8635ca91fc
6 changed files with 190 additions and 89 deletions
|
@ -64,6 +64,16 @@ Item {
|
|||
id: folderModel
|
||||
url: desktopPath()
|
||||
isDesktop: true
|
||||
viewAdapter: viewAdapter
|
||||
}
|
||||
|
||||
ItemViewAdapter {
|
||||
id: viewAdapter
|
||||
adapterView: _folderView
|
||||
adapterModel: folderModel
|
||||
adapterIconSize: 40
|
||||
adapterVisibleArea: Qt.rect(_folderView.contentX, _folderView.contentY,
|
||||
_folderView.contentWidth, _folderView.contentHeight)
|
||||
}
|
||||
|
||||
FolderGridView {
|
||||
|
@ -94,6 +104,10 @@ Item {
|
|||
if (!activeFocus)
|
||||
folderModel.clearSelection()
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
folderModel.requestRename.connect(rename)
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
|
|
|
@ -7,12 +7,12 @@ import MeuiKit 1.0 as Meui
|
|||
Window {
|
||||
id: control
|
||||
|
||||
title: qsTr("New Folder")
|
||||
title: qsTr("New folder name")
|
||||
flags: Qt.Dialog
|
||||
visible: true
|
||||
|
||||
width: 400 + Meui.Units.largeSpacing * 2
|
||||
height: _mainLayout.implicitHeight + Meui.Units.largeSpacing * 4
|
||||
height: _mainLayout.implicitHeight + Meui.Units.largeSpacing * 2
|
||||
|
||||
minimumWidth: width
|
||||
minimumHeight: height
|
||||
|
@ -31,16 +31,15 @@ Window {
|
|||
anchors.rightMargin: Meui.Units.largeSpacing
|
||||
spacing: 0
|
||||
|
||||
RowLayout {
|
||||
Label {
|
||||
text: qsTr("Name")
|
||||
}
|
||||
TextField {
|
||||
id: _textField
|
||||
Layout.fillWidth: true
|
||||
Keys.onEscapePressed: control.close()
|
||||
text: qsTr("New folder")
|
||||
focus: true
|
||||
|
||||
TextField {
|
||||
id: _textField
|
||||
Layout.fillWidth: true
|
||||
Keys.onEscapePressed: control.close()
|
||||
focus: true
|
||||
Component.onCompleted: {
|
||||
_textField.selectAll()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,10 +63,20 @@ GridView {
|
|||
}
|
||||
}
|
||||
|
||||
function reset() {
|
||||
currentIndex = -1
|
||||
anchorIndex = 0
|
||||
previouslySelectedItemIndex = -1
|
||||
cancelRename()
|
||||
hoveredItem = null
|
||||
pressedItem = null
|
||||
cPress = null
|
||||
}
|
||||
|
||||
highlightMoveDuration: 0
|
||||
keyNavigationEnabled : true
|
||||
keyNavigationWraps : true
|
||||
Keys.onPressed: {
|
||||
Keys.onPressed: {
|
||||
if (event.key === Qt.Key_Control) {
|
||||
ctrlPressed = true
|
||||
} else if (event.key === Qt.Key_Shift) {
|
||||
|
@ -90,6 +100,13 @@ GridView {
|
|||
anchorIndex = 0
|
||||
}
|
||||
}
|
||||
Keys.onEscapePressed: {
|
||||
if (!editor || !editor.targetItem) {
|
||||
previouslySelectedItemIndex = -1
|
||||
folderModel.clearSelection()
|
||||
event.accepted = false
|
||||
}
|
||||
}
|
||||
|
||||
cellHeight: {
|
||||
var iconHeight = iconSize + (Meui.Units.fontMetrics.height * 2) + Meui.Units.largeSpacing * 2
|
||||
|
@ -269,6 +286,9 @@ GridView {
|
|||
control.dragY = -1
|
||||
clearPressState()
|
||||
} else {
|
||||
if (control.editor && control.editor.targetItem)
|
||||
return;
|
||||
|
||||
folderModel.pinSelection()
|
||||
control.rubberBand = rubberBandObject.createObject(control.contentItem, {x: cPress.x, y: cPress.y})
|
||||
control.interactive = false
|
||||
|
@ -429,6 +449,8 @@ GridView {
|
|||
wrapMode: TextEdit.Wrap
|
||||
horizontalAlignment: TextEdit.AlignHCenter
|
||||
z: 999
|
||||
topPadding: Meui.Units.smallSpacing
|
||||
bottomPadding: Meui.Units.smallSpacing
|
||||
|
||||
property Item targetItem: null
|
||||
|
||||
|
@ -443,12 +465,14 @@ GridView {
|
|||
targetItem.labelArea.visible = false
|
||||
_editor.select(0, folderModel.fileExtensionBoundary(targetItem.index))
|
||||
visible = true
|
||||
control.interactive = false
|
||||
} else {
|
||||
x = 0
|
||||
y = 0
|
||||
width = 0
|
||||
height = 0
|
||||
visible = false
|
||||
control.interactive = true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -457,9 +481,11 @@ GridView {
|
|||
case Qt.Key_Return:
|
||||
case Qt.Key_Enter:
|
||||
commit()
|
||||
event.accepted = true
|
||||
break
|
||||
case Qt.Key_Escape:
|
||||
cancel()
|
||||
event.accepted = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -477,13 +503,18 @@ GridView {
|
|||
folderModel.rename(targetItem.index, text)
|
||||
control.currentIndex = targetItem.index
|
||||
targetItem = null
|
||||
|
||||
control.editor.destroy()
|
||||
}
|
||||
}
|
||||
|
||||
function cancel() {
|
||||
if (targetItem) {
|
||||
targetItem.labelArea.visible = true
|
||||
control.currentIndex = targetItem.index
|
||||
targetItem = null
|
||||
|
||||
control.editor.destroy()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,9 +38,39 @@ ListView {
|
|||
|
||||
ScrollBar.vertical: ScrollBar { }
|
||||
|
||||
function rename() {
|
||||
if (currentIndex !== -1) {
|
||||
var renameAction = control.model.action("rename")
|
||||
if (renameAction && !renameAction.enabled)
|
||||
return
|
||||
|
||||
if (!control.editor)
|
||||
control.editor = editorComponent.createObject(control)
|
||||
|
||||
control.editor.targetItem = control.currentItem
|
||||
}
|
||||
}
|
||||
|
||||
function cancelRename() {
|
||||
if (control.editor) {
|
||||
control.editor.cancel()
|
||||
control.editor.destroy()
|
||||
control.editor = null
|
||||
}
|
||||
}
|
||||
|
||||
function reset() {
|
||||
currentIndex = -1
|
||||
anchorIndex = 0
|
||||
previouslySelectedItemIndex = -1
|
||||
cancelRename()
|
||||
hoveredItem = null
|
||||
pressedItem = null
|
||||
cPress = null
|
||||
}
|
||||
|
||||
highlightMoveDuration: 0
|
||||
keyNavigationEnabled : true
|
||||
keyNavigationWraps : true
|
||||
Keys.enabled: true
|
||||
Keys.onPressed: {
|
||||
if (event.key === Qt.Key_Control) {
|
||||
ctrlPressed = true
|
||||
|
@ -53,6 +83,7 @@ ListView {
|
|||
|
||||
control.keyPress(event)
|
||||
}
|
||||
|
||||
Keys.onReleased: {
|
||||
if (event.key === Qt.Key_Control) {
|
||||
ctrlPressed = false
|
||||
|
@ -62,6 +93,40 @@ ListView {
|
|||
}
|
||||
}
|
||||
|
||||
Keys.onEscapePressed: {
|
||||
if (!editor || !editor.targetItem) {
|
||||
previouslySelectedItemIndex = -1
|
||||
folderModel.clearSelection()
|
||||
event.accepted = false
|
||||
}
|
||||
}
|
||||
|
||||
Keys.onUpPressed: {
|
||||
if (!editor || !editor.targetItem) {
|
||||
var newIndex = currentIndex
|
||||
newIndex--;
|
||||
|
||||
if (newIndex < 0)
|
||||
newIndex = 0
|
||||
|
||||
currentIndex = newIndex
|
||||
updateSelection(event.modifiers)
|
||||
}
|
||||
}
|
||||
|
||||
Keys.onDownPressed: {
|
||||
if (!editor || !editor.targetItem) {
|
||||
var newIndex = currentIndex
|
||||
newIndex++
|
||||
|
||||
if (newIndex >= control.count)
|
||||
return
|
||||
|
||||
currentIndex = newIndex
|
||||
updateSelection(event.modifiers)
|
||||
}
|
||||
}
|
||||
|
||||
onCachedRectangleSelectionChanged: {
|
||||
if (cachedRectangleSelection === null)
|
||||
return
|
||||
|
@ -88,26 +153,6 @@ ListView {
|
|||
cPress = mapToItem(control.contentItem, pressX, pressY)
|
||||
}
|
||||
|
||||
function rename() {
|
||||
if (currentIndex !== -1) {
|
||||
var renameAction = control.model.action("rename")
|
||||
if (renameAction && !renameAction.enabled)
|
||||
return
|
||||
|
||||
if (!control.editor)
|
||||
control.editor = editorComponent.createObject(control)
|
||||
|
||||
control.editor.targetItem = control.currentItem
|
||||
}
|
||||
}
|
||||
|
||||
function cancelRename() {
|
||||
if (control.editor) {
|
||||
control.editor.cancel()
|
||||
control.editor = null
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: _mouseArea
|
||||
anchors.fill: parent
|
||||
|
@ -253,6 +298,9 @@ ListView {
|
|||
control.dragY = -1
|
||||
clearPressState()
|
||||
} else {
|
||||
if (control.editor && control.editor.targetItem)
|
||||
return;
|
||||
|
||||
folderModel.pinSelection()
|
||||
control.rubberBand = rubberBandObject.createObject(control.contentItem, {x: cPress.x, y: cPress.y})
|
||||
control.interactive = false
|
||||
|
@ -306,9 +354,9 @@ ListView {
|
|||
|
||||
function updateSelection(modifier) {
|
||||
if (modifier & Qt.ShiftModifier) {
|
||||
folderModel.setRangeSelected(anchorIndex, hoveredItem)
|
||||
folderModel.setRangeSelected(anchorIndex, currentIndex)
|
||||
} else {
|
||||
folderModel.clear()
|
||||
folderModel.clearSelection()
|
||||
folderModel.setSelected(currentIndex)
|
||||
if (currentIndex == -1)
|
||||
previouslySelectedItemIndex = -1
|
||||
|
@ -319,46 +367,33 @@ ListView {
|
|||
Component {
|
||||
id: editorComponent
|
||||
|
||||
TextArea {
|
||||
TextField {
|
||||
id: _editor
|
||||
visible: false
|
||||
wrapMode: Text.NoWrap
|
||||
textMargin: 0
|
||||
verticalAlignment: TextEdit.AlignVCenter
|
||||
leftPadding: 0
|
||||
z: 999
|
||||
|
||||
property Item targetItem: null
|
||||
|
||||
background: Item {}
|
||||
|
||||
onTargetItemChanged: {
|
||||
if (targetItem != null) {
|
||||
var pos = control.mapFromItem(targetItem, targetItem.labelArea.x, targetItem.labelArea.y)
|
||||
width = targetItem.labelArea.width
|
||||
height = targetItem.height
|
||||
height = Meui.Units.fontMetrics.height + Meui.Units.largeSpacing * 2
|
||||
x = control.mapFromItem(targetItem.labelArea, 0, 0).x
|
||||
y = pos.y
|
||||
y = pos.y + (targetItem.height - height) / 2
|
||||
text = targetItem.labelArea.text
|
||||
targetItem.labelArea.visible = false
|
||||
targetItem.labelArea2.visible = false
|
||||
_editor.select(0, folderModel.fileExtensionBoundary(targetItem.index))
|
||||
visible = true
|
||||
control.interactive = false
|
||||
} else {
|
||||
x: 0
|
||||
y: 0
|
||||
visible = false
|
||||
}
|
||||
}
|
||||
|
||||
Keys.onPressed: {
|
||||
switch (event.key) {
|
||||
case Qt.Key_Return:
|
||||
case Qt.Key_Enter:
|
||||
commit()
|
||||
break
|
||||
case Qt.Key_Escape:
|
||||
cancel()
|
||||
break
|
||||
control.interactive = true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -369,6 +404,20 @@ ListView {
|
|||
control.forceActiveFocus()
|
||||
}
|
||||
|
||||
Keys.onPressed: {
|
||||
switch (event.key) {
|
||||
case Qt.Key_Return:
|
||||
case Qt.Key_Enter:
|
||||
commit()
|
||||
event.accepted = true
|
||||
break
|
||||
case Qt.Key_Escape:
|
||||
cancel()
|
||||
event.accepted = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
function commit() {
|
||||
if (targetItem) {
|
||||
targetItem.labelArea.visible = true
|
||||
|
@ -376,6 +425,8 @@ ListView {
|
|||
folderModel.rename(targetItem.index, text)
|
||||
control.currentIndex = targetItem.index
|
||||
targetItem = null
|
||||
|
||||
control.editor.destroy()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -383,7 +434,10 @@ ListView {
|
|||
if (targetItem) {
|
||||
targetItem.labelArea.visible = true
|
||||
targetItem.labelArea2.visible = true
|
||||
control.currentIndex = targetItem.index
|
||||
targetItem = null
|
||||
|
||||
control.editor.destroy()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ Item {
|
|||
signal requestPathEditor()
|
||||
|
||||
onCurrentUrlChanged: {
|
||||
_viewLoader.item.reset()
|
||||
_viewLoader.item.forceActiveFocus()
|
||||
}
|
||||
|
||||
|
@ -31,7 +32,8 @@ Item {
|
|||
|
||||
Label {
|
||||
id: _fileTips
|
||||
text: qsTr("No files")
|
||||
text: qsTr("Empty folder")
|
||||
font.pointSize: 20
|
||||
anchors.centerIn: parent
|
||||
visible: false
|
||||
}
|
||||
|
@ -70,6 +72,11 @@ Item {
|
|||
case 0: return _listViewComponent
|
||||
case 1: return _gridViewComponent
|
||||
}
|
||||
|
||||
onSourceComponentChanged: {
|
||||
// 焦点
|
||||
_viewLoader.item.forceActiveFocus()
|
||||
}
|
||||
}
|
||||
|
||||
Loader {
|
||||
|
|
|
@ -5,21 +5,21 @@
|
|||
<name>CreateFolderDialog</name>
|
||||
<message>
|
||||
<location filename="../qml/Dialogs/CreateFolderDialog.qml" line="10"/>
|
||||
<source>New Folder</source>
|
||||
<translation>新建文件夹</translation>
|
||||
<source>New folder name</source>
|
||||
<translation>新文件夹名</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/Dialogs/CreateFolderDialog.qml" line="36"/>
|
||||
<source>Name</source>
|
||||
<translation>名称</translation>
|
||||
<location filename="../qml/Dialogs/CreateFolderDialog.qml" line="38"/>
|
||||
<source>New folder</source>
|
||||
<translation>新文件夹</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/Dialogs/CreateFolderDialog.qml" line="49"/>
|
||||
<location filename="../qml/Dialogs/CreateFolderDialog.qml" line="48"/>
|
||||
<source>Cancel</source>
|
||||
<translation>取消</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/Dialogs/CreateFolderDialog.qml" line="55"/>
|
||||
<location filename="../qml/Dialogs/CreateFolderDialog.qml" line="54"/>
|
||||
<source>OK</source>
|
||||
<translation>确定</translation>
|
||||
</message>
|
||||
|
@ -27,7 +27,7 @@
|
|||
<context>
|
||||
<name>DesktopView</name>
|
||||
<message>
|
||||
<location filename="../desktop/desktopview.cpp" line="38"/>
|
||||
<location filename="../desktop/desktopview.cpp" line="44"/>
|
||||
<source>Desktop</source>
|
||||
<translation>桌面</translation>
|
||||
</message>
|
||||
|
@ -35,81 +35,77 @@
|
|||
<context>
|
||||
<name>FolderModel</name>
|
||||
<message>
|
||||
<source>%1 selected</source>
|
||||
<translation type="vanished">选中了 %1 项</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="137"/>
|
||||
<location filename="../model/foldermodel.cpp" line="139"/>
|
||||
<source>%1 item</source>
|
||||
<translation>%1 项</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="137"/>
|
||||
<location filename="../model/foldermodel.cpp" line="139"/>
|
||||
<source>%1 items</source>
|
||||
<translation>%1 项</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="805"/>
|
||||
<location filename="../model/foldermodel.cpp" line="807"/>
|
||||
<source>Select All</source>
|
||||
<translation>全选</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="1007"/>
|
||||
<location filename="../model/foldermodel.cpp" line="1009"/>
|
||||
<source>Open</source>
|
||||
<translation>打开</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="1010"/>
|
||||
<location filename="../model/foldermodel.cpp" line="1012"/>
|
||||
<source>Cut</source>
|
||||
<translation>剪切</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="1013"/>
|
||||
<location filename="../model/foldermodel.cpp" line="1015"/>
|
||||
<source>Copy</source>
|
||||
<translation>复制</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="1016"/>
|
||||
<location filename="../model/foldermodel.cpp" line="1018"/>
|
||||
<source>Paste</source>
|
||||
<translation>粘贴</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="1019"/>
|
||||
<location filename="../model/foldermodel.cpp" line="1021"/>
|
||||
<source>New Folder</source>
|
||||
<translation>新建文件夹</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="1022"/>
|
||||
<location filename="../model/foldermodel.cpp" line="1024"/>
|
||||
<source>Move To Trash</source>
|
||||
<translation>移动到回收站</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="1025"/>
|
||||
<location filename="../model/foldermodel.cpp" line="1027"/>
|
||||
<source>Empty Trash</source>
|
||||
<translation>清空回收站</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="1028"/>
|
||||
<location filename="../model/foldermodel.cpp" line="1030"/>
|
||||
<source>Delete</source>
|
||||
<translation>删除</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="1031"/>
|
||||
<location filename="../model/foldermodel.cpp" line="1033"/>
|
||||
<source>Rename</source>
|
||||
<translation>重命名</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="1034"/>
|
||||
<location filename="../model/foldermodel.cpp" line="1036"/>
|
||||
<source>Open in Terminal</source>
|
||||
<translation>在终端中打开</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="1037"/>
|
||||
<location filename="../model/foldermodel.cpp" line="1039"/>
|
||||
<source>Set as Wallpaper</source>
|
||||
<translation>设置为壁纸</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../model/foldermodel.cpp" line="1040"/>
|
||||
<location filename="../model/foldermodel.cpp" line="1042"/>
|
||||
<source>Properties</source>
|
||||
<translation>属性</translation>
|
||||
</message>
|
||||
|
@ -118,26 +114,26 @@
|
|||
<name>FolderPage</name>
|
||||
<message>
|
||||
<location filename="../qml/FolderPage.qml" line="34"/>
|
||||
<source>No files</source>
|
||||
<translation>无文件</translation>
|
||||
<source>Empty folder</source>
|
||||
<translation>空文件夹</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/FolderPage.qml" line="105"/>
|
||||
<location filename="../qml/FolderPage.qml" line="106"/>
|
||||
<source>%1 item</source>
|
||||
<translation>%1 项</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/FolderPage.qml" line="106"/>
|
||||
<location filename="../qml/FolderPage.qml" line="107"/>
|
||||
<source>%1 items</source>
|
||||
<translation>%1 项</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/FolderPage.qml" line="111"/>
|
||||
<location filename="../qml/FolderPage.qml" line="112"/>
|
||||
<source>%1 selected</source>
|
||||
<translation>选中了 %1 项</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../qml/FolderPage.qml" line="122"/>
|
||||
<location filename="../qml/FolderPage.qml" line="123"/>
|
||||
<source>Empty Trash</source>
|
||||
<translation>清空回收站</translation>
|
||||
</message>
|
||||
|
|
Loading…
Reference in a new issue