Merge branch 'dbus-interface' of http://gitlab2.kylin.com/kylin-desktop/kylin-nm into new-dbus

This commit is contained in:
jzxc95 2021-08-25 13:42:46 +08:00
commit 27c12dec74
19 changed files with 303 additions and 49 deletions

View File

@ -11,6 +11,7 @@ class KyWirelessNetItem
{
public:
KyWirelessNetItem(NetworkManager::WirelessNetwork::Ptr net);
KyWirelessNetItem() {;}
~KyWirelessNetItem();
private:

View File

@ -69,7 +69,7 @@ bool KyWirelessNetResource::getDeviceWifiNetwork(QString devIfaceName, QList<KyW
}
}
bool KyWirelessNetResource::getWifiNetwork(QString &devIfaceName, QString &ssid, KyWirelessNetItem &wirelessNetResource)
bool KyWirelessNetResource::getWifiNetwork(const QString &devIfaceName, const QString &ssid, KyWirelessNetItem &wirelessNetResource)
{
// onWifiNetworkDeviceDisappear();
@ -490,5 +490,5 @@ void KyWirelessNetResource::onConnectionUpdate(QString uuid)
}
m_WifiNetworkList.clear();
kyWirelessNetItemListInit();
emit wifiNetworkUpadte();
emit wifiNetworkUpdate();
}

View File

@ -18,7 +18,7 @@ public:
~KyWirelessNetResource();
//ui层调用接口
bool getWifiNetwork(QString &devIfaceName, QString &ssid, KyWirelessNetItem &wirelessNetResource);
bool getWifiNetwork(const QString &devIfaceName, const QString &ssid, KyWirelessNetItem &wirelessNetResource);
bool getAllDeviceWifiNetwork(QMap<QString, QList<KyWirelessNetItem> > &map);
bool getDeviceWifiNetwork(QString devIfaceName, QList<KyWirelessNetItem> &wirelessNetResource);
@ -50,7 +50,7 @@ signals:
void secuTypeChange(QString, QString, QString);
void connectionRemove(QString, QString);
void connectionAdd(QString, QString);
void wifiNetworkUpadte();
void wifiNetworkUpdate();
void wifiNetworkAdd(QString, KyWirelessNetItem&);
void wifiNetworkRemove(QString, QString);

View File

@ -48,7 +48,7 @@ void ListItem::initUI()
m_hItemLayout->setContentsMargins(ITEM_FRAME_MARGINS);
m_hItemLayout->setSpacing(ITEM_FRAME_SPACING);
m_netButton = new NetButton(m_itemFrame);
m_netButton = new RadioItemButton(m_itemFrame);
m_nameLabel = new QLabel(m_itemFrame);
m_infoButton = new InfoButton(m_itemFrame);
@ -62,7 +62,7 @@ void ListItem::initUI()
void ListItem::initConnection()
{
connect(this->m_netButton, &NetButton::clicked, this, &ListItem::onNetButtonClicked);
connect(this->m_netButton, &RadioItemButton::clicked, this, &ListItem::onNetButtonClicked);
connect(this->m_infoButton, &InfoButton::clicked, this, &ListItem::onInfoButtonClicked);
}

View File

@ -2,7 +2,7 @@
#define LISTITEM_H
#include <QFrame>
#include <QHBoxLayout>
#include "netbutton.h"
#include "radioitembutton.h"
#include "infobutton.h"
class ListItem : public QFrame
@ -20,7 +20,7 @@ protected:
QVBoxLayout * m_mainLayout = nullptr;
QFrame * m_itemFrame = nullptr;
QHBoxLayout * m_hItemLayout = nullptr;
NetButton * m_netButton = nullptr;
RadioItemButton * m_netButton = nullptr;
QLabel * m_nameLabel = nullptr;
InfoButton * m_infoButton = nullptr;

View File

