fix(frontend):修改索引弹窗和搜索框之间的交互逻辑

索引弹窗出现不影响搜索框功能,无论如何搜索框都会失焦退出,除非焦点被索引弹窗夺走;快捷键和任务栏按钮触发无论如何都会开关搜索框,不受弹窗影响;
This commit is contained in:
JunjieBai 2023-12-25 10:03:52 +08:00
parent 59434e6129
commit 8f71e3e7c6
4 changed files with 16 additions and 4 deletions

View File

@ -167,5 +167,10 @@ bool CreateIndexAskDialog::eventFilter(QObject *watched, QEvent *event)
this->hide(); this->hide();
return true; return true;
} }
if (event->type() == QEvent::ActivationChange) {
if (QApplication::activeWindow() != this) {
Q_EMIT this->focusChanged();
}
}
return QDialog::eventFilter(watched, event); return QDialog::eventFilter(watched, event);
} }

View File

@ -72,6 +72,7 @@ protected:
Q_SIGNALS: Q_SIGNALS:
void closed(); void closed();
void btnClicked(const bool&, const bool&); void btnClicked(const bool&, const bool&);
void focusChanged();
}; };
} }

View File

@ -155,6 +155,11 @@ void MainWindow::initConnections()
connect(m_askDialog, &CreateIndexAskDialog::btnClicked, this, [ = ](const bool &isCreateIndex, const bool &isAskAgain) { connect(m_askDialog, &CreateIndexAskDialog::btnClicked, this, [ = ](const bool &isCreateIndex, const bool &isAskAgain) {
setSearchMethodConfig(isCreateIndex, 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(m_settingsBtn, &QPushButton::clicked, this, &MainWindow::settingsBtnClickedSlot);
//主题改变时,更新自定义标题栏的图标 //主题改变时,更新自定义标题栏的图标
// connect(qApp, &QApplication::paletteChanged, this, [ = ]() { // connect(qApp, &QApplication::paletteChanged, this, [ = ]() {
@ -178,6 +183,7 @@ void MainWindow::bootOptionsFilter(QString opt) {
this->m_searchBarWidget->setFocus(); this->m_searchBarWidget->setFocus();
} }
this->activateWindow(); this->activateWindow();
this->raise();
} }
} }
@ -200,8 +206,8 @@ void MainWindow::trayIconActivatedSlot(QSystemTrayIcon::ActivationReason reason)
clearSearchResult(); clearSearchResult();
centerToScreen(this); centerToScreen(this);
// this->m_searchLineEdit->focusIn(); //打开主界面时输入框夺焦,可直接输入 // this->m_searchLineEdit->focusIn(); //打开主界面时输入框夺焦,可直接输入
this->raise();
this->activateWindow(); this->activateWindow();
this->raise();
} else { } else {
tryHideMainwindow(); tryHideMainwindow();
} }
@ -377,7 +383,7 @@ void MainWindow::initTimer() {
*/ */
bool MainWindow::tryHideMainwindow() bool MainWindow::tryHideMainwindow()
{ {
if (!m_isAskDialogVisible && QApplication::activeModalWidget() == nullptr) { if (QApplication::activeModalWidget() == nullptr) {
qDebug()<<"Mainwindow will be hidden"; qDebug()<<"Mainwindow will be hidden";
m_currentSearchAsked = false; m_currentSearchAsked = false;
m_askTimer->stop(); m_askTimer->stop();
@ -454,7 +460,7 @@ bool MainWindow::eventFilter(QObject *watched, QEvent *event)
if (watched == this) { if (watched == this) {
//失焦退出 //失焦退出
if (event->type() == QEvent::ActivationChange) { if (event->type() == QEvent::ActivationChange) {
if (QApplication::activeWindow() != this) { if (QApplication::activeWindow() != this && QApplication::activeWindow() != m_askDialog) {
tryHideMainwindow(); tryHideMainwindow();
return true; return true;
} }

View File

@ -151,7 +151,7 @@ void UkuiSearchDbusServices::onSearchKeyword(const QString &display, const QStri
void UkuiSearchDbusServices::onMainWindowSwitch(const QString &display) void UkuiSearchDbusServices::onMainWindowSwitch(const QString &display)
{ {
if(m_display == display) { if(m_display == display) {
if (m_mainWindow->isActiveWindow()) { if (m_mainWindow->isVisible()) {
m_mainWindow->tryHide(); m_mainWindow->tryHide();
} else { } else {
m_mainWindow->bootOptionsFilter("-s"); m_mainWindow->bootOptionsFilter("-s");