mirror of
https://github.com/monero-project/monero-gui.git
synced 2024-12-23 03:59:38 +00:00
LanguageSidebar: navigate/select language with keyboard; enable accessibility; selected indicator; remember previous focused item
This commit is contained in:
parent
b58bff39a0
commit
8419fce062
2 changed files with 55 additions and 19 deletions
|
@ -53,26 +53,64 @@ Drawer {
|
||||||
color: "red"
|
color: "red"
|
||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
|
id: languagesListView
|
||||||
clip: true
|
clip: true
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
boundsBehavior: Flickable.StopAtBounds
|
boundsBehavior: Flickable.StopAtBounds
|
||||||
width: sideBar.width
|
width: sideBar.width
|
||||||
height: sideBar.height
|
height: sideBar.height
|
||||||
|
focus: true
|
||||||
|
|
||||||
model: langModel
|
model: langModel
|
||||||
|
|
||||||
|
Keys.onUpPressed: currentIndex !== 0 ? currentIndex = currentIndex - 1 : ""
|
||||||
|
Keys.onBacktabPressed: currentIndex !== 0 ? currentIndex = currentIndex - 1 : ""
|
||||||
|
Keys.onDownPressed: currentIndex + 1 !== count ? currentIndex = currentIndex + 1 : ""
|
||||||
|
Keys.onTabPressed: currentIndex + 1 !== count ? currentIndex = currentIndex + 1 : ""
|
||||||
|
|
||||||
delegate: Rectangle {
|
delegate: Rectangle {
|
||||||
id: item
|
id: item
|
||||||
color: "transparent"
|
color: index == languagesListView.currentIndex ? MoneroComponents.Style.titleBarButtonHoverColor : "transparent"
|
||||||
width: sideBar.width
|
width: sideBar.width
|
||||||
height: 32
|
height: 32
|
||||||
|
|
||||||
|
Accessible.role: Accessible.ListItem
|
||||||
|
Accessible.name: display_name
|
||||||
|
Keys.onEnterPressed: setSelectedItemAsLanguage();
|
||||||
|
Keys.onReturnPressed: setSelectedItemAsLanguage();
|
||||||
|
Keys.onSpacePressed: setSelectedItemAsLanguage();
|
||||||
|
|
||||||
|
function setSelectedItemAsLanguage() {
|
||||||
|
var locale_spl = locale.split("_");
|
||||||
|
|
||||||
|
// reload active translations
|
||||||
|
console.log(locale_spl[0]);
|
||||||
|
translationManager.setLanguage(locale_spl[0]);
|
||||||
|
|
||||||
|
// set wizard language settings
|
||||||
|
persistentSettings.locale = locale;
|
||||||
|
persistentSettings.language = display_name;
|
||||||
|
persistentSettings.language_wallet = wallet_language;
|
||||||
|
|
||||||
|
appWindow.showStatusMessage(qsTr("Language changed."), 3);
|
||||||
|
appWindow.toggleLanguageView();
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: selectedIndicator
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.leftMargin: 0
|
||||||
|
height: parent.height
|
||||||
|
width: 2
|
||||||
|
color: index == languagesListView.currentIndex ? MoneroComponents.Style.buttonBackgroundColor : "transparent"
|
||||||
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: flagRect
|
id: flagRect
|
||||||
height: 24
|
height: 24
|
||||||
width: 24
|
width: 24
|
||||||
anchors.left: parent.left
|
anchors.left: selectedIndicator.right
|
||||||
anchors.leftMargin: 4
|
anchors.leftMargin: 4
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
color: "transparent"
|
color: "transparent"
|
||||||
|
@ -85,8 +123,8 @@ Drawer {
|
||||||
|
|
||||||
MoneroComponents.TextPlain {
|
MoneroComponents.TextPlain {
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.leftMargin: 30
|
anchors.leftMargin: 32
|
||||||
font.bold: true
|
font.bold: languagesListView.currentIndex == index ? true : false
|
||||||
font.pixelSize: 14
|
font.pixelSize: 14
|
||||||
color: MoneroComponents.Style.defaultFontColor
|
color: MoneroComponents.Style.defaultFontColor
|
||||||
text: display_name
|
text: display_name
|
||||||
|
@ -112,21 +150,7 @@ Drawer {
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: {
|
onClicked: setSelectedItemAsLanguage();
|
||||||
var locale_spl = locale.split("_");
|
|
||||||
|
|
||||||
// reload active translations
|
|
||||||
console.log(locale_spl[0]);
|
|
||||||
translationManager.setLanguage(locale_spl[0]);
|
|
||||||
|
|
||||||
// set wizard language settings
|
|
||||||
persistentSettings.locale = locale;
|
|
||||||
persistentSettings.language = display_name;
|
|
||||||
persistentSettings.language_wallet = wallet_language;
|
|
||||||
|
|
||||||
appWindow.showStatusMessage(qsTr("Language changed."), 3);
|
|
||||||
appWindow.toggleLanguageView();
|
|
||||||
}
|
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
onEntered: {
|
onEntered: {
|
||||||
// item.color = "#26FFFFFF"
|
// item.color = "#26FFFFFF"
|
||||||
|
@ -166,4 +190,12 @@ Drawer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function selectCurrentLanguage() {
|
||||||
|
for (var i = 0; i < langModel.count; ++i) {
|
||||||
|
if (langModel.get(i).display_name === persistentSettings.language) {
|
||||||
|
languagesListView.currentIndex = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
4
main.qml
4
main.qml
|
@ -62,6 +62,7 @@ ApplicationWindow {
|
||||||
minimumHeight: 450
|
minimumHeight: 450
|
||||||
|
|
||||||
property var currentItem
|
property var currentItem
|
||||||
|
property var previousActiveFocusItem
|
||||||
property bool hideBalanceForced: false
|
property bool hideBalanceForced: false
|
||||||
property bool ctrlPressed: false
|
property bool ctrlPressed: false
|
||||||
property alias persistentSettings : persistentSettings
|
property alias persistentSettings : persistentSettings
|
||||||
|
@ -1942,6 +1943,7 @@ ApplicationWindow {
|
||||||
|
|
||||||
function toggleLanguageView(){
|
function toggleLanguageView(){
|
||||||
languageSidebar.visible ? languageSidebar.close() : languageSidebar.open();
|
languageSidebar.visible ? languageSidebar.close() : languageSidebar.open();
|
||||||
|
languageSidebar.selectCurrentLanguage()
|
||||||
resetLanguageFields()
|
resetLanguageFields()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2357,6 +2359,8 @@ ApplicationWindow {
|
||||||
MoneroComponents.LanguageSidebar {
|
MoneroComponents.LanguageSidebar {
|
||||||
id: languageSidebar
|
id: languageSidebar
|
||||||
dragMargin: 0
|
dragMargin: 0
|
||||||
|
onAboutToShow: previousActiveFocusItem = activeFocusItem;
|
||||||
|
onClosed: { if (previousActiveFocusItem) previousActiveFocusItem.forceActiveFocus() }
|
||||||
}
|
}
|
||||||
|
|
||||||
MoneroComponents.MenuBar { }
|
MoneroComponents.MenuBar { }
|
||||||
|
|
Loading…
Reference in a new issue