From 8f71e3e7c6c09ba7b7770273567b0273a3dfd4fe Mon Sep 17 00:00:00 2001 From: JunjieBai Date: Mon, 25 Dec 2023 10:03:52 +0800 Subject: [PATCH] =?UTF-8?q?fix(frontend):=E4=BF=AE=E6=94=B9=E7=B4=A2?= =?UTF-8?q?=E5=BC=95=E5=BC=B9=E7=AA=97=E5=92=8C=E6=90=9C=E7=B4=A2=E6=A1=86?= =?UTF-8?q?=E4=B9=8B=E9=97=B4=E7=9A=84=E4=BA=A4=E4=BA=92=E9=80=BB=E8=BE=91?= =?UTF-8?q?=20=E7=B4=A2=E5=BC=95=E5=BC=B9=E7=AA=97=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E4=B8=8D=E5=BD=B1=E5=93=8D=E6=90=9C=E7=B4=A2=E6=A1=86=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E6=97=A0=E8=AE=BA=E5=A6=82=E4=BD=95=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=A1=86=E9=83=BD=E4=BC=9A=E5=A4=B1=E7=84=A6=E9=80=80?= =?UTF-8?q?=E5=87=BA=EF=BC=8C=E9=99=A4=E9=9D=9E=E7=84=A6=E7=82=B9=E8=A2=AB?= =?UTF-8?q?=E7=B4=A2=E5=BC=95=E5=BC=B9=E7=AA=97=E5=A4=BA=E8=B5=B0=EF=BC=9B?= =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E9=94=AE=E5=92=8C=E4=BB=BB=E5=8A=A1=E6=A0=8F?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E8=A7=A6=E5=8F=91=E6=97=A0=E8=AE=BA=E5=A6=82?= =?UTF-8?q?=E4=BD=95=E9=83=BD=E4=BC=9A=E5=BC=80=E5=85=B3=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E6=A1=86=EF=BC=8C=E4=B8=8D=E5=8F=97=E5=BC=B9=E7=AA=97=E5=BD=B1?= =?UTF-8?q?=E5=93=8D=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/control/create-index-ask-dialog.cpp | 5 +++++ frontend/control/create-index-ask-dialog.h | 1 + frontend/mainwindow.cpp | 12 +++++++++--- frontend/ukui-search-dbus-service.cpp | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/frontend/control/create-index-ask-dialog.cpp b/frontend/control/create-index-ask-dialog.cpp index 5c2a16a..8724ec4 100644 --- a/frontend/control/create-index-ask-dialog.cpp +++ b/frontend/control/create-index-ask-dialog.cpp @@ -167,5 +167,10 @@ bool CreateIndexAskDialog::eventFilter(QObject *watched, QEvent *event) this->hide(); return true; } + if (event->type() == QEvent::ActivationChange) { + if (QApplication::activeWindow() != this) { + Q_EMIT this->focusChanged(); + } + } return QDialog::eventFilter(watched, event); } diff --git a/frontend/control/create-index-ask-dialog.h b/frontend/control/create-index-ask-dialog.h index 4be0ae4..9d3d9f5 100644 --- a/frontend/control/create-index-ask-dialog.h +++ b/frontend/control/create-index-ask-dialog.h @@ -72,6 +72,7 @@ protected: Q_SIGNALS: void closed(); void btnClicked(const bool&, const bool&); + void focusChanged(); }; } diff --git a/frontend/mainwindow.cpp b/frontend/mainwindow.cpp index f9c980d..f9a6f11 100644 --- a/frontend/mainwindow.cpp +++ b/frontend/mainwindow.cpp @@ -155,6 +155,11 @@ void MainWindow::initConnections() connect(m_askDialog, &CreateIndexAskDialog::btnClicked, this, [ = ](const bool &isCreateIndex, const bool &isAskAgain) { setSearchMethodConfig(isCreateIndex, isAskAgain); }); + connect(m_askDialog, &CreateIndexAskDialog::focusChanged, this, [ & ] { + if (QApplication::activeWindow() != this) { + this->tryHideMainwindow(); + } + }); // connect(m_settingsBtn, &QPushButton::clicked, this, &MainWindow::settingsBtnClickedSlot); //主题改变时,更新自定义标题栏的图标 // connect(qApp, &QApplication::paletteChanged, this, [ = ]() { @@ -178,6 +183,7 @@ void MainWindow::bootOptionsFilter(QString opt) { this->m_searchBarWidget->setFocus(); } this->activateWindow(); + this->raise(); } } @@ -200,8 +206,8 @@ void MainWindow::trayIconActivatedSlot(QSystemTrayIcon::ActivationReason reason) clearSearchResult(); centerToScreen(this); // this->m_searchLineEdit->focusIn(); //打开主界面时输入框夺焦,可直接输入 - this->raise(); this->activateWindow(); + this->raise(); } else { tryHideMainwindow(); } @@ -377,7 +383,7 @@ void MainWindow::initTimer() { */ bool MainWindow::tryHideMainwindow() { - if (!m_isAskDialogVisible && QApplication::activeModalWidget() == nullptr) { + if (QApplication::activeModalWidget() == nullptr) { qDebug()<<"Mainwindow will be hidden"; m_currentSearchAsked = false; m_askTimer->stop(); @@ -454,7 +460,7 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event) if (watched == this) { //失焦退出 if (event->type() == QEvent::ActivationChange) { - if (QApplication::activeWindow() != this) { + if (QApplication::activeWindow() != this && QApplication::activeWindow() != m_askDialog) { tryHideMainwindow(); return true; } diff --git a/frontend/ukui-search-dbus-service.cpp b/frontend/ukui-search-dbus-service.cpp index f18958c..524c101 100644 --- a/frontend/ukui-search-dbus-service.cpp +++ b/frontend/ukui-search-dbus-service.cpp @@ -151,7 +151,7 @@ void UkuiSearchDbusServices::onSearchKeyword(const QString &display, const QStri void UkuiSearchDbusServices::onMainWindowSwitch(const QString &display) { if(m_display == display) { - if (m_mainWindow->isActiveWindow()) { + if (m_mainWindow->isVisible()) { m_mainWindow->tryHide(); } else { m_mainWindow->bootOptionsFilter("-s");