forked from qt-creator/qt-creator
EffectComposer: Add a button for inserting uniform id to code editor
Task-number: QDS-14140 Change-Id: Ic4505a25ed46aee8e58fc1a9fd1af6e47c5172d2 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -9,7 +9,7 @@ import StudioTheme as StudioTheme
|
||||
Rectangle {
|
||||
id: root
|
||||
|
||||
property var rootView: shaderEditor
|
||||
property var rootEditor: shaderEditor
|
||||
|
||||
color: StudioTheme.Values.themeToolbarBackground
|
||||
|
||||
@@ -52,8 +52,8 @@ Rectangle {
|
||||
text: qsTr("Live Update")
|
||||
actionIndicatorVisible: false
|
||||
style: StudioTheme.Values.viewBarControlStyle
|
||||
checked: root.rootView ? root.rootView.liveUpdate : false
|
||||
onToggled: root.rootView.liveUpdate = checked
|
||||
checked: root.rootEditor ? root.rootEditor.liveUpdate : false
|
||||
onToggled: root.rootEditor.liveUpdate = checked
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
}
|
||||
}
|
||||
|
@@ -99,24 +99,28 @@ ColumnLayout {
|
||||
sourceComponent: MouseArea {
|
||||
id: hoverArea
|
||||
|
||||
width: 15
|
||||
width: buttonsRow.implicitWidth
|
||||
hoverEnabled: true
|
||||
enabled: true
|
||||
|
||||
Row {
|
||||
id: buttonsRow
|
||||
|
||||
anchors.fill: parent
|
||||
spacing: StudioTheme.Values.controlGap
|
||||
visible: hoverArea.containsMouse
|
||||
|
||||
StudioControls.AbstractButton {
|
||||
width: iconSize
|
||||
height: iconSize
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
buttonIcon: StudioTheme.Constants.copy_small
|
||||
backgroundVisible: false
|
||||
onClicked: rootView.copyText(dataScope.display)
|
||||
CellButton {
|
||||
buttonIcon: StudioTheme.Constants.assignTo_medium
|
||||
onClicked: rootEditor.insertTextToCursorPosition(dataScope.display)
|
||||
tooltip: qsTr("Insert into the editor cursor position.")
|
||||
}
|
||||
|
||||
// ToDo: Add a button for placing the value to the editor
|
||||
CellButton {
|
||||
buttonIcon: StudioTheme.Constants.copy_small
|
||||
onClicked: rootEditor.copyText(dataScope.display)
|
||||
tooltip: qsTr("Copy uniform name to clipboard.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -182,4 +186,22 @@ ColumnLayout {
|
||||
color: StudioTheme.Values.themeStateSeparator
|
||||
}
|
||||
}
|
||||
|
||||
component CellButton: StudioControls.AbstractButton {
|
||||
id: cellBtn
|
||||
|
||||
property alias tooltip: cellBtnTooltip.text
|
||||
|
||||
width: iconSize
|
||||
height: iconSize
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
buttonIcon: StudioTheme.Constants.assignTo_medium
|
||||
backgroundVisible: false
|
||||
|
||||
StudioControls.ToolTip {
|
||||
id: cellBtnTooltip
|
||||
|
||||
visible: cellBtn.hovered && text !== ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -184,6 +184,16 @@ void EffectShadersCodeEditor::copyText(const QString &text)
|
||||
qApp->clipboard()->setText(text);
|
||||
}
|
||||
|
||||
void EffectShadersCodeEditor::insertTextToCursorPosition(const QString &text)
|
||||
{
|
||||
auto editor = currentEditor();
|
||||
if (!editor)
|
||||
return;
|
||||
|
||||
editor->textCursor().insertText(text);
|
||||
editor->setFocus();
|
||||
}
|
||||
|
||||
EffectShadersCodeEditor *EffectShadersCodeEditor::instance()
|
||||
{
|
||||
static EffectShadersCodeEditor *editorInstance = new EffectShadersCodeEditor(
|
||||
@@ -310,4 +320,18 @@ void EffectShadersCodeEditor::selectNonEmptyShader(ShaderEditorData *data)
|
||||
widgetToSelect->setFocus();
|
||||
}
|
||||
|
||||
EffectCodeEditorWidget *EffectShadersCodeEditor::currentEditor() const
|
||||
{
|
||||
QWidget *currentTab = m_tabWidget->currentWidget();
|
||||
if (!m_currentEditorData || !currentTab)
|
||||
return nullptr;
|
||||
|
||||
if (currentTab == m_currentEditorData->fragmentEditor.get())
|
||||
return m_currentEditorData->fragmentEditor.get();
|
||||
if (currentTab == m_currentEditorData->vertexEditor.get())
|
||||
return m_currentEditorData->vertexEditor.get();
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace EffectComposer
|
||||
|
@@ -65,6 +65,7 @@ public:
|
||||
EffectComposerUniformsModel *uniforms);
|
||||
|
||||
Q_INVOKABLE void copyText(const QString &text);
|
||||
Q_INVOKABLE void insertTextToCursorPosition(const QString &text);
|
||||
|
||||
static EffectShadersCodeEditor *instance();
|
||||
|
||||
@@ -89,6 +90,8 @@ private:
|
||||
void setUniformsModel(EffectComposerUniformsTableModel *uniforms);
|
||||
void selectNonEmptyShader(ShaderEditorData *data);
|
||||
|
||||
EffectCodeEditorWidget *currentEditor() const;
|
||||
|
||||
QSettings *m_settings = nullptr;
|
||||
QPointer<StudioQuickWidget> m_headerWidget;
|
||||
QPointer<QTabWidget> m_tabWidget;
|
||||
|
Reference in New Issue
Block a user