Commit 32da0826 authored by Karel Slaný's avatar Karel Slaný

Experimenting with accessible combo boxes.

parent dbfb4930
/*
* Copyright (C) 2014-2018 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*/
import QtQuick 2.7
import QtQuick.Controls 2.2
import cz.nic.mobileDatovka 1.0
/*
* Accessible combo box component.
*/
ComboBox {
id: root
/* These properties must be set by caller. */
property string accessibleDescription: ""
/*
* The model entries must contain these properties.
* label - (string with item description)
* item description
* key - (string holding one of the keys)
* unique string identifying an item
* e.g.:
ListModel {
id: listModel
ListElement {
label: qsTr("Some selection")
key: "some"
}
}
*/
currentIndex: 0
textRole: "label"
height: inputItemHeight
font.pointSize: defaultTextFont.font.pointSize
/*
* Return current key value.
*/
function currentKey() {
return root.model.get(root.currentIndex).key
}
delegate: ItemDelegate {
width: root.width
height: inputItemHeight
contentItem: AccessibleTextButton {
text: label
color: datovkaPalette.text
font.pointSize: defaultTextFont.font.pointSize
elide: Text.ElideRight
verticalAlignment: Text.AlignVCenter
onClicked: {
console.log("Clicked " + label)
root.currentIndex = index
root.popup.close()
}
}
highlighted: root.highlightedIndex == index
}
Accessible.role: Accessible.ComboBox
Accessible.description: accessibleDescription
Accessible.name: root.currentText
Accessible.onPressAction: {
console.log("Accessible combo box pressed")
root.popup.open()
}
}
......@@ -156,35 +156,19 @@ Item {
color: datovkaPalette.text
text: qsTr("Login method")
}
ComboBox {
AccessibleComboBox {
id: loginMethodComboBox
currentIndex: 0
width: parent.width
height: inputItemHeight
textRole: "label"
font.pointSize: defaultTextFont.font.pointSize
delegate: ItemDelegate {
width: loginMethodComboBox.width
height: inputItemHeight
contentItem: Text {
text: label
color: datovkaPalette.text
font.pointSize: defaultTextFont.font.pointSize
elide: Text.ElideRight
verticalAlignment: Text.AlignVCenter
}
highlighted: loginMethodComboBox.highlightedIndex == index
}
accessibleDescription: qsTr("Select login method")
model: ListModel {
id: loginMethodModel
// Don't change position of list elements, keys and values.
ListElement { label: qsTr("Username + Password"); value: "pwd" }
ListElement { label: qsTr("Certificate + Password"); value: "cert" }
ListElement { label: qsTr("Password + Security code"); value: "hotp" }
ListElement { label: qsTr("Password + Security SMS"); value: "totp" }
ListElement { label: qsTr("Username + Password"); key: "pwd" }
ListElement { label: qsTr("Certificate + Password"); key: "cert" }
ListElement { label: qsTr("Password + Security code"); key: "hotp" }
ListElement { label: qsTr("Password + Security SMS"); key: "totp" }
}
onCurrentIndexChanged: {
sLoginMethod = loginMethodModel.get(currentIndex).value
sLoginMethod = currentKey()
if (sLoginMethod === "cert") {
certificateLabel.visible = true
certPathButtonId.visible = true
......
......@@ -101,6 +101,7 @@
<file>cznic.png</file>
<file>ui/datovka@2x.png</file>
<file>../qml/components/AccessibleButton.qml</file>
<file>../qml/components/AccessibleComboBox.qml</file>
<file>../qml/components/AccessibleImageButton.qml</file>
<file>../qml/components/AccessibleMenu.qml</file>
<file>../qml/components/AccessibleOverlaidImageButton.qml</file>
......
......@@ -124,6 +124,7 @@ const struct QmlTypeEntry qmlPages[] = {
static
const struct QmlTypeEntry qmlComponents[] = {
{ "AccessibleButton", 1, 0 },
{ "AccessibleComboBox", 1, 0 },
{ "AccessibleImageButton", 1, 0 },
{ "AccessibleMenu", 1, 0 },
{ "AccessibleOverlaidImageButton", 1, 0 },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment