forked from mumble-voip/mumble
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX(a11y): Add semantic description to sliders in Settings
- Loading branch information
Showing
7 changed files
with
199 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright 2023-2024 The Mumble Developers. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license | ||
// that can be found in the LICENSE file at the root of the | ||
// Mumble source tree or at <https://www.mumble.info/LICENSE>. | ||
|
||
#include "SemanticSlider.h" | ||
|
||
#include <QDebug> | ||
|
||
SemanticAbstractSlider::SemanticAbstractSlider(QWidget *w, QAccessible::Role r) | ||
: QAccessibleWidget(w, r) | ||
{ | ||
Q_ASSERT(qobject_cast<QAbstractSlider *>(w)); | ||
} | ||
|
||
void *SemanticAbstractSlider::interface_cast(QAccessible::InterfaceType t) | ||
{ | ||
if (t == QAccessible::ValueInterface) { | ||
return static_cast<QAccessibleValueInterface*>(this); | ||
} | ||
return QAccessibleWidget::interface_cast(t); | ||
} | ||
|
||
QVariant SemanticAbstractSlider::currentValue() const | ||
{ | ||
return abstractSlider()->value(); | ||
} | ||
|
||
void SemanticAbstractSlider::setCurrentValue(const QVariant &value) | ||
{ | ||
abstractSlider()->setValue(value.toInt()); | ||
} | ||
|
||
QVariant SemanticAbstractSlider::maximumValue() const | ||
{ | ||
return abstractSlider()->maximum(); | ||
} | ||
|
||
QVariant SemanticAbstractSlider::minimumValue() const | ||
{ | ||
return abstractSlider()->minimum(); | ||
} | ||
|
||
QVariant SemanticAbstractSlider::minimumStepSize() const | ||
{ | ||
return abstractSlider()->singleStep(); | ||
} | ||
|
||
QAbstractSlider *SemanticAbstractSlider::abstractSlider() const | ||
{ | ||
return static_cast<QAbstractSlider *>(object()); | ||
} | ||
|
||
SemanticSlider::SemanticSlider(QWidget *w) | ||
: SemanticAbstractSlider(w), m_semanticValue("test!") | ||
{ | ||
Q_ASSERT(slider()); | ||
addControllingSignal(QLatin1String("valueChanged(int)")); | ||
} | ||
|
||
QSlider *SemanticSlider::slider() const | ||
{ | ||
return qobject_cast<QSlider*>(object()); | ||
} | ||
|
||
QString SemanticSlider::text(QAccessible::Text t) const | ||
{ | ||
qDebug() << "text method" << t; | ||
if (t == QAccessible::Value) { | ||
qDebug() << "send text"; | ||
if (!m_semanticValue.isEmpty()) { | ||
qDebug() << "send text " << m_semanticValue; | ||
return m_semanticValue; | ||
} | ||
return QString::number(slider()->value()); | ||
} | ||
|
||
return SemanticAbstractSlider::text(t); | ||
} | ||
|
||
QAccessibleInterface *SemanticSlider::semanticSliderFactory(const QString &classname, QObject *object) { | ||
QAccessibleInterface *interface = nullptr; | ||
|
||
if(object && object->isWidgetType()) { | ||
if (classname == QLatin1String("QSlider")) { | ||
interface = new SemanticSlider(static_cast<QWidget *>(object)); | ||
qDebug() << "created interface"; | ||
} else if (classname == QLatin1String("QAbstractSlider")) { | ||
qDebug() << "created abstract interface"; | ||
interface = new SemanticAbstractSlider(static_cast<QWidget *>(object)); | ||
} else { | ||
qDebug() << "not interfaced"; | ||
} | ||
} | ||
|
||
return interface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2023-2024 The Mumble Developers. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license | ||
// that can be found in the LICENSE file at the root of the | ||
// Mumble source tree or at <https://www.mumble.info/LICENSE>. | ||
|
||
#ifndef MUMBLE_MUMBLE_WIDGETS_SEMANTICSLIDER_H_ | ||
#define MUMBLE_MUMBLE_WIDGETS_SEMANTICSLIDER_H_ | ||
|
||
#include <QAccessible> | ||
#include <QAccessibleValueInterface> | ||
#include <QAccessibleWidget> | ||
|
||
#include <QString> | ||
#include <QWidget> | ||
#include <QObject> | ||
#include <QVariant> | ||
|
||
#include <QtWidgets/QAbstractSlider> | ||
#include <QtWidgets/QSlider> | ||
|
||
class SemanticAbstractSlider: public QAccessibleWidget, public QAccessibleValueInterface | ||
{ | ||
public: | ||
explicit SemanticAbstractSlider(QWidget *w, QAccessible::Role r = QAccessible::Slider); | ||
void *interface_cast(QAccessible::InterfaceType t) override; | ||
|
||
QVariant currentValue() const override; | ||
void setCurrentValue(const QVariant &value) override; | ||
QVariant maximumValue() const override; | ||
QVariant minimumValue() const override; | ||
QVariant minimumStepSize() const override; | ||
|
||
protected: | ||
QAbstractSlider *abstractSlider() const; | ||
}; | ||
|
||
class SemanticSlider : public SemanticAbstractSlider | ||
{ | ||
public: | ||
explicit SemanticSlider(QWidget *w); | ||
QString text(QAccessible::Text t) const override; | ||
|
||
static QAccessibleInterface *semanticSliderFactory(const QString &classname, QObject *object); | ||
|
||
QString m_semanticValue; | ||
|
||
protected: | ||
QSlider *slider() const; | ||
}; | ||
|
||
#endif |