Skip to content

Commit 2ffc900

Browse files
committed
fix: tray tips and popup display
1.use popupWindow for tray tips displaying 2.show tray plugin popup in lockContent Log: as title Pms: BUG-314221,BUG-312899
1 parent 18ecc5c commit 2ffc900

File tree

4 files changed

+97
-126
lines changed

4 files changed

+97
-126
lines changed

src/session-widgets/lockcontent.cpp

Lines changed: 59 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "controlwidget.h"
88
#include "logowidget.h"
99
#include "mfa_widget.h"
10-
#include "modules_loader.h"
1110
#include "popupwindow.h"
1211
#include "sessionbasemodel.h"
1312
#include "sfa_widget.h"
@@ -34,25 +33,10 @@ DCORE_USE_NAMESPACE
3433

3534
LockContent::LockContent(QWidget *parent)
3635
: SessionBaseWindow(parent)
37-
, m_model(nullptr)
38-
, m_controlWidget(nullptr)
39-
, m_centerTopWidget(nullptr)
40-
, m_virtualKB(nullptr)
4136
, m_wmInter(new com::deepin::wm("com.deepin.wm", "/com/deepin/wm", QDBusConnection::sessionBus(), this))
42-
, m_sfaWidget(nullptr)
43-
, m_mfaWidget(nullptr)
44-
, m_authWidget(nullptr)
45-
, m_fmaWidget(nullptr)
46-
, m_userListWidget(nullptr)
4737
, m_localServer(new QLocalServer(this))
4838
, m_currentModeStatus(SessionBaseModel::ModeStatus::NoStatus)
49-
, m_initialized(false)
50-
, m_isUserSwitchVisible(false)
51-
, m_popWin(nullptr)
52-
, m_isPANGUCpu(false)
53-
, m_MPRISEnable(false)
5439
, m_showMediaWidget(DConfigHelper::instance()->getConfig(SHOW_MEDIA_WIDGET, false).toBool())
55-
, m_hasResetPasswordDialog(false)
5640
{
5741

5842
}
@@ -143,7 +127,7 @@ void LockContent::initUI()
143127
m_logoWidget->setAccessibleName("LogoWidget");
144128
setLeftBottomWidget(m_logoWidget);
145129

146-
m_controlWidget = new ControlWidget(m_model);
130+
m_controlWidget = new ControlWidget(m_model, this);
147131
m_controlWidget->setAccessibleName("ControlWidget");
148132
setRightBottomWidget(m_controlWidget);
149133

@@ -176,6 +160,7 @@ void LockContent::initConnections()
176160
});
177161
connect(m_controlWidget, &ControlWidget::requestSwitchVirtualKB, this, &LockContent::toggleVirtualKB);
178162
connect(m_controlWidget, &ControlWidget::requestShowModule, this, &LockContent::showModule);
163+
connect(m_controlWidget, &ControlWidget::requestShowTrayModule, this, &LockContent::showTrayPopup);
179164

180165
// 刷新背景单独与onStatusChanged信号连接,避免在showEvent事件时调用onStatusChanged而重复刷新背景,减少刷新次数
181166
connect(m_model, &SessionBaseModel::onStatusChanged, this, &LockContent::onStatusChanged);
@@ -212,12 +197,6 @@ void LockContent::initConnections()
212197

213198
connect(m_wmInter, &com::deepin::wm::WorkspaceSwitched, this, &LockContent::currentWorkspaceChanged);
214199
connect(m_localServer, &QLocalServer::newConnection, this, &LockContent::onNewConnection);
215-
connect(m_controlWidget, &ControlWidget::notifyKeyboardLayoutHidden, this, [this]{
216-
if (!m_model->isUseWayland() && isVisible() && window()->windowHandle()) {
217-
qCDebug(DDE_SHELL) << "Grab keyboard after keyboard layout hidden";
218-
window()->windowHandle()->setKeyboardGrabEnabled(true);
219-
}
220-
});
221200

