diff --git a/frontend/control/create-index-ask-dialog.cpp b/frontend/control/create-index-ask-dialog.cpp index 5d79699..dcf62d7 100644 --- a/frontend/control/create-index-ask-dialog.cpp +++ b/frontend/control/create-index-ask-dialog.cpp @@ -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); +} diff --git a/frontend/control/create-index-ask-dialog.h b/frontend/control/create-index-ask-dialog.h index a59c5f2..4be0ae4 100644 --- a/frontend/control/create-index-ask-dialog.h +++ b/frontend/control/create-index-ask-dialog.h @@ -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&); diff --git a/frontend/mainwindow.cpp b/frontend/mainwindow.cpp index 02c0d26..5d77297 100644 --- a/frontend/mainwindow.cpp +++ b/frontend/mainwindow.cpp @@ -96,7 +96,7 @@ MainWindow::~MainWindow() { if(m_settingsWidget) { delete m_settingsWidget; m_settingsWidget = NULL; - + } #endif if(m_askDialog) { delete m_askDialog; @@ -189,13 +189,13 @@ void MainWindow::initConnections() */ void MainWindow::bootOptionsFilter(QString opt) { if(opt == "-s" || opt == "--show") { - clearSearchResult(); - centerToScreen(this); - if(this->isHidden()) { + if (this->isHidden()) { + clearSearchResult(); + centerToScreen(this); this->show(); + this->m_searchBarWidget->setFocus(); + this->activateWindow(); } - this->m_searchBarWidget->setFocus(); - this->activateWindow(); } } @@ -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); +} diff --git a/frontend/mainwindow.h b/frontend/mainwindow.h index b7aa55b..2558654 100644 --- a/frontend/mainwindow.h +++ b/frontend/mainwindow.h @@ -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();