File indexing completed on 2024-09-29 07:11:22

0001 /*
0002     SPDX-FileCopyrightText: 2012 Sebastian Sauer <sebastian.sauer@kdab.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "roleobjects_p.h"
0008 
0009 using namespace QAccessibleClient;
0010 
0011 namespace QAccessibleClient {
0012 
0013 class ObjectRole::Private
0014 {
0015 public:
0016     AccessibleObject m_acc;
0017     explicit Private(const AccessibleObject &acc)
0018         : m_acc(acc)
0019     {
0020     }
0021 };
0022 
0023 }
0024 
0025 ObjectRole::ObjectRole(const AccessibleObject &acc
0026     : QObject()
0027     , d(new Private(acc))
0028 {
0029 }
0030 
0031 ObjectRole::ObjectRole(Private *dd)
0032     : QObject()
0033     , d(dd)
0034 {
0035 }
0036 
0037 ObjectRole::~ObjectRole()
0038 {
0039     delete d;
0040 }
0041 
0042 AccessibleObject ObjectRole::accessible() const
0043 {
0044     return d->m_acc;
0045 }
0046 
0047 AccessibleObject::Role ObjectRole::role() const
0048 {
0049     return d->m_acc.role();
0050 }
0051 
0052 QString ObjectRole::roleName() const
0053 {
0054     return d->m_acc.roleName();
0055 }
0056 
0057 QString ObjectRole::localizedRoleName() const
0058 {
0059     return d->m_acc.localizedRoleName();
0060 }
0061 
0062 QString ObjectRole::url() const
0063 {
0064     return d->m_acc.url().toString();
0065 }
0066 
0067 QString ObjectRole::name() const
0068 {
0069     return d->m_acc.name();
0070 }
0071 
0072 QString ObjectRole::description() const
0073 {
0074     return d->m_acc.description();
0075 }
0076 
0077 QRect ObjectRole::boundingRect() const
0078 {
0079     return d->m_acc.boundingRect();
0080 }
0081 
0082 ObjectRole* ObjectRole::create(const AccessibleObject &acc)
0083 {
0084     switch (acc.role()) {
0085         case AccessibleObject::CheckBox: return new CheckBoxRole(acc);
0086         // case AccessibleObject::CheckableMenuItem:
0087         // case AccessibleObject::ColumnHeader:
0088         case AccessibleObject::ComboBox: return new ComboBoxRole(acc);
0089         // case AccessibleObject::DesktopFrame:
0090         // case AccessibleObject::Dial:
0091         // case AccessibleObject::Dialog:
0092         // case AccessibleObject::Filler:
0093         // case AccessibleObject::Frame:
0094         // case AccessibleObject::Icon:
0095         case AccessibleObject::Label: return new LabelRole(acc);
0096         // case AccessibleObject::ListView:
0097         // case AccessibleObject::ListItem:
0098         // case AccessibleObject::Menu:
0099         // case AccessibleObject::MenuBar:
0100         // case AccessibleObject::MenuItem:
0101         // case AccessibleObject::Tab:
0102         // case AccessibleObject::TabContainer:
0103         // case AccessibleObject::PasswordText:
0104         // case AccessibleObject::PopupMenu:
0105         // case AccessibleObject::ProgressBar:
0106         case AccessibleObject::Button: return new ButtonRole(acc);
0107         case AccessibleObject::RadioButton: return new RadioButtonRole(acc);
0108         // case AccessibleObject::RadioMenuItem:
0109         // case AccessibleObject::RowHeader:
0110         // case AccessibleObject::ScrollBar:
0111         // case AccessibleObject::ScrollArea:
0112         // case AccessibleObject::Separator:
0113         // case AccessibleObject::Slider:
0114         // case AccessibleObject::SpinButton:
0115         // case AccessibleObject::StatusBar:
0116         // case AccessibleObject::TableView:
0117         // case AccessibleObject::TableCell:
0118         // case AccessibleObject::TableColumnHeader:
0119         // case AccessibleObject::TableColumn:
0120         // case AccessibleObject::TableRowHeader:
0121         // case AccessibleObject::TableRow:
0122         // case AccessibleObject::Terminal:
0123         case AccessibleObject::Text: return new TextRole(acc);
0124         case AccessibleObject::ToggleButton: return new ToggleRole(acc);
0125         // case AccessibleObject::ToolBar:
0126         // case AccessibleObject::ToolTip:
0127         // case AccessibleObject::TreeView:
0128         // case AccessibleObject::Window:
0129         // case AccessibleObject::TreeItem:
0130     }
0131     return 0;
0132 }
0133 
0134 CheckBoxRole::CheckBoxRole(const AccessibleObject &acc)
0135     : ObjectRole(acc)
0136 {
0137 }
0138 
0139 QString CheckBoxRole::text() const
0140 {
0141     return accessible().name();
0142 }
0143 
0144 ComboBoxRole::ComboBoxRole(const AccessibleObject &acc)
0145     : ObjectRole(acc)
0146 {
0147 }
0148 
0149 QString ComboBoxRole::text() const
0150 {
0151     return accessible().name();
0152 }
0153 
0154 LabelRole::LabelRole(const AccessibleObject &acc)
0155     : ObjectRole(acc)
0156 {
0157 }
0158 
0159 QString LabelRole::text() const
0160 {
0161     return accessible().name();
0162 }
0163 
0164 ButtonRole::ButtonRole(const AccessibleObject &acc)
0165     : ObjectRole(acc)
0166 {
0167 }
0168 
0169 QString ButtonRole::text() const
0170 {
0171     return accessible().name();
0172 }
0173 
0174 RadioButtonRole::RadioButtonRole(const AccessibleObject &acc)
0175     : ObjectRole(acc)
0176 {
0177 }
0178 
0179 QString RadioButtonRole::text() const
0180 {
0181     return accessible().name();
0182 }
0183 
0184 TextRole::TextRole(const AccessibleObject &acc)
0185     : ObjectRole(acc)
0186 {
0187 }
0188 
0189 QString TextRole::text() const
0190 {
0191     if (accessible().supportedInterfaces().testFlag(AccessibleObject::TextInterface))
0192         return accessible().text();
0193     return accessible().name();
0194 }
0195 
0196 void TextRole::setText(const QString &text)
0197 {
0198     if (isEditable())
0199         accessible().setText(text);
0200     else
0201         qWarning() << "Cannot TextRole::setText on none editable text object";
0202 }
0203 
0204 bool TextRole::isEditable() const
0205 {
0206     return accessible().supportedInterfaces().testFlag(AccessibleObject::EditableTextInterface);
0207 }
0208 
0209 ToggleButtonRole::ToggleButtonRole(const AccessibleObject &acc)
0210     : ObjectRole(acc)
0211 {
0212 }
0213 
0214 QString ToggleButtonRole::text() const
0215 {
0216     return accessible().name();
0217 }
0218 
0219 #include "moc_roleobjects_p.cpp"