AccessibleAlignmentCell.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 "AccessibleAlignmentCell.hpp"
  15. #include <OBSApp.hpp>
  16. using namespace std::string_view_literals;
  17. constexpr std::array indexToStrings = {
  18. "Basic.TransformWindow.Alignment.TopLeft"sv, "Basic.TransformWindow.Alignment.TopCenter"sv,
  19. "Basic.TransformWindow.Alignment.TopRight"sv, "Basic.TransformWindow.Alignment.CenterLeft"sv,
  20. "Basic.TransformWindow.Alignment.Center"sv, "Basic.TransformWindow.Alignment.CenterRight"sv,
  21. "Basic.TransformWindow.Alignment.BottomLeft"sv, "Basic.TransformWindow.Alignment.BottomCenter"sv,
  22. "Basic.TransformWindow.Alignment.BottomRight"sv};
  23. AccessibleAlignmentCell::AccessibleAlignmentCell(QAccessibleInterface *parent, AlignmentSelector *widget, int index)
  24. : parent_(parent),
  25. widget(widget),
  26. index_(index)
  27. {
  28. }
  29. QRect AccessibleAlignmentCell::rect() const
  30. {
  31. return widget->cellRect(index_);
  32. }
  33. QString AccessibleAlignmentCell::text(QAccessible::Text text) const
  34. {
  35. if (text == QAccessible::Name || text == QAccessible::Value) {
  36. return QString(indexToStrings[index_].data());
  37. }
  38. return QString();
  39. }
  40. QAccessible::State AccessibleAlignmentCell::state() const
  41. {
  42. QAccessible::State state;
  43. bool enabled = widget->isEnabled();
  44. bool isSelectedCell = widget->currentIndex() == index_;
  45. bool isFocusedCell = widget->focusedCell == index_;
  46. state.disabled = !enabled;
  47. state.focusable = enabled;
  48. state.focused = widget->hasFocus() && isFocusedCell;
  49. state.checkable = true;
  50. state.checked = isSelectedCell;
  51. state.selected = isSelectedCell;
  52. return state;
  53. }
  54. QAccessible::Role AccessibleAlignmentCell::role() const
  55. {
  56. return QAccessible::CheckBox;
  57. }