From 8355b90ccc25e2a20d35a4263e6546aa88c34eb4 Mon Sep 17 00:00:00 2001 From: hewenfei Date: Thu, 21 Apr 2022 17:15:32 +0800 Subject: [PATCH] =?UTF-8?q?[FIX]=20bug:#=20116337=20=E3=80=90=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E6=90=9C=E7=B4=A2=E3=80=91=E9=A6=96=E6=AC=A1=E6=89=93?= =?UTF-8?q?=E5=BC=80=E6=90=9C=E7=B4=A2=E8=BE=93=E5=85=A5=E5=86=85=E5=AE=B9?= =?UTF-8?q?=EF=BC=8C=E5=BC=B9=E5=87=BA=E6=98=AF=E5=90=A6=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E7=B4=A2=E5=BC=95=E6=A1=86=E5=90=8Ewin+s=E5=86=8D=E6=AC=A1?= =?UTF-8?q?=E6=89=93=E5=BC=80=E6=90=9C=E7=B4=A2=EF=BC=8C=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=8F=AA=E8=83=BD=E9=80=9A=E8=BF=87alt+F4=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/control/create-index-ask-dialog.cpp | 23 +++++++++++++++++--- frontend/control/create-index-ask-dialog.h | 4 ++++ frontend/mainwindow.cpp | 23 +++++++++++++++----- frontend/mainwindow.h | 3 +++ 4 files changed, 44 insertions(+), 9 deletions(-) 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();