Optimize code.

This commit is contained in:
zhangjiaping 2021-08-16 16:54:12 +08:00
parent df6d30e66f
commit 06b0e4c513
13 changed files with 315 additions and 277 deletions

View File

@ -12,16 +12,27 @@ QSize CustomStyle::sizeFromContents(QStyle::ContentsType type, const QStyleOptio
QSize size(0,40);
if (const QStyleOptionTab *tab= qstyleoption_cast<const QStyleOptionTab *>(option)) {
switch (tab->shape) {
case QTabBar::RoundedNorth: case QTabBar::RoundedSouth:
case QTabBar::RoundedNorth:
case QTabBar::RoundedSouth: {
return size + QSize(50,0);
case QTabBar::RoundedWest: case QTabBar::RoundedEast:
break;
}
case QTabBar::RoundedWest:
case QTabBar::RoundedEast: {
return size + QSize(0,50);
default: break;
break;
}
default: {
break;
}
}
}
return size;
} break;
default: break;
break;
}
default: {
break;
}
}
return QProxyStyle::sizeFromContents(type, option, contentsSize, widget);
}
@ -38,7 +49,9 @@ void CustomStyle::drawControl(QStyle::ControlElement element, const QStyleOption
// }
// break;
// }
// default: break;
// default: {
// break;
// }
// }
return QProxyStyle::drawControl(element, option, painter, widget);
}

View File

