commit
d1c1e02b4f
|
@ -115,6 +115,7 @@ void MainWindow::firstlyStart()
|
||||||
{
|
{
|
||||||
initWindowProperties();
|
initWindowProperties();
|
||||||
initTransparency();
|
initTransparency();
|
||||||
|
registerTrayIcon();
|
||||||
initUI();
|
initUI();
|
||||||
initDbusConnnect();
|
initDbusConnnect();
|
||||||
initWindowTheme();
|
initWindowTheme();
|
||||||
|
@ -265,6 +266,30 @@ void MainWindow::initUI()
|
||||||
paintWithTrans();
|
paintWithTrans();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief MainWindow::initTrayIcon 初始化托盘图标和托盘右键菜单
|
* @brief MainWindow::initTrayIcon 初始化托盘图标和托盘右键菜单
|
||||||
*/
|
*/
|
||||||
|
@ -285,17 +310,14 @@ void MainWindow::initTrayIcon()
|
||||||
iconTimer = new QTimer(this);
|
iconTimer = new QTimer(this);
|
||||||
connect(iconTimer, &QTimer::timeout, this, &MainWindow::onSetTrayIconLoading);
|
connect(iconTimer, &QTimer::timeout, this, &MainWindow::onSetTrayIconLoading);
|
||||||
|
|
||||||
m_trayIcon = new QSystemTrayIcon();
|
|
||||||
m_trayIconMenu = new QMenu();
|
m_trayIconMenu = new QMenu();
|
||||||
m_showMainwindowAction = new QAction(tr("Show MainWindow"),this);
|
m_showMainwindowAction = new QAction(tr("Show MainWindow"),this);
|
||||||
m_showSettingsAction = new QAction(tr("Settings"),this);
|
m_showSettingsAction = new QAction(tr("Settings"),this);
|
||||||
|
|
||||||
m_trayIcon->setToolTip(QString(tr("kylin-nm")));
|
|
||||||
m_showSettingsAction->setIcon(QIcon::fromTheme("document-page-setup-symbolic", QIcon(":/res/x/setup.png")) );
|
m_showSettingsAction->setIcon(QIcon::fromTheme("document-page-setup-symbolic", QIcon(":/res/x/setup.png")) );
|
||||||
// m_trayIconMenu->addAction(m_showMainwindowAction);
|
// m_trayIconMenu->addAction(m_showMainwindowAction);
|
||||||
m_trayIconMenu->addAction(m_showSettingsAction);
|
m_trayIconMenu->addAction(m_showSettingsAction);
|
||||||
|
|
||||||
m_trayIcon->setContextMenu(m_trayIconMenu);
|
m_trayIcon->setContextMenu(m_trayIconMenu);
|
||||||
m_trayIcon->setIcon(QIcon::fromTheme("network-wired-signal-excellent-symbolic"));
|
|
||||||
iconStatus = IconActiveType::LAN_CONNECTED;
|
iconStatus = IconActiveType::LAN_CONNECTED;
|
||||||
onRefreshTrayIcon();
|
onRefreshTrayIcon();
|
||||||
|
|
||||||
|
|
|
@ -124,6 +124,7 @@ private:
|
||||||
void paintWithTrans();
|
void paintWithTrans();
|
||||||
void initUI();
|
void initUI();
|
||||||
void initDbusConnnect();
|
void initDbusConnnect();
|
||||||
|
void registerTrayIcon();
|
||||||
void initTrayIcon();
|
void initTrayIcon();
|
||||||
void resetTrayIconTool();
|
void resetTrayIconTool();
|
||||||
void initWindowTheme();
|
void initWindowTheme();
|
||||||
|
@ -157,6 +158,8 @@ private:
|
||||||
QMenu * m_trayIconMenu = nullptr;
|
QMenu * m_trayIconMenu = nullptr;
|
||||||
QAction * m_showMainwindowAction = nullptr;
|
QAction * m_showMainwindowAction = nullptr;
|
||||||
QAction * m_showSettingsAction = nullptr;
|
QAction * m_showSettingsAction = nullptr;
|
||||||
|
uint m_intervalTime = 100;
|
||||||
|
uint m_registerCount = 0;
|
||||||
|
|
||||||
bool m_lanIsLoading = false;
|
bool m_lanIsLoading = false;
|
||||||
bool m_wlanIsLoading = false;
|
bool m_wlanIsLoading = false;
|
||||||
|
|
Loading…
Reference in New Issue