QmlDesigner: Focus material browser's sections separately

Focus is shown by a thicker selection border for material and
texture items. Delete shortcut works on the selected focused item.

Fixes: QDS-8401
Change-Id: I1ddbbd595a0da3f0e2b7cf2bb9e611532770bc3c
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
Mahmoud Badri
2022-11-25 17:30:05 +02:00
parent ddecd338a8
commit ea55e01051
7 changed files with 49 additions and 4 deletions

View File

@@ -36,7 +36,7 @@ Rectangle {
mouseArea.forceActiveFocus()
}
border.width: materialBrowserModel.selectedIndex === index ? 1 : 0
border.width: materialBrowserModel.selectedIndex === index ? rootView.materialSectionFocused ? 3 : 1 : 0
border.color: materialBrowserModel.selectedIndex === index
? StudioTheme.Values.themeControlOutlineInteraction
: "transparent"
@@ -50,6 +50,7 @@ Rectangle {
acceptedButtons: Qt.LeftButton | Qt.RightButton
onPressed: (mouse) => {
rootView.focusMaterialSection(true)
materialBrowserModel.selectMaterial(index)
if (mouse.button === Qt.LeftButton)
@@ -116,7 +117,10 @@ Rectangle {
anchors.fill: parent
onClicked: materialBrowserModel.selectMaterial(index)
onClicked: {
rootView.focusMaterialSection(true)
materialBrowserModel.selectMaterial(index)
}
onDoubleClicked: root.startRename()
}
}

View File

@@ -13,7 +13,8 @@ Rectangle {
visible: textureVisible
color: "transparent"
border.width: materialBrowserTexturesModel.selectedIndex === index ? 1 : 0
border.width: materialBrowserTexturesModel.selectedIndex === index
? !rootView.materialSectionFocused ? 3 : 1 : 0
border.color: materialBrowserTexturesModel.selectedIndex === index
? StudioTheme.Values.themeControlOutlineInteraction
: "transparent"
@@ -27,6 +28,7 @@ Rectangle {
acceptedButtons: Qt.LeftButton | Qt.RightButton
onPressed: (mouse) => {
rootView.focusMaterialSection(false)
materialBrowserTexturesModel.selectTexture(index)
if (mouse.button === Qt.LeftButton)

View File

@@ -47,6 +47,8 @@ public:
bool hasMaterialLibrary() const;
void setHasMaterialLibrary(bool b);
bool isEmpty() const { return m_isEmpty; }
QString copiedMaterialType() const;
void setCopiedMaterialType(const QString &matType);

View File

@@ -41,6 +41,8 @@ public:
bool hasSingleModelSelection() const;
void setHasSingleModelSelection(bool b);
bool isEmpty() const { return m_isEmpty; }
void resetModel();
Q_INVOKABLE void selectTexture(int idx, bool force = false);

View File

@@ -440,7 +440,7 @@ void MaterialBrowserView::customNotification(const AbstractView *view,
refreshModel(true);
});
} else if (identifier == "delete_selected_material") {
m_widget->materialBrowserModel()->deleteSelectedMaterial();
m_widget->deleteSelectedItem();
} else if (identifier == "apply_texture_to_model3D") {
applyTextureToModel3D(nodeList.at(0), nodeList.at(1));
} else if (identifier == "apply_texture_to_material") {

View File

@@ -191,6 +191,16 @@ MaterialBrowserWidget::MaterialBrowserWidget(AsynchronousImageCache &imageCache,
m_qmlSourceUpdateShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F8), this);
connect(m_qmlSourceUpdateShortcut, &QShortcut::activated, this, &MaterialBrowserWidget::reloadQmlSource);
connect(m_materialBrowserModel, &MaterialBrowserModel::isEmptyChanged, this, [&] {
if (m_materialBrowserModel->isEmpty())
focusMaterialSection(false);
});
connect(m_materialBrowserTexturesModel, &MaterialBrowserTexturesModel::isEmptyChanged, this, [&] {
if (m_materialBrowserTexturesModel->isEmpty())
focusMaterialSection(true);
});
QmlDesignerPlugin::trackWidgetFocusTime(this, Constants::EVENT_MATERIALBROWSER_TIME);
reloadQmlSource();
@@ -204,6 +214,14 @@ void MaterialBrowserWidget::updateMaterialPreview(const ModelNode &node, const Q
QMetaObject::invokeMethod(m_quickWidget->rootObject(), "refreshPreview", Q_ARG(QVariant, idx));
}
void MaterialBrowserWidget::deleteSelectedItem()
{
if (m_materialSectionFocused)
m_materialBrowserModel->deleteSelectedMaterial();
else
m_materialBrowserTexturesModel->deleteSelectedTexture();
}
QList<QToolButton *> MaterialBrowserWidget::createToolBarWidgets()
{
return {};
@@ -247,6 +265,14 @@ void MaterialBrowserWidget::acceptBundleTextureDrop()
m_materialBrowserView->emitCustomNotification("drop_bundle_texture", {}, {}); // To ContentLibraryView
}
void MaterialBrowserWidget::focusMaterialSection(bool focusMatSec)
{
if (focusMatSec != m_materialSectionFocused) {
m_materialSectionFocused = focusMatSec;
emit materialSectionFocusedChanged();
}
}
QString MaterialBrowserWidget::qmlSourcesPath()
{
#ifdef SHARE_QML_PATH

View File

@@ -34,6 +34,8 @@ class MaterialBrowserWidget : public QFrame
{
Q_OBJECT
Q_PROPERTY(bool materialSectionFocused MEMBER m_materialSectionFocused NOTIFY materialSectionFocusedChanged)
public:
MaterialBrowserWidget(class AsynchronousImageCache &imageCache, MaterialBrowserView *view);
~MaterialBrowserWidget() = default;
@@ -47,17 +49,22 @@ public:
QPointer<MaterialBrowserModel> materialBrowserModel() const;
QPointer<MaterialBrowserTexturesModel> materialBrowserTexturesModel() const;
void updateMaterialPreview(const ModelNode &node, const QPixmap &pixmap);
void deleteSelectedItem();
Q_INVOKABLE void handleSearchFilterChanged(const QString &filterText);
Q_INVOKABLE void startDragMaterial(int index, const QPointF &mousePos);
Q_INVOKABLE void startDragTexture(int index, const QPointF &mousePos);
Q_INVOKABLE void acceptBundleMaterialDrop();
Q_INVOKABLE void acceptBundleTextureDrop();
Q_INVOKABLE void focusMaterialSection(bool focusMatSec);
QQuickWidget *quickWidget() const;
void clearPreviewCache();
signals:
void materialSectionFocusedChanged();
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
@@ -80,6 +87,8 @@ private:
ModelNode m_materialToDrag;
ModelNode m_textureToDrag;
QPoint m_dragStartPoint;
bool m_materialSectionFocused = true;
};
} // namespace QmlDesigner