222201
connect(m_model, &SessionBaseModel::showUserList, this, &LockContent::showUserList);
223202
connect(m_model, &SessionBaseModel::showLockScreen, this, &LockContent::showLockScreen);
@@ -697,38 +676,7 @@ void LockContent::showModule(const QString &name, const bool callShowForce)
697676
qCWarning(DDE_SHELL) << "TrayButton or plugin`s content is null";
698677
return;
699678
}
700-
701-
if (!m_popWin) {
702-
m_popWin = new PopupWindow(this);
703-
connect(m_model, &SessionBaseModel::visibleChanged, this, [this] (const bool visible) {
704-
if (!visible) {
705-
m_popWin->hide();
706-
}
707-
});
708-
connect(m_popWin, &PopupWindow::visibleChanged, this, [this] (bool visible) {
709-
m_controlWidget->setCanShowMenu(!visible);
710-
});
711-
connect(qobject_cast<FloatingButton*>(m_currentTray), &FloatingButton::buttonHide, m_popWin, &PopupWindow::hide);
712-
connect(this, &LockContent::parentChanged, this, [this] {
713-
if (m_popWin && m_popWin->isVisible()) {
714-
const QPoint &point = mapFromGlobal(m_currentTray->mapToGlobal(QPoint(m_currentTray->size().width() / 2, 0)));
715-
m_popWin->show(point);
716-
}
717-
});
718-
}
719-
720-
// 隐藏后需要removeEventFilter,后期优化
721-
for (auto child : this->findChildren<QWidget*>()) {
722-
child->removeEventFilter(this);
723-
child->installEventFilter(this);
724-
}
725-
726-
if (!m_popWin->getContent() || m_popWin->getContent() != plugin->content())
727-
m_popWin->setContent(plugin->content());
728-
const QPoint &point = mapFromGlobal(m_currentTray->mapToGlobal(QPoint(m_currentTray->size().width() / 2, 0)));
729-
// 插件图标不显示,窗口不显示
730-
if (m_currentTray->isVisible())
731-
callShowForce ? m_popWin->show(point) : m_popWin->toggle(point);
679+
showTrayPopup(m_currentTray, plugin->content());
732680
break;
733681
}
734682
default:
@@ -748,7 +696,6 @@ bool LockContent::eventFilter(QObject *watched, QEvent *e)
748696
if ((watched == m_currentTray || isChild) && e->type() == QEvent::Enter) {
749697
Q_EMIT qobject_cast<FloatingButton*>(m_currentTray)->requestHideTips();
750698
} else if (watched != m_currentTray && !isChild && e->type() == QEvent::MouseButtonRelease) {
751-
QMouseEvent *ev = static_cast<QMouseEvent *>(e);
752699
if (!m_popWin->geometry().contains(this->mapFromGlobal(QCursor::pos()))) {
753700
m_popWin->hide();
754701
}
@@ -932,6 +879,62 @@ void LockContent::refreshLayout(SessionBaseModel::ModeStatus status)
932879
setBottomFrameVisible(status != SessionBaseModel::ModeStatus::ShutDownMode);
933880
}
934881

