Merge branch '1209' into 'dbus-interface'
开关按钮三态&&bug#100740网络项宽度 See merge request kylin-desktop/kylin-nm!510
This commit is contained in:
commit
a69ee83af2
|
@ -203,8 +203,9 @@ void MainWindow::initUI()
|
||||||
m_tabBarLayout->addWidget(m_lanLabel);
|
m_tabBarLayout->addWidget(m_lanLabel);
|
||||||
m_tabBarLayout->addWidget(m_wlanLabel);
|
m_tabBarLayout->addWidget(m_wlanLabel);
|
||||||
m_centralWidget->tabBar()->setLayout(m_tabBarLayout);
|
m_centralWidget->tabBar()->setLayout(m_tabBarLayout);
|
||||||
|
m_centralWidget->tabBar()->setProperty("useTabbarSeparateLine", false); // 去掉中间的分割线
|
||||||
|
m_centralWidget->setAttribute(Qt::WA_TranslucentBackground, true); // 背景透明 解决切换黑屏问题
|
||||||
connect(m_centralWidget, &QTabWidget::currentChanged, m_wlanWidget, &WlanPage::onWlanPageVisibleChanged);
|
connect(m_centralWidget, &QTabWidget::currentChanged, m_wlanWidget, &WlanPage::onWlanPageVisibleChanged);
|
||||||
m_centralWidget->setAttribute(Qt::WA_TranslucentBackground, true);
|
|
||||||
paintWithTrans();
|
paintWithTrans();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -413,9 +413,14 @@ void LanPage::constructConnectionArea()
|
||||||
|
|
||||||
delete p_deactiveConnectionItem;
|
delete p_deactiveConnectionItem;
|
||||||
p_deactiveConnectionItem = nullptr;
|
p_deactiveConnectionItem = nullptr;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (m_inactivatedLanListWidget->count() < MAX_ITEMS) {
|
||||||
|
m_inactivatedLanListWidget->setFixedWidth(MIN_WIDTH);
|
||||||
|
} else {
|
||||||
|
m_inactivatedLanListWidget->setFixedWidth(MAX_WIDTH);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -457,7 +462,9 @@ bool LanPage::removeConnectionItem(QMap<QString, QListWidgetItem *> &connectMap,
|
||||||
p_listWidgetItem = nullptr;
|
p_listWidgetItem = nullptr;
|
||||||
|
|
||||||
iter = connectMap.erase(iter);
|
iter = connectMap.erase(iter);
|
||||||
|
if (m_inactivatedLanListWidget->count() < MAX_ITEMS) {
|
||||||
|
m_inactivatedLanListWidget->setFixedWidth(MIN_WIDTH);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -478,6 +485,7 @@ void LanPage::onRemoveConnection(QString path) //删除时后端会
|
||||||
if (m_activeConnectionMap.count() <= 0) {
|
if (m_activeConnectionMap.count() <= 0) {
|
||||||
addEmptyConnectItem(m_activeConnectionMap, m_activatedLanListWidget);
|
addEmptyConnectItem(m_activeConnectionMap, m_activatedLanListWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -507,7 +515,9 @@ void LanPage::onAddConnection(QString uuid) //新增一个有线
|
||||||
|
|
||||||
delete p_newItem;
|
delete p_newItem;
|
||||||
p_newItem = nullptr;
|
p_newItem = nullptr;
|
||||||
|
if (m_inactivatedLanListWidget->count() >= MAX_ITEMS) {
|
||||||
|
m_inactivatedLanListWidget->setFixedWidth(MAX_WIDTH);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -750,6 +760,7 @@ void LanPage::initUI()
|
||||||
m_activatedLanListWidget->setFrameShape(QFrame::Shape::NoFrame);
|
m_activatedLanListWidget->setFrameShape(QFrame::Shape::NoFrame);
|
||||||
m_activatedLanListWidget->setSpacing(LAN_LIST_SPACING);
|
m_activatedLanListWidget->setSpacing(LAN_LIST_SPACING);
|
||||||
m_activatedLanListWidget->setFixedHeight(ITEM_HEIGHT); //active区域固定高度,只显示一个条目
|
m_activatedLanListWidget->setFixedHeight(ITEM_HEIGHT); //active区域固定高度,只显示一个条目
|
||||||
|
m_activatedLanListWidget->setFixedWidth(MIN_WIDTH);
|
||||||
m_activatedLanListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
m_activatedLanListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
m_activatedNetLayout->addWidget(m_activatedLanListWidget);
|
m_activatedNetLayout->addWidget(m_activatedLanListWidget);
|
||||||
|
|
||||||
|
@ -805,7 +816,6 @@ QListWidgetItem *LanPage::addNewItem(KyConnectItem *itemData, QListWidget *listW
|
||||||
p_listWidgetItem->setFlags(p_listWidgetItem->flags() & (~Qt::ItemIsSelectable));
|
p_listWidgetItem->setFlags(p_listWidgetItem->flags() & (~Qt::ItemIsSelectable));
|
||||||
p_listWidgetItem->setSizeHint(QSize(listWidget->width(), ITEM_HEIGHT));
|
p_listWidgetItem->setSizeHint(QSize(listWidget->width(), ITEM_HEIGHT));
|
||||||
listWidget->addItem(p_listWidgetItem);
|
listWidget->addItem(p_listWidgetItem);
|
||||||
|
|
||||||
LanListItem *p_lanItem = nullptr;
|
LanListItem *p_lanItem = nullptr;
|
||||||
if (itemData != nullptr) {
|
if (itemData != nullptr) {
|
||||||
p_lanItem = new LanListItem(itemData, m_currentDeviceName);
|
p_lanItem = new LanListItem(itemData, m_currentDeviceName);
|
||||||
|
@ -817,7 +827,6 @@ QListWidgetItem *LanPage::addNewItem(KyConnectItem *itemData, QListWidget *listW
|
||||||
}
|
}
|
||||||
|
|
||||||
listWidget->setItemWidget(p_listWidgetItem, p_lanItem);
|
listWidget->setItemWidget(p_listWidgetItem, p_lanItem);
|
||||||
|
|
||||||
return p_listWidgetItem;
|
return p_listWidgetItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -828,7 +837,6 @@ void LanPage::updateActivatedConnectionArea(KyConnectItem *p_newItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteConnectionMapItem(m_inactiveConnectionMap, m_inactivatedLanListWidget, p_newItem->m_connectUuid);
|
deleteConnectionMapItem(m_inactiveConnectionMap, m_inactivatedLanListWidget, p_newItem->m_connectUuid);
|
||||||
|
|
||||||
if (p_newItem->m_ifaceName == m_currentDeviceName) {
|
if (p_newItem->m_ifaceName == m_currentDeviceName) {
|
||||||
qDebug()<<"[LanPage]update active connection item"<<p_newItem->m_connectName;
|
qDebug()<<"[LanPage]update active connection item"<<p_newItem->m_connectName;
|
||||||
deleteConnectionMapItem(m_activeConnectionMap, m_activatedLanListWidget, EMPTY_CONNECT_UUID);
|
deleteConnectionMapItem(m_activeConnectionMap, m_activatedLanListWidget, EMPTY_CONNECT_UUID);
|
||||||
|
@ -836,6 +844,9 @@ void LanPage::updateActivatedConnectionArea(KyConnectItem *p_newItem)
|
||||||
m_activeConnectionMap.insert(p_newItem->m_connectUuid, p_listWidgetItem);
|
m_activeConnectionMap.insert(p_newItem->m_connectUuid, p_listWidgetItem);
|
||||||
this->showDesktopNotify(tr("LAN Connected Successfully"));
|
this->showDesktopNotify(tr("LAN Connected Successfully"));
|
||||||
}
|
}
|
||||||
|
if (m_inactivatedLanListWidget->count() < MAX_ITEMS) {
|
||||||
|
m_inactivatedLanListWidget->setFixedWidth(MIN_WIDTH);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -857,6 +868,11 @@ void LanPage::updateConnectionArea(KyConnectItem *p_newItem)
|
||||||
m_inactiveConnectionMap.insert(p_newItem->m_connectUuid, p_listWidgetItem);
|
m_inactiveConnectionMap.insert(p_newItem->m_connectUuid, p_listWidgetItem);
|
||||||
this->showDesktopNotify(tr("LAN Disconnected Successfully"));
|
this->showDesktopNotify(tr("LAN Disconnected Successfully"));
|
||||||
}
|
}
|
||||||
|
if (m_inactivatedLanListWidget->count() < MAX_ITEMS) {
|
||||||
|
m_inactivatedLanListWidget->setFixedWidth(MIN_WIDTH);
|
||||||
|
} else {
|
||||||
|
m_inactivatedLanListWidget->setFixedWidth(MAX_WIDTH);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,10 @@
|
||||||
#define INACTIVE_AREA_MIN_HEIGHT 170
|
#define INACTIVE_AREA_MIN_HEIGHT 170
|
||||||
#define ACTIVE_AREA_MAX_HEIGHT 92
|
#define ACTIVE_AREA_MAX_HEIGHT 92
|
||||||
|
|
||||||
|
#define MAX_ITEMS 4
|
||||||
|
#define MAX_WIDTH 400
|
||||||
|
#define MIN_WIDTH 383
|
||||||
|
|
||||||
#define SCROLL_STEP 4
|
#define SCROLL_STEP 4
|
||||||
|
|
||||||
enum KyDeviceType
|
enum KyDeviceType
|
||||||
|
|
|
@ -79,6 +79,7 @@ void WlanPage::initWlanUI()
|
||||||
m_activatedNetListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
|
m_activatedNetListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
|
||||||
m_activatedNetListWidget->setSpacing(NET_LIST_SPACING);
|
m_activatedNetListWidget->setSpacing(NET_LIST_SPACING);
|
||||||
m_activatedNetListWidget->setFixedHeight(NORMAL_HEIGHT);
|
m_activatedNetListWidget->setFixedHeight(NORMAL_HEIGHT);
|
||||||
|
m_activatedNetListWidget->setFixedWidth(MIN_WIDTH);
|
||||||
m_activatedNetListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
m_activatedNetListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
m_activatedNetLayout->addWidget(m_activatedNetListWidget);
|
m_activatedNetLayout->addWidget(m_activatedNetListWidget);
|
||||||
|
|
||||||
|
@ -382,6 +383,9 @@ void WlanPage::deleteWirelessItemFormMap(QMap<QString, QListWidgetItem*> &wirele
|
||||||
delete p_listWidgetItem;
|
delete p_listWidgetItem;
|
||||||
p_listWidgetItem = nullptr;
|
p_listWidgetItem = nullptr;
|
||||||
|
|
||||||
|
if (m_inactivatedNetListWidget->count() < MAX_ITEMS) {
|
||||||
|
m_inactivatedNetListWidget->setFixedWidth(MIN_WIDTH);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -457,7 +461,11 @@ void WlanPage::constructWirelessNetArea()
|
||||||
|
|
||||||
qDebug() << "[WlanPage] Stopped loading wireless net list! time="
|
qDebug() << "[WlanPage] Stopped loading wireless net list! time="
|
||||||
<< QDateTime::currentDateTime().toString("hh:mm:ss.zzzz");
|
<< QDateTime::currentDateTime().toString("hh:mm:ss.zzzz");
|
||||||
|
if (m_inactivatedNetListWidget->count() < MAX_ITEMS) {
|
||||||
|
m_inactivatedNetListWidget->setFixedWidth(MIN_WIDTH);
|
||||||
|
} else {
|
||||||
|
m_inactivatedNetListWidget->setFixedWidth(MAX_WIDTH);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -507,7 +515,9 @@ void WlanPage::onWlanAdded(QString interface, KyWirelessNetItem &item)
|
||||||
updateWlanItemState(m_inactivatedNetListWidget, p_listWidgetItem, Deactivated);
|
updateWlanItemState(m_inactivatedNetListWidget, p_listWidgetItem, Deactivated);
|
||||||
|
|
||||||
addWlanMoreItem();
|
addWlanMoreItem();
|
||||||
|
if (m_inactivatedNetListWidget->count() >= MAX_ITEMS) {
|
||||||
|
m_inactivatedNetListWidget->setFixedWidth(MAX_WIDTH);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -826,7 +836,9 @@ void WlanPage::updateActivatedArea(QString uuid, QString ssid, QString devName)
|
||||||
m_activateConnectionItemMap.insert(wirelessNetItem.m_NetSsid, p_listWidgetItem);
|
m_activateConnectionItemMap.insert(wirelessNetItem.m_NetSsid, p_listWidgetItem);
|
||||||
|
|
||||||
m_activatedNetListWidget->setFixedHeight(p_listWidgetItem->sizeHint().height());
|
m_activatedNetListWidget->setFixedHeight(p_listWidgetItem->sizeHint().height());
|
||||||
|
if (m_inactivatedNetListWidget->count() < MAX_ITEMS) {
|
||||||
|
m_inactivatedNetListWidget->setFixedWidth(MIN_WIDTH);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -857,7 +869,11 @@ void WlanPage::updateWirelessNetArea(QString uuid, QString ssid, QString devName
|
||||||
|
|
||||||
// 更新‘更多’条目,以保证其处于listwidget的最底部
|
// 更新‘更多’条目,以保证其处于listwidget的最底部
|
||||||
addWlanMoreItem();
|
addWlanMoreItem();
|
||||||
|
if (m_inactivatedNetListWidget->count() < MAX_ITEMS) {
|
||||||
|
m_inactivatedNetListWidget->setFixedWidth(MIN_WIDTH);
|
||||||
|
} else {
|
||||||
|
m_inactivatedNetListWidget->setFixedWidth(MAX_WIDTH);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,10 +18,18 @@
|
||||||
#include "switchbutton.h"
|
#include "switchbutton.h"
|
||||||
#define SWITCH_WIDTH 48
|
#define SWITCH_WIDTH 48
|
||||||
#define SWITCH_HEIGHT 24
|
#define SWITCH_HEIGHT 24
|
||||||
|
#define COLOR_ACTIVE QColor(55,144,250,255)
|
||||||
|
#define COLOR_INACTIVE QColor(55,55,55,255)
|
||||||
|
#define COLOR_ACTIVE_HOVER QColor(95,166,251,255)
|
||||||
|
#define COLOR_INACTIVE_HOVER QColor(95,95,95,255)
|
||||||
|
#define COLOR_ACTIVE_PRESS QColor(65,150,250,255)
|
||||||
|
#define COLOR_INACTIVE_PRESS QColor(65,65,65,255)
|
||||||
|
#define COLOR_UNABLE QColor(76,76,79,255)
|
||||||
|
|
||||||
SwitchButton::SwitchButton(QWidget *parent) : QWidget(parent)
|
SwitchButton::SwitchButton(QWidget *parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
|
m_colorActive = COLOR_ACTIVE;
|
||||||
|
m_colorInactive = COLOR_INACTIVE;
|
||||||
setFixedSize(SWITCH_WIDTH,SWITCH_HEIGHT);
|
setFixedSize(SWITCH_WIDTH,SWITCH_HEIGHT);
|
||||||
m_fWidth = (float)width();
|
m_fWidth = (float)width();
|
||||||
m_fHeight = (float)height();
|
m_fHeight = (float)height();
|
||||||
|
@ -34,7 +42,6 @@ SwitchButton::SwitchButton(QWidget *parent) : QWidget(parent)
|
||||||
else {
|
else {
|
||||||
m_fCurrentValue = 4;
|
m_fCurrentValue = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(m_cTimer, SIGNAL(timeout()), this, SLOT(startAnimation()));
|
connect(m_cTimer, SIGNAL(timeout()), this, SLOT(startAnimation()));
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,7 +56,6 @@ void SwitchButton::setSwitchStatus(bool check) {
|
||||||
} else {
|
} else {
|
||||||
m_bIsOn = 0;
|
m_bIsOn = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit this->switchStatusChanged();
|
emit this->switchStatusChanged();
|
||||||
|
|
||||||
m_cTimer->start(); //开始播放动画
|
m_cTimer->start(); //开始播放动画
|
||||||
|
@ -106,6 +112,32 @@ void SwitchButton::mousePressEvent(QMouseEvent *event) {
|
||||||
return QWidget::mousePressEvent(event);
|
return QWidget::mousePressEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SwitchButton::enterEvent(QEvent *event)
|
||||||
|
{
|
||||||
|
if (m_enabled && m_bIsOn) {
|
||||||
|
m_colorActive = COLOR_ACTIVE_HOVER;
|
||||||
|
} else if (m_enabled && !m_bIsOn) {
|
||||||
|
m_colorInactive = COLOR_INACTIVE_HOVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->update();
|
||||||
|
|
||||||
|
return QWidget::enterEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SwitchButton::leaveEvent(QEvent *event)
|
||||||
|
{
|
||||||
|
if (m_enabled && m_bIsOn) {
|
||||||
|
m_colorActive = COLOR_ACTIVE;
|
||||||
|
} else if (m_enabled && !m_bIsOn) {
|
||||||
|
m_colorInactive = COLOR_INACTIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->update();
|
||||||
|
|
||||||
|
return QWidget::leaveEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
/* 绘制滑动按钮主体 */
|
/* 绘制滑动按钮主体 */
|
||||||
void SwitchButton::paintEvent(QPaintEvent *event) {
|
void SwitchButton::paintEvent(QPaintEvent *event) {
|
||||||
Q_UNUSED(event);
|
Q_UNUSED(event);
|
||||||
|
@ -113,28 +145,28 @@ void SwitchButton::paintEvent(QPaintEvent *event) {
|
||||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||||
painter.setRenderHint(QPainter::Antialiasing); //抗锯齿效果
|
painter.setRenderHint(QPainter::Antialiasing); //抗锯齿效果
|
||||||
painter.setPen(Qt::NoPen);
|
painter.setPen(Qt::NoPen);
|
||||||
QColor colorActive(61,107,229);
|
|
||||||
QColor colorInactive(190,190,190);
|
|
||||||
colorInactive.setAlphaF(0.12);
|
|
||||||
if(m_bIsOn && m_enabled) {
|
if(m_bIsOn && m_enabled) {
|
||||||
painter.save();
|
painter.save();
|
||||||
painter.setBrush(colorActive);
|
painter.setBrush(m_colorActive);
|
||||||
QRectF active_rect = QRectF(0,0,m_fWidth,m_fHeight);
|
QRectF active_rect = QRectF(0,0,m_fWidth,m_fHeight);
|
||||||
painter.drawRoundedRect(active_rect, 0.5 * m_fHeight, 0.5 * m_fHeight); //画开启状态
|
painter.drawRoundedRect(active_rect, 0.5 * m_fHeight, 0.5 * m_fHeight); //画开启状态
|
||||||
} else {
|
} else {
|
||||||
painter.save();
|
painter.save();
|
||||||
painter.setBrush(colorInactive);
|
painter.setBrush(m_colorInactive);
|
||||||
QRectF inactive_rect = QRectF(0 ,0,m_fWidth,m_fHeight);
|
QRectF inactive_rect = QRectF(0 ,0,m_fWidth,m_fHeight);
|
||||||
painter.drawRoundedRect(inactive_rect, 0.5 * m_fHeight, 0.5 * m_fHeight); //画关闭状态
|
painter.drawRoundedRect(inactive_rect, 0.5 * m_fHeight, 0.5 * m_fHeight); //画关闭状态
|
||||||
}
|
}
|
||||||
painter.restore();
|
painter.restore();
|
||||||
painter.save();
|
painter.save();
|
||||||
if (!m_enabled) {
|
if (!m_enabled) {
|
||||||
painter.setBrush(Qt::darkGray);
|
painter.setBrush(COLOR_UNABLE);
|
||||||
|
// QRectF enableRect = QRectF(30, 10, 8, 4);
|
||||||
|
// painter.drawRoundedRect(enableRect, 2, 2);
|
||||||
} else {
|
} else {
|
||||||
painter.setBrush(Qt::white);
|
painter.setBrush(Qt::white);
|
||||||
}
|
}
|
||||||
painter.drawEllipse(m_fCurrentValue,4, 16, 16);
|
painter.drawEllipse(m_fCurrentValue,4, 16, 16);
|
||||||
|
|
||||||
painter.restore();
|
painter.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,8 @@ public:
|
||||||
bool getEnabled();
|
bool getEnabled();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QColor m_colorActive;
|
||||||
|
QColor m_colorInactive;
|
||||||
int m_bIsOn = 1;
|
int m_bIsOn = 1;
|
||||||
QTimer *m_cTimer;
|
QTimer *m_cTimer;
|
||||||
float m_fWidth;
|
float m_fWidth;
|
||||||
|
@ -41,6 +43,8 @@ private:
|
||||||
float m_fCurrentValue;
|
float m_fCurrentValue;
|
||||||
void paintEvent(QPaintEvent *event);
|
void paintEvent(QPaintEvent *event);
|
||||||
void mousePressEvent(QMouseEvent *event);
|
void mousePressEvent(QMouseEvent *event);
|
||||||
|
void enterEvent(QEvent *event);
|
||||||
|
void leaveEvent(QEvent *event);
|
||||||
bool m_enabled = true;
|
bool m_enabled = true;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
|
Loading…
Reference in New Issue