feat(accessible):update accessible on uos branch

This commit is contained in:
fpc_diesel 2020-05-27 14:24:18 +08:00 committed by 范朋程
parent 8ebf52f9d3
commit eecce9d618
15 changed files with 340 additions and 181 deletions

View File

@ -88,7 +88,7 @@ AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent)
centralLayout->setMargin(0); centralLayout->setMargin(0);
centralLayout->setSpacing(0); centralLayout->setSpacing(0);
setAccessibleName(m_itemEntryInter->name()); setObjectName(m_itemEntryInter->name());
setAcceptDrops(true); setAcceptDrops(true);
setLayout(centralLayout); setLayout(centralLayout);
@ -96,7 +96,7 @@ AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent)
m_active = m_itemEntryInter->isActive(); m_active = m_itemEntryInter->isActive();
m_appNameTips->setObjectName("AppItemTips"); m_appNameTips->setObjectName("AppItemTips");
m_appNameTips->setAccessibleName(m_itemEntryInter->name()); m_appNameTips->setObjectName(m_itemEntryInter->name());
m_appNameTips->setVisible(false); m_appNameTips->setVisible(false);
m_appNameTips->installEventFilter(this); m_appNameTips->installEventFilter(this);

View File

@ -53,6 +53,7 @@ DockItem::DockItem(QWidget *parent)
arrowRectangle->setShadowXOffset(0); arrowRectangle->setShadowXOffset(0);
arrowRectangle->setArrowWidth(18); arrowRectangle->setArrowWidth(18);
arrowRectangle->setArrowHeight(10); arrowRectangle->setArrowHeight(10);
arrowRectangle->setObjectName("apppopup");
PopupWindow = arrowRectangle; PopupWindow = arrowRectangle;
} }

View File

@ -42,7 +42,6 @@ LauncherItem::LauncherItem(QWidget *parent)
m_tips->setVisible(false); m_tips->setVisible(false);
m_tips->setObjectName("launcher"); m_tips->setObjectName("launcher");
m_tips->setAccessibleName("launchertips");
connect(m_gsettings, &QGSettings::changed, this, &LauncherItem::onGSettingsChanged); connect(m_gsettings, &QGSettings::changed, this, &LauncherItem::onGSettingsChanged);
} }

View File

