AccessibleAlignmentSelector.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /******************************************************************************
  2. Copyright (C) 2025 by Taylor Giampaolo <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "AccessibleAlignmentSelector.hpp"
  15. #include <OBSApp.hpp>
  16. AccessibleAlignmentSelector::AccessibleAlignmentSelector(AlignmentSelector *widget_)
  17. : QAccessibleWidget(widget_, QAccessible::Grouping)
  18. {
  19. for (int i = 0; i < cellCount; ++i) {
  20. AccessibleAlignmentCell *cell = new AccessibleAlignmentCell(this, widget_, i);
  21. QAccessible::registerAccessibleInterface(cell);
  22. cellInterfaces.insert(i, QAccessible::uniqueId(cell));
  23. }
  24. }
  25. AccessibleAlignmentSelector::~AccessibleAlignmentSelector()
  26. {
  27. for (QAccessible::Id id : std::as_const(cellInterfaces)) {
  28. QAccessible::deleteAccessibleInterface(id);
  29. }
  30. }
  31. int AccessibleAlignmentSelector::childCount() const
  32. {
  33. return cellCount;
  34. }
  35. QAccessibleInterface *AccessibleAlignmentSelector::child(int index) const
  36. {
  37. if (QAccessible::Id id = cellInterfaces.value(index)) {
  38. return QAccessible::accessibleInterface(id);
  39. }
  40. return nullptr;
  41. }
  42. int AccessibleAlignmentSelector::indexOfChild(const QAccessibleInterface *child) const
  43. {
  44. if (!child) {
  45. return -1;
  46. }
  47. QAccessible::Id id = QAccessible::uniqueId(const_cast<QAccessibleInterface *>(child));
  48. return cellInterfaces.key(id, -1);
  49. }
  50. bool AccessibleAlignmentSelector::isValid() const
  51. {
  52. return widget() != nullptr;
  53. }
  54. QAccessibleInterface *AccessibleAlignmentSelector::focusChild() const
  55. {
  56. for (int i = 0; i < childCount(); ++i) {
  57. if (child(i)->state().focused) {
  58. return child(i);
  59. }
  60. }
  61. return nullptr;
  62. }
  63. QRect AccessibleAlignmentSelector::rect() const
  64. {
  65. return widget()->rect();
  66. }
  67. QString AccessibleAlignmentSelector::text(QAccessible::Text textType) const
  68. {
  69. if (textType == QAccessible::Name) {
  70. QString str = widget()->accessibleName();
  71. if (str.isEmpty()) {
  72. str = QTStr("Accessible.Widget.Name.AlignmentSelector");
  73. }
  74. return str;
  75. }
  76. if (textType == QAccessible::Value) {
  77. return value().toString();
  78. }
  79. return QAccessibleWidget::text(textType);
  80. }
  81. QAccessible::Role AccessibleAlignmentSelector::role() const
  82. {
  83. return QAccessible::Grouping;
  84. }
  85. QAccessible::State AccessibleAlignmentSelector::state() const
  86. {
  87. QAccessible::State state;
  88. state.focusable = true;
  89. state.focused = widget()->hasFocus();
  90. state.disabled = !widget()->isEnabled();
  91. state.readOnly = false;
  92. return state;
  93. }
  94. QVariant AccessibleAlignmentSelector::value() const
  95. {
  96. for (int i = 0; i < childCount(); ++i) {
  97. if (child(i)->state().checked) {
  98. return child(i)->text(QAccessible::Name);
  99. }
  100. }
  101. return QTStr("None");
  102. }