Add accessibility value API to RpWidget

Add keyboard controls and accessibility value reporting to ContinuousSlider
Remove redundant accessibilityRole overrides from intro pages; set Step role to Dialog
This commit is contained in:
Reza Bakhshi Laktasaraei
2025-11-01 05:38:41 +03:30
committed by John Preston
parent 4a77e23b54
commit 6c5f8dffa6
13 changed files with 99 additions and 16 deletions
+1
View File
@@ -742,6 +742,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_settings_language" = "Language";
"lng_settings_default_scale" = "Default interface scale";
"lng_settings_scale" = "Interface scale";
"lng_settings_connection_type" = "Connection type";
"lng_settings_downloading_update" = "Downloading update {progress}...";
"lng_settings_privacy_title" = "Privacy";
-4
View File
@@ -31,10 +31,6 @@ public:
not_null<Main::Account*> account,
not_null<Data*> data);
QAccessible::Role accessibilityRole() override {
return QAccessible::Role::Dialog;
}
bool hasBack() const override {
return true;
}
@@ -166,6 +166,10 @@ QString CodeInput::accessibilityName() {
return tr::lng_code_ph(tr::now);
}
QString CodeInput::accessibilityValue() const {
return collectDigits();
}
void CodeInput::setDigitsCountMax(int digitsCount) {
_digitsCountMax = digitsCount;
@@ -315,6 +319,7 @@ void CodeInput::insertCodeAndSubmit(const QString &code) {
&& _digits[_currentIndex]->digit() != kDigitNone) {
requestCode();
}
accessibilityValueChanged(collectDigits());
}
QString CodeInput::collectDigits() const {
@@ -22,6 +22,7 @@ public:
return QAccessible::EditableText;
}
QString accessibilityName() override;
QString accessibilityValue() const override;
void setDigitsCountMax(int digitsCount);
@@ -29,10 +29,6 @@ public:
not_null<Main::Account*> account,
not_null<Data*> data);
QAccessible::Role accessibilityRole() override {
return QAccessible::Role::Dialog;
}
void setInnerFocus() override;
void activate() override;
void cancelled() override;
-3
View File
@@ -28,9 +28,6 @@ public:
not_null<Main::Account*> account,
not_null<Data*> data);
QAccessible::Role accessibilityRole() override {
return QAccessible::Role::Dialog;
}
QString accessibilityName() override;
void selectCountry(const QString &country);
-3
View File
@@ -25,9 +25,6 @@ public:
not_null<Main::Account*> account,
not_null<Data*> data);
QAccessible::Role accessibilityRole() override {
return QAccessible::Role::Dialog;
}
QString accessibilityName() override;
QString accessibilityDescription() override;
+1 -1
View File
@@ -46,7 +46,7 @@ public:
~Step();
QAccessible::Role accessibilityRole() override {
return QAccessible::Role::Pane;
return QAccessible::Role::Dialog;
}
QString accessibilityName() override {
return _titleText.current();
@@ -1609,7 +1609,16 @@ void SetupDefaultThemes(
}
};
group->setChangedCallback([=](Type type) {
group->setValue(chosen());
const auto scheme = ranges::find(
kSchemesList,
type,
&Scheme::type);
if (scheme != end(kSchemesList)) {
apply(*scheme);
}
else {
group->setValue(chosen());
}
});
for (const auto &scheme : kSchemesList) {
refreshColorizer(scheme.type);
@@ -351,6 +351,16 @@ void IntroWidget::showContent(not_null<Window::Controller*> window) {
}
void IntroWidget::setInnerFocus() {
const auto layout = _innerWrap->entity();
for (const auto childObject : layout->children()) {
auto childWidget = qobject_cast<QWidget*>(childObject);
if (childWidget && childWidget->focusPolicy() != Qt::NoFocus) {
childWidget->setFocus(Qt::OtherFocusReason);
return;
}
}
setFocus();
}
@@ -867,6 +867,7 @@ void SetupInterfaceScale(
icon ? st::settingsScalePadding : st::settingsBigScalePadding);
const auto slider = sliderWithLabel.slider;
const auto label = sliderWithLabel.label;
slider->setAccessibleName(tr::lng_settings_scale(tr::now));
const auto updateLabel = [=](int scale) {
const auto labelText = [&](int scale) {
@@ -131,6 +131,66 @@ void ContinuousSlider::wheelEvent(QWheelEvent *e) {
_byWheelFinished->callOnce(kByWheelFinishedTimeout);
}
void ContinuousSlider::keyPressEvent(QKeyEvent* e) {
const auto key = e->key();
auto newValue = _value;
constexpr auto smallStep = 0.01;
constexpr auto largeStep = 0.10;
switch (key) {
case Qt::Key_Right:
case Qt::Key_Up:
newValue = _value + smallStep;
break;
case Qt::Key_Left:
case Qt::Key_Down:
newValue = _value - smallStep;
break;
case Qt::Key_PageUp:
newValue = _value + largeStep;
break;
case Qt::Key_PageDown:
newValue = _value - largeStep;
break;
case Qt::Key_Home:
newValue = 0.0;
break;
case Qt::Key_End:
newValue = 1.0;
break;
default:
RpWidget::keyPressEvent(e);
return;
}
e->accept();
newValue = std::clamp(_adjustCallback
? _adjustCallback(newValue)
: newValue, 0.0, 1.0);
if (newValue != _value) {
setValue(newValue);
if (_changeProgressCallback) {
_changeProgressCallback(_value);
}
if (_changeFinishedCallback) {
_changeFinishedCallback(_value);
}
const int percent = std::max(0, std::min(100, qRound(_value * 100.)));
const QString valueText = QString::number(percent) + '%';
accessibilityValueChanged(QVariant(valueText));
}
}
void ContinuousSlider::updateDownValueFromPos(const QPoint &pos) {
_downValue = computeValue(pos);
update();
@@ -58,6 +58,15 @@ public:
void setMoveByWheel(bool move);
QAccessible::Role accessibilityRole() override {
return QAccessible::Role::Slider;
}
QString accessibilityValue() const override {
const auto percent = std::clamp(qRound(_value * 100.), 0, 100);
return QString::number(percent) + '%';
}
protected:
void mouseMoveEvent(QMouseEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
@@ -65,6 +74,7 @@ protected:
void wheelEvent(QWheelEvent *e) override;
void enterEventHook(QEnterEvent *e) override;
void leaveEventHook(QEvent *e) override;
void keyPressEvent(QKeyEvent* e) override;
float64 fadeOpacity() const {
return _fadeOpacity;