@ -48,7 +48,7 @@ PluginsItem::PluginsItem(PluginsItemInterface *const pluginInter, const QString
m_centralWidget->setParent(this); m_centralWidget->setParent(this);
m_centralWidget->setVisible(true); m_centralWidget->setVisible(true);
m_centralWidget->setAccessibleName("centralwidget"); m_centralWidget->setObjectName(pluginInter->pluginName() + "-centralwidget");
m_centralWidget->installEventFilter(this); m_centralWidget->installEventFilter(this);
QBoxLayout *hLayout = new QHBoxLayout; QBoxLayout *hLayout = new QHBoxLayout;

View File

@ -107,6 +107,8 @@ void MainPanelControl::init()
m_appSpliter->setObjectName("spliter_app"); m_appSpliter->setObjectName("spliter_app");
m_traySpliter->setObjectName("spliter_tray"); m_traySpliter->setObjectName("spliter_tray");
m_appAreaWidget->setAccessibleName("AppFullArea");
m_mainPanelLayout->addWidget(m_fixedAreaWidget); m_mainPanelLayout->addWidget(m_fixedAreaWidget);
m_mainPanelLayout->addWidget(m_fixedSpliter); m_mainPanelLayout->addWidget(m_fixedSpliter);
m_mainPanelLayout->addWidget(m_appAreaWidget); m_mainPanelLayout->addWidget(m_appAreaWidget);

View File

@ -32,16 +32,12 @@ DWIDGET_USE_NAMESPACE
DockPopupWindow::DockPopupWindow(QWidget *parent) DockPopupWindow::DockPopupWindow(QWidget *parent)
: DArrowRectangle(ArrowBottom, parent), : DArrowRectangle(ArrowBottom, parent),
m_model(false), m_model(false),
m_acceptDelayTimer(new QTimer(this)), m_acceptDelayTimer(new QTimer(this)),
m_regionInter(new DRegionMonitor(this)) m_regionInter(new DRegionMonitor(this))
{ {
m_acceptDelayTimer->setSingleShot(true); m_acceptDelayTimer->setSingleShot(true);
m_acceptDelayTimer->setInterval(100); m_acceptDelayTimer->setInterval(100);
setAccessibleName("popup");
m_wmHelper = DWindowManagerHelper::instance(); m_wmHelper = DWindowManagerHelper::instance();
compositeChanged(); compositeChanged();

View File

@ -29,11 +29,13 @@
#include "../plugins/show-desktop/showdesktopwidget.h" #include "../plugins/show-desktop/showdesktopwidget.h"
#include "../plugins/sound/sounditem.h" // 这部分由sound插件单独维护,这样做是因为在标记volumeslider这个类时,需要用到其setValue的实现,
#include "../plugins/sound/soundapplet.h" // 但插件的源文件dock这边并没有包含,不想引入复杂的包含关系,其实最好的做法就是像sound插件这样,谁维护谁的
#include "../plugins/sound/sinkinputwidget.h" //#include "../plugins/sound/sounditem.h"
#include "../plugins/sound/componments/volumeslider.h" //#include "../plugins/sound/soundapplet.h"
#include "../plugins/sound/componments/horizontalseparator.h" //#include "../plugins/sound/sinkinputwidget.h"
//#include "../plugins/sound/componments/volumeslider.h"
//#include "../plugins/sound/componments/horizontalseparator.h"
#include "../plugins/datetime/datetimewidget.h" #include "../plugins/datetime/datetimewidget.h"
#include "../plugins/onboard/onboarditem.h" #include "../plugins/onboard/onboarditem.h"
@ -50,10 +52,10 @@
DWIDGET_USE_NAMESPACE DWIDGET_USE_NAMESPACE
// 添加accessible // 添加accessible
SET_WIDGET_ACCESSIBLE(MainWindow, QAccessible::Form, "mainwindow") SET_FORM_ACCESSIBLE(MainWindow, "mainwindow")
SET_BUTTON_ACCESSIBLE(MainPanelControl, "mainpanelcontrol") SET_BUTTON_ACCESSIBLE(MainPanelControl, "mainpanelcontrol")
SET_LABEL_ACCESSIBLE(TipsWidget, "tips") SET_LABEL_ACCESSIBLE(TipsWidget, "tips")
SET_WIDGET_ACCESSIBLE(DockPopupWindow, QAccessible::Form, "popupwindow") SET_FORM_ACCESSIBLE(DockPopupWindow, "popupwindow")
SET_BUTTON_ACCESSIBLE(LauncherItem, "launcheritem") SET_BUTTON_ACCESSIBLE(LauncherItem, "launcheritem")
SET_BUTTON_ACCESSIBLE(AppItem, "appitem") SET_BUTTON_ACCESSIBLE(AppItem, "appitem")
SET_BUTTON_ACCESSIBLE(PreviewContainer, "previewcontainer") SET_BUTTON_ACCESSIBLE(PreviewContainer, "previewcontainer")
@ -67,27 +69,27 @@ SET_BUTTON_ACCESSIBLE(XEmbedTrayWidget, m_w->itemKeyForConfig())
SET_BUTTON_ACCESSIBLE(IndicatorTrayWidget, m_w->itemKeyForConfig()) SET_BUTTON_ACCESSIBLE(IndicatorTrayWidget, m_w->itemKeyForConfig())
SET_BUTTON_ACCESSIBLE(SNITrayWidget, m_w->itemKeyForConfig()) SET_BUTTON_ACCESSIBLE(SNITrayWidget, m_w->itemKeyForConfig())
SET_BUTTON_ACCESSIBLE(SystemTrayItem, m_w->itemKeyForConfig()) SET_BUTTON_ACCESSIBLE(SystemTrayItem, m_w->itemKeyForConfig())
SET_WIDGET_ACCESSIBLE(FashionTrayItem, QAccessible::Form, "fashiontrayitem") SET_FORM_ACCESSIBLE(FashionTrayItem, "fashiontrayitem")
SET_WIDGET_ACCESSIBLE(FashionTrayWidgetWrapper, QAccessible::Form, "fashiontraywrapper") SET_FORM_ACCESSIBLE(FashionTrayWidgetWrapper, "fashiontraywrapper")
SET_BUTTON_ACCESSIBLE(FashionTrayControlWidget, "fashiontraycontrolwidget") SET_BUTTON_ACCESSIBLE(FashionTrayControlWidget, "fashiontraycontrolwidget")
SET_WIDGET_ACCESSIBLE(AttentionContainer, QAccessible::Form, "attentioncontainer") SET_FORM_ACCESSIBLE(AttentionContainer, "attentioncontainer")
SET_WIDGET_ACCESSIBLE(HoldContainer, QAccessible::Form, "holdcontainer") SET_FORM_ACCESSIBLE(HoldContainer, "holdcontainer")
SET_WIDGET_ACCESSIBLE(NormalContainer, QAccessible::Form, "normalcontainer") SET_FORM_ACCESSIBLE(NormalContainer, "normalcontainer")
SET_WIDGET_ACCESSIBLE(SpliterAnimated, QAccessible::Form, "spliteranimated") SET_FORM_ACCESSIBLE(SpliterAnimated, "spliteranimated")
SET_BUTTON_ACCESSIBLE(SoundItem, "plugin-sounditem") //SET_BUTTON_ACCESSIBLE(SoundItem, "plugin-sounditem")
SET_WIDGET_ACCESSIBLE(SoundApplet, QAccessible::Form, "soundapplet") //SET_FORM_ACCESSIBLE(SoundApplet, "soundapplet")
SET_WIDGET_ACCESSIBLE(SinkInputWidget, QAccessible::Form, "sinkinputwidget") //SET_FORM_ACCESSIBLE(SinkInputWidget, "sinkinputwidget")
SET_WIDGET_ACCESSIBLE(VolumeSlider, QAccessible::Slider, "volumeslider") //SET_SLIDER_ACCESSIBLE(VolumeSlider, QAccessible::Slider, "volumeslider")
SET_WIDGET_ACCESSIBLE(HorizontalSeparator, QAccessible::Separator, "horizontalseparator") //SET_FORM_ACCESSIBLE(HorizontalSeparator, "horizontalseparator")
SET_WIDGET_ACCESSIBLE(DatetimeWidget, QAccessible::Form, "plugin-datetime") SET_FORM_ACCESSIBLE(DatetimeWidget, "plugin-datetime")
SET_WIDGET_ACCESSIBLE(OnboardItem, QAccessible::Form, "plugin-onboard") SET_FORM_ACCESSIBLE(OnboardItem, "plugin-onboard")
SET_WIDGET_ACCESSIBLE(TrashWidget, QAccessible::Form, "plugin-trash") SET_FORM_ACCESSIBLE(TrashWidget, "plugin-trash")
SET_BUTTON_ACCESSIBLE(PopupControlWidget, "popupcontrolwidget") SET_BUTTON_ACCESSIBLE(PopupControlWidget, "popupcontrolwidget")
SET_WIDGET_ACCESSIBLE(ShutdownWidget, QAccessible::Form, "plugin-shutdown") SET_FORM_ACCESSIBLE(ShutdownWidget, "plugin-shutdown")
SET_WIDGET_ACCESSIBLE(MultitaskingWidget, QAccessible::Form, "plugin-multitasking") SET_FORM_ACCESSIBLE(MultitaskingWidget, "plugin-multitasking")
SET_WIDGET_ACCESSIBLE(ShowDesktopWidget, QAccessible::Form, "plugin-showdesktop") SET_FORM_ACCESSIBLE(ShowDesktopWidget, "plugin-showdesktop")
SET_WIDGET_ACCESSIBLE(OverlayWarningWidget, QAccessible::Form, "plugin-overlaywarningwidget") SET_FORM_ACCESSIBLE(OverlayWarningWidget, "plugin-overlaywarningwidget")
SET_WIDGET_ACCESSIBLE(QWidget, QAccessible::Form, m_w->objectName().isEmpty() ? "widget" : m_w->objectName()) SET_FORM_ACCESSIBLE(QWidget, m_w->objectName().isEmpty() ? "widget" : m_w->objectName())
SET_LABEL_ACCESSIBLE(QLabel, m_w->text().isEmpty() ? m_w->objectName().isEmpty() ? "text" : m_w->objectName() : m_w->text()) SET_LABEL_ACCESSIBLE(QLabel, m_w->text().isEmpty() ? m_w->objectName().isEmpty() ? "text" : m_w->objectName() : m_w->text())
SET_BUTTON_ACCESSIBLE(DImageButton, m_w->objectName().isEmpty() ? "imagebutton" : m_w->objectName()) SET_BUTTON_ACCESSIBLE(DImageButton, m_w->objectName().isEmpty() ? "imagebutton" : m_w->objectName())
SET_BUTTON_ACCESSIBLE(DSwitchButton, m_w->text().isEmpty() ? "switchbutton" : m_w->text()) SET_BUTTON_ACCESSIBLE(DSwitchButton, m_w->text().isEmpty() ? "switchbutton" : m_w->text())
@ -120,11 +122,11 @@ QAccessibleInterface *accessibleFactory(const QString &classname, QObject *objec
USE_ACCESSIBLE(classname, SpliterAnimated); USE_ACCESSIBLE(classname, SpliterAnimated);
USE_ACCESSIBLE(classname, IndicatorTrayWidget); USE_ACCESSIBLE(classname, IndicatorTrayWidget);
USE_ACCESSIBLE(classname, XEmbedTrayWidget); USE_ACCESSIBLE(classname, XEmbedTrayWidget);
USE_ACCESSIBLE(classname, SoundItem); // USE_ACCESSIBLE(classname, SoundItem);
USE_ACCESSIBLE(classname, SoundApplet); // USE_ACCESSIBLE(classname, SoundApplet);
USE_ACCESSIBLE(classname, SinkInputWidget); // USE_ACCESSIBLE(classname, SinkInputWidget);
USE_ACCESSIBLE(classname, VolumeSlider); // USE_ACCESSIBLE(classname, VolumeSlider);
USE_ACCESSIBLE(classname, HorizontalSeparator); // USE_ACCESSIBLE(classname, HorizontalSeparator);
USE_ACCESSIBLE(classname, DatetimeWidget); USE_ACCESSIBLE(classname, DatetimeWidget);
USE_ACCESSIBLE(classname, OnboardItem); USE_ACCESSIBLE(classname, OnboardItem);
USE_ACCESSIBLE(classname, TrashWidget); USE_ACCESSIBLE(classname, TrashWidget);

View File

@ -1,9 +1,9 @@
/* /*
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd. * Copyright (C) 2018 ~ 2028 Deepin Technology Co., Ltd.
* *
* Author: fpc_diesel <fanpengcheng@uniontech.com> * Author: fanpengcheng <fanpengcheng_cm@deepin.com>
* *
* Maintainer: fpc_diesel <fanpengcheng@uniontech.com> * Maintainer: fanpengcheng <fanpengcheng_cm@deepin.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -18,40 +18,14 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef ACCESSIBLEDEFINE_H
#define ACCESSIBLEDEFINE_H
// 为了方便使用,把相关定义独立出来,如有需要,直接包含这个头文件,然后使用SET_*的宏去设置,USE_*宏开启即可 // 为了方便使用,把相关定义独立出来,如有需要,直接包含这个头文件,然后使用SET_*的宏去设置,USE_*宏开启即可
// 注意对项目中出现的所有的QWidget的派生类都要再启用一次accessiblity包括qt的原生控件[qt未限制其标记名称为空的情况] // 注意对项目中出现的所有的QWidget的派生类都要再启用一次accessiblity包括qt的原生控件[qt未限制其标记名称为空的情况]
// 注意使用USE_ACCESSIBLE_BY_OBJECTNAME开启accessiblity的时候一定要再最这个类用一下USE_ACCESSIBLE否则标记可能会遗漏 // 注意使用USE_ACCESSIBLE_BY_OBJECTNAME开启accessiblity的时候一定要再最这个类用一下USE_ACCESSIBLE否则标记可能会遗漏
/* 宏参数说明 #ifndef ACCESSIBLEINTERFACE_H
* classname:,DLineEdit #define ACCESSIBLEINTERFACE_H
* accessiblename:accessible唯一标识,[getAccessibleName函数处理],使QObject::setAccessibleName值
* accessibletype:QAccessible::Role,
* classobj:QObject指针
* accessdescription:accessible描述内容,,,
*
*
* FUNC_CREATE:
* FUNC_PRESS:Press接口
* FUNC_SHOWMENU:
* FUNC_PRESS_SHOWMENU:
* FUNC_RECT:rect接口
* FUNC_TEXT:text接口
* FUNC_TEXT_BY_LABEL:text接口,使text接口Value
* USE_ACCESSIBLE:accessible功能
* USE_ACCESSIBLE_BY_OBJECTNAME:,[objectname]---objectname不同的情况
*
* Accessible控件宏
* SET_BUTTON_ACCESSIBLE_PRESS_SHOWMENU:button类型,press和showmenu功能
* SET_BUTTON_ACCESSIBLE_SHOWMENU:button类型,showmenu功能
* SET_BUTTON_ACCESSIBLE:button类型,press功能
* SET_LABEL_ACCESSIBLE:label类型,
* SET_FORM_ACCESSIBLE:form类型,widget控件
* SET_SLIDER_ACCESSIBLE:slider类型,
* SET_SEPARATOR_ACCESSIBLE:separator类型,
*/
#include <QAccessible> #include <QAccessible>
#include <QAccessibleWidget> #include <QAccessibleWidget>
#include <QEvent> #include <QEvent>
@ -88,7 +62,8 @@ inline QString getAccessibleName(QWidget *w, QAccessible::Role r, const QString
// 再加上标识 // 再加上标识
QString accessibleName = QString::fromLatin1(prefix) + SEPARATOR; QString accessibleName = QString::fromLatin1(prefix) + SEPARATOR;
accessibleName += oldAccessName.isEmpty() ? lowerFallback : oldAccessName; QString objectName = w->objectName().toLower();
accessibleName += oldAccessName.isEmpty() ? (objectName.isEmpty() ?lowerFallback : objectName) : oldAccessName;
// 检查名称是否唯一 // 检查名称是否唯一
if (accessibleMap[r].contains(accessibleName)) { if (accessibleMap[r].contains(accessibleName)) {
if (!objnameMap.key(accessibleName)) { if (!objnameMap.key(accessibleName)) {
@ -118,137 +93,278 @@ inline QString getAccessibleName(QWidget *w, QAccessible::Role r, const QString
} }
} }
// 公共的功能
#define FUNC_CREATE(classname,accessibletype,accessdescription) Accessible##classname(classname *w) \ #define FUNC_CREATE(classname,accessibletype,accessdescription) Accessible##classname(classname *w) \
: QAccessibleWidget(w,accessibletype,#classname)\ : QAccessibleWidget(w,accessibletype,#classname)\
, m_w(w)\ , m_w(w)\
, m_description(accessdescription)\ , 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());\
}\
#define FUNC_FUNC_MINIMUMSTEPSIZE(classname) QVariant Accessible##classname::minimumStepSize() const{\
return QVariant(m_w->singleStep());\
}\
#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:\ private:\
classname *m_w;\ classname *m_w;\
QString m_description;\ QString m_description;\
};\
FUNC_TEXT(classname,accessiblename)\
#define FUNC_PRESS(classobj) QStringList actionNames() const override{\ #define SET_BUTTON_ACCESSIBLE_WITH_DESCRIPTION(classname,accessiblename,accessdescription) class Accessible##classname : public QAccessibleWidget\
if(!classobj->isEnabled())\ {\
return QStringList();\ public:\
return QStringList() << pressAction();}\ FUNC_CREATE(classname,QAccessible::Button,accessdescription)\
void doAction(const QString &actionName) override{\ QString text(QAccessible::Text t) const override;\
if(actionName == pressAction())\ void *interface_cast(QAccessible::InterfaceType t) override{\
{\ switch (t) {\
QPointF localPos = classobj->geometry().center();\ case QAccessible::ActionInterface:\
QMouseEvent event(QEvent::MouseButtonPress,localPos,Qt::LeftButton,Qt::LeftButton,Qt::NoModifier);\ return static_cast<QAccessibleActionInterface*>(this);\
QMouseEvent event2(QEvent::MouseButtonRelease,localPos,Qt::LeftButton,Qt::LeftButton,Qt::NoModifier);\ default:\
qApp->sendEvent(classobj,&event);\ return nullptr;\
qApp->sendEvent(classobj,&event2);\
}\
}\ }\
}\
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 FUNC_SHOWMENU(classobj) QStringList actionNames() const override{\ #define SET_LABEL_ACCESSIBLE_WITH_DESCRIPTION(classname,accessiblename,accessdescription) class Accessible##classname : public QAccessibleWidget, public QAccessibleTextInterface\
if(!classobj->isEnabled())\ {\
return QStringList();\ public:\
return QStringList() << showMenuAction();}\ FUNC_CREATE(classname,QAccessible::StaticText,accessdescription)\
void doAction(const QString &actionName) override{\ QString text(QAccessible::Text t) const override;\
if(actionName == showMenuAction())\ void *interface_cast(QAccessible::InterfaceType t) override{\
{\ switch (t) {\
QPointF localPos = classobj->geometry().center();\ case QAccessible::ActionInterface:\
QMouseEvent event(QEvent::MouseButtonPress,localPos,Qt::RightButton,Qt::RightButton,Qt::NoModifier);\ return static_cast<QAccessibleActionInterface*>(this);\
QMouseEvent event2(QEvent::MouseButtonRelease,localPos,Qt::RightButton,Qt::RightButton,Qt::NoModifier);\ case QAccessible::TextInterface:\
qApp->sendEvent(classobj,&event);\ return static_cast<QAccessibleTextInterface*>(this);\
qApp->sendEvent(classobj,&event2);\ default:\
}\ return nullptr;\
}\ }\
}\
QString text(int startOffset, int endOffset) const override;\
void selection(int selectionIndex, int *startOffset, int *endOffset) const override {}\
int selectionCount() const override { return 0; }\
void addSelection(int startOffset, int endOffset) override {}\
void removeSelection(int selectionIndex) override {}\
void setSelection(int selectionIndex, int startOffset, int endOffset) override {}\
int cursorPosition() const override { return 0; }\
void setCursorPosition(int position) override {}\
int characterCount() const override { return 0; }\
QRect characterRect(int offset) const override { return QRect(); }\
int offsetAtPoint(const QPoint &point) const override { return 0; }\
void scrollToSubstring(int startIndex, int endIndex) override {}\
QString attributes(int offset, int *startOffset, int *endOffset) const override { return QString(); }\
private:\
classname *m_w;\
QString m_description;\
};\
FUNC_TEXT(classname,accessiblename)\
FUNC_TEXT_(classname)\
#define FUNC_PRESS_SHOWMENU(classobj) QStringList actionNames() const override{\ #define SET_SLIDER_ACCESSIBLE_WITH_DESCRIPTION(classname,accessiblename,accessdescription) class Accessible##classname : public QAccessibleWidget, public QAccessibleValueInterface\
if(!classobj->isEnabled())\ {\
return QStringList();\ public:\
return QStringList() << pressAction() << showMenuAction();}\ FUNC_CREATE(classname,QAccessible::Slider,accessdescription)\
void doAction(const QString &actionName) override{\ QString text(QAccessible::Text t) const override;\
if(actionName == pressAction())\ void *interface_cast(QAccessible::InterfaceType t) override{\
{\ switch (t) {\
QPointF localPos = classobj->geometry().center();\ case QAccessible::ActionInterface:\
QMouseEvent event(QEvent::MouseButtonPress,localPos,Qt::LeftButton,Qt::LeftButton,Qt::NoModifier);\ return static_cast<QAccessibleActionInterface*>(this);\
QMouseEvent event2(QEvent::MouseButtonRelease,localPos,Qt::LeftButton,Qt::LeftButton,Qt::NoModifier);\ case QAccessible::ValueInterface:\
qApp->sendEvent(classobj,&event);\ return static_cast<QAccessibleValueInterface*>(this);\
qApp->sendEvent(classobj,&event2);\ default:\
}\ return nullptr;\
else if(actionName == showMenuAction())\
{\
QPointF localPos = classobj->geometry().center();\
QMouseEvent event(QEvent::MouseButtonPress,localPos,Qt::RightButton,Qt::RightButton,Qt::NoModifier);\
QMouseEvent event2(QEvent::MouseButtonRelease,localPos,Qt::RightButton,Qt::RightButton,Qt::NoModifier);\
qApp->sendEvent(classobj,&event);\
qApp->sendEvent(classobj,&event2);\
}\
}\ }\
}\
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 FUNC_RECT(classobj) QRect rect() const override{\ #define SET_EDITABLE_ACCESSIBLE_WITH_DESCRIPTION(classname,accessiblename,accessdescription) class Accessible##classname : public QAccessibleWidget, public QAccessibleEditableTextInterface, public QAccessibleTextInterface\
if (!classobj->isVisible())\ {\
return QRect();\ public:\
QPoint pos = classobj->mapToGlobal(QPoint(0, 0));\ FUNC_CREATE(classname,QAccessible::EditableText,accessdescription)\
return QRect(pos.x(), pos.y(), classobj->width(), classobj->height());\ QString text(QAccessible::Text t) const override;\
QAccessibleInterface *child(int index) const override { 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;\
}\ }\
#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();\
}\
}\ }\
QString text(int startOffset, int endOffset) const override;\
#define FUNC_TEXT_BY_LABEL(classname,accessiblename) QString Accessible##classname::text(QAccessible::Text t) const{\ void selection(int selectionIndex, int *startOffset, int *endOffset) const override {\
switch (t) {\ Q_UNUSED(selectionIndex)\
case QAccessible::Name:\ Q_UNUSED(startOffset)\
return getAccessibleName(m_w, this->role(), accessiblename);\ Q_UNUSED(endOffset)\
case QAccessible::Description:\
return m_description;\
case QAccessible::Value:\
return m_w->text();\
default:\
return QString();\
}\
}\ }\
int selectionCount() const override { return 0; }\
void addSelection(int startOffset, int endOffset) override {\
Q_UNUSED(startOffset)\
Q_UNUSED(endOffset)\
}\
void removeSelection(int selectionIndex) override {}\
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())\ #define USE_ACCESSIBLE(classnamestring,classname) if (classnamestring == QLatin1String(#classname) && object && object->isWidgetType())\
{\ {\
interface = new Accessible##classname(static_cast<classname *>(object));\ 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())\ #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));\ interface = new Accessible##classname(static_cast<classname *>(object));\
}\ }\
#define SET_ACCESSIBLE_WITH_PRESS_SHOWMENU_DESCRIPTION(classname,aaccessibletype,accessdescription) class Accessible##classname : public QAccessibleWidget\
{\
public:\
FUNC_CREATE(classname,aaccessibletype,accessdescription)\
QString text(QAccessible::Text t) const override;\
FUNC_PRESS_SHOWMENU(m_w)\
};\
#define SET_ACCESSIBLE_WITH_DESCRIPTION(classname,aaccessibletype,accessdescription) class Accessible##classname : public QAccessibleWidget\
{\
public:\
FUNC_CREATE(classname,aaccessibletype,accessdescription)\
QString text(QAccessible::Text t) const override;\
FUNC_RECT(m_w)\
};\
/*******************************************简化使用*******************************************/ /*******************************************简化使用*******************************************/
#define SET_BUTTON_ACCESSIBLE(classname,accessiblename) SET_ACCESSIBLE_WITH_PRESS_SHOWMENU_DESCRIPTION(classname,QAccessible::Button,"")\ #define SET_FORM_ACCESSIBLE(classname,accessiblename) SET_FORM_ACCESSIBLE_WITH_DESCRIPTION(classname,accessiblename,"")
FUNC_TEXT(classname,accessiblename)
#define SET_MENU_ACCESSIBLE(classname,accessiblename) SET_ACCESSIBLE_WITH_PRESS_SHOWMENU_DESCRIPTION(classname,QAccessible::PopupMenu,"")\ #define SET_BUTTON_ACCESSIBLE(classname,accessiblename) SET_BUTTON_ACCESSIBLE_WITH_DESCRIPTION(classname,accessiblename,"")
FUNC_TEXT(classname,accessiblename)
#define SET_LABEL_ACCESSIBLE(classname,accessiblename) SET_ACCESSIBLE_WITH_DESCRIPTION(classname,QAccessible::StaticText,"")\ #define SET_LABEL_ACCESSIBLE(classname,accessiblename) SET_LABEL_ACCESSIBLE_WITH_DESCRIPTION(classname,accessiblename,"")
FUNC_TEXT_BY_LABEL(classname,accessiblename)
#define SET_WIDGET_ACCESSIBLE(classname,aaccessibletype,accessiblename) SET_ACCESSIBLE_WITH_DESCRIPTION(classname,aaccessibletype,"");\ #define SET_SLIDER_ACCESSIBLE(classname,accessiblename) SET_SLIDER_ACCESSIBLE_WITH_DESCRIPTION(classname,accessiblename,"")
FUNC_TEXT(classname,accessiblename)
#define SET_EDITABLE_ACCESSIBLE(classname,accessiblename) SET_EDITABLE_ACCESSIBLE_WITH_DESCRIPTION(classname,accessiblename,"")
/************************************************************************************************/ /************************************************************************************************/
#endif // ACCESSIBLEDEFINE_H #endif // ACCESSIBLEINTERFACE_H

