QmlDesigner: Improve keyboard navigation on assets view

keyboard navigation now works when you focus the tab without
requiring to also click on the treeview itself.

Fixes: QDS-10397
Change-Id: I2cda08365c1a68c72121166d4fd50f1786f913bc
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Miikka Heikkinen
2023-08-04 13:48:15 +03:00
parent a80dc7789e
commit 60ea887d5f
3 changed files with 18 additions and 28 deletions

View File

@@ -264,6 +264,7 @@ Item {
contextMenu: contextMenu contextMenu: contextMenu
width: parent.width width: parent.width
height: parent.height - assetsView.y height: parent.height - assetsView.y
focus: true
} }
} }
} }

View File

@@ -348,22 +348,21 @@ TreeView {
root.currentFilePath = filePath root.currentFilePath = filePath
} }
Keys.enabled: true function moveSelection(amount)
{
Keys.onUpPressed: { if (!assetsModel.haveFiles || !amount)
if (!root.currentFilePath)
return return
let index = assetsModel.indexForPath(root.currentFilePath) let index = root.currentFilePath ? assetsModel.indexForPath(root.currentFilePath)
: root.__modelIndex(root.firstRow)
let row = root.rowAtIndex(index) let row = root.rowAtIndex(index)
let nextRow = row let nextRow = row
let nextIndex = index let nextIndex = index
do { do {
if (nextRow <= root.firstRow) nextRow = nextRow + amount
return // don't select hidden rows if ((amount < 0 && nextRow < root.firstRow) || (amount > 0 && nextRow > root.lastRow))
return
nextRow--
nextIndex = root.__modelIndex(nextRow) nextIndex = root.__modelIndex(nextRow)
} while (assetsModel.isDirectory(nextIndex)) } while (assetsModel.isDirectory(nextIndex))
@@ -371,26 +370,14 @@ TreeView {
root.positionViewAtRow(nextRow, TableView.Contain) root.positionViewAtRow(nextRow, TableView.Contain)
} }
Keys.enabled: true
Keys.onUpPressed: {
moveSelection(-1)
}
Keys.onDownPressed: { Keys.onDownPressed: {
if (!root.currentFilePath) moveSelection(1)
return
let index = assetsModel.indexForPath(root.currentFilePath)
let row = root.rowAtIndex(index)
let nextRow = row
let nextIndex = index
do {
if (nextRow >= root.lastRow)
return // don't select hidden rows
nextRow++
nextIndex = root.__modelIndex(nextRow)
} while (assetsModel.isDirectory(nextIndex))
root.__selectRow(nextRow)
root.positionViewAtRow(nextRow, TableView.Contain)
} }
ConfirmDeleteFilesDialog { ConfirmDeleteFilesDialog {

View File

@@ -151,6 +151,8 @@ AssetsLibraryWidget::AssetsLibraryWidget(AsynchronousImageCache &asynchronousFon
// init the first load of the QML UI elements // init the first load of the QML UI elements
reloadQmlSource(); reloadQmlSource();
setFocusProxy(m_assetsWidget->quickWidget());
} }
void AssetsLibraryWidget::contextHelp(const Core::IContext::HelpCallback &callback) const void AssetsLibraryWidget::contextHelp(const Core::IContext::HelpCallback &callback) const