@ -1,9 +1,17 @@
#include "wlanlistitem.h"
WlanListItem::WlanListItem(KyWirelessNetItem *data, QWidget *parent) : ListItem(parent)
WlanListItem::WlanListItem(KyWirelessNetResource *resource, KyWirelessNetItem *data, QWidget *parent) : ListItem(parent)
{
m_data = data;
m_resource = resource;
initWlanUI();
setExpanded(false);
initWlanConnection();
}
WlanListItem::~WlanListItem()
{
disconnect(m_resource, &KyWirelessNetResource::secuTypeChange, this, &WlanListItem::onSecurityChanged);
}
void WlanListItem::setWlanSignal(const int &signal)
@ -18,34 +26,75 @@ void WlanListItem::setWlanState(const int &state)
refreshIcon();
}
void WlanListItem::setExpanded(const bool &expanded)
{
m_isExpanded = expanded;
this->setFixedHeight(expanded ? EXPANDED_HEIGHT : NORMAL_HEIGHT);
}
void WlanListItem::initWlanUI()
{
m_hasPwd = (m_data->m_secuType.isEmpty() || m_data->m_secuType == "") ? false : true;
//设置显示的Wlan名称
this->setName(m_data->m_connName);
this->setName((m_data->m_connName != "") ? m_data->m_connName : m_data->m_NetSsid);
//刷新左侧按钮图标
refreshIcon();
}
void WlanListItem::initWlanConnection()
{
connect(m_resource, &KyWirelessNetResource::secuTypeChange, this, &WlanListItem::onSecurityChanged);
}
void WlanListItem::refreshIcon()
{
#define FULL_SIGNAL 5
#define EXCELLENT_SIGNAL 4
#define GOOD_SIGNAL 3
#define OK_SIGNAL 2
#define LOW_SIGNAL 1
#define STEP 25
// if (m_data->m_state) //ZJP_TODO 连接中、已连接、未连接的处理,要单独写逻辑,后端接口待补全
if (m_data->m_secuType.isEmpty() ||m_data->m_secuType == "") {
if (!m_hasPwd) {
//ZJP_TODO 无加密 注意信号格数计算方式,可能需要修改
switch (m_data->m_signalStrength / 25 + 1) {
case 5:
case 4:
switch (m_data->m_signalStrength / STEP + 1) {
case FULL_SIGNAL:
case EXCELLENT_SIGNAL:
m_netButton->setIcon(QIcon::fromTheme("network-wireless-signal-excellent-symbolic", QIcon(":/res/w/wifi-full.png")));
break;
case 3:
case GOOD_SIGNAL:
m_netButton->setIcon(QIcon::fromTheme("network-wireless-signal-good-symbolic", QIcon(":/res/w/wifi-high.png")));
break;
case 2:
case OK_SIGNAL:
m_netButton->setIcon(QIcon::fromTheme("network-wireless-signal-ok", QIcon(":/res/w/wifi-medium.png")));
break;
case 1:
case LOW_SIGNAL:
m_netButton->setIcon(QIcon::fromTheme("network-wireless-signal-low", QIcon(":/res/w/wifi-low.png")));
break;
default:
qDebug() << "Set wlan(without passwd) icon failed, signal = " << m_data->m_signalStrength << Q_FUNC_INFO << __LINE__;
break;
}
} else {
//ZJP_TODO 有加密
switch (m_data->m_signalStrength / STEP + 1) {
case FULL_SIGNAL:
case EXCELLENT_SIGNAL:
m_netButton->setIcon(QIcon::fromTheme("network-wireless-signal-excellent-secure-symbolic", QIcon(":/res/w/wifi-full-pwd.png")));
break;
case GOOD_SIGNAL:
m_netButton->setIcon(QIcon::fromTheme("network-wireless-signal-good-secure-symbolic", QIcon(":/res/w/wifi-high-pwd.png")));
break;
case OK_SIGNAL:
m_netButton->setIcon(QIcon::fromTheme("network-wireless-signal-ok-secure-symbolic", QIcon(":/res/w/wifi-medium-pwd.png")));
break;
case LOW_SIGNAL:
m_netButton->setIcon(QIcon::fromTheme("network-wireless-signal-low-secure-symbolic", QIcon(":/res/w/wifi-low-pwd.png")));
break;
default:
qDebug() << "Set wlan(with passwd) icon failed, signal = " << m_data->m_signalStrength << Q_FUNC_INFO << __LINE__;
break;
}
}
}
@ -60,3 +109,17 @@ void WlanListItem::onNetButtonClicked()
//ZJP_TODO 点击连接/断开
qDebug() << "On wlan clicked! ssid = " << m_data->m_NetSsid << "; name = " << m_data->m_connName << "." <<Q_FUNC_INFO << __LINE__;
}
void WlanListItem::onSecurityChanged(QString interface, QString ssid, QString securityType)
{
if (ssid != m_data->m_NetSsid) {
return;
}
qDebug() << "Security changed! ssid = " << m_data->m_NetSsid << "; security = " << m_data->m_secuType << "." <<Q_FUNC_INFO << __LINE__;
m_data->m_secuType = securityType;
bool newSecu = (m_data->m_secuType.isEmpty() || m_data->m_secuType == "") ? false : true;
if (m_hasPwd^newSecu) {
m_hasPwd = newSecu;
refreshIcon();
}
}

View File

@ -2,17 +2,22 @@
#define WLANLISTITEM_H
#include "listitem.h"
#include "kywirelessnetitem.h"
#include "kywirelessnetresource.h"
#define NORMAL_HEIGHT 48
#define EXPANDED_HEIGHT 120
class WlanListItem : public ListItem
{
Q_OBJECT
public:
WlanListItem(KyWirelessNetItem *data, QWidget *parent = nullptr);
~WlanListItem() = default;
WlanListItem(KyWirelessNetResource *resource, KyWirelessNetItem *data, QWidget *parent = nullptr);
~WlanListItem();
public:
void setWlanSignal(const int &signal);
void setWlanState(const int &state);
void setExpanded(const bool &expanded);
private:
void initWlanUI();
@ -20,11 +25,15 @@ private:
void refreshIcon();
private:
KyWirelessNetItem * m_data = nullptr;
KyWirelessNetResource *m_resource = nullptr;
KyWirelessNetItem *m_data = nullptr;
bool m_isExpanded = false;
bool m_hasPwd = true;
private slots:
void onInfoButtonClicked();
void onNetButtonClicked();
void onSecurityChanged(QString interface, QString ssid, QString securityType);
};
#endif // WLANLISTITEM_H

View File

@ -158,7 +158,7 @@ void NmDemo::initConnect()
connect(m_wnr, &KyWirelessNetResource::connectionRemove, this ,&NmDemo::onConnectionRemove);
connect(m_wnr, &KyWirelessNetResource::connectionAdd, this ,&NmDemo::onConnectionAdd);
connect(m_wnr, &KyWirelessNetResource::wifiNetworkUpadte, this ,&NmDemo::onWifiNetworkUpdate);
connect(m_wnr, &KyWirelessNetResource::wifiNetworkUpdate, this ,&NmDemo::onWifiNetworkUpdate);
connect(m_wnr, &KyWirelessNetResource::wifiNetworkAdd, this ,&NmDemo::onWifiNetworkAdd);
connect(m_wnr, &KyWirelessNetResource::wifiNetworkRemove, this ,&NmDemo::onWifiNetworkRemove);

View File

@ -10,4 +10,12 @@ void LanPage::initLanUI()
m_titleLabel->setText(tr("LAN"));
m_activatedNetLabel->setText(tr("Activated LAN"));
m_inactivatedNetLabel->setText(tr("Inactivated LAN"));
m_inactivatedNetListWidget = new QListWidget(m_inactivatedNetListArea);
m_inactivatedNetListArea->setWidget(m_inactivatedNetListWidget);
m_inactivatedNetListArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_inactivatedNetListArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
m_inactivatedNetListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_inactivatedNetListWidget->setSpacing(NET_LIST_SPACING);
m_inactivatedNetListWidget->setFrameShape(QFrame::Shape::NoFrame);
}

