控制面板ui优化
This commit is contained in:
parent
ce5e20537d
commit
c0eb659b82
|
@ -47,11 +47,28 @@ LanItem::LanItem(bool isAcitve, QWidget *parent)
|
||||||
statusLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
statusLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||||||
// statusLabel->setMinimumSize(36,36);
|
// statusLabel->setMinimumSize(36,36);
|
||||||
infoLabel = new GrayInfoButton(this);
|
infoLabel = new GrayInfoButton(this);
|
||||||
|
|
||||||
|
//【更多】菜单
|
||||||
|
m_moreButton = new QToolButton(this);
|
||||||
|
m_moreButton->setProperty("useButtonPalette", true);
|
||||||
|
m_moreButton->setPopupMode(QToolButton::InstantPopup);
|
||||||
|
m_moreButton->setAutoRaise(true);
|
||||||
|
m_moreButton->setIcon(QIcon::fromTheme("view-more-horizontal-symbolic"));
|
||||||
|
m_moreMenu = new QMenu(m_moreButton);
|
||||||
|
m_connectAction = new QAction(m_moreMenu);
|
||||||
|
m_deleteAction = new QAction("Delete", m_moreMenu);
|
||||||
|
setConnectActionText(isAcitve);
|
||||||
|
|
||||||
|
m_moreMenu->addAction(m_connectAction);
|
||||||
|
m_moreMenu->addAction(m_deleteAction);
|
||||||
|
m_moreButton->setMenu(m_moreMenu);
|
||||||
|
|
||||||
mLanLyt->addWidget(iconLabel);
|
mLanLyt->addWidget(iconLabel);
|
||||||
mLanLyt->addWidget(titileLabel,Qt::AlignLeft);
|
mLanLyt->addWidget(titileLabel,Qt::AlignLeft);
|
||||||
mLanLyt->addStretch();
|
mLanLyt->addStretch();
|
||||||
mLanLyt->addWidget(statusLabel);
|
mLanLyt->addWidget(statusLabel);
|
||||||
mLanLyt->addWidget(infoLabel);
|
mLanLyt->addWidget(infoLabel);
|
||||||
|
mLanLyt->addWidget(m_moreButton);
|
||||||
|
|
||||||
loadIcons.append(QIcon::fromTheme("ukui-loading-1-symbolic"));
|
loadIcons.append(QIcon::fromTheme("ukui-loading-1-symbolic"));
|
||||||
loadIcons.append(QIcon::fromTheme("ukui-loading-2-symbolic"));
|
loadIcons.append(QIcon::fromTheme("ukui-loading-2-symbolic"));
|
||||||
|
@ -62,6 +79,10 @@ LanItem::LanItem(bool isAcitve, QWidget *parent)
|
||||||
loadIcons.append(QIcon::fromTheme("ukui-loading-7-symbolic"));
|
loadIcons.append(QIcon::fromTheme("ukui-loading-7-symbolic"));
|
||||||
waitTimer = new QTimer(this);
|
waitTimer = new QTimer(this);
|
||||||
connect(waitTimer, &QTimer::timeout, this, &LanItem::updateIcon);
|
connect(waitTimer, &QTimer::timeout, this, &LanItem::updateIcon);
|
||||||
|
|
||||||
|
connect(m_connectAction, &QAction::triggered, this, &LanItem::onConnectTriggered);
|
||||||
|
connect(m_deleteAction, &QAction::triggered, this, &LanItem::onDeletetTriggered);
|
||||||
|
m_moreMenu->installEventFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
LanItem::~LanItem()
|
LanItem::~LanItem()
|
||||||
|
@ -89,6 +110,40 @@ void LanItem::stopLoading(){
|
||||||
loading = false;
|
loading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief LanItem::setConnectActionText
|
||||||
|
* 【更多】菜单状态切换 连接/断开
|
||||||
|
* @param isAcitve
|
||||||
|
*/
|
||||||
|
void LanItem::setConnectActionText(bool isAcitve)
|
||||||
|
{
|
||||||
|
if (isAcitve) {
|
||||||
|
m_connectAction->setText(tr("Disconnect"));
|
||||||
|
} else {
|
||||||
|
m_connectAction->setText(tr("Connect"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LanItem::onConnectTriggered()
|
||||||
|
{
|
||||||
|
if (!m_connectAction) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (m_connectAction->text() == tr("Connect")) {
|
||||||
|
Q_EMIT connectActionTriggered();
|
||||||
|
} else if (m_connectAction->text() == tr("Disconnect")) {
|
||||||
|
Q_EMIT disconnectActionTriggered();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LanItem::onDeletetTriggered()
|
||||||
|
{
|
||||||
|
if (!m_deleteAction) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Q_EMIT deleteActionTriggered();
|
||||||
|
}
|
||||||
|
|
||||||
void LanItem::paintEvent(QPaintEvent *event)
|
void LanItem::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
QPalette pal = this->palette();
|
QPalette pal = this->palette();
|
||||||
|
@ -104,3 +159,18 @@ void LanItem::paintEvent(QPaintEvent *event)
|
||||||
QPushButton::paintEvent(event);
|
QPushButton::paintEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool LanItem::eventFilter(QObject *watched, QEvent *event)
|
||||||
|
{
|
||||||
|
//菜单右边界与按钮右边界对齐
|
||||||
|
if (event->type() == QEvent::Show && watched == m_moreMenu) {
|
||||||
|
int menuXPos = m_moreMenu->pos().x();
|
||||||
|
int menuWidth = m_moreMenu->size().width();
|
||||||
|
int btnWidth = m_moreButton->size().width();
|
||||||
|
|
||||||
|
QPoint pos = QPoint (menuXPos - menuWidth + btnWidth, m_moreMenu->pos().y());
|
||||||
|
m_moreMenu->move(pos);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,12 +29,16 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QToolButton>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QEvent>
|
||||||
#include "fixlabel.h"
|
#include "fixlabel.h"
|
||||||
//#include "infobutton.h"
|
//#include "infobutton.h"
|
||||||
#include "../component/AddBtn/grayinfobutton.h"
|
#include "../component/AddBtn/grayinfobutton.h"
|
||||||
|
|
||||||
class LanItem : public QPushButton
|
class LanItem : public QPushButton
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
LanItem(bool isAcitve, QWidget *parent = nullptr);
|
LanItem(bool isAcitve, QWidget *parent = nullptr);
|
||||||
~LanItem();
|
~LanItem();
|
||||||
|
@ -43,10 +47,15 @@ public:
|
||||||
GrayInfoButton * infoLabel = nullptr;
|
GrayInfoButton * infoLabel = nullptr;
|
||||||
FixLabel * titileLabel = nullptr;
|
FixLabel * titileLabel = nullptr;
|
||||||
QLabel * statusLabel = nullptr;
|
QLabel * statusLabel = nullptr;
|
||||||
|
QToolButton* m_moreButton = nullptr;
|
||||||
|
QMenu* m_moreMenu = nullptr;
|
||||||
|
QAction* m_connectAction = nullptr;
|
||||||
|
QAction* m_deleteAction = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void startLoading();
|
void startLoading();
|
||||||
void stopLoading();
|
void stopLoading();
|
||||||
|
void setConnectActionText(bool isAcitve);
|
||||||
|
|
||||||
bool loading = false;
|
bool loading = false;
|
||||||
bool isAcitve = false;
|
bool isAcitve = false;
|
||||||
|
@ -56,15 +65,23 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *);
|
void paintEvent(QPaintEvent *);
|
||||||
|
bool eventFilter(QObject *watched, QEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTimer *waitTimer = nullptr;
|
QTimer *waitTimer = nullptr;
|
||||||
QGSettings *themeGsettings = nullptr;
|
QGSettings *themeGsettings = nullptr;
|
||||||
QList<QIcon> loadIcons;
|
QList<QIcon> loadIcons;
|
||||||
int currentIconIndex=0;
|
int currentIconIndex=0;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateIcon();
|
void updateIcon();
|
||||||
|
void onConnectTriggered();
|
||||||
|
void onDeletetTriggered();
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void connectActionTriggered();
|
||||||
|
void disconnectActionTriggered();
|
||||||
|
void deleteActionTriggered();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -235,6 +235,8 @@ void NetConnect::initComponent() {
|
||||||
Q_UNUSED(checked)
|
Q_UNUSED(checked)
|
||||||
runExternalApp();
|
runExternalApp();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(this, SIGNAL(lanRemove(QString)), m_interface, SIGNAL(lanRemove(QString)));
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取网卡列表
|
//获取网卡列表
|
||||||
|
@ -353,6 +355,12 @@ void NetConnect::runExternalApp() {
|
||||||
process.startDetached(cmd);
|
process.startDetached(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//刪除
|
||||||
|
void NetConnect::deleteOneLan(QString ssid)
|
||||||
|
{
|
||||||
|
Q_EMIT lanRemove(ssid);
|
||||||
|
}
|
||||||
|
|
||||||
//激活
|
//激活
|
||||||
void NetConnect::activeConnect(QString ssid, QString deviceName, int type) {
|
void NetConnect::activeConnect(QString ssid, QString deviceName, int type) {
|
||||||
qDebug() << "[NetConnect]call activateConnect" << __LINE__;
|
qDebug() << "[NetConnect]call activateConnect" << __LINE__;
|
||||||
|
@ -421,12 +429,12 @@ void NetConnect::addLanItem(ItemFrame *frame, QString devName, QStringList infoL
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LanItem * lanItem = new LanItem(pluginWidget);
|
LanItem * lanItem = new LanItem(isActived, pluginWidget);
|
||||||
QString iconPath = KLanSymbolic;
|
QString iconPath = KLanSymbolic;
|
||||||
if (isActived) {
|
if (isActived) {
|
||||||
lanItem->statusLabel->setText(tr("connected"));
|
lanItem->statusLabel->setText(tr("connected"));
|
||||||
} else {
|
} else {
|
||||||
lanItem->statusLabel->setText("");
|
lanItem->statusLabel->setText("not connected");
|
||||||
}
|
}
|
||||||
QIcon searchIcon = QIcon::fromTheme(iconPath);
|
QIcon searchIcon = QIcon::fromTheme(iconPath);
|
||||||
// if (iconPath != KLanSymbolic && iconPath != NoNetSymbolic) {
|
// if (iconPath != KLanSymbolic && iconPath != NoNetSymbolic) {
|
||||||
|
@ -458,6 +466,16 @@ void NetConnect::addLanItem(ItemFrame *frame, QString devName, QStringList infoL
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(lanItem, &LanItem::connectActionTriggered, this, [=] {
|
||||||
|
activeConnect(lanItem->uuid, devName, WIRED_TYPE);
|
||||||
|
});
|
||||||
|
connect(lanItem, &LanItem::disconnectActionTriggered, this, [=] {
|
||||||
|
deActiveConnect(lanItem->uuid, devName, WIRED_TYPE);
|
||||||
|
});
|
||||||
|
connect(lanItem, &LanItem::deleteActionTriggered, this, [=] {
|
||||||
|
deleteOneLan(lanItem->dbusPath);
|
||||||
|
});
|
||||||
|
|
||||||
//记录到deviceFrame的itemMap中
|
//记录到deviceFrame的itemMap中
|
||||||
deviceFrameMap[devName]->itemMap.insert(infoList.at(1), lanItem);
|
deviceFrameMap[devName]->itemMap.insert(infoList.at(1), lanItem);
|
||||||
qDebug()<<"insert " << infoList.at(1) << " to " << devName << " list";
|
qDebug()<<"insert " << infoList.at(1) << " to " << devName << " list";
|
||||||
|
@ -695,7 +713,7 @@ void NetConnect::addOneLanFrame(ItemFrame *frame, QString deviceName, QStringLis
|
||||||
|
|
||||||
QString iconPath;
|
QString iconPath;
|
||||||
iconPath = KLanSymbolic;
|
iconPath = KLanSymbolic;
|
||||||
lanItem->statusLabel->setText("");
|
lanItem->statusLabel->setText("not connected");
|
||||||
|
|
||||||
QIcon searchIcon = QIcon::fromTheme(iconPath);
|
QIcon searchIcon = QIcon::fromTheme(iconPath);
|
||||||
// if (iconPath != KLanSymbolic && iconPath != NoNetSymbolic) {
|
// if (iconPath != KLanSymbolic && iconPath != NoNetSymbolic) {
|
||||||
|
@ -841,7 +859,9 @@ void NetConnect::itemActiveConnectionStatusChanged(LanItem *item, int status)
|
||||||
item->statusLabel->setMaximumSize(16777215,16777215);
|
item->statusLabel->setMaximumSize(16777215,16777215);
|
||||||
item->statusLabel->clear();
|
item->statusLabel->clear();
|
||||||
item->isAcitve = false;
|
item->isAcitve = false;
|
||||||
|
item->statusLabel->setText(tr("not connected"));
|
||||||
}
|
}
|
||||||
|
item->setConnectActionText(item->isAcitve);
|
||||||
|
|
||||||
// QIcon searchIcon = QIcon::fromTheme(iconPath);
|
// QIcon searchIcon = QIcon::fromTheme(iconPath);
|
||||||
// item->iconLabel->setPixmap(searchIcon.pixmap(searchIcon.actualSize(QSize(24, 24))));
|
// item->iconLabel->setPixmap(searchIcon.pixmap(searchIcon.actualSize(QSize(24, 24))));
|
||||||
|
|
|
@ -152,6 +152,9 @@ private slots:
|
||||||
|
|
||||||
void onDeviceStatusChanged();
|
void onDeviceStatusChanged();
|
||||||
void onDeviceNameChanged(QString, QString, int);
|
void onDeviceNameChanged(QString, QString, int);
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void lanRemove(QString dbusPath);
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(QList<QDBusObjectPath>);
|
Q_DECLARE_METATYPE(QList<QDBusObjectPath>);
|
||||||
|
|
Loading…
Reference in New Issue