forked from qt-creator/qt-creator
QmlDesigner: Scroll material browser on selection change
When selection changes in material browser, the browser grid is scrolled so that the selected item is visible. Fixes: QDS-9010 Change-Id: Ie6f4383b0c8add2965fc42ffdf740effdf02fa67 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -140,8 +140,8 @@ Item {
|
|||||||
if (newTargetIdx >= 0)
|
if (newTargetIdx >= 0)
|
||||||
targetIdx = newTargetIdx
|
targetIdx = newTargetIdx
|
||||||
}
|
}
|
||||||
rootView.materialSectionFocused = true
|
|
||||||
materialBrowserModel.selectMaterial(targetIdx)
|
materialBrowserModel.selectMaterial(targetIdx)
|
||||||
|
rootView.focusMaterialSection(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,8 +170,8 @@ Item {
|
|||||||
if (newTargetIdx >= 0)
|
if (newTargetIdx >= 0)
|
||||||
targetIdx = newTargetIdx
|
targetIdx = newTargetIdx
|
||||||
}
|
}
|
||||||
rootView.materialSectionFocused = false
|
|
||||||
materialBrowserTexturesModel.selectTexture(targetIdx)
|
materialBrowserTexturesModel.selectTexture(targetIdx)
|
||||||
|
rootView.focusMaterialSection(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (texSecFocused) {
|
} else if (texSecFocused) {
|
||||||
@@ -235,7 +235,9 @@ Item {
|
|||||||
MouseArea {
|
MouseArea {
|
||||||
id: rootMouseArea
|
id: rootMouseArea
|
||||||
|
|
||||||
anchors.fill: parent
|
y: topContent.height
|
||||||
|
width: parent.width
|
||||||
|
height: parent.height - topContent.height
|
||||||
|
|
||||||
acceptedButtons: Qt.RightButton
|
acceptedButtons: Qt.RightButton
|
||||||
|
|
||||||
@@ -253,15 +255,65 @@ Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ensureVisible(yPos, itemHeight)
|
||||||
|
{
|
||||||
|
if (yPos < 0) {
|
||||||
|
let adjustedY = scrollView.contentY + yPos
|
||||||
|
if (adjustedY < itemHeight)
|
||||||
|
scrollView.contentY = 0
|
||||||
|
else
|
||||||
|
scrollView.contentY = adjustedY
|
||||||
|
} else if (yPos + itemHeight > scrollView.height) {
|
||||||
|
let adjustedY = scrollView.contentY + yPos + itemHeight - scrollView.height + 8
|
||||||
|
if (scrollView.contentHeight - adjustedY - scrollView.height < itemHeight)
|
||||||
|
scrollView.contentY = scrollView.contentHeight - scrollView.height
|
||||||
|
else
|
||||||
|
scrollView.contentY = adjustedY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: materialBrowserModel
|
target: materialBrowserModel
|
||||||
|
|
||||||
function onSelectedIndexChanged() {
|
function onSelectedIndexChanged()
|
||||||
|
{
|
||||||
// commit rename upon changing selection
|
// commit rename upon changing selection
|
||||||
if (root.currMaterialItem)
|
if (root.currMaterialItem)
|
||||||
root.currMaterialItem.commitRename();
|
root.currMaterialItem.commitRename();
|
||||||
|
|
||||||
root.currMaterialItem = materialRepeater.itemAt(materialBrowserModel.selectedIndex);
|
root.currMaterialItem = materialRepeater.itemAt(materialBrowserModel.selectedIndex);
|
||||||
|
|
||||||
|
if (materialsSection.expanded) {
|
||||||
|
ensureVisible(root.currMaterialItem.mapToItem(scrollView, 0, 0).y,
|
||||||
|
root.currMaterialItem.height)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: materialBrowserTexturesModel
|
||||||
|
|
||||||
|
function onSelectedIndexChanged()
|
||||||
|
{
|
||||||
|
if (texturesSection.expanded) {
|
||||||
|
let currItem = texturesRepeater.itemAt(materialBrowserTexturesModel.selectedIndex)
|
||||||
|
ensureVisible(currItem.mapToItem(scrollView, 0, 0).y, currItem.height)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: rootView
|
||||||
|
|
||||||
|
function onMaterialSectionFocusedChanged()
|
||||||
|
{
|
||||||
|
if (rootView.materialSectionFocused && materialsSection.expanded) {
|
||||||
|
ensureVisible(root.currMaterialItem.mapToItem(scrollView, 0, 0).y,
|
||||||
|
root.currMaterialItem.height)
|
||||||
|
} else if (!rootView.materialSectionFocused && texturesSection.expanded) {
|
||||||
|
let currItem = texturesRepeater.itemAt(materialBrowserTexturesModel.selectedIndex)
|
||||||
|
ensureVisible(currItem.mapToItem(scrollView, 0, 0).y, currItem.height)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,6 +330,7 @@ Item {
|
|||||||
spacing: 5
|
spacing: 5
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
id: topContent
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: StudioTheme.Values.doubleToolbarHeight
|
height: StudioTheme.Values.doubleToolbarHeight
|
||||||
color: StudioTheme.Values.themeToolbarBackground
|
color: StudioTheme.Values.themeToolbarBackground
|
||||||
@@ -350,11 +403,15 @@ Item {
|
|||||||
id: scrollView
|
id: scrollView
|
||||||
|
|
||||||
width: root.width
|
width: root.width
|
||||||
height: root.height - searchBox.height
|
height: root.height - topContent.height
|
||||||
clip: true
|
clip: true
|
||||||
visible: root.enableUiElements
|
visible: root.enableUiElements
|
||||||
interactive: !ctxMenu.opened && !ctxMenuTextures.opened && !rootView.isDragging
|
interactive: !ctxMenu.opened && !ctxMenuTextures.opened && !rootView.isDragging
|
||||||
|
|
||||||
|
Behavior on contentY {
|
||||||
|
PropertyAnimation { easing.type: Easing.InOutQuad }
|
||||||
|
}
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
Item {
|
Item {
|
||||||
width: root.width
|
width: root.width
|
||||||
|
@@ -62,8 +62,8 @@ Rectangle {
|
|||||||
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||||
|
|
||||||
onPressed: (mouse) => {
|
onPressed: (mouse) => {
|
||||||
rootView.focusMaterialSection(true)
|
|
||||||
materialBrowserModel.selectMaterial(index)
|
materialBrowserModel.selectMaterial(index)
|
||||||
|
rootView.focusMaterialSection(true)
|
||||||
|
|
||||||
if (mouse.button === Qt.LeftButton)
|
if (mouse.button === Qt.LeftButton)
|
||||||
rootView.startDragMaterial(index, mapToGlobal(mouse.x, mouse.y))
|
rootView.startDragMaterial(index, mapToGlobal(mouse.x, mouse.y))
|
||||||
@@ -130,8 +130,8 @@ Rectangle {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
rootView.focusMaterialSection(true)
|
|
||||||
materialBrowserModel.selectMaterial(index)
|
materialBrowserModel.selectMaterial(index)
|
||||||
|
rootView.focusMaterialSection(true)
|
||||||
}
|
}
|
||||||
onDoubleClicked: root.startRename()
|
onDoubleClicked: root.startRename()
|
||||||
}
|
}
|
||||||
|
@@ -30,8 +30,8 @@ Rectangle {
|
|||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
|
|
||||||
onPressed: (mouse) => {
|
onPressed: (mouse) => {
|
||||||
rootView.focusMaterialSection(false)
|
|
||||||
materialBrowserTexturesModel.selectTexture(index)
|
materialBrowserTexturesModel.selectTexture(index)
|
||||||
|
rootView.focusMaterialSection(false)
|
||||||
|
|
||||||
if (mouse.button === Qt.LeftButton)
|
if (mouse.button === Qt.LeftButton)
|
||||||
rootView.startDragTexture(index, mapToGlobal(mouse.x, mouse.y))
|
rootView.startDragTexture(index, mapToGlobal(mouse.x, mouse.y))
|
||||||
|
Reference in New Issue
Block a user