View File

@ -0,0 +1,30 @@
#ifndef SOUNDACCESSIBLE_H
#define SOUNDACCESSIBLE_H
#include "../frame/window/accessibledefine.h"
#include "sounditem.h"
#include "soundapplet.h"
#include "sinkinputwidget.h"
#include "./componments/volumeslider.h"
#include "./componments/horizontalseparator.h"
SET_BUTTON_ACCESSIBLE(SoundItem, "plugin-sounditem")
SET_FORM_ACCESSIBLE(SoundApplet, "soundapplet")
SET_FORM_ACCESSIBLE(SinkInputWidget, "sinkinputwidget")
SET_SLIDER_ACCESSIBLE(VolumeSlider, "volumeslider")
SET_FORM_ACCESSIBLE(HorizontalSeparator, "horizontalseparator")
QAccessibleInterface *soundAccessibleFactory(const QString &classname, QObject *object)
{
QAccessibleInterface *interface = nullptr;
USE_ACCESSIBLE(classname, SoundItem);
USE_ACCESSIBLE(classname, SoundApplet);
USE_ACCESSIBLE(classname, SinkInputWidget);
USE_ACCESSIBLE(classname, VolumeSlider);
USE_ACCESSIBLE(classname, HorizontalSeparator);
return interface;
}
#endif // SOUNDACCESSIBLE_H

