summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2023-02-20 15:39:42 +0200
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2023-02-23 12:38:29 +0000
commitd39f469e513539987da15d402b577ddde62427c6 (patch)
tree08cfe6cf535082e29cff855b1f0ec8c7947168ad
parent8b5c454881dcad5436dc3d7fb97642f65bfba2ed (diff)
downloadqt-creator-d39f469e513539987da15d402b577ddde62427c6.tar.gz
QmlDesigner: Fix focus issues in material browser
Fixed focus loss on context menu close. Fixed an issue with main view also handling cursor and enter keys when editing material name. Expanding a section now focuses the expanded section. Dragging items from content library now focuses correct section. Fixes: QDS-9215 Change-Id: I2176c7e52d8855c547db426b55ab739ca8f1db06 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
-rw-r--r--share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialBrowser.qml19
-rw-r--r--share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialBrowserContextMenu.qml7
-rw-r--r--share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialItem.qml5
-rw-r--r--src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp2
-rw-r--r--src/plugins/qmldesigner/components/createtexture.cpp2
-rw-r--r--src/plugins/qmldesigner/components/materialbrowser/materialbrowserview.cpp4
6 files changed, 35 insertions, 4 deletions
diff --git a/share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialBrowser.qml b/share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialBrowser.qml
index 27df4d0f46..7829c2aade 100644
--- a/share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialBrowser.qml
+++ b/share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialBrowser.qml
@@ -367,10 +367,17 @@ Item {
MaterialBrowserContextMenu {
id: ctxMenu
+ onClosed: {
+ if (restoreFocusOnClose)
+ scrollView.forceActiveFocus()
+ }
}
TextureBrowserContextMenu {
id: ctxMenuTextures
+ onClosed: {
+ scrollView.forceActiveFocus()
+ }
}
component DoubleButton: Rectangle {
@@ -629,7 +636,11 @@ Item {
}
onExpandedChanged: {
- if (!expanded) {
+ if (expanded) {
+ if (root.visibleItemCount(materialBrowserModel) > 0)
+ rootView.focusMaterialSection(true)
+ scrollView.forceActiveFocus()
+ } else {
root.startDelayedEnsureTimer(300) // wait for section collapse animation
rootView.focusMaterialSection(false)
}
@@ -714,7 +725,11 @@ Item {
}
onExpandedChanged: {
- if (!expanded) {
+ if (expanded) {
+ if (root.visibleItemCount(materialBrowserTexturesModel) > 0)
+ rootView.focusMaterialSection(false)
+ scrollView.forceActiveFocus()
+ } else {
root.startDelayedEnsureTimer(300) // wait for section collapse animation
rootView.focusMaterialSection(true)
}
diff --git a/share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialBrowserContextMenu.qml b/share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialBrowserContextMenu.qml
index 25e271c1c4..df65d61c22 100644
--- a/share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialBrowserContextMenu.qml
+++ b/share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialBrowserContextMenu.qml
@@ -13,11 +13,13 @@ StudioControls.Menu {
property var targetItem: null
property int copiedMaterialInternalId: -1
property var matSectionsModel: []
+ property bool restoreFocusOnClose: true
function popupMenu(targetItem = null, targetMaterial = null)
{
this.targetItem = targetItem
this.targetMaterial = targetMaterial
+ restoreFocusOnClose = true
popup()
}
@@ -102,7 +104,10 @@ StudioControls.Menu {
StudioControls.MenuItem {
text: qsTr("Rename")
enabled: root.targetItem
- onTriggered: root.targetItem.startRename();
+ onTriggered: {
+ restoreFocusOnClose = false
+ root.targetItem.startRename()
+ }
}
StudioControls.MenuItem {
diff --git a/share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialItem.qml b/share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialItem.qml
index 3783cc8c10..220262c2ae 100644
--- a/share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialItem.qml
+++ b/share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialItem.qml
@@ -91,6 +91,11 @@ Rectangle {
cache: false
}
+ // Eat keys so they are not passed to parent while editing name
+ Keys.onPressed: (e) => {
+ e.accepted = true;
+ }
+
TextInput {
id: matName
diff --git a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp
index 764bb7f155..13e5fa35b3 100644
--- a/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp
+++ b/src/plugins/qmldesigner/components/contentlibrary/contentlibraryview.cpp
@@ -323,6 +323,8 @@ ModelNode ContentLibraryView::createMaterial(const NodeMetaInfo &metaInfo)
VariantProperty objNameProp = newMatNode.variantProperty("objectName");
objNameProp.setValue(newName);
+ emitCustomNotification("focus_material_section", {});
+
return newMatNode;
}
diff --git a/src/plugins/qmldesigner/components/createtexture.cpp b/src/plugins/qmldesigner/components/createtexture.cpp
index 3f0f588b99..f716a63bcc 100644
--- a/src/plugins/qmldesigner/components/createtexture.cpp
+++ b/src/plugins/qmldesigner/components/createtexture.cpp
@@ -36,7 +36,7 @@ ModelNode CreateTexture::execute(const QString &filePath, AddTextureMode mode, i
QTimer::singleShot(0, m_view, [this, texture]() {
if (m_view->model())
- m_view->emitCustomNotification("selected_texture_changed", {texture});
+ m_view->emitCustomNotification("selected_texture_changed", {texture}, {true});
});
return texture;
diff --git a/src/plugins/qmldesigner/components/materialbrowser/materialbrowserview.cpp b/src/plugins/qmldesigner/components/materialbrowser/materialbrowserview.cpp
index 5c01dff841..fc1db47fd4 100644
--- a/src/plugins/qmldesigner/components/materialbrowser/materialbrowserview.cpp
+++ b/src/plugins/qmldesigner/components/materialbrowser/materialbrowserview.cpp
@@ -497,6 +497,8 @@ void MaterialBrowserView::customNotification(const AbstractView *view,
if (idx != -1) {
m_widget->materialBrowserTexturesModel()->selectTexture(idx);
m_widget->materialBrowserTexturesModel()->refreshSearch();
+ if (!data.isEmpty() && data[0].toBool())
+ m_widget->focusMaterialSection(false);
}
} else if (identifier == "refresh_material_browser") {
QTimer::singleShot(0, model(), [this]() {
@@ -511,6 +513,8 @@ void MaterialBrowserView::customNotification(const AbstractView *view,
applyTextureToModel3D(nodeList.at(0), nodeList.at(1));
} else if (identifier == "apply_texture_to_material") {
applyTextureToMaterial({nodeList.at(0)}, nodeList.at(1));
+ } else if (identifier == "focus_material_section") {
+ m_widget->focusMaterialSection(true);
}
}