882+
void LockContent::showTrayPopup(QWidget *trayWidget, QWidget *contentWidget, const bool callShowForce)
883+
{
884+
if (!trayWidget || !contentWidget) {
885+
return;
886+
}
887+
888+
if (!m_popWin) {
889+
m_popWin = new PopupWindow(this);
890+
connect(m_model, &SessionBaseModel::visibleChanged, this, [this] (const bool visible) {
891+
if (!visible) {
892+
m_popWin->hide();
893+
}
894+
});
895+
connect(m_popWin, &PopupWindow::visibleChanged, this, [this] (bool visible) {
896+
m_controlWidget->setCanShowMenu(!visible);
897+
// BUG-134087, tray popup窗口隐藏后,锁屏界面需要重新抓取键盘
898+
if (!visible && !m_model->isUseWayland() && isVisible() && window()->windowHandle()) {
899+
qCDebug(DDE_SHELL) << "Grab keyboard after keyboard layout hidden";
900+
window()->windowHandle()->setKeyboardGrabEnabled(true);
901+
}
902+
});
903+
904+
connect(this, &LockContent::parentChanged, this, [this] {
905+
if (m_popWin && m_popWin->isVisible()) {
906+
const QPoint &point = mapFromGlobal(m_currentTray->mapToGlobal(QPoint(m_currentTray->size().width() / 2, 0)));
907+
m_popWin->show(point);
908+
}
909+
});
910+
911+
// for BUG-256133
912+
connect(m_model, &SessionBaseModel::onStatusChanged, this, [this] (SessionBaseModel::ModeStatus status) {
913+
if (status != SessionBaseModel::ModeStatus::PasswordMode) {
914+
m_popWin->hide();
915+
}
916+
});
917+
}
918+
919+
m_currentTray = trayWidget;
920+
921+
// 隐藏后需要removeEventFilter,后期优化
922+
for (auto child : this->findChildren<QWidget*>()) {
923+
child->removeEventFilter(this);
924+
child->installEventFilter(this);
925+
}
926+
927+
if (!m_popWin->getContent() || m_popWin->getContent() != contentWidget)
928+
m_popWin->setContent(contentWidget);
929+
930+
const QPoint point = mapFromGlobal(m_currentTray->mapToGlobal(QPoint(m_currentTray->size().width() / 2, 0)));
931+
// 插件图标不显示,窗口不显示
932+
if (m_currentTray->isVisible()) {
933+
m_popWin->move(point.x(), point.y());
934+
callShowForce ? m_popWin->show(point) : m_popWin->toggle(point);
935+
}
936+
}
937+
935938
void LockContent::keyPressEvent(QKeyEvent *event)
936939
{
937940
switch (event->key()) {

src/session-widgets/lockcontent.h

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public slots:
9292
void updateWallpaper(const QString &path);
9393
void refreshBackground(SessionBaseModel::ModeStatus status);
9494
void refreshLayout(SessionBaseModel::ModeStatus status);
95+
void showTrayPopup(QWidget *trayWidget, QWidget *contentWidget, const bool callShowForce = false);
9596

9697
void initUI();
9798
void initConnections();
@@ -102,36 +103,36 @@ public slots:
102103
void enableSystemShortcut(const QStringList &shortcuts, bool enabled, bool isPersistent);
103104

104105
protected:
105-
SessionBaseModel *m_model;
106-
ControlWidget *m_controlWidget;
107-
CenterTopWidget *m_centerTopWidget;
108-
ShutdownWidget *m_shutdownFrame;
109-
QPointer<QWidget> m_virtualKB;
106+
SessionBaseModel *m_model = nullptr;
107+
ControlWidget *m_controlWidget = nullptr;
108+
CenterTopWidget *m_centerTopWidget = nullptr;
109+
ShutdownWidget *m_shutdownFrame = nullptr;
110+
QPointer<QWidget> m_virtualKB = nullptr;
110111
std::shared_ptr<User> m_user;
111112
QList<QMetaObject::Connection> m_currentUserConnects;
112-
LogoWidget *m_logoWidget;
113+
LogoWidget *m_logoWidget = nullptr;
113114
MediaWidget *m_mediaWidget = nullptr;
114-
com::deepin::wm *m_wmInter;
115-
QWidget *m_loginWidget;
115+
com::deepin::wm *m_wmInter = nullptr;
116+
QWidget *m_loginWidget = nullptr;
116117

117-
SFAWidget *m_sfaWidget;
118-
MFAWidget *m_mfaWidget;
119-
AuthWidget *m_authWidget;
120-
FullManagedAuthWidget *m_fmaWidget;
121-
UserFrameList *m_userListWidget;
118+
SFAWidget *m_sfaWidget = nullptr;
119+
MFAWidget *m_mfaWidget = nullptr;
120+
AuthWidget *m_authWidget = nullptr;
121+
FullManagedAuthWidget *m_fmaWidget = nullptr;
122+
UserFrameList *m_userListWidget = nullptr;
122123

123124
int m_failures = 0;
124-
QLocalServer *m_localServer;
125+
QLocalServer *m_localServer = nullptr;
125126
SessionBaseModel::ModeStatus m_currentModeStatus;
126-
bool m_initialized;
127-
bool m_isUserSwitchVisible;
128-
PopupWindow *m_popWin;
129-
QPointer<QWidget> m_currentTray;
130-
131-
bool m_isPANGUCpu;
132-
bool m_MPRISEnable;
133-
bool m_showMediaWidget;
134-
bool m_hasResetPasswordDialog;
127+
bool m_initialized = false;
128+
bool m_isUserSwitchVisible = false;
129+
PopupWindow *m_popWin = nullptr;
130+
QPointer<QWidget> m_currentTray = nullptr;
131+
132+
bool m_isPANGUCpu = false;
133+
bool m_MPRISEnable = false;
134+
bool m_showMediaWidget = false;
135+
bool m_hasResetPasswordDialog = false;
135136
};
136137

137138
#endif // LOCKCONTENT_H

src/widgets/controlwidget.cpp

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
#include "controlwidget.h"
66
#include "sessionbasemodel.h"
77
#include "kblayoutlistview.h"
8-
#include "modules_loader.h"
9-
#include "tipswidget.h"
108
#include "public_func.h"
119
#include "plugin_manager.h"
1210
#include "dconfig_helper.h"
11+
#include "popupwindow.h"
1312

1413
#include <DFloatingButton>
1514
#include <DArrowRectangle>
@@ -88,10 +87,7 @@ void FloatingButton::paintEvent(QPaintEvent *event)
8887
ControlWidget::ControlWidget(const SessionBaseModel *model, QWidget *parent)
8988
: QWidget(parent)
9089
, m_contextMenu(new QMenu(this))
91-
, m_tipsWidget(new TipsWidget())
92-
, m_arrowRectWidget(new DArrowRectangle(DArrowRectangle::ArrowBottom, this))
93-
, m_kbLayoutListView(nullptr)
94-
, m_keyboardBtn(nullptr)
90+
, m_tipsWidget(new PopupWindow(parent))
9591
, m_onboardBtnVisible(true)
9692
, m_doGrabKeyboard(true)
9793
, m_canShowMenu(true)
@@ -144,26 +140,6 @@ void ControlWidget::initKeyboardLayoutList()
144140
if (!languageList.isEmpty())
145141
static_cast<QAbstractButton *>(m_keyboardBtn)->setText(languageList.at(0).toUpper());
146142

147-
// 无特效模式时,让窗口圆角
148-
m_arrowRectWidget->setProperty("_d_radius_force", true);
149-
m_arrowRectWidget->setWindowFlags(Qt::Popup | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint | Qt::WindowStaysOnTopHint);
150-
m_arrowRectWidget->setMargin(0);
151-
m_arrowRectWidget->setShadowBlurRadius(20);
152-
m_arrowRectWidget->setRadius(6);
153-
m_arrowRectWidget->setShadowYOffset(2);
154-
m_arrowRectWidget->setShadowXOffset(0);
155-
m_arrowRectWidget->setArrowWidth(18);
156-
m_arrowRectWidget->setArrowHeight(10);
157-
m_arrowRectWidget->setMinimumWidth(DDESESSIONCC::KEYBOARD_LAYOUT_WIDTH);
158-
m_arrowRectWidget->setMaximumSize(DDESESSIONCC::KEYBOARD_LAYOUT_WIDTH, DDESESSIONCC::LAYOUT_BUTTON_HEIGHT * 7);
159-
m_arrowRectWidget->setFocusPolicy(Qt::NoFocus);
160-
m_arrowRectWidget->setBackgroundColor(QColor(235, 235, 235, int(0.05 * 255)));
161-
m_arrowRectWidget->installEventFilter(this);
162-
163-
QPalette pal = m_arrowRectWidget->palette();
164-
pal.setColor(DPalette::Inactive, DPalette::Base, QColor(235, 235, 235, int(0.05 * 255)));
165-
setPalette(pal);
166-
167143
connect(m_kbLayoutListView, &KBLayoutListView::itemClicked, this, &ControlWidget::onItemClicked);
168144
}
169145