View File

@ -20,7 +20,10 @@
*/ */
#include "soundplugin.h" #include "soundplugin.h"
#include "soundaccessible.h"
#include <QDebug> #include <QDebug>
#include <QAccessible>
#define STATE_KEY "enable" #define STATE_KEY "enable"
@ -28,6 +31,7 @@ SoundPlugin::SoundPlugin(QObject *parent)
: QObject(parent), : QObject(parent),
m_soundItem(nullptr) m_soundItem(nullptr)
{ {
QAccessible::installFactory(soundAccessibleFactory);
} }
const QString SoundPlugin::pluginName() const const QString SoundPlugin::pluginName() const

View File

@ -53,7 +53,6 @@ PopupControlWidget::PopupControlWidget(QWidget *parent)
{ {
connect(m_fsWatcher, &QFileSystemWatcher::directoryChanged, this, &PopupControlWidget::trashStatusChanged, Qt::QueuedConnection); connect(m_fsWatcher, &QFileSystemWatcher::directoryChanged, this, &PopupControlWidget::trashStatusChanged, Qt::QueuedConnection);
setObjectName("trash");
setFixedWidth(80); setFixedWidth(80);
trashStatusChanged(); trashStatusChanged();

View File

@ -37,7 +37,7 @@ TrashPlugin::TrashPlugin(QObject *parent)
, m_trashWidget(nullptr) , m_trashWidget(nullptr)
, m_tipsLabel(new TipsWidget) , m_tipsLabel(new TipsWidget)
{ {
m_tipsLabel->setObjectName("trash"); m_tipsLabel->setObjectName("trashtips");
} }
const QString TrashPlugin::pluginName() const const QString TrashPlugin::pluginName() const

View File

@ -59,6 +59,7 @@ SNITrayWidget::SNITrayWidget(const QString &sniServicePath, QWidget *parent)
arrowRectangle->setShadowXOffset(0); arrowRectangle->setShadowXOffset(0);
arrowRectangle->setArrowWidth(18); arrowRectangle->setArrowWidth(18);
arrowRectangle->setArrowHeight(10); arrowRectangle->setArrowHeight(10);
arrowRectangle->setObjectName("snitraypopup");
PopupWindow = arrowRectangle; PopupWindow = arrowRectangle;
} }