View File

@ -37,6 +37,7 @@ void TabPage::initUI()
m_activatedNetLabel = new QLabel(m_activatedNetFrame);
m_activatedNetLabel->setContentsMargins(TEXT_MARGINS);
m_activatedNetListWidget = new QListWidget(m_activatedNetFrame);
m_activatedNetListWidget->setFrameShape(QFrame::Shape::NoFrame);
m_activatedNetListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_activatedNetListWidget->setSpacing(NET_LIST_SPACING);
m_activatedNetLayout->addWidget(m_activatedNetLabel);
@ -51,13 +52,8 @@ void TabPage::initUI()
m_inactivatedNetLabel = new QLabel(m_inactivatedNetFrame);
m_inactivatedNetLabel->setContentsMargins(TEXT_MARGINS);
m_inactivatedNetListArea = new QScrollArea(m_inactivatedNetFrame);
m_inactivatedNetListWidget = new QListWidget(m_inactivatedNetListArea);
m_inactivatedNetListArea->setWidget(m_inactivatedNetListWidget);
m_inactivatedNetListArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_inactivatedNetListArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
m_inactivatedNetListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_inactivatedNetListWidget->setSpacing(NET_LIST_SPACING);
// m_inactivated_Net_list_area->setFixedHeight(SCROLL_AREA_HEIGHT);
m_inactivatedNetListArea->setFrameShape(QFrame::Shape::NoFrame);
m_inactivatedNetListArea->setWidgetResizable(true);
m_inactivatedNetLayout->addWidget(m_inactivatedNetLabel);
m_inactivatedNetLayout->addWidget(m_inactivatedNetListArea);
m_inactivatedNetDivider = new Divider(this);

