[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"));
initUi();
this->installEventFilter(this);
}
void CreateIndexAskDialog::initUi() {
@ -74,7 +76,6 @@ void CreateIndexAskDialog::initUi() {
m_closeBtn->setFlat(true);
connect(m_closeBtn, &QPushButton::clicked, this, [ = ]() {
this->hide();
Q_EMIT this->closed();
});
m_titleLyt->addWidget(m_iconLabel);
m_titleLyt->addWidget(m_titleLabel);
@ -118,12 +119,10 @@ void CreateIndexAskDialog::initUi() {
connect(m_cancelBtn, &QPushButton::clicked, this, [ = ]() {
Q_EMIT this->btnClicked(false, m_checkBox->isChecked());
this->hide();
Q_EMIT this->closed();
});
connect(m_confirmBtn, &QPushButton::clicked, this, [ = ]() {
Q_EMIT this->btnClicked(true, m_checkBox->isChecked());
this->hide();
Q_EMIT this->closed();
});
m_btnLyt->addStretch();
m_btnLyt->addWidget(m_cancelBtn);
@ -150,3 +149,21 @@ void CreateIndexAskDialog::paintEvent(QPaintEvent *event) {
p.restore();
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 *);
protected:
void hideEvent(QHideEvent *event) override;
bool eventFilter(QObject *watched, QEvent *event) override;
Q_SIGNALS:
void closed();
void btnClicked(const bool&, const bool&);

View File

@ -96,7 +96,7 @@ MainWindow::~MainWindow() {
if(m_settingsWidget) {
delete m_settingsWidget;
m_settingsWidget = NULL;
}
#endif
if(m_askDialog) {
delete m_askDialog;
@ -189,15 +189,15 @@ void MainWindow::initConnections()
*/
void MainWindow::bootOptionsFilter(QString opt) {
if(opt == "-s" || opt == "--show") {
if (this->isHidden()) {
clearSearchResult();
centerToScreen(this);
if(this->isHidden()) {
this->show();
}
this->m_searchBarWidget->setFocus();
this->activateWindow();
}
}
}
/**
* @brief clearSearchResult
@ -555,3 +555,14 @@ void MainWindow::paintEvent(QPaintEvent *event) {
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 initConnections();
public:
bool eventFilter(QObject *watched, QEvent *event) override;
Q_SIGNALS:
void searchMethodChanged(FileUtils::SearchMethod);
void webEngineChanged();