Group :: Desktop gráfico/Outros
RPM: deepin-dock
Main Changelog Spec Patches Sources Download Gear Bugs e FR Repocop
Patch: 0001-chore-cleanup-code.patch
Download
Download
From 7b7f5c1f19b6a5813e06df9b45d58bd6b24f520c Mon Sep 17 00:00:00 2001
From: 范朋程 <fanpengcheng@uniontech.com>
Date: Tue, 6 Dec 2022 17:42:17 +0800
Subject: [PATCH] chore: 整理代码
整理代码缩进,减少代码量
Log: 无
Influence: 自动化标记功能
Task: https://pms.uniontech.com/task-view-124695.html
Change-Id: Icb22250683d5cd19ef328781e80cd5886da16c3c
---
frame/accessible/accessible.h | 341 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
frame/accessible/accessibledefine.h | 400 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
frame/main.cpp | 2 +-
plugins/sound/soundaccessible.h | 28 ----------------------------
plugins/sound/soundplugin.cpp | 4 +---
plugins/tray/abstracttraywidget.h | 1 +
6 files changed, 159 insertions(+), 617 deletions(-)
delete mode 100644 frame/accessible/accessibledefine.h
delete mode 100644 plugins/sound/soundaccessible.h
diff --git a/frame/accessible/accessible.h b/frame/accessible/accessible.h
index c7dd350..a5d9746 100644
--- a/frame/accessible/accessible.h
+++ b/frame/accessible/accessible.h
@@ -3,192 +3,163 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
-#include "accessibledefine.h"
-
-#include "mainwindow.h"
-#include "mainpanelcontrol.h"
-#include "desktop_widget.h"
-#include "tipswidget.h"
-#include "dockpopupwindow.h"
-
-#include "launcheritem.h"
-#include "appitem.h"
-#include "components/previewcontainer.h"
-#include "pluginsitem.h"
-#include "traypluginitem.h"
-#include "placeholderitem.h"
-#include "components/appdragwidget.h"
-#include "components/appsnapshot.h"
-#include "components/floatingpreview.h"
-
-#include "snitraywidget.h"
-#include "abstracttraywidget.h"
-#include "indicatortraywidget.h"
-#include "xembedtraywidget.h"
-#include "system-trays/systemtrayitem.h"
-#include "fashiontray/fashiontrayitem.h"
-#include "fashiontray/fashiontraywidgetwrapper.h"
-#include "fashiontray/fashiontraycontrolwidget.h"
-#include "fashiontray/containers/attentioncontainer.h"
-#include "fashiontray/containers/holdcontainer.h"
-#include "fashiontray/containers/normalcontainer.h"
-#include "fashiontray/containers/spliteranimated.h"
-
-// 这部分由sound插件单独维护,这样做是因为在标记volumeslider这个类时,需要用到其setValue的实现,
-// 但插件的源文件dock这边并没有包含,不想引入复杂的包含关系,其实最好的做法就是像sound插件这样,谁维护谁的
-//#include "../plugins/sound/sounditem.h"
-//#include "../plugins/sound/soundapplet.h"
-//#include "../plugins/sound/sinkinputwidget.h"
-//#include "../plugins/sound/componments/volumeslider.h"
-//#include "../plugins/sound/componments/horizontalseparator.h"
-
-#include "showdesktopwidget.h"
-#include "datetimewidget.h"
-#include "onboarditem.h"
-#include "trashwidget.h"
-#include "popupcontrolwidget.h"
-#include "shutdownwidget.h"
-#include "multitaskingwidget.h"
-#include "overlaywarningwidget.h"
-#include "horizontalseperator.h"
-
-#include <DIconButton>
-#include <DSwitchButton>
-#include <DPushButton>
-#include <DListView>
-#include <DSwitchButton>
-#include <DSpinner>
-#include <dloadingindicator.h>
-
-#include <QScrollBar>
-
-DWIDGET_USE_NAMESPACE
-using namespace Dock;
-
-// 添加accessible
-SET_FORM_ACCESSIBLE(MainWindow, "mainwindow")
-SET_BUTTON_ACCESSIBLE(MainPanelControl, "mainpanelcontrol")
-SET_LABEL_ACCESSIBLE(TipsWidget, "tips")
-SET_FORM_ACCESSIBLE(DockPopupWindow, "popupwindow")
-SET_BUTTON_ACCESSIBLE(LauncherItem, "launcheritem")
-SET_BUTTON_ACCESSIBLE(AppItem, "appitem")
-SET_BUTTON_ACCESSIBLE(PreviewContainer, "previewcontainer")
-SET_BUTTON_ACCESSIBLE(PluginsItem, m_w->pluginName())
-SET_BUTTON_ACCESSIBLE(TrayPluginItem, m_w->pluginName())
-SET_BUTTON_ACCESSIBLE(PlaceholderItem, "placeholderitem")
-SET_BUTTON_ACCESSIBLE(AppDragWidget, "appdragwidget")
-SET_BUTTON_ACCESSIBLE(AppSnapshot, "appsnapshot")
-SET_BUTTON_ACCESSIBLE(FloatingPreview, "floatingpreview")
-SET_BUTTON_ACCESSIBLE(XEmbedTrayWidget, m_w->itemKeyForConfig().replace("sni:", ""))
-SET_BUTTON_ACCESSIBLE(IndicatorTrayWidget, m_w->itemKeyForConfig().replace("sni:", ""))
-SET_BUTTON_ACCESSIBLE(SNITrayWidget, m_w->itemKeyForConfig().replace("sni:", ""))
-SET_BUTTON_ACCESSIBLE(AbstractTrayWidget, m_w->itemKeyForConfig().replace("sni:", ""))
-SET_BUTTON_ACCESSIBLE(SystemTrayItem, m_w->itemKeyForConfig().replace("sni:", ""))
-SET_FORM_ACCESSIBLE(FashionTrayItem, "fashiontrayitem")
-SET_FORM_ACCESSIBLE(FashionTrayWidgetWrapper, "fashiontraywrapper")
-SET_BUTTON_ACCESSIBLE(FashionTrayControlWidget, "fashiontraycontrolwidget")
-SET_FORM_ACCESSIBLE(AttentionContainer, "attentioncontainer")
-SET_FORM_ACCESSIBLE(HoldContainer, "holdcontainer")
-SET_FORM_ACCESSIBLE(NormalContainer, "normalcontainer")
-SET_FORM_ACCESSIBLE(SpliterAnimated, "spliteranimated")
-SET_FORM_ACCESSIBLE(DatetimeWidget, "plugin-datetime")
-SET_FORM_ACCESSIBLE(OnboardItem, "plugin-onboard")
-SET_FORM_ACCESSIBLE(TrashWidget, "plugin-trash")
-SET_BUTTON_ACCESSIBLE(PopupControlWidget, "popupcontrolwidget")
-SET_FORM_ACCESSIBLE(ShutdownWidget, "plugin-shutdown")
-SET_FORM_ACCESSIBLE(MultitaskingWidget, "plugin-multitasking")
-SET_FORM_ACCESSIBLE(ShowDesktopWidget, "plugin-showdesktop")
-SET_FORM_ACCESSIBLE(OverlayWarningWidget, "plugin-overlaywarningwidget")
-SET_FORM_ACCESSIBLE(QWidget, m_w->objectName().isEmpty() ? "widget" : m_w->objectName())
-SET_LABEL_ACCESSIBLE(QLabel, m_w->objectName() == "notifications" ? m_w->objectName() : m_w->text().isEmpty() ? m_w->objectName().isEmpty() ? "text" : m_w->objectName() : m_w->text())
-SET_BUTTON_ACCESSIBLE(DIconButton, m_w->objectName().isEmpty() ? "imagebutton" : m_w->objectName())
-SET_BUTTON_ACCESSIBLE(DSwitchButton, m_w->text().isEmpty() ? "switchbutton" : m_w->text())
-SET_BUTTON_ACCESSIBLE(DesktopWidget, "desktopWidget");
-SET_FORM_ACCESSIBLE(HorizontalSeperator, "HorizontalSeperator");
-// 几个没什么用的标记,但为了提醒大家不要遗漏标记控件,还是不要去掉
-SET_FORM_ACCESSIBLE(DBlurEffectWidget, "DBlurEffectWidget")
-SET_FORM_ACCESSIBLE(DListView, "DListView")
-SET_FORM_ACCESSIBLE(DLoadingIndicator, "DLoadingIndicator")
-SET_FORM_ACCESSIBLE(DSpinner, "DSpinner")
-SET_FORM_ACCESSIBLE(QMenu, "QMenu")
-SET_FORM_ACCESSIBLE(QPushButton, "QPushButton")
-SET_FORM_ACCESSIBLE(QSlider, "QSlider")
-SET_FORM_ACCESSIBLE(QScrollBar, "QScrollBar")
-SET_FORM_ACCESSIBLE(QScrollArea, "QScrollArea")
-SET_FORM_ACCESSIBLE(QFrame, "QFrame")
-SET_FORM_ACCESSIBLE(QGraphicsView, "QGraphicsView")
-SET_FORM_ACCESSIBLE(DragWidget, "DragWidget")
+#include <QAccessible>
+#include <QAccessibleWidget>
+#include <QMap>
+#include <QMetaEnum>
+#include <QObject>
+#include <QWidget>
-QAccessibleInterface *accessibleFactory(const QString &classname, QObject *object)
+inline QString getAccessibleName(QWidget *w, QAccessible::Role r, const QString &fallback)
{
- // 自动化标记确定不需要的控件,方可加入忽略列表
- const static QStringList ignoreLst = {"WirelessItem", "WiredItem", "SsidButton", "WirelessList", "AccessPointWidget"};
-
- QAccessibleInterface *interface = nullptr;
-
- USE_ACCESSIBLE(classname, MainWindow)
- ELSE_USE_ACCESSIBLE(classname, MainPanelControl)
- ELSE_USE_ACCESSIBLE(QString(classname).replace("Dock::", ""), TipsWidget)
- ELSE_USE_ACCESSIBLE(classname, DockPopupWindow)
- ELSE_USE_ACCESSIBLE(classname, LauncherItem)
- ELSE_USE_ACCESSIBLE(classname, AppItem)
- ELSE_USE_ACCESSIBLE(classname, PreviewContainer)
- ELSE_USE_ACCESSIBLE(classname, PluginsItem)
- ELSE_USE_ACCESSIBLE(classname, TrayPluginItem)
- ELSE_USE_ACCESSIBLE(classname, PlaceholderItem)
- ELSE_USE_ACCESSIBLE(classname, AppDragWidget)
- ELSE_USE_ACCESSIBLE(classname, AppSnapshot)
- ELSE_USE_ACCESSIBLE(classname, FloatingPreview)
- ELSE_USE_ACCESSIBLE(classname, SNITrayWidget)
- ELSE_USE_ACCESSIBLE(classname, AbstractTrayWidget)
- ELSE_USE_ACCESSIBLE(classname, SystemTrayItem)
- ELSE_USE_ACCESSIBLE(classname, FashionTrayItem)
- ELSE_USE_ACCESSIBLE(classname, FashionTrayWidgetWrapper)
- ELSE_USE_ACCESSIBLE(classname, FashionTrayControlWidget)
- ELSE_USE_ACCESSIBLE(classname, AttentionContainer)
- ELSE_USE_ACCESSIBLE(classname, HoldContainer)
- ELSE_USE_ACCESSIBLE(classname, NormalContainer)
- ELSE_USE_ACCESSIBLE(classname, SpliterAnimated)
- ELSE_USE_ACCESSIBLE(classname, IndicatorTrayWidget)
- ELSE_USE_ACCESSIBLE(classname, XEmbedTrayWidget)
- ELSE_USE_ACCESSIBLE(classname, DesktopWidget)
- ELSE_USE_ACCESSIBLE(classname, DatetimeWidget)
- ELSE_USE_ACCESSIBLE(classname, OnboardItem)
- ELSE_USE_ACCESSIBLE(classname, TrashWidget)
- ELSE_USE_ACCESSIBLE(classname, PopupControlWidget)
- ELSE_USE_ACCESSIBLE(classname, ShutdownWidget)
- ELSE_USE_ACCESSIBLE(classname, MultitaskingWidget)
- ELSE_USE_ACCESSIBLE(classname, ShowDesktopWidget)
- ELSE_USE_ACCESSIBLE(classname, OverlayWarningWidget)
- ELSE_USE_ACCESSIBLE(classname, QWidget)
- ELSE_USE_ACCESSIBLE_BY_OBJECTNAME(classname, QLabel, "spliter_fix")
- ELSE_USE_ACCESSIBLE_BY_OBJECTNAME(classname, QLabel, "spliter_app")
- ELSE_USE_ACCESSIBLE_BY_OBJECTNAME(classname, QLabel, "spliter_tray")
- ELSE_USE_ACCESSIBLE(classname, QLabel)
- ELSE_USE_ACCESSIBLE_BY_OBJECTNAME(QString(classname).replace("Dtk::Widget::", ""), DIconButton, "closebutton-2d")
- ELSE_USE_ACCESSIBLE_BY_OBJECTNAME(QString(classname).replace("Dtk::Widget::", ""), DIconButton, "closebutton-3d")
- ELSE_USE_ACCESSIBLE_BY_OBJECTNAME(QString(classname).replace("Dtk::Widget::", ""), DSwitchButton, "")
- ELSE_USE_ACCESSIBLE(QString(classname).replace("Dtk::Widget::", ""), DBlurEffectWidget)
- ELSE_USE_ACCESSIBLE(QString(classname).replace("Dtk::Widget::", ""), DListView)
- ELSE_USE_ACCESSIBLE(QString(classname).replace("Dtk::Widget::", ""), DLoadingIndicator)
- ELSE_USE_ACCESSIBLE(QString(classname).replace("Dtk::Widget::", ""), DSpinner)
- ELSE_USE_ACCESSIBLE(QString(classname).replace("Dtk::Widget::", ""), DSwitchButton)
- ELSE_USE_ACCESSIBLE(QString(classname).replace("Dtk::Widget::", ""), DIconButton)
- ELSE_USE_ACCESSIBLE(classname, QMenu)
- ELSE_USE_ACCESSIBLE(classname, QPushButton)
- ELSE_USE_ACCESSIBLE(classname, QSlider)
- ELSE_USE_ACCESSIBLE(classname, QScrollBar)
- ELSE_USE_ACCESSIBLE(classname, QScrollArea)
- ELSE_USE_ACCESSIBLE(classname, QFrame)
- ELSE_USE_ACCESSIBLE(classname, QGraphicsView)
- ELSE_USE_ACCESSIBLE(classname, DragWidget)
- ELSE_USE_ACCESSIBLE(classname, HorizontalSeperator);
-
- if (!interface && object->inherits("QWidget") && !ignoreLst.contains(classname)) {
- QWidget *w = static_cast<QWidget *>(object);
- // 如果你看到这里的输出,说明代码中仍有控件未兼顾到accessible功能,请帮忙添加
- if (w->accessibleName().isEmpty())
- qWarning() << "accessibleFactory()" + QString("Class: " + classname + " cannot access");
+#define SEPARATOR "_"
+ const QString lowerFallback = fallback.toLower();
+ // 避免重复生成
+ static QMap<QObject *, QString > objnameMap;
+ if (!objnameMap[w].isEmpty())
+ return objnameMap[w];
+
+ static QMap< QAccessible::Role, QList< QString > > accessibleMap;
+ QString oldAccessName = w->accessibleName().toLower();
+ oldAccessName.replace(SEPARATOR, "");
+
+ // 按照类型添加固定前缀
+ QMetaEnum metaEnum = QMetaEnum::fromType<QAccessible::Role>();
+ QByteArray prefix = metaEnum.valueToKeys(r);
+ switch (r) {
+ case QAccessible::Button: prefix = "Btn"; break;
+ case QAccessible::StaticText: prefix = "Label"; break;
+ default: break;
+ }
+
+ // 再加上标识
+ QString accessibleName = QString::fromLatin1(prefix) + SEPARATOR;
+ QString objectName = w->objectName().toLower();
+ accessibleName += oldAccessName.isEmpty() ? (objectName.isEmpty() ?lowerFallback : objectName) : oldAccessName;
+ // 检查名称是否唯一
+ if (accessibleMap[r].contains(accessibleName)) {
+ if (!objnameMap.key(accessibleName)) {
+ objnameMap.remove(objnameMap.key(accessibleName));
+ objnameMap.insert(w, accessibleName);
+ return accessibleName;
+ }
+ // 获取编号,然后+1
+ int pos = accessibleName.indexOf(SEPARATOR);
+ int id = accessibleName.mid(pos + 1).toInt();
+
+ QString newAccessibleName;
+ do {
+ // 一直找到一个不重复的名字
+ newAccessibleName = accessibleName + SEPARATOR + QString::number(++id);
+ } while (accessibleMap[r].contains(newAccessibleName));
+
+ accessibleMap[r].append(newAccessibleName);
+ objnameMap.insert(w, newAccessibleName);
+
+ // 对象销毁后移除占用名称
+ QObject::connect(w, &QWidget::destroyed, [ = ] (QObject *obj) {
+ objnameMap.remove(obj);
+ accessibleMap[r].removeOne(newAccessibleName);
+ });
+ return newAccessibleName;
+ } else {
+ accessibleMap[r].append(accessibleName);
+ objnameMap.insert(w, accessibleName);
+
+ // 对象销毁后移除占用名称
+ QObject::connect(w, &QWidget::destroyed, [ = ] (QObject *obj) {
+ objnameMap.remove(obj);
+ accessibleMap[r].removeOne(accessibleName);
+ });
+ return accessibleName;
+ }
+}
+
+class Accessible : public QAccessibleWidget {
+public:
+ Accessible(QWidget *parent, QAccessible::Role r, const QString &accessibleName)
+ : QAccessibleWidget(parent, r)
+ , w(parent)
+ , accessibleName(accessibleName)
+ {}
+
+ // 对于使用dogtail的AT自动化测试工作,实际上只需要使用我们提供的text方法获取控件唯一ID,,然后再通过QAccessibleWidget的rect方法找到其坐标,模拟点击即可
+ // rect没必要重新实现,text方法通过getAccessibleName确定返回唯一值
+ QString text(QAccessible::Text t) const override {
+ switch (t) {
+ case QAccessible::Name:
+ return getAccessibleName(w, this->role(), accessibleName);
+ default:
+ return QString();
+ }
}
- return interface;
+private:
+ QWidget *w;
+ QString accessibleName;
+};
+
+QAccessibleInterface *accessibleFactory(const QString &classname, QObject *object)
+{
+ Q_UNUSED(classname);
+
+ static QMap<QString, QAccessible::Role> s_roleMap = {
+ {"MainWindow", QAccessible::Role::Form}
+ , {"MainPanelControl", QAccessible::Role::Button}
+ , {"Dock::TipsWidget", QAccessible::Role::StaticText}
+ , {"DockPopupWindow", QAccessible::Role::Form}
+ , {"LauncherItem", QAccessible::Role::Button}
+ , {"AppItem", QAccessible::Role::Button}
+ , {"PreviewContainer", QAccessible::Role::Button}
+ , {"PluginsItem", QAccessible::Role::Button}
+ , {"TrayPluginItem", QAccessible::Role::Button}
+ , {"PlaceholderItem", QAccessible::Role::Button}
+ , {"AppDragWidget", QAccessible::Role::Button}
+ , {"AppSnapshot", QAccessible::Role::Button}
+ , {"FloatingPreview", QAccessible::Role::Button}
+ , {"XEmbedTrayWidget", QAccessible::Role::Button}
+ , {"IndicatorTrayWidget", QAccessible::Role::Button}
+ , {"SNITrayWidget", QAccessible::Role::Button}
+ , {"AbstractTrayWidget", QAccessible::Role::Button}
+ , {"SystemTrayItem", QAccessible::Role::Button}
+ , {"FashionTrayItem", QAccessible::Role::Form}
+ , {"FashionTrayWidgetWrapper", QAccessible::Role::Form}
+ , {"FashionTrayControlWidget", QAccessible::Role::Button}
+ , {"AttentionContainer", QAccessible::Role::Form}
+ , {"HoldContainer", QAccessible::Role::Form}
+ , {"NormalContainer", QAccessible::Role::Form}
+ , {"SpliterAnimated", QAccessible::Role::Form}
+ , {"DatetimeWidget", QAccessible::Role::Form}
+ , {"OnboardItem", QAccessible::Role::Form}
+ , {"TrashWidget", QAccessible::Role::Form}
+ , {"PopupControlWidget", QAccessible::Role::Button}
+ , {"ShutdownWidget", QAccessible::Role::Form}
+ , {"MultitaskingWidget", QAccessible::Role::Form}
+ , {"ShowDesktopWidget", QAccessible::Role::Form}
+ , {"OverlayWarningWidget", QAccessible::Role::Form}
+ , {"QWidget", QAccessible::Role::Form}
+ , {"QLabel", QAccessible::Role::StaticText}
+ , {"Dtk::Widget::DIconButton", QAccessible::Role::Button}
+ , {"Dtk::Widget::DSwitchButton", QAccessible::Role::Button}
+ , {"DesktopWidget", QAccessible::Role::Button}
+ , {"HorizontalSeperator", QAccessible::Role::Form}
+ };
+
+ static QMap<QString, QString> s_classNameMap = {
+ {"Dock::TipsWidget", "tips"}
+ , {"DatetimeWidget", "plugin-datetime"}
+ , {"OnboardItem", "plugin-onboard"}
+ , {"TrashWidget", "plugin-trash"}
+ , {"ShutdownWidget", "plugin-shutdown"}
+ , {"MultitaskingWidget", "plugin-multitasking"}
+ , {"ShowDesktopWidget", "plugin-showdesktop"}
+ , {"OverlayWarningWidget", "plugin-overlaywarningwidget"}
+ , {"SoundItem", "plugin-sounditem"}
+ };
+
+ if (object->isWidgetType())
+ return new Accessible(qobject_cast<QWidget *>(object)
+ , s_roleMap.value(classname, QAccessible::Role::Form)
+ , s_classNameMap.value(object->metaObject()->className(), object->metaObject()->className()));
+
+ return nullptr;
}
diff --git a/frame/accessible/accessibledefine.h b/frame/accessible/accessibledefine.h
deleted file mode 100644
index 014fde0..0000000
--- a/frame/accessible/accessibledefine.h
+++ /dev/null
@@ -1,400 +0,0 @@
-// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd.
-//
-// SPDX-License-Identifier: LGPL-3.0-or-later
-
-#ifndef ACCESSIBLEINTERFACE_H
-#define ACCESSIBLEINTERFACE_H
-
-#include <QAccessible>
-#include <QAccessibleWidget>
-#include <QEvent>
-#include <QMap>
-#include <QString>
-#include <QWidget>
-#include <QObject>
-#include <QMetaEnum>
-#include <QMouseEvent>
-#include <QApplication>
-
-#define SEPARATOR "_"
-
-inline QString getAccessibleName(QWidget *w, QAccessible::Role r, const QString &fallback)
-{
- const QString lowerFallback = fallback.toLower();
- // 避免重复生成
- static QMap< QObject *, QString > objnameMap;
- if (!objnameMap[w].isEmpty())
- return objnameMap[w];
-
- static QMap< QAccessible::Role, QList< QString > > accessibleMap;
- QString oldAccessName = w->accessibleName().toLower();
- oldAccessName.replace(SEPARATOR, "");
-
- // 按照类型添加固定前缀
- QMetaEnum metaEnum = QMetaEnum::fromType<QAccessible::Role>();
- QByteArray prefix = metaEnum.valueToKeys(r);
- switch (r) {
- case QAccessible::Button: prefix = "Btn"; break;
- case QAccessible::StaticText: prefix = "Label"; break;
- default: break;
- }
-
- // 再加上标识
- QString accessibleName = QString::fromLatin1(prefix) + SEPARATOR;
- QString objectName = w->objectName().toLower();
- accessibleName += oldAccessName.isEmpty() ? (objectName.isEmpty() ?lowerFallback : objectName) : oldAccessName;
- // 检查名称是否唯一
- if (accessibleMap[r].contains(accessibleName)) {
- if (!objnameMap.key(accessibleName)) {
- objnameMap.remove(objnameMap.key(accessibleName));
- objnameMap.insert(w, accessibleName);
- return accessibleName;
- }
- // 获取编号,然后+1
- int pos = accessibleName.indexOf(SEPARATOR);
- int id = accessibleName.mid(pos + 1).toInt();
-
- QString newAccessibleName;
- do {
- // 一直找到一个不重复的名字
- newAccessibleName = accessibleName + SEPARATOR + QString::number(++id);
- } while (accessibleMap[r].contains(newAccessibleName));
-
- accessibleMap[r].append(newAccessibleName);
- objnameMap.insert(w, newAccessibleName);
-
- // 对象销毁后移除占用名称
- QObject::connect(w, &QWidget::destroyed, [ = ] (QObject *obj) {
- objnameMap.remove(obj);
- accessibleMap[r].removeOne(newAccessibleName);
- });
- return newAccessibleName;
- } else {
- accessibleMap[r].append(accessibleName);
- objnameMap.insert(w, accessibleName);
-
- // 对象销毁后移除占用名称
- QObject::connect(w, &QWidget::destroyed, [ = ] (QObject *obj) {
- objnameMap.remove(obj);
- accessibleMap[r].removeOne(accessibleName);
- });
- return accessibleName;
- }
-}
-
-// 公共的功能
-#define FUNC_CREATE(classname,accessibletype,accessdescription) explicit Accessible##classname(classname *w) \
- : QAccessibleWidget(w,accessibletype,#classname)\
- , m_w(w)\
- , m_description(accessdescription)\
-{}\
-
-#define FUNC_TEXT(classname,accessiblename) QString Accessible##classname::text(QAccessible::Text t) const{\
- switch (t) {\
- case QAccessible::Name:\
- return getAccessibleName(m_w, this->role(), accessiblename);\
- case QAccessible::Description:\
- return m_description;\
- default:\
- return QString();\
- }\
- }\
-
-// button控件特有功能
-#define FUNC_ACTIONNAMES(classname) QStringList Accessible##classname::actionNames() const{\
- if(!m_w->isEnabled())\
- return QStringList();\
- return QStringList() << pressAction()<< showMenuAction();\
- }\
-
-#define FUNC_DOACTION(classname) void Accessible##classname::doAction(const QString &actionName){\
- if(actionName == pressAction())\
-{\
- QPointF localPos = m_w->geometry().center();\
- QMouseEvent event(QEvent::MouseButtonPress,localPos,Qt::LeftButton,Qt::LeftButton,Qt::NoModifier);\
- qApp->sendEvent(m_w,&event);\
- }\
- else if(actionName == showMenuAction())\
-{\
- QPointF localPos = m_w->geometry().center();\
- QMouseEvent event(QEvent::MouseButtonPress,localPos,Qt::RightButton,Qt::RightButton,Qt::NoModifier);\
- qApp->sendEvent(m_w,&event);\
- }\
- }\
-
-// Label控件特有功能
-#define FUNC_TEXT_(classname) QString Accessible##classname::text(int startOffset, int endOffset) const{\
- Q_UNUSED(startOffset)\
- Q_UNUSED(endOffset)\
- return m_w->text();\
- }\
-
-// Slider控件特有功能
-#define FUNC_CURRENTVALUE(classname) QVariant Accessible##classname::currentValue() const{\
- return m_w->value();\
- }\
-
-#define FUNC_SETCURRENTVALUE(classname) void Accessible##classname::setCurrentValue(const QVariant &value){\
- return m_w->setValue(value.toInt());\
- }\
-
-#define FUNC_MAXMUMVALUE(classname) QVariant Accessible##classname::maximumValue() const{\
- return QVariant(m_w->maximum());\
- }\
-
-#define FUNC_FUNC_MINIMUMVALUE(classname) QVariant Accessible##classname::minimumValue() const{\
- return QVariant(m_w->minimum());\
- }\
-
-// DSlider控件特有功能函数
-#define FUNC_FUNC_MINIMUMSTEPSIZE(classname) QVariant Accessible##classname::minimumStepSize() const{\
- return QVariant(m_w->pageStep());\
- }\
-
-#define SET_FORM_ACCESSIBLE_WITH_DESCRIPTION(classname,accessiblename,accessdescription) class Accessible##classname : public QAccessibleWidget\
-{\
- public:\
- FUNC_CREATE(classname,QAccessible::Form,accessdescription)\
- QString text(QAccessible::Text t) const override;\
- void *interface_cast(QAccessible::InterfaceType t) override{\
- switch (t) {\
- case QAccessible::ActionInterface:\
- return static_cast<QAccessibleActionInterface*>(this);\
- default:\
- return nullptr;\
- }\
- }\
- private:\
- classname *m_w;\
- QString m_description;\
- };\
- FUNC_TEXT(classname,accessiblename)\
-
-#define SET_BUTTON_ACCESSIBLE_WITH_DESCRIPTION(classname,accessiblename,accessdescription) class Accessible##classname : public QAccessibleWidget\
-{\
- public:\
- FUNC_CREATE(classname,QAccessible::Button,accessdescription)\
- QString text(QAccessible::Text t) const override;\
- void *interface_cast(QAccessible::InterfaceType t) override{\
- switch (t) {\
- case QAccessible::ActionInterface:\
- return static_cast<QAccessibleActionInterface*>(this);\
- default:\
- return nullptr;\
- }\
- }\
- QStringList actionNames() const override;\
- void doAction(const QString &actionName) override;\
- private:\
- classname *m_w;\
- QString m_description;\
- };\
- FUNC_TEXT(classname,accessiblename)\
- FUNC_ACTIONNAMES(classname)\
- FUNC_DOACTION(classname)\
-
-#define SET_LABEL_ACCESSIBLE_WITH_DESCRIPTION(classname,accessiblename,accessdescription) class Accessible##classname : public QAccessibleWidget, public QAccessibleTextInterface\
-{\
- public:\
- FUNC_CREATE(classname,QAccessible::StaticText,accessdescription)\
- QString text(QAccessible::Text t) const override;\
- void *interface_cast(QAccessible::InterfaceType t) override{\
- switch (t) {\
- case QAccessible::ActionInterface:\
- return static_cast<QAccessibleActionInterface*>(this);\
- case QAccessible::TextInterface:\
- return static_cast<QAccessibleTextInterface*>(this);\
- default:\
- return nullptr;\
- }\
- }\
- QString text(int startOffset, int endOffset) const override;\
- void selection(int selectionIndex, int *startOffset, int *endOffset) const override {\
- Q_UNUSED(selectionIndex)\
- Q_UNUSED(startOffset)\
- Q_UNUSED(endOffset)\
- }\
- int selectionCount() const override { return 0; }\
- void addSelection(int startOffset, int endOffset) override {\
- Q_UNUSED(startOffset)\
- Q_UNUSED(endOffset)\
- }\
- void removeSelection(int selectionIndex) override {\
- Q_UNUSED(selectionIndex)\
- }\
- void setSelection(int selectionIndex, int startOffset, int endOffset) override {\
- Q_UNUSED(selectionIndex)\
- Q_UNUSED(startOffset)\
- Q_UNUSED(endOffset)\
- }\
- int cursorPosition() const override { return 0; }\
- void setCursorPosition(int position) override {\
- Q_UNUSED(position)\
- }\
- int characterCount() const override { return 0; }\
- QRect characterRect(int offset) const override {\
- Q_UNUSED(offset)\
- return QRect();\
- }\
- int offsetAtPoint(const QPoint &point) const override {\
- Q_UNUSED(point)\
- return 0;\
- }\
- void scrollToSubstring(int startIndex, int endIndex) override {\
- Q_UNUSED(startIndex)\
- Q_UNUSED(endIndex)\
- }\
- QString attributes(int offset, int *startOffset, int *endOffset) const override {\
- Q_UNUSED(offset)\
- Q_UNUSED(startOffset)\
- Q_UNUSED(endOffset)\
- return QString();\
- }\
- private:\
- classname *m_w;\
- QString m_description;\
- };\
- FUNC_TEXT(classname,accessiblename)\
- FUNC_TEXT_(classname)\
-
-#define SET_SLIDER_ACCESSIBLE_WITH_DESCRIPTION(classname,accessiblename,accessdescription) class Accessible##classname : public QAccessibleWidget, public QAccessibleValueInterface\
-{\
- public:\
- FUNC_CREATE(classname,QAccessible::Slider,accessdescription)\
- QString text(QAccessible::Text t) const override;\
- void *interface_cast(QAccessible::InterfaceType t) override{\
- switch (t) {\
- case QAccessible::ActionInterface:\
- return static_cast<QAccessibleActionInterface*>(this);\
- case QAccessible::ValueInterface:\
- return static_cast<QAccessibleValueInterface*>(this);\
- default:\
- return nullptr;\
- }\
- }\
- QVariant currentValue() const override;\
- void setCurrentValue(const QVariant &value) override;\
- QVariant maximumValue() const override;\
- QVariant minimumValue() const override;\
- QVariant minimumStepSize() const override;\
- private:\
- classname *m_w;\
- QString m_description;\
- };\
- FUNC_TEXT(classname,accessiblename)\
- FUNC_CURRENTVALUE(classname)\
- FUNC_SETCURRENTVALUE(classname)\
- FUNC_MAXMUMVALUE(classname)\
- FUNC_FUNC_MINIMUMVALUE(classname)\
- FUNC_FUNC_MINIMUMSTEPSIZE(classname)\
-
-#define SET_EDITABLE_ACCESSIBLE_WITH_DESCRIPTION(classname,accessiblename,accessdescription) class Accessible##classname : public QAccessibleWidget, public QAccessibleEditableTextInterface, public QAccessibleTextInterface\
-{\
- public:\
- FUNC_CREATE(classname,QAccessible::EditableText,accessdescription)\
- QString text(QAccessible::Text t) const override;\
- QAccessibleInterface *child(int index) const override { Q_UNUSED(index); return nullptr; }\
- void *interface_cast(QAccessible::InterfaceType t) override{\
- switch (t) {\
- case QAccessible::ActionInterface:\
- return static_cast<QAccessibleActionInterface*>(this);\
- case QAccessible::TextInterface:\
- return static_cast<QAccessibleTextInterface*>(this);\
- case QAccessible::EditableTextInterface:\
- return static_cast<QAccessibleEditableTextInterface*>(this);\
- default:\
- return nullptr;\
- }\
- }\
- QString text(int startOffset, int endOffset) const override;\
- void selection(int selectionIndex, int *startOffset, int *endOffset) const override {\
- Q_UNUSED(selectionIndex)\
- Q_UNUSED(startOffset)\
- Q_UNUSED(endOffset)\
- }\
- int selectionCount() const override { return 0; }\
- void addSelection(int startOffset, int endOffset) override {\
- Q_UNUSED(startOffset)\
- Q_UNUSED(endOffset)\
- }\
- void removeSelection(int selectionIndex) override { Q_UNUSED(selectionIndex);}\
- void setSelection(int selectionIndex, int startOffset, int endOffset) override {\
- Q_UNUSED(selectionIndex)\
- Q_UNUSED(startOffset)\
- Q_UNUSED(endOffset)\
- }\
- int cursorPosition() const override { return 0; }\
- void setCursorPosition(int position) override {\
- Q_UNUSED(position)\
- }\
- int characterCount() const override { return 0; }\
- QRect characterRect(int offset) const override { \
- Q_UNUSED(offset)\
- return QRect(); }\
- int offsetAtPoint(const QPoint &point) const override {\
- Q_UNUSED(point)\
- return 0; }\
- void scrollToSubstring(int startIndex, int endIndex) override {\
- Q_UNUSED(startIndex)\
- Q_UNUSED(endIndex)\
- }\
- QString attributes(int offset, int *startOffset, int *endOffset) const override {\
- Q_UNUSED(offset)\
- Q_UNUSED(startOffset)\
- Q_UNUSED(endOffset)\
- return QString(); }\
- void insertText(int offset, const QString &text) override {\
- Q_UNUSED(offset)\
- Q_UNUSED(text)\
- }\
- void deleteText(int startOffset, int endOffset) override {\
- Q_UNUSED(startOffset)\
- Q_UNUSED(endOffset)\
- }\
- void replaceText(int startOffset, int endOffset, const QString &text) override {\
- Q_UNUSED(startOffset)\
- Q_UNUSED(endOffset)\
- Q_UNUSED(text)\
- }\
- private:\
- classname *m_w;\
- QString m_description;\
- };\
- FUNC_TEXT(classname,accessiblename)\
- FUNC_TEXT_(classname)\
-
-#define USE_ACCESSIBLE(classnamestring,classname) if (classnamestring == QLatin1String(#classname) && object && object->isWidgetType())\
-{\
- interface = new Accessible##classname(static_cast<classname *>(object));\
- }\
-
-#define ELSE_USE_ACCESSIBLE(classnamestring,classname) else if (classnamestring == QLatin1String(#classname) && object && object->isWidgetType())\
-{\
- interface = new Accessible##classname(static_cast<classname *>(object));\
- }\
-
-
-// [指定objectname]---适用同一个类,但objectname不同的情况
-#define USE_ACCESSIBLE_BY_OBJECTNAME(classnamestring,classname,objectname) if (classnamestring == QLatin1String(#classname) && object && (object->objectName() == objectname) && object->isWidgetType())\
-{\
- interface = new Accessible##classname(static_cast<classname *>(object));\
- }\
-
-#define ELSE_USE_ACCESSIBLE_BY_OBJECTNAME(classnamestring,classname,objectname) else if (classnamestring == QLatin1String(#classname) && object && (object->objectName() == objectname) && object->isWidgetType())\
-{\
- interface = new Accessible##classname(static_cast<classname *>(object));\
- }\
-
-/*******************************************简化使用*******************************************/
-#define SET_FORM_ACCESSIBLE(classname,accessiblename) SET_FORM_ACCESSIBLE_WITH_DESCRIPTION(classname,accessiblename,"")
-
-#define SET_BUTTON_ACCESSIBLE(classname,accessiblename) SET_BUTTON_ACCESSIBLE_WITH_DESCRIPTION(classname,accessiblename,"")
-
-#define SET_LABEL_ACCESSIBLE(classname,accessiblename) SET_LABEL_ACCESSIBLE_WITH_DESCRIPTION(classname,accessiblename,"")
-
-#define SET_SLIDER_ACCESSIBLE(classname,accessiblename) SET_SLIDER_ACCESSIBLE_WITH_DESCRIPTION(classname,accessiblename,"")
-
-#define SET_EDITABLE_ACCESSIBLE(classname,accessiblename) SET_EDITABLE_ACCESSIBLE_WITH_DESCRIPTION(classname,accessiblename,"")
-/************************************************************************************************/
-
-#endif // ACCESSIBLEINTERFACE_H
diff --git a/frame/main.cpp b/frame/main.cpp
index d45144a..532920a 100644
--- a/frame/main.cpp
+++ b/frame/main.cpp
@@ -174,5 +174,5 @@ int main(int argc, char *argv[])
app.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
- // 自动化标记由此开始
+ // 自动化标记
QAccessible::installFactory(accessibleFactory);
diff --git a/plugins/sound/soundaccessible.h b/plugins/sound/soundaccessible.h
deleted file mode 100644
index 511bf79..0000000
--- a/plugins/sound/soundaccessible.h
+++ /dev/null
@@ -1,28 +0,0 @@
-// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
-//
-// SPDX-License-Identifier: LGPL-3.0-or-later
-
-#ifndef SOUNDACCESSIBLE_H
-#define SOUNDACCESSIBLE_H
-#include "accessibledefine.h"
-
-#include "sounditem.h"
-#include "soundapplet.h"
-#include "./componments/volumeslider.h"
-
-SET_BUTTON_ACCESSIBLE(SoundItem, "plugin-sounditem")
-SET_FORM_ACCESSIBLE(SoundApplet, "soundapplet")
-SET_SLIDER_ACCESSIBLE(VolumeSlider, "volumeslider")
-
-QAccessibleInterface *soundAccessibleFactory(const QString &classname, QObject *object)
-{
- QAccessibleInterface *interface = nullptr;
-
- USE_ACCESSIBLE(classname, SoundItem)
- ELSE_USE_ACCESSIBLE(classname, SoundApplet)
- ELSE_USE_ACCESSIBLE(classname, VolumeSlider);
-
- return interface;
-}
-
-#endif // SOUNDACCESSIBLE_H
diff --git a/plugins/sound/soundplugin.cpp b/plugins/sound/soundplugin.cpp
index a7ee637..1eea08d 100644
--- a/plugins/sound/soundplugin.cpp
+++ b/plugins/sound/soundplugin.cpp
@@ -4,8 +4,6 @@
#include "soundplugin.h"
-#include "soundaccessible.h"
#include <QDebug>
-#include <QAccessible>
#define STATE_KEY "enable"
@@ -15,5 +13,5 @@ SoundPlugin::SoundPlugin(QObject *parent)
m_soundItem(nullptr)
{
- QAccessible::installFactory(soundAccessibleFactory);
+
}
diff --git a/plugins/tray/abstracttraywidget.h b/plugins/tray/abstracttraywidget.h
index eb356dd..11c9b6e 100644
--- a/plugins/tray/abstracttraywidget.h
+++ b/plugins/tray/abstracttraywidget.h
@@ -23,4 +23,5 @@ public:
virtual QString itemKeyForConfig() = 0;
+ QString accessibleName() {return itemKeyForConfig().replace("sni:", "");}
virtual void updateIcon() = 0;
virtual void sendClick(uint8_t mouseButton, int x, int y) = 0;
--
libgit2 1.3.2