View File

@ -63,6 +63,7 @@ SystemTrayItem::SystemTrayItem(PluginsItemInterface *const pluginInter, const QS
arrowRectangle->setShadowXOffset(0); arrowRectangle->setShadowXOffset(0);
arrowRectangle->setArrowWidth(18); arrowRectangle->setArrowWidth(18);
arrowRectangle->setArrowHeight(10); arrowRectangle->setArrowHeight(10);
arrowRectangle->setObjectName("systemtraypopup");
PopupWindow = arrowRectangle; PopupWindow = arrowRectangle;
} }

View File

@ -1,6 +1,7 @@
#include "tipswidget.h" #include "tipswidget.h"
#include <QPainter> #include <QPainter>
#include <QAccessible>
TipsWidget::TipsWidget(QWidget *parent) : QFrame(parent) TipsWidget::TipsWidget(QWidget *parent) : QFrame(parent)
{ {
@ -15,6 +16,13 @@ void TipsWidget::setText(const QString &text)
setFixedSize(fontMetrics().width(text) + 6, fontMetrics().height()); setFixedSize(fontMetrics().width(text) + 6, fontMetrics().height());
update(); update();
#ifndef QT_NO_ACCESSIBILITY
if (accessibleName().isEmpty()) {
QAccessibleEvent event(this, QAccessible::NameChanged);
QAccessible::updateAccessibility(&event);
}
#endif
} }
void TipsWidget::setTextList(const QStringList &textList) void TipsWidget::setTextList(const QStringList &textList)