@ -24,8 +24,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
*/
void MainWindow::showMainwindow()
{
if (!m_load_finished) {
m_secondary_start_timer->stop();
if (!m_loadFinished) {
m_secondaryStartTimer->stop();
secondaryStart();
}
this->resetWindowPosition();
@ -52,12 +52,12 @@ void MainWindow::firstlyStart()
initWindowTheme();
initTrayIcon();
installEventFilter(this);
m_secondary_start_timer = new QTimer(this);
connect(m_secondary_start_timer, &QTimer::timeout, this, [ = ]() {
m_secondary_start_timer->stop();
m_secondaryStartTimer = new QTimer(this);
connect(m_secondaryStartTimer, &QTimer::timeout, this, [ = ]() {
m_secondaryStartTimer->stop();
secondaryStart();//满足条件后执行比较耗时的二级启动
});
m_secondary_start_timer->start(5 * 1000);
m_secondaryStartTimer->start(5 * 1000);
}
/**
@ -65,9 +65,9 @@ void MainWindow::firstlyStart()
*/
void MainWindow::secondaryStart()
{
if (m_load_finished)
if (m_loadFinished)
return;
m_load_finished = true;
m_loadFinished = true;
}
/**
@ -91,13 +91,13 @@ void MainWindow::initWindowProperties()
*/
void MainWindow::initUI()
{
m_central_widget = new QTabWidget(this);
this->setCentralWidget(m_central_widget);
m_central_widget->tabBar()->setFixedWidth(this->width());
LanPage * m_lanWidget = new LanPage(m_central_widget);
WlanPage * m_wlanWidget = new WlanPage(m_central_widget);
m_central_widget->addTab(m_lanWidget, QIcon::fromTheme("network-wired-connected-symbolic", QIcon::fromTheme("network-wired-symbolic", QIcon(":/res/l/network-online.svg"))), tr("LAN"));
m_central_widget->addTab(m_wlanWidget, QIcon::fromTheme("network-wireless-signal-excellent-symbolic", QIcon(":/res/x/wifi-list-bg.svg")), tr("WLAN"));
m_centralWidget = new QTabWidget(this);
this->setCentralWidget(m_centralWidget);
m_centralWidget->tabBar()->setFixedWidth(this->width());
LanPage * m_lanWidget = new LanPage(m_centralWidget);
WlanPage * m_wlanWidget = new WlanPage(m_centralWidget);
m_centralWidget->addTab(m_lanWidget, QIcon::fromTheme("network-wired-connected-symbolic", QIcon::fromTheme("network-wired-symbolic", QIcon(":/res/l/network-online.svg"))), tr("LAN"));
m_centralWidget->addTab(m_wlanWidget, QIcon::fromTheme("network-wireless-signal-excellent-symbolic", QIcon(":/res/x/wifi-list-bg.svg")), tr("WLAN"));
}
/**
@ -105,22 +105,22 @@ void MainWindow::initUI()
*/
void MainWindow::initTrayIcon()
{
m_tray_icon = new QSystemTrayIcon();
m_tray_icon_menu = new QMenu();
m_show_mainwindow_action = new QAction(tr("Show MainWindow"),this);
m_show_settings_action = new QAction(tr("Settings"),this);
m_trayIcon = new QSystemTrayIcon();
m_trayIconMenu = new QMenu();
m_showMainwindowAction = new QAction(tr("Show MainWindow"),this);
m_showSettingsAction = new QAction(tr("Settings"),this);
m_tray_icon->setToolTip(QString(tr("kylin-nm")));
m_show_settings_action->setIcon(QIcon::fromTheme("document-page-setup-symbolic", QIcon(":/res/x/setup.png")) );
m_tray_icon_menu->addAction(m_show_mainwindow_action);
m_tray_icon_menu->addAction(m_show_settings_action);
m_tray_icon->setContextMenu(m_tray_icon_menu);
m_tray_icon->setIcon(QIcon::fromTheme("network-wireless-signal-excellent-symbolic"));
m_trayIcon->setToolTip(QString(tr("kylin-nm")));
m_showSettingsAction->setIcon(QIcon::fromTheme("document-page-setup-symbolic", QIcon(":/res/x/setup.png")) );
m_trayIconMenu->addAction(m_showMainwindowAction);
m_trayIconMenu->addAction(m_showSettingsAction);
m_trayIcon->setContextMenu(m_trayIconMenu);
m_trayIcon->setIcon(QIcon::fromTheme("network-wireless-signal-excellent-symbolic"));
connect(m_tray_icon, &QSystemTrayIcon::activated, this, &MainWindow::onTrayIconActivated);
connect(m_show_mainwindow_action, &QAction::triggered, this, &MainWindow::onShowMainwindowActionTriggled);
connect(m_show_settings_action, &QAction::triggered, this, &MainWindow::onShowSettingsActionTriggled);
m_tray_icon->show();
connect(m_trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::onTrayIconActivated);
connect(m_showMainwindowAction, &QAction::triggered, this, &MainWindow::onShowMainwindowActionTriggled);
connect(m_showSettingsAction, &QAction::triggered, this, &MainWindow::onShowSettingsActionTriggled);
m_trayIcon->show();
}
/**
@ -129,15 +129,19 @@ void MainWindow::initTrayIcon()
void MainWindow::resetWindowPosition()
{
#define MARGIN 4
if (!m_position_interface) {
m_position_interface = new QDBusInterface("org.ukui.panel",
#define PANEL_TOP 1
#define PANEL_LEFT 2
#define PANEL_RIGHT 3
//#define PANEL_BOTTOM 4
if (!m_positionInterface) {
m_positionInterface = new QDBusInterface("org.ukui.panel",
"/panel/position",
"org.ukui.panel",
QDBusConnection::sessionBus());
}
QDBusReply<QVariantList> reply = m_position_interface->call("GetPrimaryScreenGeometry");
QDBusReply<QVariantList> reply = m_positionInterface->call("GetPrimaryScreenGeometry");
//reply获取的参数共5个分别是 主屏可用区域的起点x坐标主屏可用区域的起点y坐标主屏可用区域的宽度主屏可用区域高度任务栏位置
if (!m_position_interface->isValid() || !reply.isValid() || reply.value().size() < 5) {
if (!m_positionInterface->isValid() || !reply.isValid() || reply.value().size() < 5) {
qCritical() << QDBusConnection::sessionBus().lastError().message();
this->setGeometry(0, 0, this->width(), this->height());
return;
@ -145,20 +149,20 @@ void MainWindow::resetWindowPosition()
QVariantList position_list = reply.value();
int position = position_list.at(4).toInt();
switch(position){
case 1:
case PANEL_TOP:
//任务栏位于上方
this->setGeometry(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN,
position_list.at(1).toInt() + MARGIN,
this->width(), this->height());
break;
//任务栏位于左边
case 2:
case PANEL_LEFT:
this->setGeometry(position_list.at(0).toInt() + MARGIN,
position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN,
this->width(), this->height());
break;
//任务栏位于右边
case 3:
case PANEL_RIGHT:
this->setGeometry(position_list.at(0).toInt() + position_list.at(2).toInt() - this->width() - MARGIN,
position_list.at(1).toInt() + reply.value().at(3).toInt() - this->height() - MARGIN,
this->width(), this->height());
@ -205,14 +209,9 @@ void MainWindow::initWindowTheme()
{
const QByteArray style_id(THEME_SCHAME);
if (QGSettings::isSchemaInstalled(style_id)) {
m_style_gsettings = new QGSettings(style_id);
m_styleGsettings = new QGSettings(style_id);
resetWindowTheme();
connect(m_style_gsettings, &QGSettings::changed, this, [ = ](const QString &key) {
if (key == COLOR_THEME) {
qDebug() << "Received signal of theme changed, will reset theme." << Q_FUNC_INFO << __LINE__;
resetWindowTheme();
}
});
connect(m_styleGsettings, &QGSettings::changed, this, &MainWindow::onThemeChanged);
} else {
qWarning() << "Gsettings interface \"org.ukui.style\" is not exist!" << Q_FUNC_INFO << __LINE__;
}
@ -223,8 +222,8 @@ void MainWindow::initWindowTheme()
*/
void MainWindow::resetWindowTheme()
{
if (!m_style_gsettings) return;
QString currentTheme = m_style_gsettings->get(COLOR_THEME).toString();
if (!m_styleGsettings) { return; }
QString currentTheme = m_styleGsettings->get(COLOR_THEME).toString();
auto app = static_cast<QApplication*>(QCoreApplication::instance());
if(currentTheme == "ukui-dark" || currentTheme == "ukui-black"){
app->setStyle(new CustomStyle("ukui-dark"));
@ -269,6 +268,16 @@ void MainWindow::onShowSettingsActionTriggled()
showControlCenter();
}
void MainWindow::onThemeChanged(const QString &key)
{
if (key == COLOR_THEME) {
qDebug() << "Received signal of theme changed, will reset theme." << Q_FUNC_INFO << __LINE__;
resetWindowTheme();
} else {
qDebug() << "Received signal of theme changed, key=" << key << " will do nothing." << Q_FUNC_INFO << __LINE__;
}
}
/**
* @brief MainWindow::keyPressEvent esc键关闭主界面
* @param event

View File

@ -23,14 +23,14 @@ signals:
public slots:
protected:
void keyPressEvent(QKeyEvent *);
bool eventFilter(QObject *, QEvent *) override;
void keyPressEvent(QKeyEvent *event);
bool eventFilter(QObject *watched, QEvent *event) override;
private:
void firstlyStart(); //一级启动
void secondaryStart(); //二级启动
bool m_load_finished = false; //是否二级启动已执行完
QTimer * m_secondary_start_timer = nullptr; //执行二级启动的倒计时
bool m_loadFinished = false; //是否二级启动已执行完
QTimer * m_secondaryStartTimer = nullptr; //执行二级启动的倒计时
void initWindowProperties();
void initUI();
void initTrayIcon();
@ -40,25 +40,26 @@ private:
void showControlCenter();
//主窗口的主要构成控件
QTabWidget * m_central_widget = nullptr;
QTabWidget * m_centralWidget = nullptr;
//监听主题的Gsettings
QGSettings * m_style_gsettings = nullptr;
QGSettings * m_styleGsettings = nullptr;
//获取和重置窗口位置
void resetWindowPosition();
QDBusInterface * m_position_interface = nullptr;
QDBusInterface * m_positionInterface = nullptr;
//托盘图标,托盘图标右键菜单
QSystemTrayIcon * m_tray_icon = nullptr;
QMenu * m_tray_icon_menu = nullptr;
QAction * m_show_mainwindow_action = nullptr;
QAction * m_show_settings_action = nullptr;
QSystemTrayIcon * m_trayIcon = nullptr;
QMenu * m_trayIconMenu = nullptr;
QAction * m_showMainwindowAction = nullptr;
QAction * m_showSettingsAction = nullptr;
private slots:
void onTrayIconActivated();
void onShowMainwindowActionTriggled();
void onShowSettingsActionTriggled();
void onThemeChanged(const QString &key);
};
#endif // MAINWINDOW_H

View File

@ -18,77 +18,77 @@ LanPage::LanPage(QWidget *parent) : QWidget(parent)
LanPage::~LanPage()
{
delete m_title_divider;
delete m_activated_lan_divider;
delete m_inactivated_lan_divider;
delete m_titleDivider;
delete m_activatedLanDivider;
delete m_inactivatedLanDivider;
}
void LanPage::initUI()
{
m_main_layout = new QVBoxLayout(this);
m_main_layout->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_main_layout->setSpacing(MAIN_LAYOUT_SPACING);
this->setLayout(m_main_layout);
m_mainLayout = new QVBoxLayout(this);
m_mainLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_mainLayout->setSpacing(MAIN_LAYOUT_SPACING);
this->setLayout(m_mainLayout);
m_title_frame = new QFrame(this);
m_title_frame->setFixedHeight(TITLE_FRAME_HEIGHT);
m_title_layout = new QHBoxLayout(m_title_frame);
m_title_layout->setContentsMargins(TITLE_LAYOUT_MARGINS);
m_title_label = new QLabel(m_title_frame);
m_title_label->setText(tr("LAN"));
m_lan_switch = new SwitchButton(m_title_frame);
m_title_layout->addWidget(m_title_label);
m_title_layout->addStretch();
m_title_layout->addWidget(m_lan_switch);
m_title_divider = new Divider(this);
m_titleFrame = new QFrame(this);
m_titleFrame->setFixedHeight(TITLE_FRAME_HEIGHT);
m_titleLayout = new QHBoxLayout(m_titleFrame);
m_titleLayout->setContentsMargins(TITLE_LAYOUT_MARGINS);
m_titleLabel = new QLabel(m_titleFrame);
m_titleLabel->setText(tr("LAN"));
m_lanSwitch = new SwitchButton(m_titleFrame);
m_titleLayout->addWidget(m_titleLabel);
m_titleLayout->addStretch();
m_titleLayout->addWidget(m_lanSwitch);
m_titleDivider = new Divider(this);
m_activated_lan_frame = new QFrame(this);
m_activated_lan_layout = new QVBoxLayout(m_activated_lan_frame);
m_activated_lan_layout->setContentsMargins(LAN_LAYOUT_MARGINS);
m_activated_lan_layout->setSpacing(LAN_LAYOUT_SPACING);
m_activated_lan_label = new QLabel(m_activated_lan_frame);
m_activated_lan_label->setContentsMargins(TEXT_MARGINS);
m_activated_lan_label->setText(tr("Activated LAN"));
m_activated_lan_list_widget = new QListWidget(m_activated_lan_frame);
m_activated_lan_list_widget->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_activated_lan_list_widget->setSpacing(LAN_LIST_SPACING);
m_activated_lan_layout->addWidget(m_activated_lan_label);
m_activated_lan_layout->addWidget(m_activated_lan_list_widget);
m_activated_lan_divider = new Divider(this);
m_activatedLanFrame = new QFrame(this);
m_activatedLanLayout = new QVBoxLayout(m_activatedLanFrame);
m_activatedLanLayout->setContentsMargins(LAN_LAYOUT_MARGINS);
m_activatedLanLayout->setSpacing(LAN_LAYOUT_SPACING);
m_activatedLanLabel = new QLabel(m_activatedLanFrame);
m_activatedLanLabel->setContentsMargins(TEXT_MARGINS);
m_activatedLanLabel->setText(tr("Activated LAN"));
m_activatedLanListWidget = new QListWidget(m_activatedLanFrame);
m_activatedLanListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_activatedLanListWidget->setSpacing(LAN_LIST_SPACING);
m_activatedLanLayout->addWidget(m_activatedLanLabel);
m_activatedLanLayout->addWidget(m_activatedLanListWidget);
m_activatedLanDivider = new Divider(this);
m_inactivated_lan_frame = new QFrame(this);
m_inactivated_lan_layout = new QVBoxLayout(m_inactivated_lan_frame);
m_inactivated_lan_layout->setContentsMargins(LAN_LAYOUT_MARGINS);
m_inactivated_lan_layout->setSpacing(LAN_LAYOUT_SPACING);
m_inactivated_lan_frame->setLayout(m_inactivated_lan_layout);
m_inactivated_lan_label = new QLabel(m_inactivated_lan_frame);
m_inactivated_lan_label->setContentsMargins(TEXT_MARGINS);
m_inactivated_lan_label->setText(tr("Inactivated LAN"));
m_inactivated_lan_list_area = new QScrollArea(m_inactivated_lan_frame);
m_inactivated_lan_list_widget = new QListWidget(m_inactivated_lan_list_area);
m_inactivated_lan_list_area->setWidget(m_inactivated_lan_list_widget);
m_inactivated_lan_list_area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_inactivated_lan_list_area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
m_inactivated_lan_list_widget->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_inactivated_lan_list_widget->setSpacing(LAN_LIST_SPACING);
m_inactivatedLanFrame = new QFrame(this);
m_inactivatedLanLayout = new QVBoxLayout(m_inactivatedLanFrame);
m_inactivatedLanLayout->setContentsMargins(LAN_LAYOUT_MARGINS);
m_inactivatedLanLayout->setSpacing(LAN_LAYOUT_SPACING);
m_inactivatedLanFrame->setLayout(m_inactivatedLanLayout);
m_inactivatedLanLabel = new QLabel(m_inactivatedLanFrame);
m_inactivatedLanLabel->setContentsMargins(TEXT_MARGINS);
m_inactivatedLanLabel->setText(tr("Inactivated LAN"));
m_inactivatedLanListArea = new QScrollArea(m_inactivatedLanFrame);
m_inactivatedLanListWidget = new QListWidget(m_inactivatedLanListArea);
m_inactivatedLanListArea->setWidget(m_inactivatedLanListWidget);
m_inactivatedLanListArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_inactivatedLanListArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
m_inactivatedLanListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_inactivatedLanListWidget->setSpacing(LAN_LIST_SPACING);
// m_inactivated_lan_list_area->setFixedHeight(SCROLL_AREA_HEIGHT);
m_inactivated_lan_layout->addWidget(m_inactivated_lan_label);
m_inactivated_lan_layout->addWidget(m_inactivated_lan_list_area);
m_inactivated_lan_divider = new Divider(this);
m_inactivatedLanLayout->addWidget(m_inactivatedLanLabel);
m_inactivatedLanLayout->addWidget(m_inactivatedLanListArea);
m_inactivatedLanDivider = new Divider(this);
m_settings_frame = new QFrame(this);
m_settings_layout = new QHBoxLayout(m_settings_frame);
m_settings_layout->setContentsMargins(SETTINGS_LAYOUT_MARGINS);
m_settings_label = new QLabel(m_settings_frame);
m_settings_label->setText(tr("Settings"));
m_settings_layout->addWidget(m_settings_label);
m_settings_frame->setLayout(m_settings_layout);
m_settingsFrame = new QFrame(this);
m_settingsLayout = new QHBoxLayout(m_settingsFrame);
m_settingsLayout->setContentsMargins(SETTINGS_LAYOUT_MARGINS);
m_settingsLabel = new QLabel(m_settingsFrame);
m_settingsLabel->setText(tr("Settings"));
m_settingsLayout->addWidget(m_settingsLabel);
m_settingsFrame->setLayout(m_settingsLayout);
m_main_layout->addWidget(m_title_frame);
m_main_layout->addWidget(m_title_divider);
m_main_layout->addWidget(m_activated_lan_frame);
m_main_layout->addWidget(m_activated_lan_divider);
m_main_layout->addWidget(m_inactivated_lan_frame);
m_main_layout->addWidget(m_inactivated_lan_divider);
m_main_layout->addWidget(m_settings_frame);
m_mainLayout->addWidget(m_titleFrame);
m_mainLayout->addWidget(m_titleDivider);
m_mainLayout->addWidget(m_activatedLanFrame);
m_mainLayout->addWidget(m_activatedLanDivider);
m_mainLayout->addWidget(m_inactivatedLanFrame);
m_mainLayout->addWidget(m_inactivatedLanDivider);
m_mainLayout->addWidget(m_settingsFrame);
}

View File

@ -20,29 +20,29 @@ signals:
private:
void initUI();
QVBoxLayout * m_main_layout = nullptr;
QFrame * m_title_frame = nullptr;
QHBoxLayout * m_title_layout = nullptr;
QLabel * m_title_label = nullptr;
SwitchButton * m_lan_switch = nullptr;
Divider * m_title_divider = nullptr;
QVBoxLayout * m_mainLayout = nullptr;
QFrame * m_titleFrame = nullptr;
QHBoxLayout * m_titleLayout = nullptr;
QLabel * m_titleLabel = nullptr;
SwitchButton * m_lanSwitch = nullptr;
Divider * m_titleDivider = nullptr;
QFrame * m_activated_lan_frame = nullptr;
QVBoxLayout * m_activated_lan_layout = nullptr;
QLabel * m_activated_lan_label = nullptr;
QListWidget * m_activated_lan_list_widget = nullptr;
Divider * m_activated_lan_divider = nullptr;
QFrame * m_activatedLanFrame = nullptr;
QVBoxLayout * m_activatedLanLayout = nullptr;
QLabel * m_activatedLanLabel = nullptr;
QListWidget * m_activatedLanListWidget = nullptr;
Divider * m_activatedLanDivider = nullptr;
QFrame * m_inactivated_lan_frame = nullptr;
QVBoxLayout * m_inactivated_lan_layout = nullptr;
QLabel * m_inactivated_lan_label = nullptr;
QScrollArea * m_inactivated_lan_list_area = nullptr;
QListWidget * m_inactivated_lan_list_widget = nullptr;
Divider * m_inactivated_lan_divider = nullptr;
QFrame * m_inactivatedLanFrame = nullptr;
QVBoxLayout * m_inactivatedLanLayout = nullptr;
QLabel * m_inactivatedLanLabel = nullptr;
QScrollArea * m_inactivatedLanListArea = nullptr;
QListWidget * m_inactivatedLanListWidget = nullptr;
Divider * m_inactivatedLanDivider = nullptr;
QFrame * m_settings_frame = nullptr;
QHBoxLayout * m_settings_layout = nullptr;
QLabel * m_settings_label = nullptr;
QFrame * m_settingsFrame = nullptr;
QHBoxLayout * m_settingsLayout = nullptr;
QLabel * m_settingsLabel = nullptr;
};
#endif // LANPAGE_H

View File

@ -19,17 +19,17 @@ WlanPage::WlanPage(QWidget *parent) : QWidget(parent)
WlanPage::~WlanPage()
{
delete m_title_divider;
delete m_activated_wlan_divider;
delete m_inactivated_wlan_divider;
delete m_titleDivider;
delete m_activatedWlanDivider;
delete m_inactivatedWlanDivider;
}
bool WlanPage::eventFilter(QObject *w, QEvent *e)
{
if (e->type() == QEvent::MouseButtonPress) {
if (w == m_hidden_wlan_label) {
if (w == m_hiddenWlanLabel) {
//ZJP_TODO 打开隐藏WiFi添加弹窗
} else if (w == m_settings_label) {
} else if (w == m_settingsLabel) {
//ZJP_TODO 打开控制面板
}
}
@ -38,84 +38,84 @@ bool WlanPage::eventFilter(QObject *w, QEvent *e)
void WlanPage::initUI()
{
m_main_layout = new QVBoxLayout(this);
m_main_layout->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_main_layout->setSpacing(MAIN_LAYOUT_SPACING);
this->setLayout(m_main_layout);
m_mainLayout = new QVBoxLayout(this);
m_mainLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_mainLayout->setSpacing(MAIN_LAYOUT_SPACING);
this->setLayout(m_mainLayout);
m_title_frame = new QFrame(this);
m_title_frame->setFixedHeight(TITLE_FRAME_HEIGHT);
m_title_layout = new QHBoxLayout(m_title_frame);
m_title_layout->setContentsMargins(TITLE_LAYOUT_MARGINS);
m_title_label = new QLabel(m_title_frame);
m_title_label->setText(tr("WLAN"));
m_lan_switch = new SwitchButton(m_title_frame);
m_title_layout->addWidget(m_title_label);
m_title_layout->addStretch();
m_title_layout->addWidget(m_lan_switch);
m_title_divider = new Divider(this);
m_titleFrame = new QFrame(this);
m_titleFrame->setFixedHeight(TITLE_FRAME_HEIGHT);
m_titleLayout = new QHBoxLayout(m_titleFrame);
m_titleLayout->setContentsMargins(TITLE_LAYOUT_MARGINS);
m_titleLabel = new QLabel(m_titleFrame);
m_titleLabel->setText(tr("WLAN"));
m_lanSwitch = new SwitchButton(m_titleFrame);
m_titleLayout->addWidget(m_titleLabel);
m_titleLayout->addStretch();
m_titleLayout->addWidget(m_lanSwitch);
m_titleDivider = new Divider(this);
m_activated_wlan_frame = new QFrame(this);
m_activated_wlan_layout = new QVBoxLayout(m_activated_wlan_frame);
m_activated_wlan_layout->setContentsMargins(LAN_LAYOUT_MARGINS);
m_activated_wlan_layout->setSpacing(LAN_LAYOUT_SPACING);
m_activated_wlan_label = new QLabel(m_activated_wlan_frame);
m_activated_wlan_label->setContentsMargins(TEXT_MARGINS);
m_activated_wlan_label->setText(tr("Activated WLAN"));
m_activated_wlan_list_widget = new QListWidget(m_activated_wlan_frame);
m_activated_wlan_list_widget->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_activated_wlan_list_widget->setSpacing(LAN_LIST_SPACING);
m_activated_wlan_layout->addWidget(m_activated_wlan_label);
m_activated_wlan_layout->addWidget(m_activated_wlan_list_widget);
m_activated_wlan_divider = new Divider(this);
m_activatedWlanFrame = new QFrame(this);
m_activatedWlanLayout = new QVBoxLayout(m_activatedWlanFrame);
m_activatedWlanLayout->setContentsMargins(LAN_LAYOUT_MARGINS);
m_activatedWlanLayout->setSpacing(LAN_LAYOUT_SPACING);
m_activatedWlanLabel = new QLabel(m_activatedWlanFrame);
m_activatedWlanLabel->setContentsMargins(TEXT_MARGINS);
m_activatedWlanLabel->setText(tr("Activated WLAN"));
m_activatedWlanListWidget = new QListWidget(m_activatedWlanFrame);
m_activatedWlanListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_activatedWlanListWidget->setSpacing(LAN_LIST_SPACING);
m_activatedWlanLayout->addWidget(m_activatedWlanLabel);
m_activatedWlanLayout->addWidget(m_activatedWlanListWidget);
m_activatedWlanDivider = new Divider(this);
m_inactivated_wlan_frame = new QFrame(this);
m_inactivated_wlan_layout = new QVBoxLayout(m_inactivated_wlan_frame);
m_inactivated_wlan_layout->setContentsMargins(LAN_LAYOUT_MARGINS);
m_inactivated_wlan_layout->setSpacing(LAN_LAYOUT_SPACING);
m_inactivated_wlan_frame->setLayout(m_inactivated_wlan_layout);
m_inactivated_wlan_label = new QLabel(m_inactivated_wlan_frame);
m_inactivated_wlan_label->setContentsMargins(TEXT_MARGINS);
m_inactivated_wlan_label->setText(tr("Inactivated WLAN"));
m_inactivated_wlan_list_area = new QScrollArea(m_inactivated_wlan_frame);
m_inactivated_wlan_list_area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_inactivated_wlan_list_area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
m_inactivated_wlan_list_area_central_widget = new QFrame(m_inactivated_wlan_list_area);
m_inactivated_wlan_list_area->setWidget(m_inactivated_wlan_list_area_central_widget);
m_inactivated_wlan_list_area_layout = new QVBoxLayout(m_inactivated_wlan_list_area_central_widget);
m_inactivated_wlan_list_area_central_widget->setLayout(m_inactivated_wlan_list_area_layout);
m_inactivated_wlan_list_area_layout->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_inactivated_wlan_list_widget = new QListWidget(m_inactivated_wlan_list_area_central_widget);
m_inactivated_wlan_list_widget->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_inactivated_wlan_list_widget->setSpacing(LAN_LIST_SPACING);
m_hidden_wlan_widget = new QFrame(m_inactivated_wlan_list_area_central_widget);
m_hidden_wlan_layout = new QHBoxLayout(m_hidden_wlan_widget);
m_hidden_wlan_layout->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_hidden_wlan_label = new QLabel(m_hidden_wlan_widget);
m_hidden_wlan_label->setText(tr("More..."));
m_hidden_wlan_layout->addWidget(m_hidden_wlan_label);
m_hidden_wlan_layout->addStretch();
m_inactivated_wlan_list_area_layout->addWidget(m_inactivated_wlan_list_widget);
m_inactivated_wlan_list_area_layout->addWidget(m_hidden_wlan_widget);
m_inactivatedWlanFrame = new QFrame(this);
m_inactivatedWlanLayout = new QVBoxLayout(m_inactivatedWlanFrame);
m_inactivatedWlanLayout->setContentsMargins(LAN_LAYOUT_MARGINS);
m_inactivatedWlanLayout->setSpacing(LAN_LAYOUT_SPACING);
m_inactivatedWlanFrame->setLayout(m_inactivatedWlanLayout);
m_inactivatedWlanLabel = new QLabel(m_inactivatedWlanFrame);
m_inactivatedWlanLabel->setContentsMargins(TEXT_MARGINS);
m_inactivatedWlanLabel->setText(tr("Inactivated WLAN"));
m_inactivatedWlanListArea = new QScrollArea(m_inactivatedWlanFrame);
m_inactivatedWlanListArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_inactivatedWlanListArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
m_inactivatedWlanListAreaCentralWidget = new QFrame(m_inactivatedWlanListArea);
m_inactivatedWlanListArea->setWidget(m_inactivatedWlanListAreaCentralWidget);
m_inactivatedWlanListAreaLayout = new QVBoxLayout(m_inactivatedWlanListAreaCentralWidget);
m_inactivatedWlanListAreaCentralWidget->setLayout(m_inactivatedWlanListAreaLayout);
m_inactivatedWlanListAreaLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_inactivatedWlanListWidget = new QListWidget(m_inactivatedWlanListAreaCentralWidget);
m_inactivatedWlanListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_inactivatedWlanListWidget->setSpacing(LAN_LIST_SPACING);
m_hiddenWlanWidget = new QFrame(m_inactivatedWlanListAreaCentralWidget);
m_hiddenWlanLayout = new QHBoxLayout(m_hiddenWlanWidget);
m_hiddenWlanLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_hiddenWlanLabel = new QLabel(m_hiddenWlanWidget);
m_hiddenWlanLabel->setText(tr("More..."));
m_hiddenWlanLayout->addWidget(m_hiddenWlanLabel);
m_hiddenWlanLayout->addStretch();
m_inactivatedWlanListAreaLayout->addWidget(m_inactivatedWlanListWidget);
m_inactivatedWlanListAreaLayout->addWidget(m_hiddenWlanWidget);
// m_inactivated_lan_list_area->setFixedHeight(SCROLL_AREA_HEIGHT);
m_inactivated_wlan_layout->addWidget(m_inactivated_wlan_label);
m_inactivated_wlan_layout->addWidget(m_inactivated_wlan_list_area);
m_inactivated_wlan_divider = new Divider(this);
m_inactivatedWlanLayout->addWidget(m_inactivatedWlanLabel);
m_inactivatedWlanLayout->addWidget(m_inactivatedWlanListArea);
m_inactivatedWlanDivider = new Divider(this);
m_settings_frame = new QFrame(this);
m_settings_layout = new QHBoxLayout(m_settings_frame);
m_settings_layout->setContentsMargins(SETTINGS_LAYOUT_MARGINS);
m_settings_label = new QLabel(m_settings_frame);
m_settings_label->setText(tr("Settings"));
m_settings_layout->addWidget(m_settings_label);
m_settings_frame->setLayout(m_settings_layout);
m_settingsFrame = new QFrame(this);
m_settingsLayout = new QHBoxLayout(m_settingsFrame);
m_settingsLayout->setContentsMargins(SETTINGS_LAYOUT_MARGINS);
m_settingsLabel = new QLabel(m_settingsFrame);
m_settingsLabel->setText(tr("Settings"));
m_settingsLayout->addWidget(m_settingsLabel);
m_settingsFrame->setLayout(m_settingsLayout);
m_main_layout->addWidget(m_title_frame);
m_main_layout->addWidget(m_title_divider);
m_main_layout->addWidget(m_activated_wlan_frame);
m_main_layout->addWidget(m_activated_wlan_divider);
m_main_layout->addWidget(m_inactivated_wlan_frame);
m_main_layout->addWidget(m_inactivated_wlan_divider);
m_main_layout->addWidget(m_settings_frame);
m_mainLayout->addWidget(m_titleFrame);
m_mainLayout->addWidget(m_titleDivider);
m_mainLayout->addWidget(m_activatedWlanFrame);
m_mainLayout->addWidget(m_activatedWlanDivider);
m_mainLayout->addWidget(m_inactivatedWlanFrame);
m_mainLayout->addWidget(m_inactivatedWlanDivider);
m_mainLayout->addWidget(m_settingsFrame);
}

View File

@ -19,38 +19,38 @@ public:
signals:
protected:
bool eventFilter(QObject *, QEvent *);
bool eventFilter(QObject *watched, QEvent *event);
private:
void initUI();
QVBoxLayout * m_main_layout = nullptr;
QFrame * m_title_frame = nullptr;
QHBoxLayout * m_title_layout = nullptr;
QLabel * m_title_label = nullptr;
SwitchButton * m_lan_switch = nullptr;
Divider * m_title_divider = nullptr;
QVBoxLayout * m_mainLayout = nullptr;
QFrame * m_titleFrame = nullptr;
QHBoxLayout * m_titleLayout = nullptr;
QLabel * m_titleLabel = nullptr;
SwitchButton * m_lanSwitch = nullptr;
Divider * m_titleDivider = nullptr;
QFrame * m_activated_wlan_frame = nullptr;
QVBoxLayout * m_activated_wlan_layout = nullptr;
QLabel * m_activated_wlan_label = nullptr;
QListWidget * m_activated_wlan_list_widget = nullptr;
Divider * m_activated_wlan_divider = nullptr;
QFrame * m_activatedWlanFrame = nullptr;
QVBoxLayout * m_activatedWlanLayout = nullptr;
QLabel *m_activatedWlanLabel = nullptr;
QListWidget * m_activatedWlanListWidget = nullptr;
Divider * m_activatedWlanDivider = nullptr;
QFrame * m_inactivated_wlan_frame = nullptr;
QVBoxLayout * m_inactivated_wlan_layout = nullptr;
QLabel * m_inactivated_wlan_label = nullptr;
QScrollArea * m_inactivated_wlan_list_area = nullptr;
QFrame * m_inactivated_wlan_list_area_central_widget = nullptr;
QVBoxLayout * m_inactivated_wlan_list_area_layout = nullptr;
QListWidget * m_inactivated_wlan_list_widget = nullptr;
QFrame * m_hidden_wlan_widget = nullptr;
QHBoxLayout * m_hidden_wlan_layout = nullptr;
QLabel * m_hidden_wlan_label = nullptr;
Divider * m_inactivated_wlan_divider = nullptr;
QFrame * m_inactivatedWlanFrame = nullptr;
QVBoxLayout * m_inactivatedWlanLayout = nullptr;
QLabel * m_inactivatedWlanLabel = nullptr;
QScrollArea * m_inactivatedWlanListArea = nullptr;
QFrame * m_inactivatedWlanListAreaCentralWidget = nullptr;
QVBoxLayout * m_inactivatedWlanListAreaLayout = nullptr;
QListWidget * m_inactivatedWlanListWidget = nullptr;
QFrame * m_hiddenWlanWidget = nullptr;
QHBoxLayout * m_hiddenWlanLayout = nullptr;
QLabel * m_hiddenWlanLabel = nullptr;
Divider * m_inactivatedWlanDivider = nullptr;
QFrame * m_settings_frame = nullptr;
QHBoxLayout * m_settings_layout = nullptr;
QLabel * m_settings_label = nullptr;
QFrame * m_settingsFrame = nullptr;
QHBoxLayout * m_settingsLayout = nullptr;
QLabel * m_settingsLabel = nullptr;
};
#endif // WLANPAGE_H

View File

@ -9,7 +9,7 @@ public:
~Divider() = default;
protected:
void paintEvent(QPaintEvent *);
void paintEvent(QPaintEvent *event);
};
#endif // DIVIDER_H

View File

@ -13,9 +13,9 @@ private:
void initUI();
protected:
virtual void enterEvent(QEvent *);
virtual void leaveEvent(QEvent *);
bool eventFilter(QObject *, QEvent *);
virtual void enterEvent(QEvent *event);
virtual void leaveEvent(QEvent *event);
bool eventFilter(QObject *watched, QEvent *event);
};
#endif // INFOBUTTON_H

View File

@ -4,10 +4,10 @@ NetButton::NetButton(bool isActivated, QWidget *parent) : QPushButton(parent)
{
connect(this, &NetButton::requestStartLoading, this, &NetButton::onLoadingStarted);
connect(this, &NetButton::requestStopLoading, this, &NetButton::onLoadingStopped);
m_is_activated = isActivated;
m_isActivated = isActivated;
this->setAutoFillBackground(false);
m_icon_label = new QLabel(this);
m_icon_label->setScaledContents(true);
m_iconLabel = new QLabel(this);
m_iconLabel->setScaledContents(true);
}
void NetButton::startLoading()
@ -23,7 +23,7 @@ void NetButton::stopLoading()
void NetButton::setPressed()
{
//ZJP_TODO 设置颜色为点击颜色,注意区分已连接/未连接
if (m_is_activated)
if (m_isActivated)
;
;
}
@ -31,15 +31,15 @@ void NetButton::setPressed()
void NetButton::setReleased()
{
//ZJP_TODO 设置颜色为未点击颜色,注意区分已连接/未连接
if (m_is_activated)
if (m_isActivated)
;
;
}
void NetButton::setButtonIcon(QIcon *icon)
{
if (!icon) return;
m_icon_label->setPixmap(icon->pixmap(this->size()));
if (!icon) { return; }
m_iconLabel->setPixmap(icon->pixmap(this->size()));
}
void NetButton::onLoadingStarted()

View File

@ -23,8 +23,8 @@ signals:
void requestStopLoading();
private:
bool m_is_activated = INACTIVATED;
QLabel * m_icon_label = nullptr;
bool m_isActivated = INACTIVATED;
QLabel * m_iconLabel = nullptr;
private slots:
void onLoadingStarted();

View File

@ -28,13 +28,15 @@
static XAtomHelper *global_instance = nullptr;
XAtomHelper *XAtomHelper::getInstance() {
XAtomHelper *XAtomHelper::getInstance()
{
if(!global_instance)
global_instance = new XAtomHelper;
return global_instance;
}
bool XAtomHelper::isFrameLessWindow(int winId) {
bool XAtomHelper::isFrameLessWindow(int winId)
{
auto hints = getInstance()->getWindowMotifHint(winId);
if(hints.flags == MWM_HINTS_DECORATIONS && hints.functions == 1) {
return true;
@ -42,7 +44,8 @@ bool XAtomHelper::isFrameLessWindow(int winId) {
return false;
}
bool XAtomHelper::isWindowDecorateBorderOnly(int winId) {
bool XAtomHelper::isWindowDecorateBorderOnly(int winId)
{
return isWindowMotifHintDecorateBorderOnly(getInstance()->getWindowMotifHint(winId));
}
@ -55,12 +58,14 @@ bool XAtomHelper::isWindowMotifHintDecorateBorderOnly(const MotifWmHints &hint)
return isDeco;
}
bool XAtomHelper::isUKUICsdSupported() {
bool XAtomHelper::isUKUICsdSupported()
{
// fixme:
return false;
}
bool XAtomHelper::isUKUIDecorationWindow(int winId) {
bool XAtomHelper::isUKUIDecorationWindow(int winId)
{
if(m_ukuiDecorationAtion == None)
return false;
@ -87,7 +92,8 @@ bool XAtomHelper::isUKUIDecorationWindow(int winId) {
return isUKUIDecoration;
}
UnityCorners XAtomHelper::getWindowBorderRadius(int winId) {
UnityCorners XAtomHelper::getWindowBorderRadius(int winId)
{
UnityCorners corners;
Atom type;
@ -117,7 +123,8 @@ UnityCorners XAtomHelper::getWindowBorderRadius(int winId) {
return corners;
}
void XAtomHelper::setWindowBorderRadius(int winId, const UnityCorners &data) {
void XAtomHelper::setWindowBorderRadius(int winId, const UnityCorners &data)
{
if(m_unityBorderRadiusAtom == None)
return;
@ -127,7 +134,8 @@ void XAtomHelper::setWindowBorderRadius(int winId, const UnityCorners &data) {
32, XCB_PROP_MODE_REPLACE, (const unsigned char *) &corners, sizeof(corners) / sizeof(corners[0]));
}
void XAtomHelper::setWindowBorderRadius(int winId, int topLeft, int topRight, int bottomLeft, int bottomRight) {
void XAtomHelper::setWindowBorderRadius(int winId, int topLeft, int topRight, int bottomLeft, int bottomRight)
{
if(m_unityBorderRadiusAtom == None)
return;
@ -137,14 +145,16 @@ void XAtomHelper::setWindowBorderRadius(int winId, int topLeft, int topRight, in
32, XCB_PROP_MODE_REPLACE, (const unsigned char *) &corners, sizeof(corners) / sizeof(corners[0]));
}
void XAtomHelper::setUKUIDecoraiontHint(int winId, bool set) {
void XAtomHelper::setUKUIDecoraiontHint(int winId, bool set)
{
if(m_ukuiDecorationAtion == None)
return;
XChangeProperty(QX11Info::display(), winId, m_ukuiDecorationAtion, m_ukuiDecorationAtion, 32, XCB_PROP_MODE_REPLACE, (const unsigned char *) &set, 1);
}
void XAtomHelper::setWindowMotifHint(int winId, const MotifWmHints &hints) {
void XAtomHelper::setWindowMotifHint(int winId, const MotifWmHints &hints)
{
if(m_unityBorderRadiusAtom == None)
return;
@ -152,7 +162,8 @@ void XAtomHelper::setWindowMotifHint(int winId, const MotifWmHints &hints) {
32, XCB_PROP_MODE_REPLACE, (const unsigned char *)&hints, sizeof(MotifWmHints) / sizeof(ulong));
}
MotifWmHints XAtomHelper::getWindowMotifHint(int winId) {
MotifWmHints XAtomHelper::getWindowMotifHint(int winId)
{
MotifWmHints hints;
if(m_unityBorderRadiusAtom == None)
@ -177,7 +188,8 @@ MotifWmHints XAtomHelper::getWindowMotifHint(int winId) {
return hints;
}
XAtomHelper::XAtomHelper(QObject *parent) : QObject(parent) {
XAtomHelper::XAtomHelper(QObject *parent) : QObject(parent)
{
if(!QX11Info::isPlatformX11())
return;
@ -186,11 +198,13 @@ XAtomHelper::XAtomHelper(QObject *parent) : QObject(parent) {
m_ukuiDecorationAtion = XInternAtom(QX11Info::display(), "_KWIN_UKUI_DECORAION", false);
}
Atom XAtomHelper::registerUKUICsdNetWmSupportAtom() {
Atom XAtomHelper::registerUKUICsdNetWmSupportAtom()
{
// fixme:
return None;
}
void XAtomHelper::unregisterUKUICsdNetWmSupportAtom() {
void XAtomHelper::unregisterUKUICsdNetWmSupportAtom()
{
// fixme:
}

View File

@ -74,7 +74,8 @@ namespace UKUI {
class Decoration;
}
class XAtomHelper : public QObject {
class XAtomHelper : public QObject
{
// friend class UKUI::Decoration;
Q_OBJECT
public: