diff --git a/src/frontend/mainwindow.cpp b/src/frontend/mainwindow.cpp index d8754ee1..3c7b149b 100644 --- a/src/frontend/mainwindow.cpp +++ b/src/frontend/mainwindow.cpp @@ -154,6 +154,7 @@ void MainWindow::firstlyStart() { initWindowProperties(); initTransparency(); + registerTrayIcon(); initUI(); initDbusConnnect(); initWindowTheme(); @@ -229,6 +230,30 @@ void MainWindow::initWindowProperties() } } +/** + * @brief MainWindow::registerTrayIcon 注册托盘图标 + */ +void MainWindow::registerTrayIcon() +{ + m_registerCount++; + if (QSystemTrayIcon::isSystemTrayAvailable() || m_registerCount > 10) { + m_trayIcon = new QSystemTrayIcon(); + if (nullptr == m_trayIcon) { + qWarning()<< "分配空间trayIcon失败"; + return ; + } + m_trayIcon->setIcon(QIcon::fromTheme("network-wired-signal-excellent-symbolic")); + m_trayIcon->setToolTip(QString(tr("kylin-nm"))); + + } else { + if (m_registerCount <= 10) { + QTimer::singleShot(m_intervalTime,[this] { + registerTrayIcon(); + }); + } + } +} + void MainWindow::paintEvent(QPaintEvent *event) { QPainter painter(this); @@ -325,7 +350,6 @@ void MainWindow::initTrayIcon() iconTimer = new QTimer(this); connect(iconTimer, &QTimer::timeout, this, &MainWindow::onSetTrayIconLoading); - m_trayIcon = new QSystemTrayIcon(); m_trayIconMenu = new QMenu(); m_showMainwindowAction = new QAction(tr("Show MainWindow"),this); m_showSettingsAction = new QAction(tr("Settings"),this); @@ -334,7 +358,6 @@ void MainWindow::initTrayIcon() // m_trayIconMenu->addAction(m_showMainwindowAction); m_trayIconMenu->addAction(m_showSettingsAction); m_trayIcon->setContextMenu(m_trayIconMenu); - m_trayIcon->setIcon(QIcon::fromTheme("network-wired-signal-excellent-symbolic")); iconStatus = IconActiveType::LAN_CONNECTED; onRefreshTrayIcon(); @@ -994,6 +1017,7 @@ void MainWindow::showCreateWiredConnectWidget(const QString devName) }); m_createPagePtrMap.insert(devName, netDetail); netDetail->show(); + netDetail->centerToScreen(); } void MainWindow::showAddOtherWlanWidget(QString devName) diff --git a/src/frontend/mainwindow.h b/src/frontend/mainwindow.h index 4bf843e2..277ea6b0 100644 --- a/src/frontend/mainwindow.h +++ b/src/frontend/mainwindow.h @@ -155,6 +155,7 @@ private: void paintWithTrans(); void initUI(); void initDbusConnnect(); + void registerTrayIcon(); void initTrayIcon(); void resetTrayIconTool(); @@ -205,6 +206,9 @@ private: NetworkMode *m_networkMode; + uint m_intervalTime = 100; + uint m_registerCount = 0; + public Q_SLOTS: void onShowMainWindow(int type); diff --git a/src/frontend/netdetails/joinhiddenwifipage.cpp b/src/frontend/netdetails/joinhiddenwifipage.cpp index 58eb3537..9a908542 100644 --- a/src/frontend/netdetails/joinhiddenwifipage.cpp +++ b/src/frontend/netdetails/joinhiddenwifipage.cpp @@ -288,3 +288,18 @@ void JoinHiddenWiFiPage::onPaletteChanged() } } #endif + +void JoinHiddenWiFiPage::centerToScreen() +{ + QDesktopWidget* m = QApplication::desktop(); + QRect desk_rect = m->screenGeometry(m->screenNumber(QCursor::pos())); + int desk_x = desk_rect.width(); + int desk_y = desk_rect.height(); + int x = this->width(); + int y = this->height(); +// this->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top()); + kdk::WindowManager::setGeometry(this->windowHandle(), QRect(desk_x / 2 - x / 2 + desk_rect.left(), + desk_y / 2 - y / 2 + desk_rect.top(), + this->width(), + this->height())); +} diff --git a/src/frontend/netdetails/joinhiddenwifipage.h b/src/frontend/netdetails/joinhiddenwifipage.h index 2242c2cb..dd355361 100644 --- a/src/frontend/netdetails/joinhiddenwifipage.h +++ b/src/frontend/netdetails/joinhiddenwifipage.h @@ -24,7 +24,9 @@ #include #include #include +#include +#include "windowmanager/windowmanager.h" #include "coninfo.h" #include "kywirelessconnectoperation.h" #include "securitypage.h" @@ -43,6 +45,7 @@ public: JoinHiddenWiFiPage(QString devName, KDialog *parent = nullptr); ~JoinHiddenWiFiPage(); + void centerToScreen(); protected: void closeEvent(QCloseEvent *event); diff --git a/src/frontend/netdetails/netdetail.cpp b/src/frontend/netdetails/netdetail.cpp index dc9d43a8..80c8c2d3 100644 --- a/src/frontend/netdetails/netdetail.cpp +++ b/src/frontend/netdetails/netdetail.cpp @@ -293,11 +293,10 @@ void NetDetail::centerToScreen() int desk_y = desk_rect.height(); int x = this->width(); int y = this->height(); - this->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top()); -// kdk::WindowManager::setGeometry(this->windowHandle(), QRect(desk_x / 2 - x / 2 + desk_rect.left(), -// desk_y / 2 - y / 2 + desk_rect.top(), -// this->width(), -// this->height())); + kdk::WindowManager::setGeometry(this->windowHandle(), QRect(desk_x / 2 - x / 2 + desk_rect.left(), + desk_y / 2 - y / 2 + desk_rect.top(), + this->width(), + this->height())); } void NetDetail::initUI() diff --git a/src/frontend/netdetails/netdetail.h b/src/frontend/netdetails/netdetail.h index 3f0f7b72..40cced44 100644 --- a/src/frontend/netdetails/netdetail.h +++ b/src/frontend/netdetails/netdetail.h @@ -97,13 +97,14 @@ public: NetDetail(QString interface, QString name, QString uuid, bool isActive, bool isWlan, bool isCreateNet, QWidget *parent = nullptr); ~NetDetail(); + void centerToScreen(); + void paintEvent(QPaintEvent *event); void closeEvent(QCloseEvent *event); bool eventFilter(QObject *w, QEvent *event); private: void initUI(); - void centerToScreen(); void initComponent(); void getConInfo(ConInfo &conInfo); void loadPage(); diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index 55024ad1..6fc11972 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -1276,6 +1276,7 @@ void LanPage::showDetailPage(QString devName, QString uuid) NetDetail *netDetail = new NetDetail(devName, p_item->m_connectName, uuid, isActive, false, false); m_lanPagePtrMap.insert(p_item->m_connectPath, netDetail); netDetail->show(); + netDetail->centerToScreen(); connect(netDetail, &NetDetail::detailPageClose, [&](QString deviceName, QString lanName, QString lanUuid){ if (lanUuid.isEmpty()) { diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index 49bd5778..1206324f 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -1632,6 +1632,7 @@ void WlanPage::showHiddenWlanPage(QString devName) m_joinHiddenWiFiPagePtrMap.insert(devName, hiddenWiFi); hiddenWiFi->show(); + hiddenWiFi->centerToScreen(); } void WlanPage::showDetailPage(QString devName, QString ssid) @@ -1661,6 +1662,7 @@ void WlanPage::showDetailPage(QString devName, QString ssid) } }); netDetail->show(); + netDetail->centerToScreen(); return; }