View File

@ -15,10 +15,11 @@
#define TITLE_LAYOUT_MARGINS 24,0,0,0
#define NET_LAYOUT_MARGINS 8,8,8,8
#define NET_LAYOUT_SPACING 8
#define NET_LIST_SPACING 2
#define NET_LIST_SPACING 1
#define TEXT_MARGINS 16,0,0,0
//#define SCROLL_AREA_HEIGHT 200
#define SETTINGS_LAYOUT_MARGINS 24,16,24,16
#define TRANSPARENT_COLOR QColor(0,0,0,0)
class TabPage : public QWidget
{

View File

@ -1,9 +1,17 @@
#include "wlanpage.h"
#include "wlanlistitem.h"
#include "kywirelessnetitem.h"
#include <QEvent>
#include <QDateTime>
#include <QDebug>
WlanPage::WlanPage(QWidget *parent) : TabPage(parent)
{
m_resource = new KyWirelessNetResource(this);
initWlanUI();
initConnections();
getActiveWlan();
getAllWlan();
}
bool WlanPage::eventFilter(QObject *w, QEvent *e)
@ -26,18 +34,154 @@ void WlanPage::initWlanUI()
//一些独有控件
m_inactivatedWlanListAreaCentralWidget = new QFrame(m_inactivatedNetListArea);
m_inactivatedNetListArea->setBackgroundRole(QPalette::Base);
m_inactivatedNetListArea->setWidget(m_inactivatedWlanListAreaCentralWidget);
m_inactivatedWlanListAreaLayout = new QVBoxLayout(m_inactivatedWlanListAreaCentralWidget);
m_inactivatedWlanListAreaCentralWidget->setLayout(m_inactivatedWlanListAreaLayout);
m_inactivatedWlanListAreaLayout->setSpacing(MAIN_LAYOUT_SPACING);
m_inactivatedWlanListAreaLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_inactivatedNetListWidget = new QListWidget(m_inactivatedWlanListAreaCentralWidget);
m_inactivatedNetListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_inactivatedNetListWidget->setSpacing(NET_LIST_SPACING);
m_inactivatedNetListWidget->setFrameShape(QFrame::Shape::NoFrame);
m_inactivatedNetListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
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_hiddenWlanLabel->setContentsMargins(MORE_TEXT_MARGINS);
m_hiddenWlanLayout->addWidget(m_hiddenWlanLabel);
m_hiddenWlanLayout->addStretch();
m_inactivatedWlanListAreaLayout->addWidget(m_inactivatedNetListWidget);
m_inactivatedWlanListAreaLayout->addWidget(m_hiddenWlanLabel);
m_inactivatedWlanListAreaLayout->addStretch();
m_activatedNetListWidget->setFixedHeight(NORMAL_HEIGHT);
// m_inactivatedNetListArea->setFixedHeight(SCROLLAREA_HEIGHT);
m_inactivatedNetListArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
}
/**
* @brief WlanPage::initConnections
*/
void WlanPage::initConnections()
{
connect(m_resource, &KyWirelessNetResource::wifiNetworkAdd, this, &WlanPage::onWlanAdded);
connect(m_resource, &KyWirelessNetResource::wifiNetworkRemove, this, &WlanPage::onWlanRemoved);
connect(m_resource, &KyWirelessNetResource::wifiNetworkUpdate, this, &WlanPage::onWlanUpdated);
}
/**
* @brief WlanPage::getActiveWlan
*/
void WlanPage::getActiveWlan()
{
QMap<QString,QStringList> actMap;
m_activatedNetListWidget->clear();
m_resource->getWirelessActiveConnection(NetworkManager::ActiveConnection::State::Activated, actMap);
QMap<QString,QStringList>::iterator iter = actMap.begin();
int height = 0;
while (iter != actMap.end()) {
if (iter.key() == "wlp3s0" && !iter.value().isEmpty()) {
QString ssid = iter.value().at(0);
m_activatedWlanSSid = ssid;
KyWirelessNetItem data;
if (!m_resource->getWifiNetwork("wlp3s0", ssid, data)) {
return;
}
KyWirelessNetItem *item_data = new KyWirelessNetItem(data);
WlanListItem *wlanItemWidget = new WlanListItem(m_resource, item_data);
qDebug() << "Activated wlan: ssid = " << item_data->m_NetSsid;
QListWidgetItem *wlanItem = new QListWidgetItem(m_activatedNetListWidget);
wlanItem->setSizeHint(QSize(m_activatedNetListWidget->width(), wlanItemWidget->height()));
m_activatedNetListWidget->addItem(wlanItem);
m_activatedNetListWidget->setItemWidget(wlanItem, wlanItemWidget);
height += wlanItemWidget->height();
break;
}
iter ++;
}
if (height > 0) {
m_activatedNetListWidget->setFixedHeight(height);
} else {
//ZJP_TODO 未连接任何WiFi的情况
m_activatedWlanSSid.clear();
}
}
/**
* @brief WlanPage::getAllWlan Wlan //ZJP_TODO 需要针对网卡进行筛选
*/
void WlanPage::getAllWlan()
{
qDebug() << "Started loading wlan list! time=" << QDateTime::currentDateTime().toString("hh:mm:ss.zzzz");
m_inactivatedNetListWidget->clear();
m_itemsMap.clear();
QList<KyWirelessNetItem> wlanList;
// if (!m_resource->getAllDeviceWifiNetwork(map))
if (!m_resource->getDeviceWifiNetwork("wlp3s0", wlanList)) //ZJP_TODO 获取默认网卡并传入
{
return;
}
int height = 0;
foreach (auto itemData, wlanList) {
if (itemData.m_NetSsid == this->m_activatedWlanSSid) {
continue;
}
KyWirelessNetItem *data = new KyWirelessNetItem(itemData);
WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data);
QListWidgetItem *wlanItem = new QListWidgetItem(m_inactivatedNetListWidget);
m_itemsMap.insert(data->m_NetSsid, wlanItem);
wlanItem->setSizeHint(QSize(m_inactivatedNetListWidget->width(), wlanItemWidget->height()));
m_inactivatedNetListWidget->addItem(wlanItem);
m_inactivatedNetListWidget->setItemWidget(wlanItem, wlanItemWidget);
if (height == 0) {
height += wlanItemWidget->height();
}
height += wlanItemWidget->height() + NET_LIST_SPACING;
}
m_inactivatedNetListWidget->setFixedHeight(height);
m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_hiddenWlanLabel->height());
qDebug() << "Stopped loading wlan list! time=" << QDateTime::currentDateTime().toString("hh:mm:ss.zzzz");
}
void WlanPage::onWlanAdded(QString interface, KyWirelessNetItem &item)
{
qDebug() << "A Wlan Added! interface = " << interface << "; ssid = " << item.m_NetSsid << Q_FUNC_INFO <<__LINE__;
KyWirelessNetItem *data = new KyWirelessNetItem(item);
WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data);
QListWidgetItem *wlanItem = new QListWidgetItem(m_inactivatedNetListWidget);
wlanItem->setSizeHint(QSize(m_inactivatedNetListWidget->width(), wlanItemWidget->height()));
m_inactivatedNetListWidget->setItemWidget(wlanItem, wlanItemWidget);
// m_inactivatedNetListWidget->insertItem(N, wlanItem);
m_inactivatedNetListWidget->addItem(wlanItem); //ZJP_TODO 目前会添加到列表尾部
m_inactivatedNetListWidget->setFixedHeight(m_inactivatedNetListWidget->height() + wlanItemWidget->height() + NET_LIST_SPACING);
m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_hiddenWlanLabel->height());
m_itemsMap.insert(data->m_NetSsid, wlanItem);
}
void WlanPage::onWlanRemoved(QString interface, QString ssid)
{
if (!m_itemsMap.contains(ssid)) { return; }
qDebug() << "A Wlan Removed! interface = " << interface << "; ssid = " << ssid << Q_FUNC_INFO <<__LINE__;
m_inactivatedNetListWidget->removeItemWidget(m_itemsMap.value(ssid));
m_inactivatedNetListWidget->setFixedHeight(m_inactivatedNetListWidget->height() -
m_inactivatedNetListWidget->itemWidget(m_itemsMap.value(ssid))->height() -
NET_LIST_SPACING);
m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_hiddenWlanLabel->height());
m_itemsMap.remove(ssid);
}
void WlanPage::onWlanUpdated()
{
//ZJP_TODO 某些特定情况下不可重绘整个列表,此处代码需要修改
getAllWlan();
}

