File indexing completed on 2024-06-23 05:13:36
0001 /* 0002 accessibility/accessiblelink.cpp 0003 0004 This file is part of Kleopatra, the KDE keymanager 0005 SPDX-FileCopyrightText: 2022 g10 Code GmbH 0006 SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #include <config-kleopatra.h> 0012 0013 #include "accessiblelink_p.h" 0014 0015 #include <interfaces/anchorprovider.h> 0016 0017 #include <QWidget> 0018 0019 using namespace Kleo; 0020 0021 AccessibleLink::AccessibleLink(QWidget *label, int index) 0022 : mLabel{label} 0023 , mIndex{index} 0024 { 0025 } 0026 0027 AccessibleLink::~AccessibleLink() = default; 0028 0029 bool AccessibleLink::isValid() const 0030 { 0031 return mLabel; 0032 } 0033 0034 QObject *AccessibleLink::object() const 0035 { 0036 return nullptr; 0037 } 0038 0039 QWindow *AccessibleLink::window() const 0040 { 0041 if (auto p = parent()) { 0042 return p->window(); 0043 } 0044 return nullptr; 0045 } 0046 0047 QAccessibleInterface *AccessibleLink::childAt(int, int) const 0048 { 0049 return nullptr; 0050 } 0051 0052 QAccessibleInterface *AccessibleLink::parent() const 0053 { 0054 return QAccessible::queryAccessibleInterface(mLabel); 0055 } 0056 0057 QAccessibleInterface *AccessibleLink::child(int) const 0058 { 0059 return nullptr; 0060 } 0061 0062 int AccessibleLink::childCount() const 0063 { 0064 return 0; 0065 } 0066 0067 int AccessibleLink::indexOfChild(const QAccessibleInterface *) const 0068 { 0069 return -1; 0070 } 0071 0072 QString AccessibleLink::text(QAccessible::Text t) const 0073 { 0074 QString str; 0075 switch (t) { 0076 case QAccessible::Name: 0077 if (auto ap = anchorProvider()) { 0078 str = ap->anchorText(mIndex); 0079 } 0080 break; 0081 default: 0082 break; 0083 } 0084 return str; 0085 } 0086 0087 void AccessibleLink::setText(QAccessible::Text /*t*/, const QString & /*text */) 0088 { 0089 } 0090 0091 QRect AccessibleLink::rect() const 0092 { 0093 if (auto p = parent()) { 0094 return p->rect(); 0095 } 0096 return {}; 0097 } 0098 0099 QAccessible::Role AccessibleLink::role() const 0100 { 0101 return QAccessible::Link; 0102 } 0103 0104 QAccessible::State AccessibleLink::state() const 0105 { 0106 QAccessible::State s; 0107 if (auto p = parent()) { 0108 s = p->state(); 0109 } 0110 if (auto ap = anchorProvider()) { 0111 s.focused = ap->selectedAnchor() == mIndex; 0112 } 0113 return s; 0114 } 0115 0116 void *AccessibleLink::interface_cast(QAccessible::InterfaceType t) 0117 { 0118 if (t == QAccessible::ActionInterface) { 0119 return static_cast<QAccessibleActionInterface *>(this); 0120 } 0121 return nullptr; 0122 } 0123 0124 QStringList AccessibleLink::actionNames() const 0125 { 0126 return {pressAction()}; 0127 } 0128 0129 void AccessibleLink::doAction(const QString &actionName) 0130 { 0131 if (actionName == pressAction()) { 0132 if (auto ap = anchorProvider()) { 0133 ap->activateAnchor(mIndex); 0134 } 0135 } 0136 } 0137 0138 QStringList AccessibleLink::keyBindingsForAction(const QString &) const 0139 { 0140 return {}; 0141 } 0142 0143 int AccessibleLink::index() const 0144 { 0145 return mIndex; 0146 } 0147 0148 AnchorProvider *AccessibleLink::anchorProvider() const 0149 { 0150 return dynamic_cast<AnchorProvider *>(mLabel.data()); 0151 }