@@ -399,16 +375,16 @@ void ControlWidget::addModule(TrayPlugin *trayModule)
399375
});
400376

401377
connect(button, &FloatingButton::requestShowTips, this, [=] {
402-
if (trayModule->itemTipsWidget() && !trayModule->content()->isVisible()) {
378+
if (trayModule->itemTipsWidget() && !trayModule->content()->isVisible() && topLevelWidget()) {
403379
m_tipsWidget->setContent(trayModule->itemTipsWidget());
404380
// 因为密码框需要一直获取焦点,会导致TipsWidget在间隙时间内的Visible变为false
405381
// DArrowRectangle::show中当Visible为false时会activateWindow,抢占密码框焦点
406382
// 所以这里手动设置visible为true
407-
int x = mapToGlobal(button->pos()).x() + button->width() / 2;
408-
int y = mapToGlobal(button->pos()).y();
383+
int x = mapTo(topLevelWidget(), button->pos()).x() + button->width() / 2;
384+
int y = mapTo(topLevelWidget(), button->pos()).y();
409385
m_tipsWidget->move(x, y);
410386
m_tipsWidget->setVisible(true);
411-
m_tipsWidget->show(x, y);
387+
m_tipsWidget->show(QPoint(x, y));
412388
}
413389
});
414390

@@ -636,14 +612,7 @@ void ControlWidget::setKBLayoutVisible()
636612
if (!layoutButton)
637613
return;
638614

639-
if (!m_arrowRectWidget->getContent()) {
640-
m_arrowRectWidget->setContent(m_kbLayoutListView);
641-
}
642-
m_arrowRectWidget->resize(m_kbLayoutListView->size() + QSize(0, 10));
643-
644-
QPoint pos = QPoint(mapToGlobal(layoutButton->pos()).x() + layoutButton->width() / 2, mapToGlobal(layoutButton->pos()).y());
645-
m_arrowRectWidget->move(pos.x(), pos.y());
646-
m_arrowRectWidget->setVisible(!m_arrowRectWidget->isVisible());
615+
Q_EMIT requestShowTrayModule(layoutButton, m_kbLayoutListView);
647616
}
648617

