From 1057ce28af277fc669b702ce2ac0a5450d006613 Mon Sep 17 00:00:00 2001 From: fengshaoxiong Date: Fri, 29 May 2020 13:08:42 +0800 Subject: [PATCH] fix: show same accessible name after widget destroyed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 控件销毁后显示相同的标记名称 --- frame/panel/mainpanelcontrol.cpp | 2 +- frame/panel/mainpanelcontrol.h | 11 +++- frame/window/accessible.h | 3 +- frame/window/accessibledefine.h | 57 ++++++++++++++++--- frame/window/mainwindow.cpp | 1 + plugins/onboard/onboardplugin.cpp | 1 + plugins/shutdown/shutdownplugin.cpp | 1 + .../fashiontray/fashiontraywidgetwrapper.cpp | 1 + 8 files changed, 65 insertions(+), 12 deletions(-) diff --git a/frame/panel/mainpanelcontrol.cpp b/frame/panel/mainpanelcontrol.cpp index fc025099b..c33e605ac 100755 --- a/frame/panel/mainpanelcontrol.cpp +++ b/frame/panel/mainpanelcontrol.cpp @@ -61,7 +61,7 @@ MainPanelControl::MainPanelControl(QWidget *parent) , m_appAreaWidget(new QWidget(this)) , m_trayAreaWidget(new QWidget(this)) , m_pluginAreaWidget(new QWidget(this)) - , m_desktopWidget(new QWidget(this)) + , m_desktopWidget(new DesktopWidget(this)) , m_fixedAreaLayout(new QBoxLayout(QBoxLayout::LeftToRight)) , m_trayAreaLayout(new QBoxLayout(QBoxLayout::LeftToRight)) , m_pluginLayout(new QBoxLayout(QBoxLayout::LeftToRight)) diff --git a/frame/panel/mainpanelcontrol.h b/frame/panel/mainpanelcontrol.h index 0bb0d9dd8..fb510dd50 100755 --- a/frame/panel/mainpanelcontrol.h +++ b/frame/panel/mainpanelcontrol.h @@ -39,6 +39,15 @@ public: virtual bool appIsOnDock(const QString &appDesktop) = 0; }; +class DesktopWidget : public QWidget +{ + Q_OBJECT + +public: + DesktopWidget(QWidget *parent) : QWidget(parent){ + } +}; + class DockItem; class PlaceholderItem; class AppDragWidget; @@ -108,7 +117,7 @@ private: QWidget *m_appAreaWidget; QWidget *m_trayAreaWidget; QWidget *m_pluginAreaWidget; - QWidget *m_desktopWidget; + DesktopWidget *m_desktopWidget; QBoxLayout *m_fixedAreaLayout; QBoxLayout *m_trayAreaLayout; QBoxLayout *m_pluginLayout; diff --git a/frame/window/accessible.h b/frame/window/accessible.h index b6949dac0..e4736c461 100644 --- a/frame/window/accessible.h +++ b/frame/window/accessible.h @@ -93,7 +93,7 @@ SET_FORM_ACCESSIBLE(QWidget, m_w->objectName().isEmpty() ? "widget" : m_w->objec 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(DSwitchButton, m_w->text().isEmpty() ? "switchbutton" : m_w->text()) - +SET_BUTTON_ACCESSIBLE(DesktopWidget, "desktopWidget"); QAccessibleInterface *accessibleFactory(const QString &classname, QObject *object) { QAccessibleInterface *interface = nullptr; @@ -127,6 +127,7 @@ QAccessibleInterface *accessibleFactory(const QString &classname, QObject *objec // USE_ACCESSIBLE(classname, SinkInputWidget); // USE_ACCESSIBLE(classname, VolumeSlider); // USE_ACCESSIBLE(classname, HorizontalSeparator); + USE_ACCESSIBLE(classname, DesktopWidget); USE_ACCESSIBLE(classname, DatetimeWidget); USE_ACCESSIBLE(classname, OnboardItem); USE_ACCESSIBLE(classname, TrashWidget); diff --git a/frame/window/accessibledefine.h b/frame/window/accessibledefine.h index 800048bbe..9163f8d68 100644 --- a/frame/window/accessibledefine.h +++ b/frame/window/accessibledefine.h @@ -84,11 +84,21 @@ inline QString getAccessibleName(QWidget *w, QAccessible::Role r, const QString 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; } } @@ -219,18 +229,47 @@ inline QString getAccessibleName(QWidget *w, QAccessible::Role r, const QString }\ }\ QString text(int startOffset, int endOffset) const override;\ - void selection(int selectionIndex, 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 {}\ - void removeSelection(int selectionIndex) override {}\ - void setSelection(int selectionIndex, int startOffset, int endOffset) override {}\ + 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 {}\ + void setCursorPosition(int position) override {\ + Q_UNUSED(position)\ + }\ 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(); }\ + 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;\ diff --git a/frame/window/mainwindow.cpp b/frame/window/mainwindow.cpp index eeea05c49..5ddeeec79 100755 --- a/frame/window/mainwindow.cpp +++ b/frame/window/mainwindow.cpp @@ -60,6 +60,7 @@ private: public: DragWidget(QWidget *parent) : QWidget(parent) { + setObjectName(tr("DragWidget")); m_dragStatus = false; } diff --git a/plugins/onboard/onboardplugin.cpp b/plugins/onboard/onboardplugin.cpp index 8ce0db0fc..f4496a4a0 100644 --- a/plugins/onboard/onboardplugin.cpp +++ b/plugins/onboard/onboardplugin.cpp @@ -35,6 +35,7 @@ OnboardPlugin::OnboardPlugin(QObject *parent) { m_tipsLabel->setText(tr("Onboard")); m_tipsLabel->setVisible(false); + m_tipsLabel->setAccessibleName(tr("Onboard")); } const QString OnboardPlugin::pluginName() const diff --git a/plugins/shutdown/shutdownplugin.cpp b/plugins/shutdown/shutdownplugin.cpp index 787a95058..d64aaefa9 100644 --- a/plugins/shutdown/shutdownplugin.cpp +++ b/plugins/shutdown/shutdownplugin.cpp @@ -36,6 +36,7 @@ ShutdownPlugin::ShutdownPlugin(QObject *parent) { m_tipsLabel->setVisible(false); + m_tipsLabel->setAccessibleName(tr("shutdown")); } const QString ShutdownPlugin::pluginName() const diff --git a/plugins/tray/fashiontray/fashiontraywidgetwrapper.cpp b/plugins/tray/fashiontray/fashiontraywidgetwrapper.cpp index 30e471722..3336b0ff1 100644 --- a/plugins/tray/fashiontray/fashiontraywidgetwrapper.cpp +++ b/plugins/tray/fashiontray/fashiontraywidgetwrapper.cpp @@ -50,6 +50,7 @@ FashionTrayWidgetWrapper::FashionTrayWidgetWrapper(const QString &itemKey, Abstr { setStyleSheet("background: transparent;"); setAcceptDrops(true); + setObjectName(itemKey); m_layout->setSpacing(0); m_layout->setMargin(0);