View File

@ -2,6 +2,9 @@
#define WLANPAGE_H
#include "tabpage.h"
#include "kywirelessnetresource.h"
//#define SCROLLAREA_HEIGHT 150
#define MORE_TEXT_MARGINS 16,0,0,0
class WlanPage : public TabPage
{
@ -17,11 +20,24 @@ protected:
private:
void initWlanUI();
void initConnections();
void getActiveWlan();
void getAllWlan();
QMap<QString, QListWidgetItem*> m_itemsMap;
QFrame * m_inactivatedWlanListAreaCentralWidget = nullptr;
QVBoxLayout * m_inactivatedWlanListAreaLayout = nullptr;
QFrame * m_hiddenWlanWidget = nullptr;
QHBoxLayout * m_hiddenWlanLayout = nullptr;
QLabel * m_hiddenWlanLabel = nullptr;
QString m_activatedWlanSSid;
KyWirelessNetResource *m_resource = nullptr;
private slots:
void onWlanAdded(QString interface, KyWirelessNetItem &item);
void onWlanRemoved(QString interface, QString ssid);
void onWlanUpdated();
};
#endif // WLANPAGE_H

View File

@ -1,5 +1,8 @@
#include "infobutton.h"
#include <QEvent>
#include <QIcon>
#define BUTTON_SIZE 16,16
InfoButton::InfoButton(QWidget *parent) : QPushButton(parent)
{
@ -9,22 +12,27 @@ InfoButton::InfoButton(QWidget *parent) : QPushButton(parent)
void InfoButton::initUI()
{
this->setFixedSize(BUTTON_SIZE);
this->setText("i");
}
void InfoButton::enterEvent(QEvent *)
{
}
void InfoButton::leaveEvent(QEvent *)
{
}
bool InfoButton::eventFilter(QObject *w, QEvent *e)
{
if(e->type() == QEvent::MouseButtonPress) {
emit this->clicked();
}
return QPushButton::eventFilter(w, e);
}
void InfoButton::paintEvent(QPaintEvent *event)
{
return QPushButton::paintEvent(event);
}

View File

@ -1,6 +1,7 @@
#ifndef INFOBUTTON_H
#define INFOBUTTON_H
#include <QPushButton>
#include <QLabel>
class InfoButton : public QPushButton
{
@ -9,13 +10,20 @@ public:
explicit InfoButton(QWidget * parent = nullptr);
~InfoButton() = default;
signals:
void clicked();
private:
void initUI();
private:
QLabel *m_iconLabel = nullptr;
protected:
virtual void enterEvent(QEvent *event);
virtual void leaveEvent(QEvent *event);
bool eventFilter(QObject *watched, QEvent *event);
void paintEvent(QPaintEvent *event);
};
#endif // INFOBUTTON_H

View File

@ -1,26 +1,26 @@
#include "netbutton.h"
#include "radioitembutton.h"
NetButton::NetButton(bool isActivated, QWidget *parent) : QPushButton(parent)
RadioItemButton::RadioItemButton(bool isActivated, QWidget *parent) : QPushButton(parent)
{
connect(this, &NetButton::requestStartLoading, this, &NetButton::onLoadingStarted);
connect(this, &NetButton::requestStopLoading, this, &NetButton::onLoadingStopped);
connect(this, &RadioItemButton::requestStartLoading, this, &RadioItemButton::onLoadingStarted);
connect(this, &RadioItemButton::requestStopLoading, this, &RadioItemButton::onLoadingStopped);
m_isActivated = isActivated;
this->setAutoFillBackground(false);
m_iconLabel = new QLabel(this);
m_iconLabel->setScaledContents(true);
}
void NetButton::startLoading()
void RadioItemButton::startLoading()
{
emit this->requestStartLoading();
}
void NetButton::stopLoading()
void RadioItemButton::stopLoading()
{
emit this->requestStopLoading();
}
void NetButton::setPressed()
void RadioItemButton::setPressed()
{
//ZJP_TODO 设置颜色为点击颜色,注意区分已连接/未连接
if (m_isActivated)
@ -28,7 +28,7 @@ void NetButton::setPressed()
;
}
void NetButton::setReleased()
void RadioItemButton::setReleased()
{
//ZJP_TODO 设置颜色为未点击颜色,注意区分已连接/未连接
if (m_isActivated)
@ -36,19 +36,19 @@ void NetButton::setReleased()
;
}
void NetButton::setButtonIcon(QIcon *icon)
void RadioItemButton::setButtonIcon(QIcon *icon)
{
if (!icon) { return; }
//ZJP_TODO 绘制圆形按钮
m_iconLabel->setPixmap(icon->pixmap(this->size()));
}
void NetButton::onLoadingStarted()
void RadioItemButton::onLoadingStarted()
{
//ZJP_TODO 开始播放转圈动画
}
void NetButton::onLoadingStopped()
void RadioItemButton::onLoadingStopped()
{
//ZJP_TODO 停止播放转圈动画
}

View File

@ -6,12 +6,12 @@
#define ACTIVATED true
#define INACTIVATED false
class NetButton : public QPushButton
class RadioItemButton : public QPushButton
{
Q_OBJECT
public:
NetButton(bool isActivated = INACTIVATED, QWidget * parent = nullptr);
~NetButton() = default;
RadioItemButton(bool isActivated = INACTIVATED, QWidget * parent = nullptr);
~RadioItemButton() = default;
void startLoading();
void stopLoading();
void setPressed();

View File

@ -4,7 +4,7 @@ HEADERS += \
$$PWD/divider.h \
$$PWD/infobutton.h \
$$PWD/loadingdiv.h \
$$PWD/netbutton.h \
$$PWD/radioitembutton.h \
$$PWD/switchbutton.h
@ -12,5 +12,5 @@ SOURCES += \
$$PWD/divider.cpp \
$$PWD/infobutton.cpp \
$$PWD/loadingdiv.cpp \
$$PWD/netbutton.cpp \
$$PWD/radioitembutton.cpp \
$$PWD/switchbutton.cpp

View File

@ -86,7 +86,7 @@ int main(int argc, char *argv[])
// QApplication a(argc, argv);
QString id = QString("kylin-nm"+ QLatin1String(getenv("DISPLAY")));
QtSingleApplication a(id, argc, argv);
qInstallMessageHandler(messageOutput);
// qInstallMessageHandler(messageOutput);
if (a.isRunning()) {
auto connection = QDBusConnection::sessionBus();
QDBusInterface iface("com.kylin.network",