forked from qt-creator/qt-creator
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:
@@ -36,7 +36,7 @@ Rectangle {
|
|||||||
mouseArea.forceActiveFocus()
|
mouseArea.forceActiveFocus()
|
||||||
}
|
}
|
||||||
|
|
||||||
border.width: materialBrowserModel.selectedIndex === index ? 1 : 0
|
border.width: materialBrowserModel.selectedIndex === index ? rootView.materialSectionFocused ? 3 : 1 : 0
|
||||||
border.color: materialBrowserModel.selectedIndex === index
|
border.color: materialBrowserModel.selectedIndex === index
|
||||||
? StudioTheme.Values.themeControlOutlineInteraction
|
? StudioTheme.Values.themeControlOutlineInteraction
|
||||||
: "transparent"
|
: "transparent"
|
||||||
@@ -50,6 +50,7 @@ Rectangle {
|
|||||||
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||||
|
|
||||||
onPressed: (mouse) => {
|
onPressed: (mouse) => {
|
||||||
|
rootView.focusMaterialSection(true)
|
||||||
materialBrowserModel.selectMaterial(index)
|
materialBrowserModel.selectMaterial(index)
|
||||||
|
|
||||||
if (mouse.button === Qt.LeftButton)
|
if (mouse.button === Qt.LeftButton)
|
||||||
@@ -116,7 +117,10 @@ Rectangle {
|
|||||||
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
onClicked: materialBrowserModel.selectMaterial(index)
|
onClicked: {
|
||||||
|
rootView.focusMaterialSection(true)
|
||||||
|
materialBrowserModel.selectMaterial(index)
|
||||||
|
}
|
||||||
onDoubleClicked: root.startRename()
|
onDoubleClicked: root.startRename()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,7 +13,8 @@ Rectangle {
|
|||||||
visible: textureVisible
|
visible: textureVisible
|
||||||
|
|
||||||
color: "transparent"
|
color: "transparent"
|
||||||
border.width: materialBrowserTexturesModel.selectedIndex === index ? 1 : 0
|
border.width: materialBrowserTexturesModel.selectedIndex === index
|
||||||
|
? !rootView.materialSectionFocused ? 3 : 1 : 0
|
||||||
border.color: materialBrowserTexturesModel.selectedIndex === index
|
border.color: materialBrowserTexturesModel.selectedIndex === index
|
||||||
? StudioTheme.Values.themeControlOutlineInteraction
|
? StudioTheme.Values.themeControlOutlineInteraction
|
||||||
: "transparent"
|
: "transparent"
|
||||||
@@ -27,6 +28,7 @@ Rectangle {
|
|||||||
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||||
|
|
||||||
onPressed: (mouse) => {
|
onPressed: (mouse) => {
|
||||||
|
rootView.focusMaterialSection(false)
|
||||||
materialBrowserTexturesModel.selectTexture(index)
|
materialBrowserTexturesModel.selectTexture(index)
|
||||||
|
|
||||||
if (mouse.button === Qt.LeftButton)
|
if (mouse.button === Qt.LeftButton)
|
||||||
|
@@ -47,6 +47,8 @@ public:
|
|||||||
bool hasMaterialLibrary() const;
|
bool hasMaterialLibrary() const;
|
||||||
void setHasMaterialLibrary(bool b);
|
void setHasMaterialLibrary(bool b);
|
||||||
|
|
||||||
|
bool isEmpty() const { return m_isEmpty; }
|
||||||
|
|
||||||
QString copiedMaterialType() const;
|
QString copiedMaterialType() const;
|
||||||
void setCopiedMaterialType(const QString &matType);
|
void setCopiedMaterialType(const QString &matType);
|
||||||
|
|
||||||
|
@@ -41,6 +41,8 @@ public:
|
|||||||
bool hasSingleModelSelection() const;
|
bool hasSingleModelSelection() const;
|
||||||
void setHasSingleModelSelection(bool b);
|
void setHasSingleModelSelection(bool b);
|
||||||
|
|
||||||
|
bool isEmpty() const { return m_isEmpty; }
|
||||||
|
|
||||||
void resetModel();
|
void resetModel();
|
||||||
|
|
||||||
Q_INVOKABLE void selectTexture(int idx, bool force = false);
|
Q_INVOKABLE void selectTexture(int idx, bool force = false);
|
||||||
|
@@ -440,7 +440,7 @@ void MaterialBrowserView::customNotification(const AbstractView *view,
|
|||||||
refreshModel(true);
|
refreshModel(true);
|
||||||
});
|
});
|
||||||
} else if (identifier == "delete_selected_material") {
|
} else if (identifier == "delete_selected_material") {
|
||||||
m_widget->materialBrowserModel()->deleteSelectedMaterial();
|
m_widget->deleteSelectedItem();
|
||||||
} else if (identifier == "apply_texture_to_model3D") {
|
} else if (identifier == "apply_texture_to_model3D") {
|
||||||
applyTextureToModel3D(nodeList.at(0), nodeList.at(1));
|
applyTextureToModel3D(nodeList.at(0), nodeList.at(1));
|
||||||
} else if (identifier == "apply_texture_to_material") {
|
} else if (identifier == "apply_texture_to_material") {
|
||||||
|
@@ -191,6 +191,16 @@ MaterialBrowserWidget::MaterialBrowserWidget(AsynchronousImageCache &imageCache,
|
|||||||
m_qmlSourceUpdateShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F8), this);
|
m_qmlSourceUpdateShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F8), this);
|
||||||
connect(m_qmlSourceUpdateShortcut, &QShortcut::activated, this, &MaterialBrowserWidget::reloadQmlSource);
|
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);
|
QmlDesignerPlugin::trackWidgetFocusTime(this, Constants::EVENT_MATERIALBROWSER_TIME);
|
||||||
|
|
||||||
reloadQmlSource();
|
reloadQmlSource();
|
||||||
@@ -204,6 +214,14 @@ void MaterialBrowserWidget::updateMaterialPreview(const ModelNode &node, const Q
|
|||||||
QMetaObject::invokeMethod(m_quickWidget->rootObject(), "refreshPreview", Q_ARG(QVariant, idx));
|
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()
|
QList<QToolButton *> MaterialBrowserWidget::createToolBarWidgets()
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
@@ -247,6 +265,14 @@ void MaterialBrowserWidget::acceptBundleTextureDrop()
|
|||||||
m_materialBrowserView->emitCustomNotification("drop_bundle_texture", {}, {}); // To ContentLibraryView
|
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()
|
QString MaterialBrowserWidget::qmlSourcesPath()
|
||||||
{
|
{
|
||||||
#ifdef SHARE_QML_PATH
|
#ifdef SHARE_QML_PATH
|
||||||
|
@@ -34,6 +34,8 @@ class MaterialBrowserWidget : public QFrame
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(bool materialSectionFocused MEMBER m_materialSectionFocused NOTIFY materialSectionFocusedChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MaterialBrowserWidget(class AsynchronousImageCache &imageCache, MaterialBrowserView *view);
|
MaterialBrowserWidget(class AsynchronousImageCache &imageCache, MaterialBrowserView *view);
|
||||||
~MaterialBrowserWidget() = default;
|
~MaterialBrowserWidget() = default;
|
||||||
@@ -47,17 +49,22 @@ public:
|
|||||||
QPointer<MaterialBrowserModel> materialBrowserModel() const;
|
QPointer<MaterialBrowserModel> materialBrowserModel() const;
|
||||||
QPointer<MaterialBrowserTexturesModel> materialBrowserTexturesModel() const;
|
QPointer<MaterialBrowserTexturesModel> materialBrowserTexturesModel() const;
|
||||||
void updateMaterialPreview(const ModelNode &node, const QPixmap &pixmap);
|
void updateMaterialPreview(const ModelNode &node, const QPixmap &pixmap);
|
||||||
|
void deleteSelectedItem();
|
||||||
|
|
||||||
Q_INVOKABLE void handleSearchFilterChanged(const QString &filterText);
|
Q_INVOKABLE void handleSearchFilterChanged(const QString &filterText);
|
||||||
Q_INVOKABLE void startDragMaterial(int index, const QPointF &mousePos);
|
Q_INVOKABLE void startDragMaterial(int index, const QPointF &mousePos);
|
||||||
Q_INVOKABLE void startDragTexture(int index, const QPointF &mousePos);
|
Q_INVOKABLE void startDragTexture(int index, const QPointF &mousePos);
|
||||||
Q_INVOKABLE void acceptBundleMaterialDrop();
|
Q_INVOKABLE void acceptBundleMaterialDrop();
|
||||||
Q_INVOKABLE void acceptBundleTextureDrop();
|
Q_INVOKABLE void acceptBundleTextureDrop();
|
||||||
|
Q_INVOKABLE void focusMaterialSection(bool focusMatSec);
|
||||||
|
|
||||||
QQuickWidget *quickWidget() const;
|
QQuickWidget *quickWidget() const;
|
||||||
|
|
||||||
void clearPreviewCache();
|
void clearPreviewCache();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void materialSectionFocusedChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||||
|
|
||||||
@@ -80,6 +87,8 @@ private:
|
|||||||
ModelNode m_materialToDrag;
|
ModelNode m_materialToDrag;
|
||||||
ModelNode m_textureToDrag;
|
ModelNode m_textureToDrag;
|
||||||
QPoint m_dragStartPoint;
|
QPoint m_dragStartPoint;
|
||||||
|
|
||||||
|
bool m_materialSectionFocused = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
Reference in New Issue
Block a user