From 87f4170a5eed9ee25568f5c66302bf1b70440328 Mon Sep 17 00:00:00 2001 From: iaom Date: Thu, 23 Mar 2023 10:00:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0UI=E9=92=88=E5=AF=B9=E5=B1=8F?= =?UTF-8?q?=E5=B9=95=E5=B0=BA=E5=AF=B8=E5=8F=98=E5=8C=96=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=9B=B4=E6=96=B0=E4=BD=8D=E7=BD=AE=E6=93=8D?= =?UTF-8?q?=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/mainwindow.cpp | 26 ++++++-------------------- frontend/mainwindow.h | 12 ++---------- 2 files changed, 8 insertions(+), 30 deletions(-) diff --git a/frontend/mainwindow.cpp b/frontend/mainwindow.cpp index 6bcb226..832da4a 100644 --- a/frontend/mainwindow.cpp +++ b/frontend/mainwindow.cpp @@ -81,7 +81,6 @@ MainWindow::MainWindow(QWidget *parent) : installEventFilter(this); initConnections(); - // connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this,[&](WId activeWindowId){ // qDebug() << "activeWindowChanged!!!" << activeWindowId; // if (activeWindowId != this->winId()) { @@ -134,8 +133,7 @@ void MainWindow::initUi() { void MainWindow::initConnections() { connect(m_sys_tray_icon, &QSystemTrayIcon::activated, this, &MainWindow::trayIconActivatedSlot); - connect(QApplication::primaryScreen(), &QScreen::geometryChanged, this, &MainWindow::monitorResolutionChange); - connect(qApp, &QApplication::primaryScreenChanged, this, &MainWindow::primaryScreenChangedSlot); + connect(QApplication::primaryScreen(), &QScreen::geometryChanged, this, &MainWindow::ScreenGeometryChanged); connect(m_askDialog, &CreateIndexAskDialog::closed, this, [ = ]() { m_isAskDialogVisible = false; }); @@ -258,21 +256,11 @@ void MainWindow::tryHide() this->tryHideMainwindow(); } -/** - * @brief monitorResolutionChange 监听屏幕改变 - * @param rect - */ -void MainWindow::monitorResolutionChange(QRect rect) { +void MainWindow::ScreenGeometryChanged(QRect rect) { Q_UNUSED(rect); -} - -/** - * @brief primaryScreenChangedSlot 监听分辨率改变 - * @param screen - */ -void MainWindow::primaryScreenChangedSlot(QScreen *screen) { - Q_UNUSED(screen); - + if(this->isVisible()) { + centerToScreen(this); + } } /** @@ -336,12 +324,10 @@ void MainWindow::centerToScreen(QWidget* widget) { if(!widget) return; KWindowSystem::setState(this->winId(),NET::SkipTaskbar | NET::SkipPager); - QDesktopWidget* m = QApplication::desktop(); - QRect desk_rect = m->screenGeometry(m->screenNumber(QCursor::pos())); + QRect desk_rect = qApp->screenAt(QCursor::pos())->geometry(); int desk_x = desk_rect.width(); int desk_y = desk_rect.height(); int x = widget->width(); - int y = widget->height(); widget->show(); kdk::WindowManager::setGeometry(this->windowHandle(),QRect(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 3 + desk_rect.top(), diff --git a/frontend/mainwindow.h b/frontend/mainwindow.h index 7c03cfd..cb5ed84 100644 --- a/frontend/mainwindow.h +++ b/frontend/mainwindow.h @@ -87,16 +87,8 @@ public: bool eventFilter(QObject *watched, QEvent *event) override; public Q_SLOTS: - /** - * @brief Monitor screen resolution - * @param rect: Screen resolution - */ - void monitorResolutionChange(QRect rect); - /** - * @brief Monitor primary screen changes - * @param screen: Primary screen - */ - void primaryScreenChangedSlot(QScreen *screen); + + void ScreenGeometryChanged(QRect rect); void bootOptionsFilter(QString opt); // 过滤终端命令 void clearSearchResult(); //清空搜索结果 void trayIconActivatedSlot(QSystemTrayIcon::ActivationReason reason);