Merge branch 'dbus-interface' of http://gitlab2.kylin.com/kylin-desktop/kylin-nm into up-dbus
This commit is contained in:
commit
ddea801445
|
@ -166,7 +166,7 @@ void KyNetworkResourceManager::addActiveConnection(NetworkManager::ActiveConnect
|
|||
connect(conn.data(), &NetworkManager::ActiveConnection::masterChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
|
||||
connect(conn.data(), &NetworkManager::ActiveConnection::specificObjectChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
|
||||
connect(conn.data(), &NetworkManager::ActiveConnection::stateChangedReason, this, &KyNetworkResourceManager::onActiveConnectionChangedReason);
|
||||
connect(conn.data(), &NetworkManager::ActiveConnection::stateChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
|
||||
connect(conn.data(), &NetworkManager::ActiveConnection::stateChanged, this, &KyNetworkResourceManager::onActiveConnectionChanged);
|
||||
connect(conn.data(), &NetworkManager::ActiveConnection::vpnChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
|
||||
connect(conn.data(), &NetworkManager::ActiveConnection::uuidChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
|
||||
connect(conn.data(), &NetworkManager::ActiveConnection::devicesChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
|
||||
|
@ -543,6 +543,21 @@ void KyNetworkResourceManager::onActiveConnectionChangedReason(
|
|||
return;
|
||||
}
|
||||
|
||||
void KyNetworkResourceManager::onActiveConnectionChanged(
|
||||
NetworkManager::ActiveConnection::State state)
|
||||
{
|
||||
NetworkManager::ActiveConnection * activeConnect =
|
||||
qobject_cast<NetworkManager::ActiveConnection *>(sender());
|
||||
if (activeConnect->isValid()) {
|
||||
qDebug()<<"!New state change activate connect"<<activeConnect->uuid();
|
||||
qDebug()<<"!New the active connect state"<<state;
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void KyNetworkResourceManager::onVpnActiveConnectChanagedReason(NetworkManager::VpnConnection::State state,
|
||||
NetworkManager::VpnConnection::StateChangeReason reason)
|
||||
{
|
||||
|
|
|
@ -145,6 +145,8 @@ private slots:
|
|||
void onActiveConnectionUpdated();
|
||||
void onActiveConnectionChangedReason(NetworkManager::ActiveConnection::State state,
|
||||
NetworkManager::ActiveConnection::Reason reason);
|
||||
|
||||
void onActiveConnectionChanged(NetworkManager::ActiveConnection::State state);
|
||||
void onVpnActiveConnectChanagedReason(NetworkManager::VpnConnection::State state,
|
||||
NetworkManager::VpnConnection::StateChangeReason reason);
|
||||
|
||||
|
|
|
@ -78,54 +78,6 @@ void getDeviceEnableState(int type, QMap<QString, bool> &map)
|
|||
return;
|
||||
}
|
||||
|
||||
//设置默认网卡
|
||||
void setDefaultDevice(KyDeviceType deviceType, QString deviceName)
|
||||
{
|
||||
QString key;
|
||||
switch (deviceType) {
|
||||
case WIRED:
|
||||
key = "wired";
|
||||
break;
|
||||
case WIRELESS:
|
||||
key = "wireless";
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
break;
|
||||
}
|
||||
QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat);
|
||||
m_settings->beginGroup("DEFAULTCARD");
|
||||
m_settings->setValue(key, deviceName);
|
||||
m_settings->endGroup();
|
||||
m_settings->sync();
|
||||
delete m_settings;
|
||||
m_settings = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
bool checkDeviceExist(KyDeviceType deviceType, QString deviceName)
|
||||
{
|
||||
NetworkManager::Device::Type type;
|
||||
switch (deviceType) {
|
||||
case WIRED:
|
||||
type = NetworkManager::Device::Type::Ethernet;
|
||||
break;
|
||||
case WIRELESS:
|
||||
type = NetworkManager::Device::Type::Wifi;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
KyNetworkDeviceResourse * kdr = new KyNetworkDeviceResourse();
|
||||
QStringList devList;
|
||||
devList.clear();
|
||||
|
||||
kdr->getNetworkDeviceList(type, devList);
|
||||
return devList.contains(deviceName);
|
||||
}
|
||||
|
||||
/*
|
||||
* Implementation of adaptor class DbusAdaptor
|
||||
*/
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <QtDBus/QtDBus>
|
||||
#include <QtDBus/QDBusMetaType>
|
||||
|
||||
#include "tabpage.h"
|
||||
#include "../dbus-interface/kylinnetworkdeviceresource.h"
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QByteArray;
|
||||
|
@ -33,15 +34,6 @@ QT_END_NAMESPACE
|
|||
|
||||
#include "new-mainwindow.h"
|
||||
|
||||
enum KyDeviceType
|
||||
{
|
||||
WIRED,
|
||||
WIRELESS
|
||||
};
|
||||
|
||||
bool checkDeviceExist(KyDeviceType deviceType, QString deviceName);
|
||||
void setDefaultDevice(KyDeviceType deviceType, QString deviceName);
|
||||
|
||||
class DbusAdaptor: public QDBusAbstractAdaptor
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
|
@ -10,43 +10,46 @@ LanListItem::LanListItem(KyConnectItem *data, QString deviceName, QWidget *paren
|
|||
m_connectOperation = new KyWiredConnectOperation;
|
||||
m_data = data;
|
||||
m_nameLabel->setText(m_data->m_connectName);
|
||||
|
||||
if (m_data != nullptr) {
|
||||
if (m_data->m_connectState == NetworkManager::ActiveConnection::State::Activated) {
|
||||
setIcon(true);
|
||||
m_activated = true;
|
||||
m_isActive = true;
|
||||
} else {
|
||||
setIcon(false);
|
||||
m_activated = false;
|
||||
m_isActive = false;
|
||||
}
|
||||
}
|
||||
m_netButton->setActive(m_isActive);
|
||||
m_itemFrame->installEventFilter(this);
|
||||
|
||||
}
|
||||
|
||||
bool LanListItem::eventFilter(QObject *watched, QEvent *event)
|
||||
void LanListItem::onInfoButtonClicked()
|
||||
{
|
||||
if (watched == m_itemFrame) {
|
||||
if (event->type() == QEvent::MouseButtonPress) {
|
||||
if (!m_activated) {
|
||||
//未连接,点击后连
|
||||
m_connectOperation->activateWiredConnection(m_data->m_connectUuid, deviceName);
|
||||
qDebug() << m_data->m_connectName << "Connect after user clicked!";
|
||||
m_activated = true;
|
||||
} else {
|
||||
//连接,点击后断开
|
||||
m_connectOperation->deactivateWiredConnection(m_data->m_connectName, m_data->m_connectUuid);
|
||||
qDebug() << m_data->m_connectName << "Disconnect after user clicked!";
|
||||
m_activated = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void LanListItem::onNetButtonClicked()
|
||||
{
|
||||
if (!m_isActive) {
|
||||
//未连接,点击后连
|
||||
m_connectOperation->activateWiredConnection(m_data->m_connectUuid, deviceName);
|
||||
qDebug() << m_data->m_connectName << "Connect after user clicked!";
|
||||
m_isActive = true;
|
||||
} else {
|
||||
//连接,点击后断开
|
||||
m_connectOperation->deactivateWiredConnection(m_data->m_connectName, m_data->m_connectUuid);
|
||||
qDebug() << m_data->m_connectName << "Disconnect after user clicked!";
|
||||
m_isActive = false;
|
||||
}
|
||||
return ListItem::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
void LanListItem::setIcon(bool isOn)
|
||||
{
|
||||
if (isOn) {
|
||||
m_netButton->setIcon(QIcon::fromTheme("network-wired-connected-symbolic"));
|
||||
m_netButton->setButtonIcon(QIcon::fromTheme("network-wired-connected-symbolic"));
|
||||
} else {
|
||||
m_netButton->setIcon(QIcon::fromTheme("network-wired-disconnected-symbolic"));
|
||||
m_netButton->setButtonIcon(QIcon::fromTheme("network-wired-disconnected-symbolic"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,14 +17,16 @@ public:
|
|||
|
||||
protected:
|
||||
void setIcon(bool isOn);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
private:
|
||||
KyConnectItem *m_data = nullptr;
|
||||
KyWiredConnectOperation *m_connectOperation = nullptr;
|
||||
|
||||
bool m_activated = false;
|
||||
QString deviceName = nullptr;
|
||||
|
||||
private slots:
|
||||
void onInfoButtonClicked();
|
||||
void onNetButtonClicked();
|
||||
};
|
||||
|
||||
#endif // LANLISTITEM_H
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
#include "listitem.h"
|
||||
#include <QDebug>
|
||||
|
||||
#define MAIN_LAYOUT_MARGINS 0,0,0,0
|
||||
#define MAIN_LAYOUT_SPACING 0
|
||||
#define ITEM_FRAME_MARGINS 16,6,16,6
|
||||
#define ITEM_FRAME_SPACING 10
|
||||
|
||||
#define FRAME_WIDTH 395
|
||||
#define INFO_ICON_WIDTH 16
|
||||
#define INFO_ICON_HEIGHT 16
|
||||
|
||||
|
@ -12,6 +13,7 @@ ListItem::ListItem(QWidget *parent) : QFrame(parent)
|
|||
{
|
||||
initUI();
|
||||
initConnection();
|
||||
m_itemFrame->installEventFilter(this);
|
||||
}
|
||||
|
||||
ListItem::~ListItem()
|
||||
|
@ -23,22 +25,28 @@ ListItem::~ListItem()
|
|||
m_infoButton = NULL;
|
||||
}
|
||||
|
||||
bool ListItem::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched == this) {
|
||||
if (event->type() == QEvent::MouseButtonPress) {
|
||||
this->onNetButtonClicked();
|
||||
}
|
||||
}
|
||||
return QFrame::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
|
||||
void ListItem::setName(const QString &name)
|
||||
{
|
||||
m_nameLabel->setText(name);
|
||||
}
|
||||
|
||||
//仅无线调用,有线自己获取
|
||||
void ListItem::setActive(const bool &isActive)
|
||||
{
|
||||
m_netButton->setActive(isActive);
|
||||
m_isActive = isActive;
|
||||
}
|
||||
|
||||
bool ListItem::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched == m_itemFrame) {
|
||||
if (event->type() == QEvent::MouseButtonPress) {
|
||||
onNetButtonClicked();
|
||||
}
|
||||
}
|
||||
return QFrame::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
void ListItem::initUI()
|
||||
{
|
||||
m_mainLayout = new QVBoxLayout(this);
|
||||
|
@ -47,10 +55,11 @@ void ListItem::initUI()
|
|||
this->setLayout(m_mainLayout);
|
||||
|
||||
m_itemFrame = new QFrame(this);
|
||||
m_itemFrame->setFixedWidth(FRAME_WIDTH);
|
||||
|
||||
m_hItemLayout = new QHBoxLayout(m_itemFrame);
|
||||
m_hItemLayout->setContentsMargins(ITEM_FRAME_MARGINS);
|
||||
m_hItemLayout->setSpacing(ITEM_FRAME_SPACING);
|
||||
// m_hItemLayout->setSpacing(ITEM_FRAME_SPACING);
|
||||
|
||||
m_netButton = new RadioItemButton(m_itemFrame);
|
||||
m_nameLabel = new QLabel(m_itemFrame);
|
||||
|
@ -81,4 +90,3 @@ void ListItem::onNetButtonClicked()
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <QEvent>
|
||||
#include <QHBoxLayout>
|
||||
#include "radioitembutton.h"
|
||||
#include "netbutton.h"
|
||||
#include "infobutton.h"
|
||||
class ListItem : public QFrame
|
||||
{
|
||||
|
@ -13,6 +12,7 @@ public:
|
|||
ListItem(QWidget *parent = nullptr);
|
||||
~ListItem();
|
||||
void setName(const QString &name);
|
||||
void setActive(const bool &isActive);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
@ -24,6 +24,8 @@ protected:
|
|||
RadioItemButton * m_netButton = nullptr;
|
||||
InfoButton * m_infoButton = nullptr;
|
||||
|
||||
bool m_isActive = false;
|
||||
|
||||
public:
|
||||
QVBoxLayout * m_mainLayout = nullptr;
|
||||
QHBoxLayout * m_hItemLayout = nullptr;
|
||||
|
|
|
@ -54,11 +54,6 @@ void WlanListItem::setExpanded(const bool &expanded)
|
|||
emit this->itemHeightChanged(m_data->m_NetSsid);
|
||||
}
|
||||
|
||||
void WlanListItem::setActivated(bool activated)
|
||||
{
|
||||
this->m_isActivated = activated;
|
||||
}
|
||||
|
||||
void WlanListItem::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
this->blockSignals(true);
|
||||
|
@ -212,24 +207,9 @@ void WlanListItem::onNetButtonClicked()
|
|||
qDebug() << "On wlan clicked! But there is no wlan connect!" << Q_FUNC_INFO << __LINE__;
|
||||
return;
|
||||
}
|
||||
qDebug() << "On wlan clicked! ssid = " << m_data->m_NetSsid << "; name = " << m_data->m_connName << "." << Q_FUNC_INFO << __LINE__;
|
||||
|
||||
//判断当前item处于连接还是断开对比activessid
|
||||
QString activedssid;
|
||||
QMap<QString,QStringList> actMap;
|
||||
m_resource->getWirelessActiveConnection(NetworkManager::ActiveConnection::State::Activated, actMap);
|
||||
QMap<QString,QStringList>::iterator iter = actMap.begin();
|
||||
while (iter != actMap.end()) {
|
||||
if (iter.key() == m_wlanDevice && !iter.value().isEmpty()) {
|
||||
activedssid = iter.value().at(0);
|
||||
break;
|
||||
}
|
||||
iter ++;
|
||||
}
|
||||
qDebug()<<"Get activated wlan succeed! ssid = " << activedssid <<Q_FUNC_INFO << __LINE__;
|
||||
|
||||
//执行连接或断开
|
||||
if (m_data->m_NetSsid == activedssid) {
|
||||
if (m_isActive) {
|
||||
m_connoperation->deActivateWirelessConnection(m_wlanDevice,m_data->m_connectUuid);
|
||||
qDebug()<<"Clicked on connected wifi, it will be inactivated. ssid = " << m_data->m_NetSsid << Q_FUNC_INFO << __LINE__;
|
||||
return;
|
||||
|
|
|
@ -27,7 +27,6 @@ public:
|
|||
void setWlanSignal(const int &signal);
|
||||
void setWlanState(const int &state);
|
||||
void setExpanded(const bool &expanded);
|
||||
void setActivated(bool activated);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
|
@ -46,7 +45,6 @@ private:
|
|||
KyWirelessNetItem *m_data = nullptr;
|
||||
KyWirelessConnectOperation *m_connoperation = nullptr;
|
||||
bool m_hasPwd = true;
|
||||
bool m_isActivated = false;
|
||||
QString m_wlanDevice;
|
||||
|
||||
//密码输入区域的UI
|
||||
|
|
|
@ -14,17 +14,31 @@
|
|||
#define SWITCH_HEIGHT 24
|
||||
#define ITEM_HEIGHT 48
|
||||
|
||||
const QString WIRED_SWITCH = "wiredswitch";
|
||||
const QByteArray GSETTINGS_SCHEMA = "org.ukui.kylin-nm.switch";
|
||||
|
||||
LanPage::LanPage(QWidget *parent) : TabPage(parent)
|
||||
{
|
||||
m_activeResourse = new KyActiveConnectResourse;
|
||||
m_connectResourse = new KyConnectResourse;
|
||||
m_device = new KyNetworkDeviceResourse;
|
||||
devList.empty();
|
||||
|
||||
initDevice();
|
||||
initUI();
|
||||
if (QGSettings::isSchemaInstalled(GSETTINGS_SCHEMA)) {
|
||||
m_switchGsettings = new QGSettings(GSETTINGS_SCHEMA);
|
||||
initNetSwitch();
|
||||
} else {
|
||||
qDebug()<<"[LanPage] org.ukui.kylin-nm.switch is not installed!";
|
||||
}
|
||||
initList();
|
||||
connect(m_activeResourse, &KyActiveConnectResourse::stateChangeReason, this, &LanPage::updateLanlist);
|
||||
connect(m_connectResourse, &KyConnectResourse::connectionAdd, this, &LanPage::addConnectionSlot);
|
||||
connect(m_connectResourse, &KyConnectResourse::connectionRemove, this, &LanPage::removeConnectionSlot);
|
||||
connect(m_device, &KyNetworkDeviceResourse::deviceAdd, this, &LanPage::onDeviceAdd);
|
||||
connect(m_device, &KyNetworkDeviceResourse::deviceRemove, this, &LanPage::onDeviceRemove);
|
||||
connect(m_device, &KyNetworkDeviceResourse::deviceNameUpdate, this, &LanPage::onDeviceNameUpdate);
|
||||
}
|
||||
|
||||
LanPage::~LanPage()
|
||||
|
@ -32,6 +46,41 @@ LanPage::~LanPage()
|
|||
|
||||
}
|
||||
|
||||
void LanPage::initNetSwitch()
|
||||
{
|
||||
if (m_switchGsettings->keys().contains(WIRED_SWITCH)) {
|
||||
m_netSwitch->setSwitchStatus(m_switchGsettings->get(WIRED_SWITCH).toBool());
|
||||
connect(m_switchGsettings, &QGSettings::changed, this, &LanPage::onSwithGsettingsChanged);
|
||||
}
|
||||
connect(m_netSwitch, &SwitchButton::clicked, this, &LanPage::onLanSwitchClicked);
|
||||
}
|
||||
|
||||
void LanPage::onSwithGsettingsChanged(const QString &key)
|
||||
{
|
||||
if (key == WIRED_SWITCH) {
|
||||
m_netSwitch->blockSignals(true);
|
||||
qDebug()<<"[LanPage] SwitchButton statue changed to ::"<<m_switchGsettings->get(WIRED_SWITCH).toBool();
|
||||
m_netSwitch->setSwitchStatus(m_switchGsettings->get(WIRED_SWITCH).toBool());
|
||||
m_netSwitch->blockSignals(false);
|
||||
}
|
||||
}
|
||||
|
||||
void LanPage::onLanSwitchClicked()
|
||||
{
|
||||
qDebug()<<"[LanPage] On lan switch button clicked! Status:"<<m_netSwitch->getSwitchStatus();
|
||||
if (m_netSwitch->getSwitchStatus()) {
|
||||
m_device->setDeviceAutoConnect();
|
||||
m_inactivatedLanListWidget->show();
|
||||
m_switchGsettings->set(WIRED_SWITCH,true);
|
||||
} else {
|
||||
if (m_activeMap.count() != 0) {
|
||||
m_device->disconnectDevice();
|
||||
}
|
||||
m_inactivatedLanListWidget->hide();
|
||||
m_switchGsettings->set(WIRED_SWITCH,false);
|
||||
}
|
||||
}
|
||||
|
||||
void LanPage::removeConnectionSlot(QString path) //删除时后端会自动断开激活,将其从未激活列表中删除
|
||||
{
|
||||
qDebug()<<"[LanPage] Removing a connection, path:"<<path;
|
||||
|
@ -60,17 +109,11 @@ void LanPage::addConnectionSlot(QString uuid) //新增一个有线
|
|||
{
|
||||
KyConnectItem * newItem = m_connectResourse->getConnectionItemByUuid(uuid, m_deviceName);
|
||||
if (newItem != nullptr) {
|
||||
qDebug()<<"[LanPage] Add a new connection, name:"<<newItem->m_connectName;
|
||||
LanListItem * newListItem = new LanListItem(newItem, m_deviceName);
|
||||
newListItem->setFixedHeight(ITEM_HEIGHT);
|
||||
|
||||
m_listWidgetItem = new QListWidgetItem(m_inactivatedLanListWidget);
|
||||
m_listWidgetItem->setSizeHint(QSize(m_inactivatedLanListWidget->width(),ITEM_HEIGHT));
|
||||
|
||||
m_inactivatedLanListWidget->addItem(m_listWidgetItem);
|
||||
m_inactivatedLanListWidget->setItemWidget(m_listWidgetItem, newListItem);
|
||||
m_deactiveMap.insert(newItem, m_listWidgetItem);
|
||||
|
||||
if (newItem->m_itemType == NetworkManager::ConnectionSettings::ConnectionType::Wired) {
|
||||
qDebug()<<"[LanPage] Add a new connection, name:"<<newItem->m_connectName;
|
||||
addNewItem(newItem, m_inactivatedLanListWidget);
|
||||
m_deactiveMap.insert(newItem, m_listWidgetItem);
|
||||
}
|
||||
//for dbus
|
||||
qDebug() << "[LanPage] because addConnectionSlot " << newItem->m_ifaceName;
|
||||
emit listUpdate(newItem->m_ifaceName);
|
||||
|
@ -87,11 +130,8 @@ void LanPage::initDevice()
|
|||
m_deviceName = m_settings->value(key, "").toString();
|
||||
if (m_deviceName.isEmpty()) {
|
||||
qDebug() << "initDevice but defalut wired card is null";
|
||||
QStringList list;
|
||||
list.empty();
|
||||
m_device->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, list);
|
||||
if (!list.isEmpty()) {
|
||||
m_deviceName = list.at(0);
|
||||
if (!devList.isEmpty()) {
|
||||
m_deviceName = devList.at(0);
|
||||
m_settings->setValue(key, m_deviceName);
|
||||
}
|
||||
}
|
||||
|
@ -102,6 +142,60 @@ void LanPage::initDevice()
|
|||
m_settings->sync();
|
||||
delete m_settings;
|
||||
m_settings = nullptr;
|
||||
for (int i = 0; i < devList.size(); ++i) {
|
||||
qDebug() << "[LanPage] Device: " << devList.at(i);
|
||||
}
|
||||
}
|
||||
|
||||
void LanPage::onDeviceAdd(QString deviceName, NetworkManager::Device::Type deviceType)
|
||||
{
|
||||
qDebug() << "[LanPage] Begin add device:" << deviceName;
|
||||
if (deviceType != NetworkManager::Device::Type::Ethernet) {
|
||||
return;
|
||||
}
|
||||
devList << deviceName;
|
||||
if (getDefaultDevice().isEmpty())
|
||||
{
|
||||
updateDefaultDevice(deviceName);
|
||||
setDefaultDevice(WIRED, deviceName);
|
||||
}
|
||||
emit deviceStatusChanged();
|
||||
}
|
||||
|
||||
void LanPage::onDeviceRemove(QString deviceName)
|
||||
{
|
||||
qDebug() << "deviceRemove" << deviceName;
|
||||
if (getDefaultDevice() == deviceName)
|
||||
{
|
||||
QStringList list;
|
||||
QString newDefaultDevice = "";
|
||||
list.empty();
|
||||
m_device->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, list);
|
||||
if (!list.isEmpty()) {
|
||||
newDefaultDevice = list.at(0);
|
||||
}
|
||||
updateDefaultDevice(newDefaultDevice);
|
||||
setDefaultDevice(WIRED, newDefaultDevice);
|
||||
}
|
||||
if (devList.contains(deviceName)) {
|
||||
devList.removeOne(deviceName);
|
||||
emit deviceStatusChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void LanPage::onDeviceNameUpdate(QString oldName, QString newName)
|
||||
{
|
||||
if (getDefaultDevice() == oldName) {
|
||||
updateDefaultDevice(newName);
|
||||
setDefaultDevice(WIRED, newName);
|
||||
}
|
||||
|
||||
if (devList.contains(oldName)) {
|
||||
devList.removeOne(oldName);
|
||||
devList.append(newName);
|
||||
qDebug() << "LanPage emit deviceNameUpdate " << oldName << newName;
|
||||
emit deviceNameChanged(oldName, newName);
|
||||
}
|
||||
}
|
||||
|
||||
void LanPage::initUI()
|
||||
|
@ -112,22 +206,28 @@ void LanPage::initUI()
|
|||
m_activatedNetLabel->setText(tr("Activated LAN"));
|
||||
m_activatedLanListWidget = new QListWidget(m_activatedNetFrame);
|
||||
m_activatedLanListWidget->setFrameShape(QFrame::Shape::NoFrame);
|
||||
// m_activatedLanListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
|
||||
m_activatedLanListWidget->setSpacing(LAN_LIST_SPACING);
|
||||
m_activatedLanListWidget->setFixedHeight(ITEM_HEIGHT); //active区域固定高度,只显示一个条目
|
||||
m_activatedLanListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_activatedNetLayout->addWidget(m_activatedLanListWidget);
|
||||
|
||||
m_inactivatedNetLabel->setText(tr("Inactivated LAN"));
|
||||
|
||||
m_inactivatedNetListArea->setBackgroundRole(QPalette::Base);
|
||||
m_inactivatedNetListArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
m_inactivatedNetListArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_inactivatedNetListArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
// m_inactivatedNetListArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||
|
||||
QVBoxLayout *inactiveLanListLayout = new QVBoxLayout(m_inactivatedNetListArea);
|
||||
inactiveLanListLayout->setContentsMargins(MAIN_LAYOUT_MARGINS);
|
||||
inactiveLanListLayout->setSpacing(MAIN_LAYOUT_SPACING);
|
||||
|
||||
m_inactivatedLanListWidget = new QListWidget(m_inactivatedNetListArea);
|
||||
m_inactivatedLanListWidget->setFrameShape(QFrame::Shape::NoFrame);
|
||||
// m_inactivatedLanListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
|
||||
m_inactivatedLanListWidget->setSpacing(LAN_LIST_SPACING);
|
||||
QVBoxLayout *inactiveLanListLayout = new QVBoxLayout(m_inactivatedNetListArea);
|
||||
m_inactivatedLanListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
// m_inactivatedLanListWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); //用了listwidget的滚动条
|
||||
|
||||
inactiveLanListLayout->addWidget(m_inactivatedLanListWidget);
|
||||
|
||||
// KyConnectItem *activeConnectItem = new KyConnectItem();
|
||||
|
@ -141,7 +241,16 @@ void LanPage::initUI()
|
|||
// m_listWidgetItem = new QListWidgetItem(m_inactivatedLanListWidget);
|
||||
// m_inactivatedLanListWidget->addItem(m_listWidgetItem);
|
||||
// m_inactivatedLanListWidget->setItemWidget(m_listWidgetItem, m_testLanItem);
|
||||
}
|
||||
|
||||
void LanPage::addNewItem(KyConnectItem *itemData, QListWidget *listWidget)
|
||||
{
|
||||
m_listWidgetItem = new QListWidgetItem(listWidget);
|
||||
m_listWidgetItem->setSizeHint(QSize(listWidget->width(),ITEM_HEIGHT));
|
||||
listWidget->addItem(m_listWidgetItem);
|
||||
|
||||
m_testLanItem = new LanListItem(itemData, m_deviceName);
|
||||
listWidget->setItemWidget(m_listWidgetItem, m_testLanItem);
|
||||
}
|
||||
|
||||
void LanPage::initList() //程序拉起,初始化显示
|
||||
|
@ -149,15 +258,9 @@ void LanPage::initList() //程序拉起,初始化显示
|
|||
m_activeResourse->getActiveConnectionList(m_deviceName,NetworkManager::ConnectionSettings::Wired,m_activedList); //激活列表的显示
|
||||
if (!m_activedList.isEmpty()) {
|
||||
for (int i = 0; i < m_activedList.size(); i++) {
|
||||
m_listWidgetItem = new QListWidgetItem(m_activatedLanListWidget);
|
||||
m_listWidgetItem->setSizeHint(QSize(m_activatedLanListWidget->width(),ITEM_HEIGHT));
|
||||
m_activatedLanListWidget->addItem(m_listWidgetItem);
|
||||
|
||||
KyConnectItem *activeItemData = m_activedList.at(i);
|
||||
|
||||
activeConnectItem = new LanListItem(activeItemData, m_deviceName);
|
||||
|
||||
m_activatedLanListWidget->setItemWidget(m_listWidgetItem, activeConnectItem);
|
||||
addNewItem(activeItemData, m_activatedLanListWidget);
|
||||
|
||||
m_activeMap.insert(activeItemData, m_listWidgetItem);
|
||||
}
|
||||
|
@ -166,16 +269,8 @@ void LanPage::initList() //程序拉起,初始化显示
|
|||
m_connectResourse->getConnectionList(m_deviceName, NetworkManager::ConnectionSettings::Wired, m_deactivedList); //未激活列表的显示
|
||||
if (!m_deactivedList.isEmpty()) {
|
||||
for (int i = 0; i < m_deactivedList.size(); i++) {
|
||||
m_listWidgetItem = new QListWidgetItem(m_inactivatedLanListWidget);
|
||||
m_listWidgetItem->setSizeHint(QSize(m_inactivatedLanListWidget->width(),ITEM_HEIGHT));
|
||||
m_inactivatedLanListWidget->addItem(m_listWidgetItem);
|
||||
|
||||
KyConnectItem *deactiveItemData = m_deactivedList.at(i);
|
||||
|
||||
deactiveConnectItem = new LanListItem(deactiveItemData ,m_deviceName);
|
||||
|
||||
// deactiveConnectItem->setFixedHeight(ITEM_HEIGHT);
|
||||
m_inactivatedLanListWidget->setItemWidget(m_listWidgetItem, deactiveConnectItem);
|
||||
addNewItem(deactiveItemData, m_inactivatedLanListWidget);
|
||||
|
||||
m_deactiveMap.insert(deactiveItemData, m_listWidgetItem);
|
||||
}
|
||||
|
@ -215,23 +310,16 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat
|
|||
qDebug()<<"Get an actived connection, begin to move it from deactive to avtive!";
|
||||
QMap<KyConnectItem *, QListWidgetItem *>::iterator iter; //在未激活列表里删除
|
||||
for (iter = m_deactiveMap.begin(); iter != m_deactiveMap.constEnd(); ++iter) {
|
||||
KyConnectItem *m_Item = iter.key();
|
||||
if (m_Item->m_connectUuid == uuid) {
|
||||
qDebug()<<"Add an active connection to activeList:"<<m_Item->m_connectName;
|
||||
m_Item->m_connectState = state;
|
||||
|
||||
m_listWidgetItem = new QListWidgetItem(m_activatedLanListWidget);
|
||||
m_listWidgetItem->setSizeHint(QSize(m_inactivatedLanListWidget->width(),ITEM_HEIGHT));
|
||||
m_activatedLanListWidget->addItem(iter.value());
|
||||
|
||||
m_activeItem = new LanListItem(m_Item ,m_deviceName);
|
||||
|
||||
m_activatedLanListWidget->setItemWidget(m_listWidgetItem, m_activeItem);
|
||||
KyConnectItem *m_item = iter.key();
|
||||
if (m_item->m_connectUuid == uuid) {
|
||||
qDebug()<<"Add an active connection to activeList:"<<m_item->m_connectName;
|
||||
m_item->m_connectState = state;
|
||||
addNewItem(m_item, m_activatedLanListWidget);
|
||||
|
||||
m_inactivatedLanListWidget->removeItemWidget(iter.value());
|
||||
delete(iter.value());
|
||||
|
||||
m_activeMap.insert(m_Item, m_listWidgetItem);
|
||||
m_activeMap.insert(m_item, m_listWidgetItem);
|
||||
m_deactiveMap.erase(iter);
|
||||
break;
|
||||
}
|
||||
|
@ -240,8 +328,8 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat
|
|||
qDebug()<<"Get a deactivate, begin to remove it from activeList";
|
||||
QMap<KyConnectItem *, QListWidgetItem *>::iterator i;
|
||||
for (i = m_activeMap.begin(); i != m_activeMap.constEnd(); ++i) { //有新断开,若在激活列表里则删掉
|
||||
KyConnectItem *m_Item = i.key();
|
||||
if (m_Item->m_connectUuid == uuid) {
|
||||
KyConnectItem *m_item = i.key();
|
||||
if (m_item->m_connectUuid == uuid) {
|
||||
m_activatedLanListWidget->removeItemWidget(i.value());
|
||||
delete(i.value());
|
||||
break;
|
||||
|
@ -251,8 +339,8 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat
|
|||
bool hasDeactiveNet = false;
|
||||
QMap<KyConnectItem *, QListWidgetItem *>::iterator iter;
|
||||
for (iter = m_deactiveMap.begin(); iter != m_deactiveMap.end(); ++iter) { //检查其是否已经在未激活列表中
|
||||
KyConnectItem *m_Item = iter.key();
|
||||
if (m_Item->m_connectUuid == uuid) {
|
||||
KyConnectItem *m_item = iter.key();
|
||||
if (m_item->m_connectUuid == uuid) {
|
||||
hasDeactiveNet = true;
|
||||
break;
|
||||
}
|
||||
|
@ -261,21 +349,14 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat
|
|||
|
||||
QMap<KyConnectItem *, QListWidgetItem *>::iterator iters;
|
||||
for (iters = m_activeMap.begin(); iters != m_activeMap.end(); ++iters) { //在未激活列表中增加一项连接
|
||||
KyConnectItem *m_Item = iters.key();
|
||||
if (m_Item->m_connectUuid == uuid && !hasDeactiveNet) {
|
||||
qDebug()<<"Add a deactive connection to inactiveList:"<<m_Item->m_connectName;
|
||||
m_Item->m_connectState = state;
|
||||
m_deactiveItem = new LanListItem(m_Item ,m_deviceName);
|
||||
m_deactiveItem->setFixedHeight(ITEM_HEIGHT);
|
||||
KyConnectItem *m_item = iters.key();
|
||||
if (m_item->m_connectUuid == uuid && !hasDeactiveNet) {
|
||||
qDebug()<<"Add a deactive connection to inactiveList:"<<m_item->m_connectName;
|
||||
m_item->m_connectState = state;
|
||||
|
||||
m_listWidgetItem = new QListWidgetItem(m_inactivatedLanListWidget);
|
||||
m_listWidgetItem->setSizeHint(QSize(m_inactivatedLanListWidget->width(),ITEM_HEIGHT));
|
||||
|
||||
m_inactivatedLanListWidget->addItem(m_listWidgetItem);
|
||||
m_inactivatedLanListWidget->setItemWidget(m_listWidgetItem, m_deactiveItem);
|
||||
|
||||
m_deactiveMap.insert(m_Item, m_listWidgetItem);
|
||||
addNewItem(m_item, m_inactivatedLanListWidget);
|
||||
|
||||
m_deactiveMap.insert(m_item, m_listWidgetItem);
|
||||
m_activeMap.erase(iters);
|
||||
break;
|
||||
}
|
||||
|
@ -285,19 +366,6 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
bool LanPage::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched == m_netSwitch) {
|
||||
// if(event == click)
|
||||
// {
|
||||
|
||||
// }
|
||||
}
|
||||
return QWidget::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
|
||||
void LanPage::getWiredList(QMap<QString, QVector<QStringList> > &map)
|
||||
{
|
||||
QStringList devlist;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <QScrollArea>
|
||||
#include <QListWidget>
|
||||
#include <QMap>
|
||||
#include <QGSettings>
|
||||
|
||||
#include "list-items/listitem.h"
|
||||
#include "list-items/lanlistitem.h"
|
||||
|
@ -33,25 +34,17 @@ private:
|
|||
void initDevice();//初始化默认设备
|
||||
void initUI();
|
||||
void initList();
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
void addNewItem(KyConnectItem *itemData, QListWidget *listWidget);
|
||||
|
||||
void initNetSwitch();
|
||||
|
||||
private:
|
||||
KyNetworkDeviceResourse *m_device = nullptr;
|
||||
|
||||
QListWidget * m_activatedLanListWidget = nullptr;
|
||||
QListWidget * m_inactivatedLanListWidget = nullptr;
|
||||
|
||||
LanListItem * m_testLanItem = nullptr;
|
||||
LanListItem * activeConnectItem = nullptr;
|
||||
LanListItem * deactiveConnectItem = nullptr;
|
||||
LanListItem * m_activeItem = nullptr;
|
||||
LanListItem * m_deactiveItem = nullptr;
|
||||
|
||||
QListWidgetItem *m_listWidgetItem = nullptr;
|
||||
|
||||
KyNetworkDeviceResourse * m_deviceSource = nullptr;
|
||||
KyNetworkDeviceResourse *m_device = nullptr;
|
||||
KyActiveConnectResourse *m_activeResourse = nullptr; //激活的连接
|
||||
KyConnectResourse *m_connectResourse = nullptr; //未激活的连接
|
||||
|
||||
|
@ -61,11 +54,18 @@ private:
|
|||
QMap<KyConnectItem *, QListWidgetItem *> m_deactiveMap;
|
||||
QMap<KyConnectItem *, QListWidgetItem *> m_activeMap;
|
||||
QString m_deviceName;
|
||||
QStringList devList;
|
||||
QGSettings * m_switchGsettings = nullptr;
|
||||
|
||||
private slots:
|
||||
void updateLanlist(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason);
|
||||
void addConnectionSlot(QString uuid);
|
||||
void removeConnectionSlot(QString path);
|
||||
void onSwithGsettingsChanged(const QString &key);
|
||||
void onLanSwitchClicked();
|
||||
void onDeviceAdd(QString deviceName, NetworkManager::Device::Type deviceType);
|
||||
void onDeviceRemove(QString deviceName);
|
||||
void onDeviceNameUpdate(QString oldName, QString newName);
|
||||
};
|
||||
|
||||
#endif // LANPAGE_H
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "tabpage.h"
|
||||
#include <qsettings.h>
|
||||
|
||||
TabPage::TabPage(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
|
@ -32,7 +33,7 @@ void TabPage::initUI()
|
|||
|
||||
m_activatedNetFrame = new QFrame(this);
|
||||
m_activatedNetLayout = new QVBoxLayout(m_activatedNetFrame);
|
||||
m_activatedNetLayout->setContentsMargins(NET_LAYOUT_MARGINS);
|
||||
m_activatedNetLayout->setContentsMargins(ACTIVE_NET_LAYOUT_MARGINS);
|
||||
m_activatedNetLayout->setSpacing(NET_LAYOUT_SPACING);
|
||||
m_activatedNetLabel = new QLabel(m_activatedNetFrame);
|
||||
m_activatedNetLabel->setContentsMargins(TEXT_MARGINS);
|
||||
|
@ -40,6 +41,7 @@ void TabPage::initUI()
|
|||
m_activatedNetDivider = new Divider(this);
|
||||
|
||||
m_inactivatedNetFrame = new QFrame(this);
|
||||
m_inactivatedNetFrame->setMinimumHeight(INACTIVE_AREA_MIN_HEIGHT);
|
||||
m_inactivatedNetLayout = new QVBoxLayout(m_inactivatedNetFrame);
|
||||
m_inactivatedNetLayout->setContentsMargins(NET_LAYOUT_MARGINS);
|
||||
m_inactivatedNetLayout->setSpacing(NET_LAYOUT_SPACING);
|
||||
|
@ -81,3 +83,51 @@ QString TabPage::getDefaultDevice()
|
|||
qDebug() << "getDefaultDevice" << defaultDevice;
|
||||
return defaultDevice;
|
||||
}
|
||||
|
||||
void setDefaultDevice(KyDeviceType deviceType, QString deviceName)
|
||||
{
|
||||
QString key;
|
||||
switch (deviceType) {
|
||||
case WIRED:
|
||||
key = "wired";
|
||||
break;
|
||||
case WIRELESS:
|
||||
key = "wireless";
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
break;
|
||||
}
|
||||
QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat);
|
||||
m_settings->beginGroup("DEFAULTCARD");
|
||||
m_settings->setValue(key, deviceName);
|
||||
m_settings->endGroup();
|
||||
m_settings->sync();
|
||||
delete m_settings;
|
||||
m_settings = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
bool checkDeviceExist(KyDeviceType deviceType, QString deviceName)
|
||||
{
|
||||
NetworkManager::Device::Type type;
|
||||
switch (deviceType) {
|
||||
case WIRED:
|
||||
type = NetworkManager::Device::Type::Ethernet;
|
||||
break;
|
||||
case WIRELESS:
|
||||
type = NetworkManager::Device::Type::Wifi;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
KyNetworkDeviceResourse * kdr = new KyNetworkDeviceResourse();
|
||||
QStringList devList;
|
||||
devList.clear();
|
||||
|
||||
kdr->getNetworkDeviceList(type, devList);
|
||||
delete kdr;
|
||||
return devList.contains(deviceName);
|
||||
}
|
||||
|
|
|
@ -14,16 +14,26 @@
|
|||
#define MAIN_LAYOUT_MARGINS 0,0,0,0
|
||||
#define MAIN_LAYOUT_SPACING 0
|
||||
#define TITLE_FRAME_HEIGHT 52
|
||||
#define TITLE_LAYOUT_MARGINS 24,0,0,0
|
||||
#define NET_LAYOUT_MARGINS 8,8,8,8
|
||||
#define TITLE_LAYOUT_MARGINS 24,0,24,0
|
||||
#define ACTIVE_NET_LAYOUT_MARGINS 8,8,8,8
|
||||
#define NET_LAYOUT_MARGINS 8,8,0,8
|
||||
#define NET_LAYOUT_SPACING 8
|
||||
#define NET_LIST_SPACING 1
|
||||
#define NET_LIST_SPACING 2
|
||||
#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)
|
||||
#define INACTIVE_AREA_MIN_HEIGHT 200
|
||||
|
||||
const QString CONFIG_FILE_PATH = QDir::homePath() + "/.config/ukui/kylin-nm.conf";
|
||||
enum KyDeviceType
|
||||
{
|
||||
WIRED,
|
||||
WIRELESS
|
||||
};
|
||||
|
||||
const QString CONFIG_FILE_PATH = QDir::homePath() + "/.config/ukui/kylin-nm.conf";
|
||||
bool checkDeviceExist(KyDeviceType deviceType, QString deviceName);
|
||||
void setDefaultDevice(KyDeviceType deviceType, QString deviceName);
|
||||
|
||||
class TabPage : public QWidget
|
||||
{
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#include "wlanpage.h"
|
||||
#include "kywirelessnetitem.h"
|
||||
#include "dbusadaptor.h"
|
||||
#include <QEvent>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QSettings>
|
||||
#include <QScrollBar>
|
||||
|
||||
WlanPage::WlanPage(QWidget *parent) : TabPage(parent)
|
||||
{
|
||||
|
@ -68,6 +68,7 @@ void WlanPage::initWlanUI()
|
|||
m_inactivatedNetListWidget->setSpacing(NET_LIST_SPACING);
|
||||
m_inactivatedNetListWidget->setFrameShape(QFrame::Shape::NoFrame);
|
||||
m_inactivatedNetListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_inactivatedNetListWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); //用了SCrollArea的滚动条
|
||||
|
||||
m_hiddenWlanWidget = new QFrame(m_inactivatedWlanListAreaCentralWidget);
|
||||
m_hiddenWlanLayout = new QHBoxLayout(m_hiddenWlanWidget);
|
||||
|
@ -189,12 +190,12 @@ void WlanPage::appendActiveWlan(const QString &ssid, int &height)
|
|||
}
|
||||
KyWirelessNetItem *item_data = new KyWirelessNetItem(data);
|
||||
WlanListItem *wlanItemWidget = new WlanListItem(m_resource, item_data, defaultDevice);
|
||||
wlanItemWidget->setActivated(true);
|
||||
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);
|
||||
wlanItemWidget->setActive(true);
|
||||
|
||||
height += wlanItemWidget->height();
|
||||
}
|
||||
|
|
|
@ -1,61 +1,83 @@
|
|||
#include "infobutton.h"
|
||||
#include <QEvent>
|
||||
#include <QPainter>
|
||||
|
||||
#define BUTTON_SIZE 36,36
|
||||
#define ICON_SIZE 16,16
|
||||
#define BACKGROUND_COLOR QColor(0,0,0,0)
|
||||
#define FOREGROUND_COLOR_NORMAL QColor(0,0,0,255)
|
||||
#define FOREGROUND_COLOR_HOVER QColor(55,144,250,255)
|
||||
#define FOREGROUND_COLOR_PRESS QColor(36,109,212,255)
|
||||
#define OUTER_PATH 8,8,16,16
|
||||
#define INNER_PATH 9,9,14,14
|
||||
#define TEXT_POS 14,5,16,16,0
|
||||
|
||||
#define BUTTON_SIZE 36,36
|
||||
|
||||
InfoButton::InfoButton(QWidget *parent) : QPushButton(parent)
|
||||
{
|
||||
this->setFixedSize(BUTTON_SIZE);
|
||||
initUI();
|
||||
installEventFilter(this);
|
||||
}
|
||||
|
||||
void InfoButton::initUI()
|
||||
{
|
||||
info_img = QIcon::fromTheme("network-wired-connected-symbolic", QIcon::fromTheme("network-wired-symbolic", QIcon(":/res/l/network-online.svg")));
|
||||
info_imgHover = QIcon::fromTheme("network-wireless-signal-excellent-symbolic", QIcon(":/res/x/wifi-list-bg.svg"));
|
||||
info_imgPressed = QIcon::fromTheme("document-page-setup-symbolic", QIcon(":/res/x/setup.png"));
|
||||
setIcon(info_img);
|
||||
}
|
||||
|
||||
bool InfoButton::event(QEvent *event)
|
||||
{
|
||||
switch(event->type())
|
||||
{
|
||||
case QEvent::Enter:
|
||||
setIcon(info_imgHover);
|
||||
break;
|
||||
case QEvent::Leave:
|
||||
setIcon(info_img);
|
||||
break;
|
||||
case QEvent::MouseButtonPress:
|
||||
setIcon(info_imgPressed);
|
||||
break;
|
||||
case QEvent::MouseButtonRelease:
|
||||
setIcon(info_imgHover);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QPushButton::event(event);
|
||||
}
|
||||
|
||||
void InfoButton::enterEvent(QEvent *)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void InfoButton::leaveEvent(QEvent *)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool InfoButton::eventFilter(QObject *w, QEvent *e)
|
||||
{
|
||||
if(e->type() == QEvent::MouseButtonPress) {
|
||||
}
|
||||
return QPushButton::eventFilter(w, e);
|
||||
this->setFixedSize(BUTTON_SIZE);
|
||||
m_backgroundColor = BACKGROUND_COLOR;
|
||||
m_foregroundColor = FOREGROUND_COLOR_NORMAL;
|
||||
}
|
||||
|
||||
void InfoButton::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QPalette pal = this->palette();
|
||||
pal.setColor(QPalette::Base, m_backgroundColor);
|
||||
pal.setColor(QPalette::Text, m_foregroundColor);
|
||||
|
||||
return QPushButton::paintEvent(event);
|
||||
QPainterPath cPath;
|
||||
cPath.addRect(0, 0, ICON_SIZE);
|
||||
cPath.addEllipse(0, 0, ICON_SIZE);
|
||||
|
||||
QPainterPath outerPath;
|
||||
outerPath.addEllipse(OUTER_PATH);
|
||||
|
||||
QPainterPath innerPath;
|
||||
innerPath.addEllipse(INNER_PATH);
|
||||
outerPath -= innerPath;
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter:: Antialiasing, true); //设置渲染,启动反锯齿
|
||||
painter.setPen(Qt::NoPen);
|
||||
|
||||
painter.setBrush(pal.color(QPalette::Base));
|
||||
painter.drawPath(cPath);
|
||||
|
||||
painter.fillPath(outerPath, pal.color(QPalette::Text));
|
||||
painter.setPen(m_foregroundColor);
|
||||
painter.drawText(TEXT_POS, "i");
|
||||
}
|
||||
|
||||
void InfoButton::enterEvent(QEvent *event)
|
||||
{
|
||||
m_foregroundColor = FOREGROUND_COLOR_HOVER;
|
||||
this->repaint();
|
||||
}
|
||||
|
||||
void InfoButton::leaveEvent(QEvent *event)
|
||||
{
|
||||
m_foregroundColor = FOREGROUND_COLOR_NORMAL;
|
||||
this->repaint();
|
||||
}
|
||||
|
||||
void InfoButton::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
m_foregroundColor = FOREGROUND_COLOR_PRESS;
|
||||
this->repaint();
|
||||
return QPushButton::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void InfoButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
m_foregroundColor = FOREGROUND_COLOR_HOVER;
|
||||
this->repaint();
|
||||
return QPushButton::mouseReleaseEvent(event);
|
||||
}
|
||||
|
|
|
@ -10,18 +10,19 @@ public:
|
|||
explicit InfoButton(QWidget * parent = nullptr);
|
||||
~InfoButton() = default;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
void enterEvent(QEvent *event);
|
||||
void leaveEvent(QEvent *event);
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
|
||||
private:
|
||||
void initUI();
|
||||
QIcon info_img;
|
||||
QIcon info_imgHover;
|
||||
QIcon info_imgPressed;
|
||||
|
||||
protected:
|
||||
bool event(QEvent *event);
|
||||
virtual void enterEvent(QEvent *event) override;
|
||||
virtual void leaveEvent(QEvent *event);
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
void paintEvent(QPaintEvent *event);
|
||||
private:
|
||||
QColor m_backgroundColor;
|
||||
QColor m_foregroundColor;
|
||||
};
|
||||
|
||||
#endif // INFOBUTTON_H
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
#include "netbutton.h"
|
||||
|
||||
NetButton::NetButton(bool isActivated, QWidget *parent) : QPushButton(parent)
|
||||
{
|
||||
connect(this, &NetButton::requestStartLoading, this, &NetButton::onLoadingStarted);
|
||||
connect(this, &NetButton::requestStopLoading, this, &NetButton::onLoadingStopped);
|
||||
m_isActivated = isActivated;
|
||||
this->setAutoFillBackground(false);
|
||||
m_iconLabel = new QLabel(this);
|
||||
m_iconLabel->setScaledContents(true);
|
||||
}
|
||||
|
||||
void NetButton::startLoading()
|
||||
{
|
||||
emit this->requestStartLoading();
|
||||
}
|
||||
|
||||
void NetButton::stopLoading()
|
||||
{
|
||||
emit this->requestStopLoading();
|
||||
}
|
||||
|
||||
void NetButton::setPressed()
|
||||
{
|
||||
//ZJP_TODO 设置颜色为点击颜色,注意区分已连接/未连接
|
||||
if (m_isActivated)
|
||||
;
|
||||
;
|
||||
}
|
||||
|
||||
void NetButton::setReleased()
|
||||
{
|
||||
//ZJP_TODO 设置颜色为未点击颜色,注意区分已连接/未连接
|
||||
if (m_isActivated)
|
||||
;
|
||||
;
|
||||
}
|
||||
|
||||
void NetButton::setButtonIcon(QIcon *icon)
|
||||
{
|
||||
if (!icon) { return; }
|
||||
m_iconLabel->setPixmap(icon->pixmap(this->size()));
|
||||
}
|
||||
|
||||
void NetButton::onLoadingStarted()
|
||||
{
|
||||
//ZJP_TODO 开始播放转圈动画
|
||||
}
|
||||
|
||||
void NetButton::onLoadingStopped()
|
||||
{
|
||||
//ZJP_TODO 停止播放转圈动画
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
#ifndef NETBUTTON_H
|
||||
#define NETBUTTON_H
|
||||
#include <QPushButton>
|
||||
#include <QIcon>
|
||||
#include <QLabel>
|
||||
#define ACTIVATED true
|
||||
#define INACTIVATED false
|
||||
|
||||
class NetButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
NetButton(bool isActivated = INACTIVATED, QWidget * parent = nullptr);
|
||||
~NetButton() = default;
|
||||
void startLoading();
|
||||
void stopLoading();
|
||||
void setPressed();
|
||||
void setReleased();
|
||||
void setButtonIcon(QIcon *);
|
||||
|
||||
signals:
|
||||
void requestStartLoading();
|
||||
void requestStopLoading();
|
||||
|
||||
private:
|
||||
bool m_isActivated = INACTIVATED;
|
||||
QLabel * m_iconLabel = nullptr;
|
||||
|
||||
private slots:
|
||||
void onLoadingStarted();
|
||||
void onLoadingStopped();
|
||||
};
|
||||
|
||||
#endif // NETBUTTON_H
|
|
@ -1,14 +1,19 @@
|
|||
#include "radioitembutton.h"
|
||||
#include <QPainter>
|
||||
#include <QStyle>
|
||||
#define BUTTON_SIZE 32,32
|
||||
#define ICON_SIZE 16,16
|
||||
|
||||
RadioItemButton::RadioItemButton(bool isActivated, QWidget *parent) : QPushButton(parent)
|
||||
#define BUTTON_SIZE 36,36
|
||||
#define ICON_SIZE 16,16
|
||||
#define BACKGROUND_COLOR QColor(0,0,0,0)
|
||||
#define FOREGROUND_COLOR_NORMAL_INACTIVE QColor(230,230,230,255)
|
||||
#define FOREGROUND_COLOR_PRESS_INACTIVE QColor(217,217,217,255)
|
||||
#define FOREGROUND_COLOR_NORMAL_ACTIVE QColor(55,144,250,255)
|
||||
#define FOREGROUND_COLOR_PRESS_ACTIVE QColor(36,109,212,255)
|
||||
|
||||
RadioItemButton::RadioItemButton(QWidget *parent) : QPushButton(parent)
|
||||
{
|
||||
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);
|
||||
|
||||
|
@ -16,6 +21,7 @@ RadioItemButton::RadioItemButton(bool isActivated, QWidget *parent) : QPushButto
|
|||
m_iconLabel->setFixedSize(BUTTON_SIZE);
|
||||
m_iconLabel->setAlignment(Qt::AlignCenter);
|
||||
|
||||
setActive(false);
|
||||
//JXJ_TODO loading动画
|
||||
// switchTimer = new QTimer(this);
|
||||
// connect(switchTimer, &QTimer::timeout, this, &RadioItemButton::onLoadingStarted);
|
||||
|
@ -31,22 +37,6 @@ void RadioItemButton::stopLoading()
|
|||
emit this->requestStopLoading();
|
||||
}
|
||||
|
||||
void RadioItemButton::setPressed()
|
||||
{
|
||||
//ZJP_TODO 设置颜色为点击颜色,注意区分已连接/未连接
|
||||
if (m_isActivated)
|
||||
;
|
||||
;
|
||||
}
|
||||
|
||||
void RadioItemButton::setReleased()
|
||||
{
|
||||
//ZJP_TODO 设置颜色为未点击颜色,注意区分已连接/未连接
|
||||
if (m_isActivated)
|
||||
;
|
||||
;
|
||||
}
|
||||
|
||||
void RadioItemButton::setButtonIcon(const QIcon &icon)
|
||||
{
|
||||
if (icon.isNull()) {
|
||||
|
@ -55,6 +45,12 @@ void RadioItemButton::setButtonIcon(const QIcon &icon)
|
|||
//ZJP_TODO 绘制圆形按钮
|
||||
m_iconLabel->setPixmap(icon.pixmap(ICON_SIZE));
|
||||
}
|
||||
|
||||
void RadioItemButton::setActive(const bool &isActive)
|
||||
{
|
||||
m_isActivated = isActive;
|
||||
m_backgroundColor = m_isActivated? FOREGROUND_COLOR_NORMAL_ACTIVE : FOREGROUND_COLOR_NORMAL_INACTIVE;
|
||||
}
|
||||
void RadioItemButton::onLoadingStarted()
|
||||
{
|
||||
//ZJP_TODO 开始播放转圈动画
|
||||
|
@ -88,8 +84,8 @@ void RadioItemButton::onLoadingStopped()
|
|||
void RadioItemButton::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QPalette pal = this->palette();
|
||||
pal.setColor(QPalette::Base, QColor(0,0,0,0));
|
||||
pal.setColor(QPalette::Text, QColor(230,230,230,255));
|
||||
pal.setColor(QPalette::Base, BACKGROUND_COLOR);
|
||||
pal.setColor(QPalette::Text, m_backgroundColor);
|
||||
|
||||
QPainterPath cPath;
|
||||
cPath.addRect(0, 0, this->width(), this->height());
|
||||
|
@ -106,12 +102,18 @@ void RadioItemButton::paintEvent(QPaintEvent *event)
|
|||
painter.drawPath(cPath);
|
||||
|
||||
painter.fillPath(innerPath, pal.color(QPalette::Text));
|
||||
|
||||
// QRect iconRect;
|
||||
// iconRect = this->rect();
|
||||
// iconRect.adjust(8,8,-8,-8);
|
||||
// QPixmap pixmap = this->icon().pixmap(32,32);
|
||||
// painter.drawPixmap(iconRect, pixmap);
|
||||
|
||||
// return QPushButton::paintEvent(event);
|
||||
}
|
||||
|
||||
void RadioItemButton::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
m_backgroundColor = m_isActivated? FOREGROUND_COLOR_PRESS_ACTIVE : FOREGROUND_COLOR_PRESS_INACTIVE;
|
||||
this->repaint();
|
||||
return QPushButton::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void RadioItemButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
m_backgroundColor = m_isActivated? FOREGROUND_COLOR_NORMAL_ACTIVE : FOREGROUND_COLOR_NORMAL_INACTIVE;
|
||||
this->repaint();
|
||||
return QPushButton::mouseReleaseEvent(event);
|
||||
}
|
||||
|
|
|
@ -4,30 +4,32 @@
|
|||
#include <QIcon>
|
||||
#include <QLabel>
|
||||
#include<QTimer>
|
||||
#define ACTIVATED true
|
||||
#define INACTIVATED false
|
||||
|
||||
class RadioItemButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
RadioItemButton(bool isActivated = INACTIVATED, QWidget * parent = nullptr);
|
||||
RadioItemButton(QWidget * parent = nullptr);
|
||||
~RadioItemButton() = default;
|
||||
void startLoading();
|
||||
void stopLoading();
|
||||
void setPressed();
|
||||
void setReleased();
|
||||
void setButtonIcon(const QIcon &icon);
|
||||
void setActive(const bool &isActive);
|
||||
|
||||
signals:
|
||||
void requestStartLoading();
|
||||
void requestStopLoading();
|
||||
|
||||
private:
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
bool m_isActivated = INACTIVATED;
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
|
||||
private:
|
||||
bool m_isActivated = false;
|
||||
QLabel * m_iconLabel = nullptr;
|
||||
QTimer * switchTimer = nullptr;
|
||||
QColor m_backgroundColor;
|
||||
|
||||
int currentPage;
|
||||
int countCurrentTime;
|
||||
|
|
|
@ -4,7 +4,6 @@ HEADERS += \
|
|||
$$PWD/divider.h \
|
||||
$$PWD/infobutton.h \
|
||||
$$PWD/loadingdiv.h \
|
||||
$$PWD/netbutton.h \
|
||||
$$PWD/radioitembutton.h \
|
||||
$$PWD/switchbutton.h
|
||||
|
||||
|
@ -13,6 +12,5 @@ SOURCES += \
|
|||
$$PWD/divider.cpp \
|
||||
$$PWD/infobutton.cpp \
|
||||
$$PWD/loadingdiv.cpp \
|
||||
$$PWD/netbutton.cpp \
|
||||
$$PWD/radioitembutton.cpp \
|
||||
$$PWD/switchbutton.cpp
|
||||
|
|
Loading…
Reference in New Issue