diff --git a/examples/accessibleapps/accessibleproperties.cpp b/examples/accessibleapps/accessibleproperties.cpp index fc4b499..c46a789 100644 --- a/examples/accessibleapps/accessibleproperties.cpp +++ b/examples/accessibleapps/accessibleproperties.cpp @@ -1,357 +1,357 @@ /* Copyright 2012 Sebastian Sauer This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "accessibleproperties.h" #include "qaccessibilityclient/registry.h" using namespace QAccessibleClient; ObjectProperties::ObjectProperties(QObject *parent) : QStandardItemModel(parent) { setColumnCount(2); setHorizontalHeaderLabels( QStringList() << QString("Property") << QString("Value") ); connect(this, SIGNAL(itemChanged(QStandardItem *)), this, SLOT(slotDataChanged(QStandardItem *))); } ObjectProperties::~ObjectProperties() { } void ObjectProperties::slotDataChanged(QStandardItem *item) { if (item == m_textItem) { QString newText = item->data(Qt::EditRole).toString(); m_acc.setText(newText); } else if (item == m_valueItem) { bool couldConvert; double value = item->data(Qt::EditRole).toDouble(&couldConvert); if (couldConvert) { m_acc.setCurrentValue(value); } - m_valueItem = 0; //Prevent recursion + m_valueItem = nullptr; //Prevent recursion item->setData(m_acc.currentValue(), Qt::DisplayRole); m_valueItem = item; } } QVariant ObjectProperties::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { if (section == 0) { return QStringLiteral("Property"); } if (section == 1) { return QStringLiteral("Value"); } } return QVariant(); } QHash ObjectProperties::roleNames() const { QHash roles; roles[NameRole] = "name"; roles[ValueRole] = "value"; return roles; } void ObjectProperties::setAccessibleObject(const QAccessibleClient::AccessibleObject &acc) { beginResetModel(); m_acc = acc; - m_textItem = 0; - m_valueItem = 0; + m_textItem = nullptr; + m_valueItem = nullptr; clear(); if (!acc.isValid()) { endResetModel(); return; } QAccessibleClient::AccessibleObject::Interfaces interfaces = acc.supportedInterfaces(); if (interfaces.testFlag(QAccessibleClient::AccessibleObject::AccessibleInterface)) { QStandardItem *item = append(QString("Accessible")); append(QString("Name"), acc.name(), item); append(QString("Description"), acc.description(), item); append(QString("Role"), acc.roleName(), item); append(QString("LocalizedRole"), acc.localizedRoleName(), item); append(QString("Visible"), acc.isVisible(), item); append(QString("Default"), acc.isDefault(), item); append(QString("State"), acc.stateString(), item); append(tr("Url"), acc.url(), item); AccessibleObject parent = acc.parent(); if (parent.isValid()) append(tr("Parent"), parent.url(), item); int childCount = acc.childCount(); QStandardItem *children = append(QString("Children"), acc.childCount(), item); for (int i = 0; i < childCount; ++i) { AccessibleObject child = acc.child(i); if (!child.isValid()) { append(QLatin1String("Broken child"), QString::number(i), children); } else { append(child.name().isEmpty() ? tr("[%1]").arg(child.roleName()) : child.name(), child.url(), children); } } //GetAttributes } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::ComponentInterface)) { QStandardItem *item = append(QString("Component")); append(QString("BoundingRect"), acc.boundingRect(), item); append(QString("Layer"), acc.layer(), item); append(QString("MDIZOrder"), acc.mdiZOrder(), item); append(QString("Alpha"), acc.alpha(), item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::CollectionInterface)) { QStandardItem *item = append(QString("Collection")); Q_UNUSED(item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::ApplicationInterface)) { QStandardItem *item = append(QString("Application")); append(QString("ToolkitName"), acc.appToolkitName(), item); append(QString("Version"), acc.appVersion(), item); append(QString("Id"), acc.appId(), item); append(QString("Locale"), acc.appLocale(), item); append(QString("BusAddress"), acc.appBusAddress(), item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::DocumentInterface)) { QStandardItem *item = append(QString("Document")); Q_UNUSED(item); //GetLocale //GetAttributeValue //GetAttributes } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::EditableTextInterface)) { QStandardItem *item = append(QString("EditableText")); Q_UNUSED(item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::HyperlinkInterface)) { QStandardItem *item = append(QString("Hyperlink")); Q_UNUSED(item); /* 0 */ } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::HypertextInterface)) { QStandardItem *item = append(QString("Hypertext")); Q_UNUSED(item); /* */ } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::ImageInterface)) { QStandardItem *item = append(QString("Image")); append(QString("Description"), acc.imageDescription(), item); append(QString("Locale"), acc.imageLocale(), item); append(QString("Rect"), acc.imageRect(), item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::SelectionInterface)) { QStandardItem *item = append(QString("Selection")); Q_FOREACH(const QAccessibleClient::AccessibleObject &s, acc.selection()) { append(s.name(), s.role(), item); } } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::TableInterface)) { QStandardItem *item = append(QString("Table")); Q_UNUSED(item); /* */ } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::TextInterface)) { QStandardItem *item = append(QString("Text")); int offset = acc.caretOffset(); append(QString("CaretOffset"), offset, item); append(QString("CharacterCount"), acc.characterCount(), item); append(QString("CharacterRect"), acc.characterRect(offset), item); QString text = acc.text(); if (interfaces.testFlag(QAccessibleClient::AccessibleObject::EditableTextInterface)) { append(QString("Text"), text, item, &m_textItem); } else { append(QString("Text"), text, item); } QList< QPair > selections = acc.textSelections(); QStandardItem *selectionsItem = append(QString("Selections"), selections.count(), item); for (int i = 0; i < selections.count(); ++i) { QPair sel = selections[i]; int startOffset = sel.first; int endOffset = sel.second; Q_ASSERT(startOffset <= endOffset); append( QString("%1:%2").arg(startOffset).arg(endOffset), text.mid(startOffset, endOffset - startOffset), selectionsItem ); } } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::ValueInterface)) { QStandardItem *item = append(QString("Value")); append(QString("Current"), acc.currentValue(), item, &m_valueItem); append(QString("Minimum"), acc.minimumValue(), item); append(QString("Maximum"), acc.maximumValue(), item); append(QString("Increment"), acc.minimumValueIncrement(), item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::SocketInterface)) { QStandardItem *item = append(QString("Socket")); Q_UNUSED(item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::EventKeyboardInterface)) { QStandardItem *item = append(QString("EventKeyboard")); Q_UNUSED(item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::EventMouseInterface)) { QStandardItem *item = append(QString("EventMouse")); Q_UNUSED(item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::EventObjectInterface)) { QStandardItem *item = append(QString("EventObject")); Q_UNUSED(item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::EventWindowInterface)) { QStandardItem *item = append(QString("EventWindow")); Q_UNUSED(item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::EventFocusInterface)) { QStandardItem *item = append(QString("EventFocus")); Q_UNUSED(item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::ActionInterface)) { QStandardItem *item = append(QString("Action")); Q_FOREACH(const QSharedPointer &a, acc.actions()) { QStandardItem *nameItem = new QStandardItem(a->text()); QStandardItem *valueItem = new QStandardItem(a->whatsThis()); nameItem->setEditable(false); valueItem->setEditable(false); item->appendRow(QList() << nameItem << valueItem); } } endResetModel(); } void ObjectProperties::doubleClicked(const QModelIndex &index) { if (!index.isValid() || !index.parent().isValid() || index.parent().data().toString() != QLatin1String("Action")) return; foreach (const QSharedPointer &action, m_acc.actions()) { if (action->text() == data(index).toString()) { action->trigger(); return; } } } QStandardItem* ObjectProperties::append(const QString &name, const QVariant &value, QStandardItem *parentItem, QStandardItem **changeHandler) { if (!parentItem) parentItem = invisibleRootItem(); QStandardItem *nameItem = new QStandardItem(name); QString text; switch (value.type()) { case QVariant::Point: { QPoint p = value.toPoint(); text = QString("%1:%2").arg(p.x()).arg(p.y()); } break; case QVariant::PointF: { QPointF p = value.toPointF(); text = QString("%1:%2").arg(p.x()).arg(p.y()); } break; case QVariant::Rect: { QRect r = value.toRect(); text = QString("%1:%2 %3x%4").arg(r.left()).arg(r.top()).arg(r.width()).arg(r.height()); } break; case QVariant::RectF: { QRectF r = value.toRectF(); text = QString("%1:%2 %3x%4").arg(r.left()).arg(r.top()).arg(r.width()).arg(r.height()); } break; default: text = value.toString(); break; } QStandardItem *valueItem = new QStandardItem(text); parentItem->appendRow(QList() << nameItem << valueItem); nameItem->setEditable(false); if (changeHandler) { *changeHandler = valueItem; valueItem->setEditable(true); } else { valueItem->setEditable(false); } return nameItem; } diff --git a/examples/accessibleapps/accessibleproperties.h b/examples/accessibleapps/accessibleproperties.h index 0364e6c..10bf5bb 100644 --- a/examples/accessibleapps/accessibleproperties.h +++ b/examples/accessibleapps/accessibleproperties.h @@ -1,57 +1,57 @@ /* Copyright 2012 Sebastian Sauer This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef ACCESSIBLEPROPERTIES_H #define ACCESSIBLEPROPERTIES_H #include #include #include "qaccessibilityclient/accessibleobject.h" class ObjectProperties : public QStandardItemModel { Q_OBJECT public: enum Role { NameRole, ValueRole }; - explicit ObjectProperties(QObject *parent = 0); + explicit ObjectProperties(QObject *parent = nullptr); virtual ~ObjectProperties(); QVariant headerData(int section, Qt::Orientation orientation, int role) const override; QHash roleNames() const override; void setAccessibleObject(const QAccessibleClient::AccessibleObject &acc); QAccessibleClient::AccessibleObject currentObject() const { return m_acc; } public Q_SLOTS: void doubleClicked(const QModelIndex &index); void slotDataChanged(QStandardItem *item); private: - QStandardItem* append(const QString &name, const QVariant &value = QVariant(), QStandardItem *parentItem = 0, QStandardItem **changeHandler = 0); + QStandardItem* append(const QString &name, const QVariant &value = QVariant(), QStandardItem *parentItem = nullptr, QStandardItem **changeHandler = nullptr); QString stateString(const QAccessibleClient::AccessibleObject &acc); QAccessibleClient::AccessibleObject m_acc; QStandardItem* m_textItem; QStandardItem* m_valueItem; }; #endif diff --git a/examples/accessibleapps/accessibletree.cpp b/examples/accessibleapps/accessibletree.cpp index 5e86899..15b1ca9 100644 --- a/examples/accessibleapps/accessibletree.cpp +++ b/examples/accessibleapps/accessibletree.cpp @@ -1,349 +1,349 @@ /* * Copyright 2012 Frederik Gladhorn * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "accessibletree.h" #include #include using namespace QAccessibleClient; AccessibleWrapper* AccessibleWrapper::parent() { return m_parent; } AccessibleWrapper* AccessibleWrapper::child(int index) { if (m_children.isEmpty()) { QList children = acc.children(); foreach (const AccessibleObject &c, children) { m_children.append(new AccessibleWrapper(c, this)); } } if (index >= 0 && index < m_children.count()) { return m_children.at(index); } - return 0; + return nullptr; } int AccessibleWrapper::childCount() { if (m_children.isEmpty()) return acc.childCount(); return m_children.count(); } AccessibleTree::AccessibleTree(QObject* parent) - : QAbstractItemModel(parent), m_registry(0) + : QAbstractItemModel(parent), m_registry(nullptr) { } AccessibleTree::~AccessibleTree() { } QVariant AccessibleTree::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { if (section == 0) { return "Accessible"; } else if (section == 1) { return "Role"; } } return QVariant(); } int AccessibleTree::columnCount(const QModelIndex& parent) const { Q_UNUSED(parent); return 2; } QVariant AccessibleTree::data(const QModelIndex& index, int role) const { if (!m_registry || !index.isValid()) return QVariant(); AccessibleObject acc = static_cast(index.internalPointer())->acc; switch (role) { case Qt::DisplayRole: if (index.column() == 0) { QString name = acc.name(); if (name.isEmpty()) name = QString("[%1]").arg(acc.roleName()); return name; } else if (index.column() == 1) { return acc.roleName(); } default: return QVariant(); } return QVariant(); } QModelIndex AccessibleTree::index(int row, int column, const QModelIndex& parent) const { if (!m_registry || (column < 0) || (column > 1) || (row < 0)) return QModelIndex(); // qDebug() << "index:" << row << column << parent; if (!parent.isValid()) { if (row < m_apps.count()) { return createIndex(row, column, m_apps.at(row)); } } else { AccessibleWrapper *wraper = static_cast(parent.internalPointer()); if (row < wraper->childCount()) { QModelIndex newIndex = createIndex(row, column, wraper->child(row)); if (newIndex.parent() != parent) { qWarning() << "Broken navigation: " << parent << row; emit navigationError(parent); } return newIndex; } else { qWarning() << "Could not access child: " << wraper->acc.name() << wraper->acc.roleName(); } } return QModelIndex(); } QModelIndex AccessibleTree::parent(const QModelIndex& child) const { // qDebug() << "Parent: " << child; if (child.isValid()) { AccessibleWrapper *wraper = static_cast(child.internalPointer()); AccessibleWrapper *parent = wraper->parent(); if (parent) { // if this is a top-level item, it has no parent if (parent->parent()) { return createIndex(parent->acc.indexInParent(), 0, parent); } else { return createIndex(m_apps.indexOf(parent), 0, parent); } } } return QModelIndex(); } int AccessibleTree::rowCount(const QModelIndex& parent) const { if (!m_registry || parent.column() > 0) return 0; // qDebug() << "row count:" << parent << parent.internalPointer(); if (!parent.isValid()) { return m_apps.count(); } else { if (!parent.internalPointer()) return 0; AccessibleWrapper *wraper = static_cast(parent.internalPointer()); // qDebug() << " row count:" << wraper->acc.name() << wraper->acc.roleName() << wraper->childCount(); return wraper->childCount(); } return 0; } void AccessibleTree::setRegistry(QAccessibleClient::Registry* registry) { m_registry = registry; resetModel(); } void AccessibleTree::resetModel() { beginResetModel(); qDeleteAll(m_apps); m_apps.clear(); if (m_registry) { QList children = m_registry->applications(); foreach (const AccessibleObject &c, children) { - m_apps.append(new AccessibleWrapper(c, 0)); + m_apps.append(new AccessibleWrapper(c, nullptr)); } } endResetModel(); } void AccessibleTree::updateTopLevelApps() { QList topLevelApps = m_registry->applications(); for (int i = m_apps.count() - 1; i >= 0; --i) { AccessibleObject app = m_apps.at(i)->acc; int indexOfApp = topLevelApps.indexOf(app); if (indexOfApp < 0) { removeAccessible(index(i, 0, QModelIndex())); } else { topLevelApps.takeAt(i); } } foreach (const AccessibleObject &newApp, topLevelApps) { addAccessible(newApp); } } QModelIndex AccessibleTree::indexForAccessible(const AccessibleObject& object) { if (!object.isValid()) return QModelIndex(); if (object.supportedInterfaces().testFlag(QAccessibleClient::AccessibleObject::ApplicationInterface)) { // top level for (int i = 0; i < m_apps.size(); ++i) { if (m_apps.at(i)->acc == object) return createIndex(i, 0, m_apps.at(i)); } int lastIndex = m_apps.size(); if (addAccessible(object) && m_apps.at(lastIndex)->acc == object) return createIndex(lastIndex, 0, m_apps.at(lastIndex)); } else { AccessibleObject parent = object.parent(); if (parent.isValid()) { QModelIndex parentIndex = indexForAccessible(parent); if (!parentIndex.isValid()) { if (object.isValid() && object.application().isValid()) qWarning() << Q_FUNC_INFO << object.application().name() << object.name() << object.roleName() << "Parent model index is invalid: " << object; return QModelIndex(); } int indexInParent = object.indexInParent(); if (indexInParent < 0) { qWarning() << Q_FUNC_INFO << "indexInParent is invalid: " << object; return QModelIndex(); } QModelIndex in = index(indexInParent, 0, parentIndex); //qDebug() << "indexForAccessible: " << object.name() << data(in).toString() << " parent: " << data(parentIndex).toString();//" row: " << object.indexInParent() << "parentIndex: " << parentIndex; return in; } else { qWarning() << Q_FUNC_INFO << "Invalid indexForAccessible: " << object; //Q_ASSERT(!object.supportedInterfaces().testFlag(QAccessibleClient::AccessibleObject::Application)); //return indexForAccessible(object.application()); Q_FOREACH(const QAccessibleClient::AccessibleObject &child, object.children()) { if (child.supportedInterfaces().testFlag(QAccessibleClient::AccessibleObject::ApplicationInterface)) { for (int i = 0; i < m_apps.size(); ++i) { if (m_apps.at(i)->acc == object) return createIndex(i, 0, m_apps.at(i)); } } } } } return QModelIndex(); } bool AccessibleTree::addAccessible(const QAccessibleClient::AccessibleObject &object) { // qDebug() << Q_FUNC_INFO << object; QAccessibleClient::AccessibleObject parent = object.parent(); // We have no parent -> top level. if (!parent.isValid()) { if (!object.supportedInterfaces().testFlag(QAccessibleClient::AccessibleObject::ApplicationInterface)) qWarning() << Q_FUNC_INFO << "Found top level accessible that does not implement the application interface" << object; beginInsertRows(QModelIndex(), m_apps.count(), m_apps.count()); - m_apps.append(new AccessibleWrapper(object, 0)); + m_apps.append(new AccessibleWrapper(object, nullptr)); endInsertRows(); return true; } // If the parent is not known, add it too. QModelIndex parentIndex = indexForAccessible(parent); if (!parentIndex.isValid()) { if (!addAccessible(parent)) { qWarning() << Q_FUNC_INFO << "Could not add accessible (invalid parent): " << object; return false; } parentIndex = indexForAccessible(parent); Q_ASSERT(parentIndex.isValid()); } // Add this item (or emit dataChanged, if it's there already). int idx = object.indexInParent(); if (idx < 0) { qWarning() << Q_FUNC_INFO << "Could not add accessible (invalid index in parent): " << object; return false; } QModelIndex objectIndex = index(idx, 0, parentIndex); if (objectIndex.isValid() && static_cast(objectIndex.internalPointer())->acc == object) { emit dataChanged(objectIndex, objectIndex); return false; } beginInsertRows(parentIndex, idx, idx); AccessibleWrapper *parentWrapper = static_cast(parentIndex.internalPointer()); Q_ASSERT(parentWrapper); parentWrapper->m_children.insert(idx, new AccessibleWrapper(object, parentWrapper)); endInsertRows(); return true; } bool AccessibleTree::removeAccessible(const QAccessibleClient::AccessibleObject &object) { qDebug() << Q_FUNC_INFO << object; QModelIndex index = indexForAccessible(object); if (!index.isValid()) return false; return removeAccessible(index); } bool AccessibleTree::removeAccessible(const QModelIndex &index) { qDebug() << Q_FUNC_INFO << index; Q_ASSERT(index.isValid()); Q_ASSERT(index.model() == this); QModelIndex parent = index.parent(); int row = index.row(); bool removed = false; beginRemoveRows(parent, row, row); if (parent.isValid()) { AccessibleWrapper *wraper = static_cast(parent.internalPointer()); Q_ASSERT(wraper); delete wraper->m_children.takeAt(row); removed = true; } else { AccessibleWrapper *wraper = static_cast(index.internalPointer()); Q_ASSERT(wraper); Q_ASSERT(m_apps[row] == wraper); if (m_apps[row] == wraper) { qDebug() << Q_FUNC_INFO << "Delete application accessible object! indexRow=" << row; delete m_apps.takeAt(row); removed = true; } } endRemoveRows(); return removed; } void AccessibleTree::updateAccessible(const QAccessibleClient::AccessibleObject &object) { QModelIndex index = indexForAccessible(object); emit dataChanged(index, index); } diff --git a/examples/accessibleapps/accessibletree.h b/examples/accessibleapps/accessibletree.h index 559fce2..3e4744b 100644 --- a/examples/accessibleapps/accessibletree.h +++ b/examples/accessibleapps/accessibletree.h @@ -1,95 +1,95 @@ /* * Copyright 2012 Frederik Gladhorn * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef ACCESSIBLETREE_H #define ACCESSIBLETREE_H #include #include class AccessibleTree; class AccessibleWrapper { public: AccessibleWrapper(const QAccessibleClient::AccessibleObject &object, AccessibleWrapper *parent) : acc(object), m_parent(parent) {} QAccessibleClient::AccessibleObject acc; ~AccessibleWrapper() { qDeleteAll(m_children); } int childCount(); AccessibleWrapper *child(int index); AccessibleWrapper *parent(); private: friend class AccessibleTree; AccessibleWrapper *m_parent; QList m_children; }; class AccessibleTree :public QAbstractItemModel { Q_OBJECT public: - explicit AccessibleTree(QObject* parent = 0); + explicit AccessibleTree(QObject* parent = nullptr); ~AccessibleTree(); void setRegistry(QAccessibleClient::Registry *registry); QModelIndex indexForAccessible(const QAccessibleClient::AccessibleObject &object); bool addAccessible(const QAccessibleClient::AccessibleObject &object); bool removeAccessible(const QAccessibleClient::AccessibleObject &object); bool removeAccessible(const QModelIndex &index); void updateAccessible(const QAccessibleClient::AccessibleObject &object); QList apps() const { return m_apps; } virtual int columnCount(const QModelIndex& parent = QModelIndex()) const; virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const; virtual QModelIndex parent(const QModelIndex& child) const; virtual int rowCount(const QModelIndex& parent = QModelIndex()) const; virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; public Q_SLOTS: void resetModel(); /*! \brief Updates all applications in the tree. Removes and adds top level applications. This is less invasive then modelReset. */ void updateTopLevelApps(); Q_SIGNALS: void navigationError(const QModelIndex &) const; private: QAccessibleClient::Registry *m_registry; QList m_apps; }; #endif // ACCESSIBLETREE_H diff --git a/examples/accessibleapps/clientcachedialog.h b/examples/accessibleapps/clientcachedialog.h index 3050129..2c0c07a 100644 --- a/examples/accessibleapps/clientcachedialog.h +++ b/examples/accessibleapps/clientcachedialog.h @@ -1,54 +1,54 @@ /* * Copyright 2012 Frederik Gladhorn * Copyright 2012 Sebastian Sauer * * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef CLIENTCACHEDIALOG_H #define CLIENTCACHEDIALOG_H #include #include "qaccessibilityclient/accessibleobject.h" #include "qaccessibilityclient/registry.h" class QComboBox; class QLabel; class QStandardItemModel; class QTreeView; class ClientCacheDialog : public QDialog { Q_OBJECT public: - ClientCacheDialog(QAccessibleClient::Registry *registry, QWidget *parent = 0); + ClientCacheDialog(QAccessibleClient::Registry *registry, QWidget *parent = nullptr); private Q_SLOTS: void clearCache(); void cacheStrategyChanged(); void updateView(); private: QAccessibleClient::Registry *m_registry; QAccessibleClient::RegistryPrivateCacheApi *m_cache; QTreeView *m_view; QStandardItemModel *m_model; QComboBox *m_cacheCombo; QLabel *m_countLabel; }; #endif diff --git a/examples/accessibleapps/eventview.cpp b/examples/accessibleapps/eventview.cpp index 33bd262..7483679 100644 --- a/examples/accessibleapps/eventview.cpp +++ b/examples/accessibleapps/eventview.cpp @@ -1,425 +1,425 @@ /* Copyright 2012 Frederik Gladhorn This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "eventview.h" #include #include #include #include #include #include #include #include #include #include #include #include #include class EventsModel : public QStandardItemModel { public: enum Role { AccessibleRole = 0, RoleRole = 1, EventRole = 2, ActionRole = 3, EventTypeRole = Qt::UserRole, UrlRole, AppNameRole, AppUrlRole }; explicit EventsModel(EventsWidget *view) : QStandardItemModel(view), m_view(view) { clearLog(); } ~EventsModel() {} QHash roleNames() const { QHash roles; roles[AccessibleRole] = "accessible"; roles[RoleRole] = "role"; roles[EventRole] = "event"; roles[EventTypeRole] = "eventType"; roles[UrlRole] = "url"; roles[AppNameRole] = "appName"; roles[AppUrlRole] = "appUrl"; return roles; } QString roleLabel(Role role) const { switch (role) { case AccessibleRole: return QString("Accessible"); case RoleRole: return QString("Role"); case EventRole: return QString("Event"); case ActionRole: return QString("Action"); case EventTypeRole: case UrlRole: case AppNameRole: case AppUrlRole: break; } return QString(); } void clearLog() { clear(); m_apps.clear(); setColumnCount(4); QStringList headerLabels; Q_FOREACH(Role r, QList() << AccessibleRole << RoleRole << EventRole << ActionRole) headerLabels << roleLabel(r); setHorizontalHeaderLabels(headerLabels); } struct LogItem { QStandardItem *appItem; bool isNewAppItem; LogItem(QStandardItem *appItem, bool isNewAppItem) : appItem(appItem), isNewAppItem(isNewAppItem) {} }; LogItem addLog(QList item) { QString appUrl = item.first()->data(AppUrlRole).toString(); - QStandardItem *appItem = 0; + QStandardItem *appItem = nullptr; QMap::ConstIterator it = m_apps.constFind(appUrl); bool isNewAppItem = it == m_apps.constEnd(); if (isNewAppItem) { QString appName = item.first()->data(AppNameRole).toString(); m_apps[appUrl] = appItem = new QStandardItem(appName); appItem->setData(appUrl, EventsModel::AppUrlRole); invisibleRootItem()->appendRow(appItem); } else { appItem = it.value(); } appItem->appendRow(item); return LogItem(appItem, isNewAppItem); } private: EventsWidget *m_view; QMap m_apps; }; class EventsProxyModel : public QSortFilterProxyModel { public: - explicit EventsProxyModel(QWidget *parent = 0) : QSortFilterProxyModel(parent), m_types(EventsWidget::AllEvents) {} + explicit EventsProxyModel(QWidget *parent = nullptr) : QSortFilterProxyModel(parent), m_types(EventsWidget::AllEvents) {} EventsWidget::EventTypes filter() const { return m_types; } QString accessibleFilter() const { return m_accessibleFilter; } QString roleFilter() const { return m_roleFilter; } void setFilter(EventsWidget::EventTypes types) { m_types = types; invalidateFilter(); } void setAccessibleFilter(const QString &filter) { m_accessibleFilter = filter; invalidateFilter(); } void setRoleFilter(const QString &filter) { m_roleFilter = filter; invalidateFilter(); } protected: virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { if (!source_parent.isValid()) return true; if (!m_types.testFlag(EventsWidget::AllEvents)) { QModelIndex index = sourceModel()->index(source_row, 0, source_parent); EventsWidget::EventType type = index.data(EventsModel::EventTypeRole).value(); if (!m_types.testFlag(type)) return false; } if (!m_accessibleFilter.isEmpty()) { QModelIndex index = sourceModel()->index(source_row, EventsModel::AccessibleRole, source_parent); QString accessibleName = index.data(Qt::DisplayRole).toString(); if (!accessibleName.contains(m_accessibleFilter, Qt::CaseInsensitive)) return false; } if (!m_roleFilter.isEmpty()) { QModelIndex index = sourceModel()->index(source_row, EventsModel::RoleRole, source_parent); QString roleName = index.data(Qt::DisplayRole).toString(); if (!roleName.contains(m_roleFilter, Qt::CaseInsensitive)) return false; } return true; } private: EventsWidget::EventTypes m_types; QString m_accessibleFilter; QString m_roleFilter; }; using namespace QAccessibleClient; -QAccessible::UpdateHandler EventsWidget::m_originalAccessibilityUpdateHandler = 0; -QObject *EventsWidget::m_textEditForAccessibilityUpdateHandler = 0; +QAccessible::UpdateHandler EventsWidget::m_originalAccessibilityUpdateHandler = nullptr; +QObject *EventsWidget::m_textEditForAccessibilityUpdateHandler = nullptr; EventsWidget::EventsWidget(QAccessibleClient::Registry *registry, QWidget *parent) : QWidget(parent), m_registry(registry), m_model(new EventsModel(this)), m_proxyModel(new EventsProxyModel(this)) { m_ui.setupUi(this); m_ui.eventListView->setAccessibleName(QLatin1String("Events View")); m_ui.eventListView->setAccessibleDescription(QString("Displays all received events")); m_proxyModel->setSourceModel(m_model); m_ui.eventListView->setModel(m_proxyModel); connect(m_ui.accessibleFilterEdit, SIGNAL(textChanged(QString)), this, SLOT(accessibleFilterChanged())); connect(m_ui.roleFilterEdit, SIGNAL(textChanged(QString)), this, SLOT(roleFilterChanged())); QStandardItemModel *filerModel = new QStandardItemModel(); QStandardItem *firstFilterItem = new QStandardItem(QString("Event Filter")); firstFilterItem->setFlags(Qt::ItemIsEnabled); filerModel->appendRow(firstFilterItem); QVector< EventType > filterList; filterList << StateChanged << NameChanged << DescriptionChanged << Window << Focus << Document << Object << Text << Table << Others; for(int i = 0; i < filterList.count(); ++i) { EventType t = filterList[i]; QStandardItem* item = new QStandardItem(eventName(t)); item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled); item->setData(QVariant::fromValue(t), EventsModel::EventTypeRole); item->setData(Qt::Checked, Qt::CheckStateRole); filerModel->appendRow(QList() << item); } m_ui.filterComboBox->setModel(filerModel); m_ui.clearButton->setFixedWidth(QFontMetrics(m_ui.clearButton->font()).boundingRect(m_ui.clearButton->text()).width() + 4); m_ui.clearButton->setFixedHeight(m_ui.filterComboBox->sizeHint().height()); connect(m_ui.clearButton, SIGNAL(clicked()), this, SLOT(clearLog())); connect(m_ui.filterComboBox->model(), SIGNAL(itemChanged(QStandardItem*)), this, SLOT(checkStateChanged())); connect(m_ui.eventListView, SIGNAL(activated(QModelIndex)), this, SLOT(eventActivated(QModelIndex))); // Collect multiple addLog calls and process them after 500 ms earliest. This // makes sure multiple calls to addLog will be compressed to one only one // view refresh what improves performance. m_pendingTimer.setInterval(500); connect(&m_pendingTimer, SIGNAL(timeout()), this, SLOT(processPending())); m_textEditForAccessibilityUpdateHandler = m_ui.eventListView; checkStateChanged(); // We need to wait for a11y to be active for this hack. QTimer::singleShot(500, this, SLOT(installUpdateHandler())); } void EventsWidget::installUpdateHandler() { m_originalAccessibilityUpdateHandler = QAccessible::installUpdateHandler(customUpdateHandler); if (!m_originalAccessibilityUpdateHandler) QTimer::singleShot(500, this, SLOT(installUpdateHandler())); } #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) void EventsWidget::customUpdateHandler(QAccessibleEvent *event) { QObject *object = event->object(); #else void EventsWidget::customUpdateHandler(QObject *object, int who, QAccessible::Event reason) { #endif if (object == m_textEditForAccessibilityUpdateHandler) return; //if (m_originalAccessibilityUpdateHandler) // m_originalAccessibilityUpdateHandler(object, who, reason); } QString EventsWidget::eventName(EventType eventType) const { QString s; switch (eventType) { case EventsWidget::Focus: s = QLatin1String("Focus"); break; case EventsWidget::StateChanged: s = QLatin1String("State"); break; case EventsWidget::NameChanged: s = QLatin1String("Name"); break; case EventsWidget::DescriptionChanged: s = QLatin1String("Description"); break; case EventsWidget::Window: s = QLatin1String("Window"); break; case EventsWidget::Document: s = QLatin1String("Document"); break; case EventsWidget::Object: s = QLatin1String("Object"); break; case EventsWidget::Text: s = QLatin1String("Text"); break; case EventsWidget::Table: s = QLatin1String("Table"); break; case EventsWidget::Others: s = QLatin1String("Others"); break; } return s; } void EventsWidget::loadSettings(QSettings &settings) { settings.beginGroup("events"); bool eventsFilterOk; EventTypes eventsFilter = EventTypes(settings.value("eventsFilter").toInt(&eventsFilterOk)); if (!eventsFilterOk) eventsFilter = AllEvents; QAbstractItemModel *model = m_ui.filterComboBox->model(); if (eventsFilter != m_proxyModel->filter()) { for (int i = 1; i < model->rowCount(); ++i) { QModelIndex index = model->index(i, 0); EventType type = model->data(index, EventsModel::EventTypeRole).value(); if (eventsFilter.testFlag(type)) model->setData(index, Qt::Checked, Qt::CheckStateRole); else model->setData(index, Qt::Unchecked, Qt::CheckStateRole); } m_proxyModel->setFilter(eventsFilter); } QByteArray eventListViewState = settings.value("listViewHeader").toByteArray(); if (!eventListViewState.isEmpty()) m_ui.eventListView->header()->restoreState(eventListViewState); settings.endGroup(); } void EventsWidget::saveSettings(QSettings &settings) { settings.beginGroup("events"); settings.setValue("eventsFilter", int(m_proxyModel->filter())); QByteArray eventListViewState = m_ui.eventListView->header()->saveState(); settings.setValue("listViewHeader", eventListViewState); settings.endGroup(); } void EventsWidget::clearLog() { m_model->clearLog(); } void EventsWidget::processPending() { m_pendingTimer.stop(); QVector< QList > pendingLogs = m_pendingLogs; m_pendingLogs.clear(); //bool wasMax = true;//m_ui.eventListView->verticalScrollBar()->value() - 10 >= m_ui.eventListView->verticalScrollBar()->maximum(); - QStandardItem *lastItem = 0; - QStandardItem *lastAppItem = 0; + QStandardItem *lastItem = nullptr; + QStandardItem *lastAppItem = nullptr; for(int i = 0; i < pendingLogs.count(); ++i) { QList item = pendingLogs[i]; EventsModel::LogItem logItem = m_model->addLog(item); // Logic to scroll to the last added logItem of the last appItem that is expanded. // For appItem's not expanded the logItem is added but no scrolling will happen. if (lastItem && lastAppItem && lastAppItem != logItem.appItem) - lastItem = 0; + lastItem = nullptr; bool selected = lastItem; if (lastAppItem != logItem.appItem) { lastAppItem = logItem.appItem; QModelIndex index = m_proxyModel->mapFromSource(m_model->indexFromItem(logItem.appItem)); if (logItem.isNewAppItem) { m_ui.eventListView->setExpanded(index, true); selected = true; } else { selected = m_ui.eventListView->isExpanded(index); } } if (selected) lastItem = item.first(); } if (lastItem) { // scroll down to the lastItem. //m_ui.eventListView->verticalScrollBar()->setValue(m_ui.eventListView->verticalScrollBar()->maximum()); QModelIndex index = m_proxyModel->mapFromSource(m_model->indexFromItem(lastItem)); m_ui.eventListView->scrollTo(index, QAbstractItemView::PositionAtBottom); //m_ui.eventListView->scrollTo(index, QAbstractItemView::EnsureVisible); } } void EventsWidget::addLog(const QAccessibleClient::AccessibleObject &object, EventsWidget::EventType eventType, const QString &text) { if (!object.isValid()) return; QStandardItem *nameItem = new QStandardItem(object.name()); nameItem->setData(QVariant::fromValue(eventType), EventsModel::EventTypeRole); nameItem->setData(object.url().toString(), EventsModel::UrlRole); AccessibleObject app = object.application(); if (app.isValid()) { nameItem->setData(app.name(), EventsModel::AppNameRole); nameItem->setData(app.url().toString(), EventsModel::AppUrlRole); } QStandardItem *roleItem = new QStandardItem(object.roleName()); QStandardItem *typeItem = new QStandardItem(eventName(eventType)); QStandardItem *textItem = new QStandardItem(text); m_pendingLogs.append(QList() << nameItem << roleItem << typeItem << textItem); if (!m_pendingTimer.isActive()) { m_pendingTimer.start(); } } void EventsWidget::checkStateChanged() { EventTypes types; QStringList names; bool allEvents = true; QMetaEnum e = metaObject()->enumerator(metaObject()->indexOfEnumerator("EventType")); Q_ASSERT(e.isValid()); QAbstractItemModel *model = m_ui.filterComboBox->model(); for (int i = 1; i < model->rowCount(); ++i) { QModelIndex index = model->index(i, 0); bool checked = model->data(index, Qt::CheckStateRole).toBool(); if (checked) { EventType type = model->data(index, EventsModel::EventTypeRole).value(); types |= type; names.append(QString::fromLatin1(e.valueToKey(type))); } else { allEvents = false; } } m_proxyModel->setFilter(types); } void EventsWidget::eventActivated(const QModelIndex &index) { Q_ASSERT(index.isValid()); QModelIndex parent = index.parent(); QModelIndex firstIndex = m_proxyModel->index(index.row(), 0, parent); QString s = m_proxyModel->data(firstIndex, parent.isValid() ? EventsModel::UrlRole : EventsModel::AppUrlRole).toString(); QUrl url(s); if (!url.isValid()) { qWarning() << Q_FUNC_INFO << "Invalid url=" << s; return; } emit anchorClicked(url); } void EventsWidget::accessibleFilterChanged() { m_proxyModel->setAccessibleFilter(m_ui.accessibleFilterEdit->text()); } void EventsWidget::roleFilterChanged() { m_proxyModel->setRoleFilter(m_ui.roleFilterEdit->text()); } diff --git a/examples/accessibleapps/eventview.h b/examples/accessibleapps/eventview.h index 3870ab6..b99c8cf 100644 --- a/examples/accessibleapps/eventview.h +++ b/examples/accessibleapps/eventview.h @@ -1,109 +1,109 @@ /* Copyright 2012 Frederik Gladhorn This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef EVENTVIEW_H #define EVENTVIEW_H #include #include #include #include "qaccessibilityclient/registry.h" #include "qaccessibilityclient/accessibleobject.h" #include "ui_eventview.h" class QStandardItem; class QSettings; class EventsModel; class EventsProxyModel; class EventsWidget :public QWidget { Q_OBJECT Q_ENUMS(EventType) Q_ENUMS(EventTypes) public: enum EventType { NoEvents = 0x00, StateChanged = 0x01, NameChanged = 0x02, DescriptionChanged = 0x04, Window = 0x08, Focus = 0x10, Document = 0x20, Object = 0x40, Text = 0x80, Table = 0x100, Others = 0x100000, AllEvents = 0xffff }; Q_DECLARE_FLAGS(EventTypes, EventType) QString eventName(EventType eventType) const; - explicit EventsWidget(QAccessibleClient::Registry *registry, QWidget *parent = 0); + explicit EventsWidget(QAccessibleClient::Registry *registry, QWidget *parent = nullptr); void loadSettings(QSettings &settings); void saveSettings(QSettings &settings); void addLog(const QAccessibleClient::AccessibleObject &object, EventType eventType, const QString &text = QString()); Q_SIGNALS: void anchorClicked(const QUrl &); public Q_SLOTS: void checkStateChanged(); private Q_SLOTS: void installUpdateHandler(); void clearLog(); void processPending(); void eventActivated(const QModelIndex &index); void accessibleFilterChanged(); void roleFilterChanged(); private: QAccessibleClient::Registry *m_registry; Ui::EventViewWidget m_ui; EventsModel *m_model; EventsProxyModel *m_proxyModel; QTimer m_pendingTimer; QVector< QList > m_pendingLogs; // This is to avoid sending updates for the events view. // The reason is that we end up in endless loops with other accessible tools such as accerciser. // No normal application should have to do this. #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) static void customUpdateHandler(QAccessibleEvent *event); #else static void customUpdateHandler(QObject*object, int who, QAccessible::Event reason); #endif static QAccessible::UpdateHandler m_originalAccessibilityUpdateHandler; static QObject *m_textEditForAccessibilityUpdateHandler; }; Q_DECLARE_METATYPE(EventsWidget::EventType) Q_DECLARE_METATYPE(EventsWidget::EventTypes) #endif diff --git a/examples/accessibleapps/mainwindow.h b/examples/accessibleapps/mainwindow.h index ea1eb5f..a6e32c4 100644 --- a/examples/accessibleapps/mainwindow.h +++ b/examples/accessibleapps/mainwindow.h @@ -1,130 +1,130 @@ /* Copyright 2012 Frederik Gladhorn This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef MAINWINDOW_H #define MAINWINDOW_H #include #include #include #include #include #include "qaccessibilityclient/accessibleobject.h" #include "qaccessibilityclient/registry.h" #include "clientcachedialog.h" class AccessibleTree; class ObjectProperties; class EventsWidget; class UiView; class MainWindow :public QMainWindow { Q_OBJECT public: - MainWindow(QWidget *parent = 0); + MainWindow(QWidget *parent = nullptr); ~MainWindow(); protected: void closeEvent(QCloseEvent *event); private Q_SLOTS: void selectionChanged(const QModelIndex ¤t, const QModelIndex &); void treeCustomContextMenuRequested(const QPoint &pos); void anchorClicked(const QUrl &url); void showClientCache(); void copyValue(); void added(const QAccessibleClient::AccessibleObject &object); void removed(const QAccessibleClient::AccessibleObject &object); void defunct(const QAccessibleClient::AccessibleObject &object); void windowCreated(const QAccessibleClient::AccessibleObject &object); void windowDestroyed(const QAccessibleClient::AccessibleObject &object); void windowClosed(const QAccessibleClient::AccessibleObject &object); void windowReparented(const QAccessibleClient::AccessibleObject &object); void windowMinimized(const QAccessibleClient::AccessibleObject &object); void windowMaximized(const QAccessibleClient::AccessibleObject &object); void windowRestored(const QAccessibleClient::AccessibleObject &object); void windowActivated(const QAccessibleClient::AccessibleObject &object); void windowDeactivated(const QAccessibleClient::AccessibleObject &object); void windowDesktopCreated(const QAccessibleClient::AccessibleObject &object); void windowDesktopDestroyed(const QAccessibleClient::AccessibleObject &object); void windowRaised(const QAccessibleClient::AccessibleObject &object); void windowLowered(const QAccessibleClient::AccessibleObject &object); void windowMoved(const QAccessibleClient::AccessibleObject &object); void windowResized(const QAccessibleClient::AccessibleObject &object); void windowShaded(const QAccessibleClient::AccessibleObject &object); void windowUnshaded(const QAccessibleClient::AccessibleObject &object); void stateChanged(const QAccessibleClient::AccessibleObject &object, const QString &state, bool active); void childAdded(const QAccessibleClient::AccessibleObject &object, int childIndex); void childRemoved(const QAccessibleClient::AccessibleObject &object, int childIndex); void visibleDataChanged(const QAccessibleClient::AccessibleObject &object); void selectionChanged(const QAccessibleClient::AccessibleObject &object); void modelChanged(const QAccessibleClient::AccessibleObject &object); void focusChanged(const QAccessibleClient::AccessibleObject &object); void textCaretMoved(const QAccessibleClient::AccessibleObject &object, int pos); void textSelectionChanged(const QAccessibleClient::AccessibleObject &object); void textChanged(const QAccessibleClient::AccessibleObject &object, const QString& text, int startOffset, int endOffset); void textInserted(const QAccessibleClient::AccessibleObject &object, const QString& text, int startOffset, int endOffset); void textRemoved(const QAccessibleClient::AccessibleObject &object, const QString& text, int startOffset, int endOffset); void accessibleNameChanged(const QAccessibleClient::AccessibleObject &object); void accessibleDescriptionChanged(const QAccessibleClient::AccessibleObject &object); private: void initActions(); void initMenu(); void initUi(); void addLog(const QAccessibleClient::AccessibleObject &object, const QString &eventName, const QString &text = QString()); void setCurrentObject(const QAccessibleClient::AccessibleObject &object); void updateDetails(const QAccessibleClient::AccessibleObject &object, bool force = false); QAccessibleClient::Registry *m_registry; QTreeView *m_accessibleObjectTreeView; AccessibleTree *m_accessibleObjectTreeModel; QTreeView *m_propertyView; ObjectProperties *m_propertyModel; EventsWidget *m_eventsWidget; UiView *m_uiview; QAction *m_resetTreeAction; QAction *m_followFocusAction; QAction *m_showClientCacheAction; QAction *m_enableA11yAction; QAction *m_enableScreenReaderAction; QAction *m_quitAction; QAction *m_copyValueAction; }; #endif diff --git a/examples/accessibleapps/uiview.cpp b/examples/accessibleapps/uiview.cpp index d771b89..12d800c 100644 --- a/examples/accessibleapps/uiview.cpp +++ b/examples/accessibleapps/uiview.cpp @@ -1,287 +1,287 @@ /* Copyright 2012 Sebastian Sauer This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "uiview.h" #include #include #include #include #include #include using namespace QAccessibleClient; struct RoleColor { AccessibleObject::Role m_role; const char *m_color; RoleColor(AccessibleObject::Role role, const char *color) : m_role(role), m_color(color) {} }; static RoleColor roleColors[] = { { AccessibleObject::NoRole, "#ff0000" }, // { ATSPI_ROLE_ACCELERATOR_LABEL, "" }, // { ATSPI_ROLE_ALERT, "#ffacac" }, //// { ATSPI_ROLE_ANIMATION, "" }, //// { ATSPI_ROLE_ARROW, "" }, //// { ATSPI_ROLE_CALENDAR, "" }, //// { ATSPI_ROLE_CANVAS, "" }, { AccessibleObject::CheckBox, "#6666ff" }, { AccessibleObject::MenuItem, "#ff6666" }, // { ATSPI_ROLE_COLOR_CHOOSER, "#6666ff" }, //// { ATSPI_ROLE_COLUMN_HEADER, "" }, { AccessibleObject::ComboBox, "#6666ff" }, // { ATSPI_ROLE_DATE_EDITOR, "#6666ff" }, //// { ATSPI_ROLE_DESKTOP_ICON, "" }, { AccessibleObject::DesktopFrame, "#c0c0c0" }, { AccessibleObject::Dial, "#6666ff" }, { AccessibleObject::Dialog, "#c0c0c0" }, //// { ATSPI_ROLE_DIRECTORY_PANE, "" }, //// { ATSPI_ROLE_DRAWING_AREA, "" }, // { ATSPI_ROLE_FILE_CHOOSER, "#6666ff" }, //// { ATSPI_ROLE_FILLER, "" }, //// { ATSPI_ROLE_FOCUS_TRAVERSABLE, "" }, // { ATSPI_ROLE_FONT_CHOOSER, "#6666ff" }, { AccessibleObject::Frame, "#c0c0c0" }, //// { ATSPI_ROLE_GLASS_PANE, "" }, //// { ATSPI_ROLE_HTML_CONTAINER, "" }, //// { ATSPI_ROLE_ICON, "" }, //// { ATSPI_ROLE_IMAGE, "" }, // { ATSPI_ROLE_INTERNAL_FRAME, "#c0c0c0" }, // { ATSPI_ROLE_LABEL, "#ffffaa" }, //// { ATSPI_ROLE_LAYERED_PANE, "" }, { AccessibleObject::ListView, "#acacff" }, { AccessibleObject::ListItem, "#6666ff" }, { AccessibleObject::Menu, "#acacff" }, { AccessibleObject::MenuBar, "#acacff" }, { AccessibleObject::MenuItem, "#6666ff" }, //// { ATSPI_ROLE_OPTION_PANE, "" }, { AccessibleObject::Tab, "#acacff" }, { AccessibleObject::TabContainer, "#6666ff" }, // { AccessibleObject::Panel, "#c0c0c0" }, { AccessibleObject::PasswordText, "#ffffaa" }, { AccessibleObject::PopupMenu, "#acacff" }, //// { ATSPI_ROLE_PROGRESS_BAR, "" }, { AccessibleObject::Button, "#6666ff" }, { AccessibleObject::RadioButton, "#6666ff" }, { AccessibleObject::RadioMenuItem, "#6666ff" }, // { ATSPI_ROLE_ROOT_PANE, "#c0c0c0" }, //// { ATSPI_ROLE_ROW_HEADER, "" }, //// { ATSPI_ROLE_SCROLL_BAR, "" }, //// { ATSPI_ROLE_SCROLL_PANE, "" }, { AccessibleObject::Separator, "#acacff" }, { AccessibleObject::Slider, "#6666ff" }, { AccessibleObject::SpinButton, "#6666ff" }, //// { ATSPI_ROLE_SPLIT_PANE, "" }, { AccessibleObject::StatusBar, "#c0c0c0" }, { AccessibleObject::TableView, "#acacff" }, { AccessibleObject::TableCell, "#6666ff" }, { AccessibleObject::TableColumnHeader, "#3333ff" }, { AccessibleObject::TableRowHeader, "#3333ff" }, // { ATSPI_ROLE_TEAROFF_MENU_ITEM, "#6666ff" }, { AccessibleObject::Terminal, "#6666ff" }, { AccessibleObject::Text, "#ffffaa" }, { AccessibleObject::ToggleButton, "#6666ff" }, // { ATSPI_ROLE_TOOL_BAR, "" }, { AccessibleObject::ToolTip, "#ffffaa" }, { AccessibleObject::TreeView, "#acacff" }, // { ATSPI_ROLE_TREE_TABLE, "#acacff" }, // { ATSPI_ROLE_UNKNOWN, "" }, // { ATSPI_ROLE_VIEWPORT, "#c0c0c0" }, { AccessibleObject::Window, "#c0c0c0" }, // { ATSPI_ROLE_EXTENDED, "" }, // { ATSPI_ROLE_HEADER, "" }, // { ATSPI_ROLE_FOOTER, "" }, // { ATSPI_ROLE_PARAGRAPH, "#ffffaa" }, // { ATSPI_ROLE_RULER, "" }, // { ATSPI_ROLE_APPLICATION, "" }, // { ATSPI_ROLE_AUTOCOMPLETE, "" }, // { ATSPI_ROLE_EDITBAR, "#6666ff" }, // { ATSPI_ROLE_EMBEDDED, "" }, // { ATSPI_ROLE_ENTRY, "" }, // { ATSPI_ROLE_CHART, "" }, // { ATSPI_ROLE_CAPTION, "#ffffaa" }, // { ATSPI_ROLE_DOCUMENT_FRAME, "" }, // { ATSPI_ROLE_HEADING, "" }, // { ATSPI_ROLE_PAGE, "" }, // { ATSPI_ROLE_SECTION, "#ffffaa" }, // { ATSPI_ROLE_REDUNDANT_OBJECT, "" }, // { ATSPI_ROLE_FORM, "" }, // { ATSPI_ROLE_LINK, "#6666ff" }, // { ATSPI_ROLE_INPUT_METHOD_WINDOW, "" }, { AccessibleObject::TableRow, "#6666ff" }, { AccessibleObject::TableCell, "#6666ff" }, // { ATSPI_ROLE_DOCUMENT_SPREADSHEET, "" }, // { ATSPI_ROLE_DOCUMENT_PRESENTATION, "" }, // { ATSPI_ROLE_DOCUMENT_TEXT, "#ffffaa" }, // { ATSPI_ROLE_DOCUMENT_WEB, "#ffffaa" }, // { ATSPI_ROLE_DOCUMENT_EMAIL, "#ffffaa" }, // { ATSPI_ROLE_COMMENT, "#ffffaa" }, // { ATSPI_ROLE_LIST_BOX, "#6666ff" }, //// { ATSPI_ROLE_GROUPING, "" }, //// { ATSPI_ROLE_IMAGE_MAP, "" }, //// { ATSPI_ROLE_NOTIFICATION, "" }, // { ATSPI_ROLE_INFO_BAR, "#ffffaa" }, // { ATSPI_ROLE_LAST_DEFINED, "" } }; #define ROLECOLORSCOUNT (sizeof(roleColors)/(sizeof(roleColors[0]))) #define ROLECOLOR "#aaffff" UiWidget::UiWidget(UiView *view) : QWidget(view) - , m_image(0) + , m_image(nullptr) { QPalette p = view->palette(); p.setColor(QPalette::Window, Qt::white); view->setPalette(p); view->setAutoFillBackground(true); for(int i = 0; i < ROLECOLORSCOUNT; ++i) { RoleColor &rc = roleColors[i]; m_roleColors[rc.m_role] = rc.m_color; } } void UiWidget::setAccessibleObject(const QAccessibleClient::AccessibleObject &acc) { - delete m_image; m_image = 0; + delete m_image; m_image = nullptr; m_object = acc; m_screen = QPixmap(); m_bounds = bounds(acc); adjustSize(); updateGeometry(); update(); } QSize UiWidget::sizeHint() const { return m_bounds.size(); } void UiWidget::paintEvent(QPaintEvent *event) { if (!m_image) { if (m_bounds.isNull()) return; m_image = new QImage(m_bounds.size(), QImage::Format_ARGB32_Premultiplied); QPainter painter(m_image); //painter.setClipRect(QRect(QPoint(0,0), QSize(m_bounds.size()))); if (m_screen.isNull()) m_screen = grabScreen(); painter.setOpacity(0.6); painter.drawPixmap(0, 0, m_screen); painter.setOpacity(1.0); drawObject(&painter, m_object); } QPainter painter(this); painter.drawImage(0, 0, *m_image); painter.end(); } QPixmap UiWidget::grabScreen() const { if (m_bounds.isNull()) return QPixmap(); Q_ASSERT(m_bounds.left() < m_bounds.right() && m_bounds.top() < m_bounds.bottom()); QPixmap pm = QPixmap::grabWindow(QApplication::desktop()->winId(), m_bounds.x(), m_bounds.y(), m_bounds.width(), m_bounds.height()); return pm; } QRect UiWidget::bounds(const QAccessibleClient::AccessibleObject &acc) const { if (!acc.isValid()) return QRect(); QRect rect; AccessibleObject::Interfaces ifaces = acc.supportedInterfaces(); if( !(ifaces & AccessibleObject::ApplicationInterface) ) { QAccessibleClient::AccessibleObject parent = acc.parent(); rect = bounds(parent); } if( ifaces & AccessibleObject::ComponentInterface ) { QRect r = acc.boundingRect(); if (!r.isNull()) rect = rect.isNull() ? r : rect.united(r); } return rect; } void UiWidget::drawObject(QPainter *painter, const QAccessibleClient::AccessibleObject &acc, int depth) { if (!acc.isValid()) return; ++depth; AccessibleObject::Interfaces ifaces = acc.supportedInterfaces(); if( !(ifaces & AccessibleObject::ApplicationInterface) ) { QAccessibleClient::AccessibleObject parent = acc.parent(); drawObject(painter, parent, depth); } if( ifaces & AccessibleObject::ComponentInterface ) { QRect r = acc.boundingRect(); if (!r.isNull()) { r.moveTopLeft(r.topLeft() - m_bounds.topLeft()); QColor color; QMap::ConstIterator colorIt = m_roleColors.constFind(acc.role()); if (colorIt != m_roleColors.constEnd()) { color = QColor(colorIt.value()); } else { color = QColor(ROLECOLOR); } color.setAlphaF(0.3); painter->fillRect(r, color); if (depth == 1) { color = QColor(Qt::red); } else { color = color.darker(); } painter->setPen(color); painter->drawRect(r); } } } UiView::UiView(QWidget *parent) : QScrollArea(parent) { QWidget *widget = new QWidget(this); QVBoxLayout *layout = new QVBoxLayout(widget); widget->setLayout(layout); m_uiWidget = new UiWidget(this); layout->addWidget(m_uiWidget); setWidget(widget); } UiView::~UiView() { } void UiView::setAccessibleObject(const QAccessibleClient::AccessibleObject &acc) { m_uiWidget->setAccessibleObject(acc); widget()->resize(m_uiWidget->size()); } diff --git a/examples/accessibleapps/uiview.h b/examples/accessibleapps/uiview.h index cf8817a..bd2d877 100644 --- a/examples/accessibleapps/uiview.h +++ b/examples/accessibleapps/uiview.h @@ -1,73 +1,73 @@ /* Copyright 2012 Sebastian Sauer This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef UIVIEW_H #define UIVIEW_H #include "qaccessibilityclient/accessibleobject.h" #include "qaccessibilityclient/registry.h" #include #include #include #include namespace QAccessibleClient { class AccessibleObject; } class UiView; class UiWidget : public QWidget { public: UiWidget(UiView *view); void setAccessibleObject(const QAccessibleClient::AccessibleObject &acc); virtual QSize sizeHint() const; protected: QImage *m_image; QPixmap m_screen; QRect m_bounds; QAccessibleClient::AccessibleObject m_object; QMap m_roleColors; virtual void paintEvent(QPaintEvent *event); private: QPixmap grabScreen() const; QRect bounds(const QAccessibleClient::AccessibleObject &acc) const; void drawObject(QPainter *painter, const QAccessibleClient::AccessibleObject &acc, int depth = 0); }; class UiView :public QScrollArea { Q_OBJECT public: - UiView(QWidget *parent = 0); + UiView(QWidget *parent = nullptr); ~UiView(); void setAccessibleObject(const QAccessibleClient::AccessibleObject &acc); private: UiWidget *m_uiWidget; QWidget* createWidget(const QAccessibleClient::AccessibleObject &acc, QRect &bounds); }; #endif diff --git a/src/atspi/dbusconnection.cpp b/src/atspi/dbusconnection.cpp index b54be46..af16f89 100644 --- a/src/atspi/dbusconnection.cpp +++ b/src/atspi/dbusconnection.cpp @@ -1,98 +1,98 @@ /* Copyright 2012 Frederik Gladhorn This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "dbusconnection.h" #include #include #include using namespace QAccessibleClient; DBusConnection::DBusConnection() : QObject() , m_connection(QDBusConnection::sessionBus()) - , m_initWatcher(0) + , m_initWatcher(nullptr) , m_status(Disconnected) { init(); } void DBusConnection::init() { QDBusConnection c = QDBusConnection::sessionBus(); if (!c.isConnected()) { qWarning("Could not connect to DBus session bus."); return; } QDBusMessage m = QDBusMessage::createMethodCall(QLatin1String("org.a11y.Bus"), QLatin1String("/org/a11y/bus"), QLatin1String("org.a11y.Bus"), QLatin1String("GetAddress")); QDBusPendingCall async = c.asyncCall(m); m_initWatcher = new QDBusPendingCallWatcher(async, this); connect(m_initWatcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(initFinished())); } void DBusConnection::initFinished() { if (!m_initWatcher) return; m_status = ConnectionError; QDBusPendingReply reply = *m_initWatcher; if (reply.isError() || reply.value().isEmpty()) { qWarning() << "Accessibility DBus not found. Falling back to session bus."; } else { QString busAddress = reply.value(); qDebug() << "Got Accessibility DBus address:" << busAddress; QDBusConnection c = QDBusConnection::connectToBus(busAddress, QLatin1String("a11y")); if (c.isConnected()) { qDebug() << "Connected to Accessibility DBus at address=" << busAddress; m_connection = c; m_status = Connected; } else { qWarning() << "Found Accessibility DBus address=" << busAddress << "but cannot connect. Falling back to session bus."; } } m_initWatcher->deleteLater(); - m_initWatcher = 0; + m_initWatcher = nullptr; emit connectionFetched(); } bool DBusConnection::isFetchingConnection() const { return m_initWatcher; } QDBusConnection DBusConnection::connection() const { if (m_initWatcher) { m_initWatcher->waitForFinished(); const_cast(this)->initFinished(); } return m_connection; } DBusConnection::Status DBusConnection::status() const { return m_status; } diff --git a/src/qaccessibilityclient/accessibleobject.h b/src/qaccessibilityclient/accessibleobject.h index f7d5cd8..a77b3c3 100644 --- a/src/qaccessibilityclient/accessibleobject.h +++ b/src/qaccessibilityclient/accessibleobject.h @@ -1,779 +1,779 @@ /* Copyright 2012 Frederik Gladhorn This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef QACCESSIBILITYCLIENT_ACCESSIBLEOBJECT_H #define QACCESSIBILITYCLIENT_ACCESSIBLEOBJECT_H #include namespace QAccessibleClient { class AccessibleObject; } #include #include #include #include "qaccessibilityclient_export.h" namespace QAccessibleClient { class AccessibleObjectPrivate; class RegistryPrivate; #ifndef QT_NO_DEBUG_STREAM QACCESSIBILITYCLIENT_EXPORT QDebug operator<<(QDebug, const AccessibleObject &); #endif /** This class represents an accessible object. An accessible object equals usually a visible widget or some kind of other element the user can interact with but can also present a not visible object that offers certain functionality like for example actions which can be triggered. It is implicitly shared and only created by the library. */ class QACCESSIBILITYCLIENT_EXPORT AccessibleObject { public: /** This enum describes the different interfaces that an AccessibleObject can implement. Each AccessibleObject must implement the AccessibleInterface, otherwise it is invalid. All other interfaces are optional. If the ActionInterface is implement the object will have a list of actions that can be invoked. */ enum Interface { NoInterface = 0x0, AccessibleInterface = 0x1, CacheInterface = 0x2, ActionInterface = 0x4, ApplicationInterface = 0x8, CollectionInterface = 0x10, ComponentInterface = 0x20, DocumentInterface = 0x40, EditableTextInterface = 0x80, EventKeyboardInterface = 0x100, EventMouseInterface = 0x200, EventObjectInterface = 0x400, HyperlinkInterface = 0x800, HypertextInterface = 0x1000, ImageInterface = 0x2000, SelectionInterface = 0x4000, TableInterface = 0x8000, TextInterface = 0x10000, ValueInterface = 0x20000, SocketInterface = 0x40000, EventWindowInterface = 0x80000, EventFocusInterface = 0x100000, InvalidInterface = 0x80000000 }; Q_DECLARE_FLAGS(Interfaces, Interface) /** The role indicates the type of UI element that an AccessibleObject represents. */ enum Role { NoRole, /*!< The object is invalid and has no role set. This is generally a bug. */ CheckBox, CheckableMenuItem, ColumnHeader, ComboBox, DesktopFrame, Dial, Dialog, Filler, Frame, Icon, Label, ListView, ListItem, Menu, MenuBar, MenuItem, Tab, TabContainer, PasswordText, PopupMenu, ProgressBar, Button, RadioButton, RadioMenuItem, RowHeader, ScrollBar, ScrollArea, Separator, Slider, SpinButton, StatusBar, TableView, TableCell, TableColumnHeader, TableColumn, TableRowHeader, TableRow, Terminal, Text, ToggleButton, ToolBar, ToolTip, TreeView, Window, TreeItem // Roles in Qt, I don't think we want those // TitleBar = 0x00000001, // Grip = 0x00000004, // Sound = 0x00000005, // Cursor = 0x00000006, // Caret = 0x00000007, // AlertMessage = 0x00000008, // Client = 0x0000000A, // Application = 0x0000000E, // Document = 0x0000000F, // Pane = 0x00000010, // Chart = 0x00000011, // Border = 0x00000013, // Grouping = 0x00000014, // Cell = 0x0000001D, // Link = 0x0000001E, // HelpBalloon = 0x0000001F, // Assistant = 0x00000020, // PageTab = 0x00000025, // PropertyPage = 0x00000026, // Indicator = 0x00000027, // Graphic = 0x00000028, // StaticText = 0x00000029, // EditableText = 0x0000002A, // Editable, selectable, etc. // HotkeyField = 0x00000032, // SpinBox = 0x00000034, // Canvas = 0x00000035, // Animation = 0x00000036, // Equation = 0x00000037, // ButtonDropDown = 0x00000038, // ButtonMenu = 0x00000039, // ButtonDropGrid = 0x0000003A, // Whitespace = 0x0000003B, // PageTabList = 0x0000003C, // Clock = 0x0000003D, // Splitter = 0x0000003E, // LayeredPane = 0x00000080, }; /** \brief The TextBoundaries enum represents the different boundaries when asking for text at a certain offset. */ enum TextBoundary { CharBoundary, WordStartBoundary, WordEndBoundary, SentenceStartBoundary, SentenceEndBoundary, LineStartBoundary, LineEndBoundary }; /** \brief Construct an invalid AccessibleObject. */ AccessibleObject(); /** \brief Copy constructor. */ AccessibleObject(const AccessibleObject &other); /** Destroys the AccessibleObject */ ~AccessibleObject(); /** Assignment operator */ AccessibleObject &operator=(const AccessibleObject &other); /** Comparison operator */ bool operator==(const AccessibleObject &other) const; /** Inequality operator */ inline bool operator!=(const AccessibleObject &other) const { return !operator==(other); } /** \brief Returns a unique identifier for the object. */ QString id() const; /** \brief Returns a QUrl that references the AccessibleObject. This can be used to serialize/unserialize an AccessibleObject to pass it around as string and restore the AccessibleObject by using Registry::accessibleFromUrl later on. The returned QUrl returns a scheme of "accessibleobject", the dbus path as url path and the dbus service as url fragment. */ QUrl url() const; /** \brief Returns true if this object is valid. Invalid objects are for example returned when asking for the parent of the top most item, or for a child that is out of range. */ bool isValid() const; /** \brief Returns this object's parent. \return The parent AccessibleObject */ AccessibleObject parent() const; /** \brief Returns this accessible's index in it's parent's list of children. \return index */ int indexInParent() const; /** \brief Returns this accessible's children in a list. \return children */ QList children() const; /** \brief Returns this accessible's children according to there roles. \param roles The list of roles to query. \return A vector that contains the children of this object according to there roles. The number of vector-items equals to the number and sorting of the roles items. Example code demonstrating usage: \code QList roles; roles << Label << CheckBox; QVector< QList > c = children(roles); Q_ASSERT(c.count() == roles.count()); Q_ASSERT(c[0].isEmpty() || c[0].first().role() == Label); Q_ASSERT(c[1].isEmpty() || c[1].first().role() == CheckBox); \endcode */ QVector< QList > children(const QList &roles) const; /** \brief Returns the number of children for this accessible. \return number of children */ int childCount() const; /** \brief Returns a specific child at position \a index. The list of children is 0-based. \return number of children */ AccessibleObject child(int index) const; /** \brief Returns the name of this accessible. The name is a short descriptive one or two words. It is localized. */ QString name() const; /** \brief Returns the description for this accessible. The description is more of an explanation than the name. This can be a sentence. The string is localized. */ QString description() const; /** \brief Returns the role as integer value of this accessible. */ Role role() const; /** \brief Returns the name of the role of this accessible. This name is not localized to allow tools to work with the english string. */ QString roleName() const; /** \brief Returns the name of the role of this accessible. This name is localized and can be presented to the user. */ QString localizedRoleName() const; /** \brief The ComponentLayer in which this object resides. */ int layer() const; /** \brief Obtain the relative stacking order (i.e. 'Z' order) of an object. Larger values indicate that an object is on "top" of the stack, therefore objects with smaller MDIZOrder may be obscured by objects with a larger MDIZOrder, but not vice-versa. */ int mdiZOrder() const; /** \brief Obtain the alpha value of the component. An alpha value of 1.0 or greater indicates that the object is fully opaque, and an alpha value of 0.0 indicates that the object is fully transparent. Negative alpha values have no defined meaning at this time. Alpha values are used in conjunction with Z-order calculations to determine whether an object wholly or partially obscures another object's visual intersection, in the event that their bounds intersect. */ double alpha() const; /** \brief Returns a bounding rectangle for the accessible. It returns a QRect that bounds the accessible. This can be used to get the focus coordinates. \return QRect that bounds the accessible. */ QRect boundingRect() const; /** \brief Returns a bounding rectangle for the character at position \a offset. This function is only supported for accessibles that implement the text interface. It will return an empty rectangle for invalid offsets or accessibles. \return QRect that bounds the character. */ QRect characterRect(int offset) const; /** \brief Returns List of interfaces supported by the accessible. This function provides a list of accessibile interfaces that are implemented by an accessible object. This can be used to avoid calling functions that are not supported by the accessible. \return QStringList that contains list of supported interfaces */ Interfaces supportedInterfaces() const; /** \brief Returns the offset of the caret from the beginning of the text. This function provides the current offset of the caret from the beginning of the text in an accessible that implements org.a11y.atspi.Text. \return Caret Offset as an integer */ int caretOffset() const; /** \brief Returns the number of characters. \return Number of characters. */ int characterCount() const; /** \brief Returns a list of selections the text has. Code to demonstrate usage: \code QList< QPair > sel = acc.textSelections(); int startOffset = sel[0].first; int endOffset = sel[0].second; QString allText = acc.text(); QString selText = allText.mid(startOffset, endOffset - startOffset); \endcode \return The list of selections where every item in that list is a pair of integers representing startOffset and endOffset of the selection. */ QList< QPair > textSelections() const; /** Set text \a selections, usually only one selection will be set, use a list containing one QPair with the start and end offsets for that. */ void setTextSelections(const QList< QPair > &selections); /** \brief Returns the text of the TextInterface. This function provides the current text as displayed by the org.a11y.atspi.Text TextInterface component. \param startOffset The start caret offset to return the text from. \param endOffset The end caret offset to return the text from. If -1 then the endOffset is the end of the string what means all characters are included. \return The text as displayed by the TextInterface. */ QString text(int startOffset = 0, int endOffset = -1) const; /** \brief Returns the text of the TextInterface by boundary. Especially for larger text fields it may be more performant and easier to query the text at a certain position instead of the full text. For example the line where the cursor is currently can be retrieved with this function in a convenient way. \param offset is the position of the requested text. \param startOffset returns the beginning of the offset, for example the start of the line when asking for line boundaries. \param endOffset returns the end of the text section \return the text at the offset. */ - QString textWithBoundary(int offset, TextBoundary boundary, int *startOffset = 0, int *endOffset = 0) const; + QString textWithBoundary(int offset, TextBoundary boundary, int *startOffset = nullptr, int *endOffset = nullptr) const; /** \brief Set the text of the EditableTextInterface. \param text The text to set. \return true on success and false on error. */ bool setText(const QString &text); /** \brief Insert the text into the EditableTextInterface. \param text The text to insert. \param position The caret position at which to insert the text. \param length The length of the text to insert. \return true on success and false on error. */ bool insertText(const QString &text, int position = 0, int length = -1); /** \brief Copy the text from the EditableTextInterface into the clipboard. \param startPos The caret position from which to start to copy the text from. \param endPos The caret position from which to end to copy the text from. \return true on success and false on error. */ bool copyText(int startPos, int endPos); /** \brief Cut the text from the EditableTextInterface into the clipboard. \param startPos The caret position from which to start to cut the text from. \param endPos The caret position from which to end to cut the text from. \return true on success and false on error. */ bool cutText(int startPos, int endPos); /** \brief Delete the text from the EditableTextInterface. \param startPos The caret position from which to start to delete the text. \param endPos The caret position from which to end to delete the text. \return true on success and false on error. */ bool deleteText(int startPos, int endPos); /** \brief Paste the text from the clipboard into the EditableTextInterface. \param position The caret position at which to insert the text into. \return true on success and false on error. */ bool pasteText(int position); /** \brief Returns focus-point of the object \return The Focus Point of the object */ QPoint focusPoint() const; /** \brief Returns the application object. \return The top-level application object that expose an org.a11y.atspi.Application accessibility interface. */ AccessibleObject application() const; /** \brief Returns the toolkit name. \return The tookit name. This can be for example "Qt" or "gtk". */ QString appToolkitName() const; /** \brief Returns the toolkit version. \return The tookit version. This can be for example "4.8.3" for Qt 4.8.3. */ QString appVersion() const; /** \brief Returns the unique application identifier. \return The app id. The identifier will not last over session and everytime the app quits and restarts it gets another identifier that persists as long as the application is running. */ int appId() const; /** The type of locale */ enum LocaleType { LocaleTypeMessages, LocaleTypeCollate, LocaleTypeCType, LocaleTypeMonetary, LocaleTypeNumeric, LocaleTypeTime }; /** \brief The application locale. \param lctype The \a LocaleType for which the locale is queried. \return A string compliant with the POSIX standard for locale description. */ QString appLocale(LocaleType lctype = LocaleTypeMessages) const; /** \brief The application dbus address. */ QString appBusAddress() const; /** \brief The minimum value allowed by this valuator. If both, the \a minimumValue and \a maximumValue, are zero then there is no minimum or maximum values. The \a currentValue has no range restrictions. */ double minimumValue() const; /** \brief The maximum value allowed by this valuator. If both, the \a minimumValue and \a maximumValue, are zero then there is no minimum or maximum values. The \a currentValue has no range restrictions. */ double maximumValue() const; /** \brief The smallest incremental change which this valuator allows. This is a helper value to know in what steps the \a currentValue is incremented or decremented. If 0, the incremental changes to the valuator are limited only by the precision of a double precision value on the platform. */ double minimumValueIncrement() const; /** \brief The current value of the valuator. This is the value the org.a11y.atspi.Value accessibility interface has. */ double currentValue() const; /** \brief Set the value of the valuator. \param value the value to set. \return true on success and false on error. */ bool setCurrentValue(const double value); /** \brief Returns the selection of accessible objects. */ QList selection() const; /** \brief A description text of the image. It is recommended that imageDescription be the shorter of the available image descriptions, for instance "alt text" in HTML images, and a longer description be provided in Accessible::accessible-description, if available. A short, one or two word label for the image should be provided in Accessible::accessible-name. \return A UTF-8 string providing a textual description of what is visually depicted in the image. */ QString imageDescription() const; /** \brief The locale of the image. \return A string corresponding to the POSIX LC_MESSAGES locale used by the imageDescription. */ QString imageLocale() const; /** \brief The image boundaries. Obtain a bounding box which entirely contains the image contents, as displayed on screen. The bounds returned do not account for any viewport clipping or the fact that the image may be partially or wholly obscured by other onscreen content. This method returns the bounds of the current onscreen view, and not the nominal size of the source data in the event that the original image has been rescaled.\ \return A BoundingBox enclosing the image's onscreen representation. */ QRect imageRect() const; /** \brief Returns a list of actions supported by this accessible. Just trigger() the action to execute the underlying method at the accessible. */ QVector< QSharedPointer > actions() const; // states /// Returns if the AccessibleObject is currently active bool isActive() const; /// Returns if the AccessibleObject is checkable (often indicates a check action) bool isCheckable() const; /// Returns if the AccessibleObject is currently checked bool isChecked() const; /// Returns if the AccessibleObject is defunct - that means it does not properly respont to requests /// and should be ignored for accessibility purposes bool isDefunct() const; /// Returns if the AccessibleObject is an editable text bool isEditable() const; /// Returns if the AccessibleObject is currently enabled bool isEnabled() const; /// Returns if the AccessibleObject can be expanded to show more information bool isExpandable() const; /// Returns if the AccessibleObject is currently expanded bool isExpanded() const; /// Returns if the AccessibleObject is focusable bool isFocusable() const; /// Returns if the AccessibleObject is currently focused bool isFocused() const; /// Returns if the AccessibleObject is a multi line text edit bool isMultiLine() const; /// Returns if the AccessibleObject is selectable bool isSelectable() const; /// Returns if the AccessibleObject is currently selected bool isSelected() const; /// Returns if the AccessibleObject reacts to input events bool isSensitive() const; /// Returns if the AccessibleObject is a single line text edit bool isSingleLine() const; /** \brief Return a string representing states of this object. This is useful for debugging applications. */ QString stateString() const; /* * \internal * \brief isTransient marks an object as being unreliable in that it can quickly disappear or change * * This is mostly a hint that the object should not be cached. * \return true if the object is transient */ // bool isTransient() const; /// Returns if the AccessibleObject is currently visible (it can still be off the screen, /// but there is nothing preventing the user from seeing it in general) bool isVisible() const; /* * \internal * \brief managesDescendants marks an object as being responsible for its children * * This is to notify that this object handles signals for it's children. * The property is typically used for tables and lists or other collection objects. * \return true if the object is transient */ // bool managesDescendants() const; // bool isRequired() const; // bool isAnimated() const; // bool isInvalidEntry() const; /// Returns if the AccessibleObject is the default widget (e.g. a button in a dialog) bool isDefault() const; // bool isVisited() const; /// Returns if the AccessibleObject allows text selections bool hasSelectableText() const; /// Returns if the AccessibleObject has a tool tip bool hasToolTip() const; /// Returns if the AccessibleObject supports automatic text completion bool supportsAutocompletion() const; private: AccessibleObject(RegistryPrivate *reg, const QString &service, const QString &path); AccessibleObject(const QSharedPointer &dd); QSharedPointer d; friend class Registry; friend class RegistryPrivate; friend class CacheWeakStrategy; friend class CacheStrongStrategy; #ifndef QT_NO_DEBUG_STREAM friend QDebug QAccessibleClient::operator<<(QDebug, const AccessibleObject &); #endif friend uint qHash(const QAccessibleClient::AccessibleObject& object) { return qHash(object.d); } }; } Q_DECLARE_METATYPE(QAccessibleClient::AccessibleObject) #endif