sidebar: translator: change layout to reduce eye movement

This commit is contained in:
end-4
2025-06-11 11:06:22 +02:00
parent 65983ade46
commit 0fb28af3c7
@@ -100,114 +100,118 @@ Item {
} }
} }
Flickable { ColumnLayout {
anchors.fill: parent anchors.fill: parent
contentHeight: contentColumn.implicitHeight Flickable {
Layout.fillWidth: true
Layout.fillHeight: true
contentHeight: contentColumn.implicitHeight
ColumnLayout { ColumnLayout {
id: contentColumn id: contentColumn
anchors.fill: parent anchors.fill: parent
LanguageSelectorButton { // Source language button LanguageSelectorButton { // Target language button
id: sourceLanguageButton id: targetLanguageButton
displayText: root.sourceLanguage displayText: root.targetLanguage
onClicked: {
root.showLanguageSelectorDialog(false);
}
}
TextCanvas { // Content input
id: inputCanvas
isInput: true
placeholderText: qsTr("Enter text to translate...")
onInputTextChanged: {
translateTimer.restart();
}
GroupButton {
id: pasteButton
baseWidth: height
buttonRadius: Appearance.rounding.small
contentItem: MaterialSymbol {
anchors.centerIn: parent
horizontalAlignment: Text.AlignHCenter
iconSize: Appearance.font.pixelSize.larger
text: "content_paste"
color: deleteButton.enabled ? Appearance.colors.colOnLayer1 : Appearance.colors.colSubtext
}
onClicked: { onClicked: {
root.inputField.text = Quickshell.clipboardText root.showLanguageSelectorDialog(true);
} }
} }
GroupButton {
id: deleteButton
baseWidth: height
buttonRadius: Appearance.rounding.small
enabled: inputCanvas.inputTextArea.text.length > 0
contentItem: MaterialSymbol {
anchors.centerIn: parent
horizontalAlignment: Text.AlignHCenter
iconSize: Appearance.font.pixelSize.larger
text: "close"
color: deleteButton.enabled ? Appearance.colors.colOnLayer1 : Appearance.colors.colSubtext
}
onClicked: {
root.inputField.text = ""
}
}
}
LanguageSelectorButton { // Target language button TextCanvas { // Content translation
id: targetLanguageButton id: outputCanvas
displayText: root.targetLanguage isInput: false
onClicked: { placeholderText: qsTr("Translation goes here...")
root.showLanguageSelectorDialog(true); property bool hasTranslation: (root.translatedText.trim().length > 0)
} text: hasTranslation ? root.translatedText : ""
} GroupButton {
id: copyButton
TextCanvas { // Content translation baseWidth: height
id: outputCanvas buttonRadius: Appearance.rounding.small
isInput: false enabled: outputCanvas.displayedText.trim().length > 0
placeholderText: qsTr("Translation goes here...") contentItem: MaterialSymbol {
property bool hasTranslation: (root.translatedText.trim().length > 0) anchors.centerIn: parent
text: hasTranslation ? root.translatedText : "" horizontalAlignment: Text.AlignHCenter
GroupButton { iconSize: Appearance.font.pixelSize.larger
id: copyButton text: "content_copy"
baseWidth: height color: copyButton.enabled ? Appearance.colors.colOnLayer1 : Appearance.colors.colSubtext
buttonRadius: Appearance.rounding.small }
enabled: outputCanvas.displayedText.trim().length > 0 onClicked: {
contentItem: MaterialSymbol { Quickshell.clipboardText = outputCanvas.displayedText
anchors.centerIn: parent }
horizontalAlignment: Text.AlignHCenter }
iconSize: Appearance.font.pixelSize.larger GroupButton {
text: "content_copy" id: searchButton
color: copyButton.enabled ? Appearance.colors.colOnLayer1 : Appearance.colors.colSubtext baseWidth: height
} buttonRadius: Appearance.rounding.small
onClicked: { enabled: outputCanvas.displayedText.trim().length > 0
Quickshell.clipboardText = outputCanvas.displayedText contentItem: MaterialSymbol {
} anchors.centerIn: parent
} horizontalAlignment: Text.AlignHCenter
GroupButton { iconSize: Appearance.font.pixelSize.larger
id: searchButton text: "travel_explore"
baseWidth: height color: searchButton.enabled ? Appearance.colors.colOnLayer1 : Appearance.colors.colSubtext
buttonRadius: Appearance.rounding.small }
enabled: outputCanvas.displayedText.trim().length > 0 onClicked: {
contentItem: MaterialSymbol { let url = ConfigOptions.search.engineBaseUrl + outputCanvas.displayedText;
anchors.centerIn: parent for (let site of ConfigOptions.search.excludedSites) {
horizontalAlignment: Text.AlignHCenter url += ` -site:${site}`;
iconSize: Appearance.font.pixelSize.larger }
text: "travel_explore" Qt.openUrlExternally(url);
color: searchButton.enabled ? Appearance.colors.colOnLayer1 : Appearance.colors.colSubtext
}
onClicked: {
let url = ConfigOptions.search.engineBaseUrl + outputCanvas.displayedText;
for (let site of ConfigOptions.search.excludedSites) {
url += ` -site:${site}`;
} }
Qt.openUrlExternally(url);
} }
} }
}
}
}
LanguageSelectorButton { // Source language button
id: sourceLanguageButton
displayText: root.sourceLanguage
onClicked: {
root.showLanguageSelectorDialog(false);
}
}
TextCanvas { // Content input
id: inputCanvas
isInput: true
placeholderText: qsTr("Enter text to translate...")
onInputTextChanged: {
translateTimer.restart();
}
GroupButton {
id: pasteButton
baseWidth: height
buttonRadius: Appearance.rounding.small
contentItem: MaterialSymbol {
anchors.centerIn: parent
horizontalAlignment: Text.AlignHCenter
iconSize: Appearance.font.pixelSize.larger
text: "content_paste"
color: deleteButton.enabled ? Appearance.colors.colOnLayer1 : Appearance.colors.colSubtext
}
onClicked: {
root.inputField.text = Quickshell.clipboardText
}
}
GroupButton {
id: deleteButton
baseWidth: height
buttonRadius: Appearance.rounding.small
enabled: inputCanvas.inputTextArea.text.length > 0
contentItem: MaterialSymbol {
anchors.centerIn: parent
horizontalAlignment: Text.AlignHCenter
iconSize: Appearance.font.pixelSize.larger
text: "close"
color: deleteButton.enabled ? Appearance.colors.colOnLayer1 : Appearance.colors.colSubtext
}
onClicked: {
root.inputField.text = ""
}
}
} }
} }
@@ -234,6 +238,8 @@ Item {
root.sourceLanguage = result; root.sourceLanguage = result;
ConfigOptions.language.translator.sourceLanguage = result; // Save to config ConfigOptions.language.translator.sourceLanguage = result; // Save to config
} }
translateTimer.restart(); // Restart translation after language change
} }
} }
} }