File indexing completed on 2025-01-26 03:28:31

0001 /*
0002     SPDX-FileCopyrightText: 2012 Frederik Gladhorn <gladhorn@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QAccessible>
0010 #include <QTimer>
0011 
0012 #include "qaccessibilityclient/accessibleobject.h"
0013 
0014 #include "ui_eventview.h"
0015 
0016 class QStandardItem;
0017 class QSettings;
0018 
0019 class EventsModel;
0020 class EventsProxyModel;
0021 
0022 class EventsWidget : public QWidget
0023 {
0024     Q_OBJECT
0025 public:
0026     enum EventType {
0027         NoEvents = 0x00,
0028         StateChanged = 0x01,
0029         NameChanged = 0x02,
0030         DescriptionChanged = 0x04,
0031         Window = 0x08,
0032         Focus = 0x10,
0033         Document = 0x20,
0034         Object = 0x40,
0035         Text = 0x80,
0036         Table = 0x100,
0037 
0038         Others = 0x100000,
0039 
0040         AllEvents = 0xffff
0041     };
0042     Q_DECLARE_FLAGS(EventTypes, EventType)
0043     Q_ENUM(EventType)
0044     Q_ENUM(EventTypes)
0045 
0046     explicit EventsWidget(QWidget *parent = nullptr);
0047 
0048     [[nodiscard]] QString eventName(EventType eventType) const;
0049 
0050     void loadSettings(QSettings &settings);
0051     void saveSettings(QSettings &settings);
0052 
0053     void addLog(const QAccessibleClient::AccessibleObject &object, EventType eventType, const QString &text = QString());
0054 
0055 Q_SIGNALS:
0056     void anchorClicked(const QUrl &);
0057 
0058 private:
0059     void checkStateChanged();
0060     void processPending();
0061     void eventActivated(const QModelIndex &index);
0062     void roleFilterChanged();
0063     void accessibleFilterChanged();
0064     void clearLog();
0065     void installUpdateHandler();
0066     Ui::EventViewWidget mUi;
0067     EventsModel *const mModel;
0068     EventsProxyModel *const mProxyModel;
0069     QTimer mPendingTimer;
0070     QVector<QList<QStandardItem *>> m_pendingLogs;
0071 
0072     // This is to avoid sending updates for the events view.
0073     // The reason is that we end up in endless loops with other accessible tools such as accerciser.
0074     // No normal application should have to do this.
0075     static void customUpdateHandler(QAccessibleEvent *event);
0076     static QAccessible::UpdateHandler mOriginalAccessibilityUpdateHandler;
0077     static QObject *mTextEditForAccessibilityUpdateHandler;
0078 };
0079 
0080 Q_DECLARE_METATYPE(EventsWidget::EventType)
0081 Q_DECLARE_METATYPE(EventsWidget::EventTypes)