Skip to content

Commit

Permalink
Merge pull request #1675 from srcejon/fix_1672
Browse files Browse the repository at this point in the history
Add accessibility interface for ValueDial widgets
  • Loading branch information
f4exb authored Apr 29, 2023
2 parents d0b2a8f + 7ae1951 commit ba74fcd
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sdrgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ set(sdrgui_SOURCES
set(sdrgui_HEADERS
mainwindow.h
gui/aboutdialog.h
gui/accessiblevaluedial.h
gui/accessiblevaluedialz.h
gui/addpresetdialog.h
gui/audiodialog.h
gui/audioselectdialog.h
Expand Down
105 changes: 105 additions & 0 deletions sdrgui/gui/accessiblevaluedial.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2023 Jon Beniston, M7RCE //
// //
// 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 as 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 V3 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/>. //
///////////////////////////////////////////////////////////////////////////////////

#ifndef GUI_ACCESSIBLEVALUEDIAL_H
#define GUI_ACCESSIBLEVALUEDIAL_H

#include <QAccessibleWidget>

#include "gui/valuedial.h"

class SDRGUI_API AccessibleValueDial : public QAccessibleWidget, public QAccessibleValueInterface {
public:
AccessibleValueDial(ValueDial *valueDial) :
QAccessibleWidget(valueDial)
{
addControllingSignal(QLatin1String("changed(quint64)"));
}

void *interface_cast(QAccessible::InterfaceType t) override
{
if (t == QAccessible::ValueInterface)
return static_cast<QAccessibleValueInterface*>(this);
return QAccessibleWidget::interface_cast(t);
}

QAccessible::Role role() const override
{
//return QAccessible::Dial; // This results in reader saying "custom" and not reading the value
return QAccessible::Slider;
}

QString text(QAccessible::Text t) const override
{
switch (t)
{
case QAccessible::Name:
return valueDial()->toolTip(); // Use tooltip until accessibleName field is set to something in .ui files
case QAccessible::Value:
return QString::number(valueDial()->getValueNew());
default:
return QAccessibleWidget::text(t);
}
}

static QAccessibleInterface* factory(const QString &classname, QObject *object)
{
QAccessibleInterface *iface = nullptr;

if (classname == QLatin1String("ValueDial") && object && object->isWidgetType()) {
iface = static_cast<QAccessibleInterface*>(new AccessibleValueDial(static_cast<ValueDial *>(object)));
}

return iface;
}

// QAccessibleValueInterface

QVariant currentValue() const override
{
return valueDial()->getValueNew();
}

void setCurrentValue(const QVariant &value) override
{
valueDial()->setValue(value.toInt());
}

QVariant maximumValue() const override
{
return valueDial()->m_valueMax;
}

QVariant minimumValue() const override
{
return valueDial()->m_valueMin;
}

QVariant minimumStepSize() const override
{
return 1;
}

protected:

ValueDial *valueDial() const
{
return static_cast<ValueDial*>(object());
}
};

#endif /* GUI_ACCESSIBLEVALUEDIAL_H */
105 changes: 105 additions & 0 deletions sdrgui/gui/accessiblevaluedialz.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2023 Jon Beniston, M7RCE //
// //
// 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 as 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 V3 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/>. //
///////////////////////////////////////////////////////////////////////////////////

#ifndef GUI_ACCESSIBLEVALUEDIALZ_H
#define GUI_ACCESSIBLEVALUEDIALZ_H

#include <QAccessibleWidget>

#include "gui/valuedialz.h"

class SDRGUI_API AccessibleValueDialZ : public QAccessibleWidget, public QAccessibleValueInterface {
public:
AccessibleValueDialZ(ValueDialZ *valueDialZ) :
QAccessibleWidget(valueDialZ)
{
addControllingSignal(QLatin1String("changed(qint64)"));
}

void *interface_cast(QAccessible::InterfaceType t) override
{
if (t == QAccessible::ValueInterface)
return static_cast<QAccessibleValueInterface*>(this);
return QAccessibleWidget::interface_cast(t);
}

QAccessible::Role role() const override
{
//return QAccessible::Dial; // This results in reader saying "custom" and not reading the value
return QAccessible::Slider;
}

QString text(QAccessible::Text t) const override
{
switch (t)
{
case QAccessible::Name:
return valueDialZ()->toolTip(); // Use tooltip until accessibleName field is set to something in .ui files
case QAccessible::Value:
return QString::number(valueDialZ()->getValueNew());
default:
return QAccessibleWidget::text(t);
}
}

static QAccessibleInterface* factory(const QString &classname, QObject *object)
{
QAccessibleInterface *iface = nullptr;

if (classname == QLatin1String("ValueDialZ") && object && object->isWidgetType()) {
iface = static_cast<QAccessibleInterface*>(new AccessibleValueDialZ(static_cast<ValueDialZ *>(object)));
}

return iface;
}

// QAccessibleValueInterface

QVariant currentValue() const override
{
return valueDialZ()->getValueNew();
}

void setCurrentValue(const QVariant &value) override
{
valueDialZ()->setValue(value.toInt());
}

QVariant maximumValue() const override
{
return valueDialZ()->m_valueMax;
}

QVariant minimumValue() const override
{
return valueDialZ()->m_valueMin;
}

QVariant minimumStepSize() const override
{
return 1;
}

protected:

ValueDialZ *valueDialZ() const
{
return static_cast<ValueDialZ*>(object());
}
};

#endif /* GUI_ACCESSIBLEVALUEDIALZ_H */
4 changes: 4 additions & 0 deletions sdrgui/gui/valuedial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <QPainter>
#include <QWheelEvent>
#include <QApplication>
#include <QAccessibleValueChangeEvent>
#include <cstdlib>

#include "gui/valuedial.h"
Expand Down Expand Up @@ -116,6 +117,9 @@ void ValueDial::setValue(quint64 value)
m_valueNew = m_valueMax;
}

QAccessibleValueChangeEvent event(this, value);
QAccessible::updateAccessibility(&event);

if (m_valueNew < m_value)
{
m_animationState = 1;
Expand Down
2 changes: 2 additions & 0 deletions sdrgui/gui/valuedial.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,6 @@ class SDRGUI_API ValueDial : public QWidget {
private slots:
void animate();
void blink();

friend class AccessibleValueDial;
};
4 changes: 4 additions & 0 deletions sdrgui/gui/valuedialz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QKeyEvent>
#include <QLocale>
#include <QApplication>
#include <QAccessibleValueChangeEvent>

#include "gui/valuedialz.h"

Expand Down Expand Up @@ -120,6 +121,9 @@ void ValueDialZ::setValue(qint64 value)
m_valueNew = m_valueMax;
}

QAccessibleValueChangeEvent event(this, m_valueNew);
QAccessible::updateAccessibility(&event);

if(m_valueNew < m_value) {
m_animationState = 1;
} else if(m_valueNew > m_value) {
Expand Down
3 changes: 3 additions & 0 deletions sdrgui/gui/valuedialz.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,7 @@ class SDRGUI_API ValueDialZ : public QWidget {
private slots:
void animate();
void blink();

friend class AccessibleValueDialZ;

};
6 changes: 6 additions & 0 deletions sdrgui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
#include <QSplashScreen>
#include <QProgressDialog>

#include "gui/accessiblevaluedial.h"
#include "gui/accessiblevaluedialz.h"

MainWindow *MainWindow::m_instance = 0;

MainWindow::MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parser, QWidget* parent) :
Expand All @@ -126,6 +129,9 @@ MainWindow::MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parse
bool showWelcome = false;
#endif

QAccessible::installFactory(AccessibleValueDial::factory);
QAccessible::installFactory(AccessibleValueDialZ::factory);

qDebug() << "MainWindow::MainWindow: start";
setWindowTitle("SDRangel");

Expand Down

0 comments on commit ba74fcd

Please sign in to comment.