diff --git a/sdrgui/CMakeLists.txt b/sdrgui/CMakeLists.txt index 3f9cc5e60..3e8adea62 100644 --- a/sdrgui/CMakeLists.txt +++ b/sdrgui/CMakeLists.txt @@ -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 diff --git a/sdrgui/gui/accessiblevaluedial.h b/sdrgui/gui/accessiblevaluedial.h new file mode 100644 index 000000000..378c6eb90 --- /dev/null +++ b/sdrgui/gui/accessiblevaluedial.h @@ -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 . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef GUI_ACCESSIBLEVALUEDIAL_H +#define GUI_ACCESSIBLEVALUEDIAL_H + +#include + +#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(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(new AccessibleValueDial(static_cast(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(object()); + } +}; + +#endif /* GUI_ACCESSIBLEVALUEDIAL_H */ diff --git a/sdrgui/gui/accessiblevaluedialz.h b/sdrgui/gui/accessiblevaluedialz.h new file mode 100644 index 000000000..2072637f9 --- /dev/null +++ b/sdrgui/gui/accessiblevaluedialz.h @@ -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 . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef GUI_ACCESSIBLEVALUEDIALZ_H +#define GUI_ACCESSIBLEVALUEDIALZ_H + +#include + +#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(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(new AccessibleValueDialZ(static_cast(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(object()); + } +}; + +#endif /* GUI_ACCESSIBLEVALUEDIALZ_H */ diff --git a/sdrgui/gui/valuedial.cpp b/sdrgui/gui/valuedial.cpp index 5bc7d5e91..6174ba409 100644 --- a/sdrgui/gui/valuedial.cpp +++ b/sdrgui/gui/valuedial.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include "gui/valuedial.h" @@ -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; diff --git a/sdrgui/gui/valuedial.h b/sdrgui/gui/valuedial.h index 2a467e362..d39ae2281 100644 --- a/sdrgui/gui/valuedial.h +++ b/sdrgui/gui/valuedial.h @@ -82,4 +82,6 @@ private: private slots: void animate(); void blink(); + + friend class AccessibleValueDial; }; diff --git a/sdrgui/gui/valuedialz.cpp b/sdrgui/gui/valuedialz.cpp index af29cd99a..30f7cbb67 100644 --- a/sdrgui/gui/valuedialz.cpp +++ b/sdrgui/gui/valuedialz.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include "gui/valuedialz.h" @@ -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) { diff --git a/sdrgui/gui/valuedialz.h b/sdrgui/gui/valuedialz.h index aa76fcb8b..4ddd486be 100644 --- a/sdrgui/gui/valuedialz.h +++ b/sdrgui/gui/valuedialz.h @@ -90,4 +90,7 @@ private: private slots: void animate(); void blink(); + + friend class AccessibleValueDialZ; + }; diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index d0283aaed..61c7d84bd 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -106,6 +106,9 @@ #include #include +#include "gui/accessiblevaluedial.h" +#include "gui/accessiblevaluedialz.h" + MainWindow *MainWindow::m_instance = 0; MainWindow::MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parser, QWidget* parent) : @@ -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");