[FIX] bug:# 116337 【全局搜索】首次打开搜索输入内容,弹出是否创建索引框后win+s再次打开搜索,搜索只能通过alt+F4关闭

This commit is contained in:
hewenfei 2022-04-21 17:15:32 +08:00
parent 6eecb71daf
commit 8355b90ccc
4 changed files with 44 additions and 9 deletions

View File

@ -41,6 +41,8 @@ CreateIndexAskDialog::CreateIndexAskDialog(QWidget *parent) : QDialog(parent) {
this->setWindowTitle(tr("ukui-search")); this->setWindowTitle(tr("ukui-search"));
initUi(); initUi();
this->installEventFilter(this);
} }
void CreateIndexAskDialog::initUi() { void CreateIndexAskDialog::initUi() {
@ -74,7 +76,6 @@ void CreateIndexAskDialog::initUi() {
m_closeBtn->setFlat(true); m_closeBtn->setFlat(true);
connect(m_closeBtn, &QPushButton::clicked, this, [ = ]() { connect(m_closeBtn, &QPushButton::clicked, this, [ = ]() {
this->hide(); this->hide();
Q_EMIT this->closed();
}); });
m_titleLyt->addWidget(m_iconLabel); m_titleLyt->addWidget(m_iconLabel);
m_titleLyt->addWidget(m_titleLabel); m_titleLyt->addWidget(m_titleLabel);
@ -118,12 +119,10 @@ void CreateIndexAskDialog::initUi() {
connect(m_cancelBtn, &QPushButton::clicked, this, [ = ]() { connect(m_cancelBtn, &QPushButton::clicked, this, [ = ]() {
Q_EMIT this->btnClicked(false, m_checkBox->isChecked()); Q_EMIT this->btnClicked(false, m_checkBox->isChecked());
this->hide(); this->hide();
Q_EMIT this->closed();
}); });
connect(m_confirmBtn, &QPushButton::clicked, this, [ = ]() { connect(m_confirmBtn, &QPushButton::clicked, this, [ = ]() {
Q_EMIT this->btnClicked(true, m_checkBox->isChecked()); Q_EMIT this->btnClicked(true, m_checkBox->isChecked());
this->hide(); this->hide();
Q_EMIT this->closed();
}); });
m_btnLyt->addStretch(); m_btnLyt->addStretch();
m_btnLyt->addWidget(m_cancelBtn); m_btnLyt->addWidget(m_cancelBtn);
@ -150,3 +149,21 @@ void CreateIndexAskDialog::paintEvent(QPaintEvent *event) {
p.restore(); p.restore();
return QDialog::paintEvent(event); return QDialog::paintEvent(event);
} }
// esc按键直接调用hide产生hideEvent
void CreateIndexAskDialog::hideEvent(QHideEvent *event)
{
Q_EMIT this->closed();
QWidget::hideEvent(event);
}
bool CreateIndexAskDialog::eventFilter(QObject *watched, QEvent *event)
{
// kwin alt+f4发送的close事件会改变窗口的winid,屏蔽掉该事件并发送hide事件
if ((watched == this) && (event->type() == QEvent::Close)) {
event->ignore();
this->hide();
return true;
}
return QDialog::eventFilter(watched, event);
}

View File

@ -65,6 +65,10 @@ private:
void paintEvent(QPaintEvent *); void paintEvent(QPaintEvent *);
protected:
void hideEvent(QHideEvent *event) override;
bool eventFilter(QObject *watched, QEvent *event) override;
Q_SIGNALS: Q_SIGNALS:
void closed(); void closed();
void btnClicked(const bool&, const bool&); void btnClicked(const bool&, const bool&);

View File

@ -96,7 +96,7 @@ MainWindow::~MainWindow() {
if(m_settingsWidget) { if(m_settingsWidget) {
delete m_settingsWidget; delete m_settingsWidget;
m_settingsWidget = NULL; m_settingsWidget = NULL;
}
#endif #endif
if(m_askDialog) { if(m_askDialog) {
delete m_askDialog; delete m_askDialog;
@ -189,14 +189,14 @@ void MainWindow::initConnections()
*/ */
void MainWindow::bootOptionsFilter(QString opt) { void MainWindow::bootOptionsFilter(QString opt) {
if(opt == "-s" || opt == "--show") { if(opt == "-s" || opt == "--show") {
if (this->isHidden()) {
clearSearchResult(); clearSearchResult();
centerToScreen(this); centerToScreen(this);
if(this->isHidden()) {
this->show(); this->show();
}
this->m_searchBarWidget->setFocus(); this->m_searchBarWidget->setFocus();
this->activateWindow(); this->activateWindow();
} }
}
} }
/** /**
@ -555,3 +555,14 @@ void MainWindow::paintEvent(QPaintEvent *event) {
KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon())); KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon()));
} }
bool MainWindow::eventFilter(QObject *watched, QEvent *event)
{
//kwin alt+f4发出close事件, 需要在存在子窗口时屏蔽该事件
if ((watched == this) && (event->type() == QEvent::Close)) {
event->ignore();
tryHideMainwindow();
return true;
}
return QObject::eventFilter(watched, event);
}

View File

@ -84,6 +84,9 @@ protected:
void initUi(); void initUi();
void initConnections(); void initConnections();
public:
bool eventFilter(QObject *watched, QEvent *event) override;
Q_SIGNALS: Q_SIGNALS:
void searchMethodChanged(FileUtils::SearchMethod); void searchMethodChanged(FileUtils::SearchMethod);
void webEngineChanged(); void webEngineChanged();