Commit 31933226 authored by Martin Straka's avatar Martin Straka

Merge branch 'qml-accessibility' into 'develop'

Expose QML to Accessibility

See merge request !103
parents fc056d31 b2533984
......@@ -125,6 +125,7 @@ SOURCES += \
src/qml_interaction/interaction_zfo_file.cpp \
src/qml_interaction/message_envelope.cpp \
src/qml_interaction/message_info.cpp \
src/qml_interaction/string_manipulation.cpp \
src/settings.cpp \
src/setwrapper.cpp \
src/sqlite/account_db.cpp \
......@@ -188,6 +189,7 @@ HEADERS += \
src/qml_interaction/interaction_zfo_file.h \
src/qml_interaction/message_envelope.h \
src/qml_interaction/message_info.h \
src/qml_interaction/string_manipulation.h \
src/settings.h \
src/setwrapper.h \
src/sqlite/account_db.h \
......
/*
* 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
/*
* Accessible button component.
*/
Button {
id: root
/* These properties must be set by caller. */
property string accessibleDescription: ""
property string accessibleName: ""
Accessible.role: Accessible.Button
Accessible.checkable: root.checkable
Accessible.checked: root.checked
Accessible.description: root.accessibleDescription
Accessible.name: (root.accessibleName !== "") ? root.accessibleName : root.text
Accessible.pressed: root.pressed
Accessible.onPressAction: {
root.clicked()
}
}
/*
* 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
}
/*
* Selects entry with given key.
*/
function selectCurrentKey(key) {
for (var i = 0; i < root.model.count; ++i) {
//root.model.get(i)["key"]
if (root.model.get(i).key === key) {
root.currentIndex = i;
return;
}
}
/* Not found. */
console.log("No entry found for key '" + 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: {
root.currentIndex = index
root.popup.close()
}
}
highlighted: root.highlightedIndex == index
}
Accessible.role: Accessible.ComboBox
Accessible.description: accessibleDescription
Accessible.name: root.currentText
Accessible.onPressAction: {
root.popup.open()
}
}
/*
* 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
/*
* Accessible button image component.
*/
Image {
id: root
/* These properties must be set by caller. */
property string accessibleName: ""
signal clicked()
MouseArea {
function handleClick() {
root.clicked()
}
anchors.fill: parent
Accessible.role: Accessible.Button
Accessible.name: root.accessibleName
Accessible.onPressAction: {
handleClick()
}
onClicked: {
handleClick()
}
}
}
/*
* 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 QtGraphicalEffects 1.0
import QtQuick 2.7
import cz.nic.mobileDatovka 1.0
/*
* Accessible menu component.
*
* An object containing functions to be called and a model in specified form
* must be provided.
*/
ScrollableListView {
id: root
delegateHeight: headerHeight
/* These properties must be set by caller. */
property var funcArr: null /* https://stackoverflow.com/a/24376300 */
/*
* The property funcArr must hold an object (associative array).
* The keys must be strings, values must be functions.
* e.g.:
property var funcs: {
"funcName": function callFuncName {
console.log("Calling function funcName.")
}
}
* The model entries must contain these properties.
* image - (string containing path of image resource)
* image to be shown in the menu before the text
* showEntry - (boolean value)
* true means that the entire menu entry is being shown
* showNext - (boolean value)
* true means that an further menu is being indicated
* name - (string with action description)
* action
* funcName - (string holding one of function array keys)
* string identifying function to be called
* e.g.:
ListModel {
id: listModel
ListElement {
image: "qrc:/ui/settings.svg"
showEntry: true
showNext: false
name: qsTr("Perform some action")
funcName: "funcName"
}
}
*/
/*
* Return the first index of the element having a specified property of
* specified value.
*
* Returns -1 if nothing found.
*/
function get_model_index(model, property, value) {
for (var i = 0; i < model.count; ++i) {
if (model.get(i)[property] === value) {
return i;
}
}
/* Not found. */
return -1;
}
/* https://stackoverflow.com/a/7356528 */
function isFunction(functionToCheck) {
var getType = {};
return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
}
Component {
id: menuDelegate
Rectangle {
visible: showEntry
color: datovkaPalette.base
height: showEntry ? root.delegateHeight : 0 /* Collapse when not visible. */
width: parent.width
Image {
id: menuImage
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: defaultMargin
sourceSize.height: imgHeight
source: image
}
ColorOverlay {
anchors.fill: menuImage
source: menuImage
color: datovkaPalette.text
}
Text {
anchors.verticalCenter: parent.verticalCenter
anchors.left: menuImage.right
anchors.leftMargin: defaultMargin
color: datovkaPalette.text
text: name
}
Rectangle {
id: next2
visible: showNext
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
height: parent.height
width: parent.width * 0.07
color: parent.color
Image {
id: nextImage2
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
anchors.rightMargin: defaultMargin
sourceSize.height: navImgHeight
source: "qrc:/ui/next.svg"
}
ColorOverlay {
anchors.fill: nextImage2
source: nextImage2
color: datovkaPalette.text
}
}
MouseArea {
function handleClick() {
/* https://stackoverflow.com/a/1098955 */
if (funcName in funcArr) {
if (isFunction(funcArr[funcName])) {
/* Call function. */
funcArr[funcName]()
} else {
console.log("'" + funcName + "' is not a function.")
}
} else {
console.log("Unknown function '" + funcName + "'.")
}
}
anchors.fill: parent
Accessible.role: Accessible.Button
Accessible.name: name
Accessible.onScrollDownAction: {
root.scrollDown()
}
Accessible.onScrollUpAction: {
root.scrollUp()
}
Accessible.onPressAction: {
handleClick()
}
onClicked: {
handleClick()
}
}
}
}
delegate: menuDelegate
}
/*
* 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 cz.nic.mobileDatovka 1.0
/*
* Accessible button ovelaid image component.
*/
OverlaidImage {
id: root
/* These properties must be set by caller. */
property string accessibleName: ""
signal clicked()
MouseArea {
function handleClick() {
root.clicked()
}
anchors.fill: parent
Accessible.role: Accessible.Button
Accessible.name: root.accessibleName
Accessible.onPressAction: {
handleClick()
}
onClicked: {
handleClick()
}
}
}
/*
* 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
/*
* Accessible spin box component.
*/
SpinBox {
id: root
/* These properties must be set by caller. */
property string accessibleDescription: ""
height: inputItemHeight
font.pointSize: defaultTextFont.font.pointSize
/*
* Return spin box value.
*/
function val() {
return root.value;
}
/*
* Set spin box value.
*/
function setVal(v) {
if (v < root.from) {
root.value = root.from
} else if (v > root.to) {
root.value = root.to
} else {
root.value = v
}
}
MouseArea {
anchors.fill: root.down.indicator
function handleClick() {
root.decrease()
root.valueModified()
}
Accessible.role: Accessible.Button
Accessible.description: root.accessibleDescription
//Accessible.focusable: true
Accessible.name: qsTr("Decrease value '%1'.").arg(root.val())
Accessible.onPressAction: {
handleClick()
}
onClicked: {
handleClick()
}
}
MouseArea {
anchors.top: root.top
anchors.bottom: root.bottom
anchors.left: (root.down.indicator.x < root.up.indicator.x) ? root.down.indicator.right : root.up.indicator.right
anchors.right: (root.down.indicator.x < root.up.indicator.x) ? root.up.indicator.left : root.up.indicator.left
Accessible.role: root.editable ? Accessible.EditableText : Accessible.StaticText
Accessible.description: root.accessibleDescription
Accessible.editable: root.editable
Accessible.focusable: true
Accessible.multiLine: false
Accessible.name: root.val()
Accessible.readOnly: !root.editable
}
MouseArea {
anchors.fill: root.up.indicator
function handleClick() {
root.increase()
root.valueModified()
}
Accessible.role: Accessible.Button
Accessible.description: root.accessibleDescription
//Accessible.focusable: true
Accessible.name: qsTr("Increase value '%1'.").arg(root.val())
Accessible.onPressAction: {
handleClick()
}
onClicked: {
handleClick()
}
}
}
/*
* Copyright (C) 2014-2017 CZ.NIC
* 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
......@@ -21,9 +21,13 @@
* the two.
*/
import QtQuick 2.7
import QtQuick.Controls 2.2
import cz.nic.mobileDatovka 1.0
AccessibleSpinBox {
id: root
SpinBox {
/* Must be a non-decreasing list ending with infinity. */
property var items: [1, qsTr("max")]
property int dfltIdx: 0
......@@ -73,4 +77,57 @@ SpinBox {
value = from
}
}
MouseArea {
anchors.fill: root.down.indicator
function handleClick() {
root.decrease()
root.valueModified()
}
Accessible.role: Accessible.Button
Accessible.description: root.accessibleDescription
//Accessible.focusable: true
Accessible.name: qsTr("Decrease value '%1'.").arg(root.textFromValue(root.value))
Accessible.onPressAction: {
handleClick()
}
onClicked: {
handleClick()
}
}
MouseArea {
anchors.top: root.top
anchors.bottom: root.bottom
anchors.left: (root.down.indicator.x < root.up.indicator.x) ? root.down.indicator.right : root.up.indicator.right
anchors.right: (root.down.indicator.x < root.up.indicator.x) ? root.up.indicator.left : root.up.indicator.left
Accessible.role: root.editable ? Accessible.EditableText : Accessible.StaticText
Accessible.description: root.accessibleDescription
Accessible.editable: root.editable
Accessible.focusable: true
Accessible.multiLine: false
Accessible.name: root.textFromValue(root.value)
Accessible.readOnly: !root.editable
}
MouseArea {
anchors.fill: root.up.indicator
function handleClick() {
root.increase()
root.valueModified()
}
Accessible.role: Accessible.Button
Accessible.description: root.accessibleDescription
//Accessible.focusable: true
Accessible.name: qsTr("Increase value '%1'.").arg(root.textFromValue(root.value))
Accessible.onPressAction: {
handleClick()
}
onClicked: {
handleClick()
}
}
}
/*
* 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
/*
* Accessible switch component.
*/
Switch {
id: root
/* These properties must be set by caller. */
property string accessibleDescription: ""
property string accessibleName: ""
Accessible.role: Accessible.CheckBox
Accessible.checkStateMixed: false
Accessible.checkable: true
Accessible.checked: root.checked
Accessible.description: root.accessibleDescription
//Accessible.focusable: true
Accessible.name: (root.accessibleName !== "") ? root.accessibleName : root.text
Accessible.onPressAction: {
root.toggle()
}
Accessible.onToggleAction: {
root.toggle()
}
}
/*
* 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/>.