Commit ff70129e authored by Karel Slaný's avatar Karel Slaný
Browse files

Experimenting with AccessibleSpinBox component.

parent 4c8205fa
/*
* 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: fontSizeSpinBox.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.fill: fontSizeSpinBox.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()
}
}
}
......@@ -95,34 +95,22 @@ Item {
width: parent.width
text: qsTr("Font size and application scale")
}
SpinBox {
AccessibleSpinBox {
/* Actually holds font pixel size. */
id: fontSizeSpinBox
height: inputItemHeight
font.pointSize: defaultTextFont.font.pointSize
property int dflt: 16
from: 14
to: 20
stepSize: 1
accessibleDescription: qsTr("Set application font size")
/*
* Cannot use onValueChanged here because this resets
* the font size to minimal value on spin box creation.
*/
onValueModified: settings.setFontSize(fontSizeSpinBox.val())
function val() {
return value
}
function setVal(v) {
if (v < from) {
value = from
} else if (v > to) {
value = to
} else {
value = v
}
}
Accessible.description: qsTr("Select the font and application scale.")
}
AccessibleText {
color: datovkaPalette.mid
......
......@@ -105,6 +105,7 @@
<file>../qml/components/AccessibleImageButton.qml</file>
<file>../qml/components/AccessibleMenu.qml</file>
<file>../qml/components/AccessibleOverlaidImageButton.qml</file>
<file>../qml/components/AccessibleSpinBox.qml</file>
<file>../qml/components/AccessibleSwitch.qml</file>
<file>../qml/components/AccessibleText.qml</file>
<file>../qml/components/AccessibleTextButton.qml</file>
......
......@@ -128,6 +128,7 @@ const struct QmlTypeEntry qmlComponents[] = {
{ "AccessibleImageButton", 1, 0 },
{ "AccessibleMenu", 1, 0 },
{ "AccessibleOverlaidImageButton", 1, 0 },
{ "AccessibleSpinBox", 1, 0 },
{ "AccessibleSwitch", 1, 0 },
{ "AccessibleText", 1, 0 },
{ "AccessibleTextButton", 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