649618
void ControlWidget::setKeyboardType(const QString &str)
@@ -681,7 +650,8 @@ void ControlWidget::onItemClicked(const QString &str)
681650
currentText = currentText.split("/").last();
682651

683652
static_cast<QAbstractButton *>(m_keyboardBtn)->setText(currentText.toUpper());
684-
m_arrowRectWidget->hide();
653+
// hide keyboard layout popup
654+
Q_EMIT requestShowTrayModule(m_keyboardBtn, m_kbLayoutListView);
685655
m_curUser->setKeyboardLayout(str);
686656
}
687657

@@ -722,10 +692,6 @@ bool ControlWidget::eventFilter(QObject *watched, QEvent *event)
722692
}
723693
}
724694

725-
if (watched == m_arrowRectWidget && event->type() == QEvent::Hide) {
726-
emit notifyKeyboardLayoutHidden();
727-
}
728-
729695
#else
730696
Q_UNUSED(watched);
731697
Q_UNUSED(event);

src/widgets/controlwidget.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class QMenu;
3838
class SessionBaseModel;
3939
class KBLayoutListView;
4040
class TipsWidget;
41+
class PopupWindow;
4142

4243
const int BlurRadius = 15;
4344
const int BlurTransparency = 70;
@@ -106,6 +107,7 @@ class ControlWidget : public QWidget
106107
void requestSwitchVirtualKB();
107108
void requestKeyboardLayout(const QPoint &pos);
108109
void requestShowModule(const QString &name, const bool callShowForce = false);
110+
void requestShowTrayModule(QWidget *trayWidget, QWidget *contentWidget, const bool callShowForce = false);
109111
void notifyKeyboardLayoutHidden();
110112

111113
public slots:
@@ -157,12 +159,11 @@ public slots:
157159
QMap<QString, bool> m_modulesVisible;
158160

159161
QMenu *m_contextMenu;
160-
TipsWidget *m_tipsWidget;
162+
PopupWindow *m_tipsWidget = nullptr;
161163
const SessionBaseModel *m_model;
162164

163-
DArrowRectangle *m_arrowRectWidget;
164-
KBLayoutListView *m_kbLayoutListView; // 键盘布局列表
165-
DFloatingButton *m_keyboardBtn; // 键盘布局按钮
165+
KBLayoutListView *m_kbLayoutListView = nullptr; // 键盘布局列表
166+
FloatingButton *m_keyboardBtn = nullptr; // 键盘布局按钮
166167
std::shared_ptr<User> m_curUser;
167168
QList<QMetaObject::Connection> m_connectionList;
168169
bool m_onboardBtnVisible;

0 commit comments

Comments
 (0)