开关按钮三态&&bug#100740
This commit is contained in:
parent
e4622eb543
commit
3ccad670cf
|
@ -413,9 +413,14 @@ void LanPage::constructConnectionArea()
|
|||
|
||||
delete p_deactiveConnectionItem;
|
||||
p_deactiveConnectionItem = nullptr;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (m_inactivatedLanListWidget->count() < 4) {
|
||||
m_inactivatedLanListWidget->setFixedWidth(383);
|
||||
} else {
|
||||
m_inactivatedLanListWidget->setFixedWidth(400);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -457,7 +462,9 @@ bool LanPage::removeConnectionItem(QMap<QString, QListWidgetItem *> &connectMap,
|
|||
p_listWidgetItem = nullptr;
|
||||
|
||||
iter = connectMap.erase(iter);
|
||||
|
||||
if (m_inactivatedLanListWidget->count() < 4) {
|
||||
m_inactivatedLanListWidget->setFixedWidth(383);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -478,6 +485,7 @@ void LanPage::onRemoveConnection(QString path) //删除时后端会
|
|||
if (m_activeConnectionMap.count() <= 0) {
|
||||
addEmptyConnectItem(m_activeConnectionMap, m_activatedLanListWidget);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -507,7 +515,9 @@ void LanPage::onAddConnection(QString uuid) //新增一个有线
|
|||
|
||||
delete p_newItem;
|
||||
p_newItem = nullptr;
|
||||
|
||||
if (m_inactivatedLanListWidget->count() >= 4) {
|
||||
m_inactivatedLanListWidget->setFixedWidth(400);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -750,6 +760,7 @@ void LanPage::initUI()
|
|||
m_activatedLanListWidget->setFrameShape(QFrame::Shape::NoFrame);
|
||||
m_activatedLanListWidget->setSpacing(LAN_LIST_SPACING);
|
||||
m_activatedLanListWidget->setFixedHeight(ITEM_HEIGHT); //active区域固定高度,只显示一个条目
|
||||
m_activatedLanListWidget->setFixedWidth(383);
|
||||
m_activatedLanListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
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->setSizeHint(QSize(listWidget->width(), ITEM_HEIGHT));
|
||||
listWidget->addItem(p_listWidgetItem);
|
||||
|
||||
LanListItem *p_lanItem = nullptr;
|
||||
if (itemData != nullptr) {
|
||||
p_lanItem = new LanListItem(itemData, m_currentDeviceName);
|
||||
|
@ -817,7 +827,6 @@ QListWidgetItem *LanPage::addNewItem(KyConnectItem *itemData, QListWidget *listW
|
|||
}
|
||||
|
||||
listWidget->setItemWidget(p_listWidgetItem, p_lanItem);
|
||||
|
||||
return p_listWidgetItem;
|
||||
}
|
||||
|
||||
|
@ -828,7 +837,6 @@ void LanPage::updateActivatedConnectionArea(KyConnectItem *p_newItem)
|
|||
}
|
||||
|
||||
deleteConnectionMapItem(m_inactiveConnectionMap, m_inactivatedLanListWidget, p_newItem->m_connectUuid);
|
||||
|
||||
if (p_newItem->m_ifaceName == m_currentDeviceName) {
|
||||
qDebug()<<"[LanPage]update active connection item"<<p_newItem->m_connectName;
|
||||
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);
|
||||
this->showDesktopNotify(tr("LAN Connected Successfully"));
|
||||
}
|
||||
if (m_inactivatedLanListWidget->count() < 4) {
|
||||
m_inactivatedLanListWidget->setFixedWidth(383);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -857,6 +868,11 @@ void LanPage::updateConnectionArea(KyConnectItem *p_newItem)
|
|||
m_inactiveConnectionMap.insert(p_newItem->m_connectUuid, p_listWidgetItem);
|
||||
this->showDesktopNotify(tr("LAN Disconnected Successfully"));
|
||||
}
|
||||
if (m_inactivatedLanListWidget->count() < 4) {
|
||||
m_inactivatedLanListWidget->setFixedWidth(383);
|
||||
} else {
|
||||
m_inactivatedLanListWidget->setFixedWidth(400);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -79,6 +79,7 @@ void WlanPage::initWlanUI()
|
|||
m_activatedNetListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
|
||||
m_activatedNetListWidget->setSpacing(NET_LIST_SPACING);
|
||||
m_activatedNetListWidget->setFixedHeight(NORMAL_HEIGHT);
|
||||
m_activatedNetListWidget->setFixedWidth(383);
|
||||
m_activatedNetListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_activatedNetLayout->addWidget(m_activatedNetListWidget);
|
||||
|
||||
|
@ -382,6 +383,9 @@ void WlanPage::deleteWirelessItemFormMap(QMap<QString, QListWidgetItem*> &wirele
|
|||
delete p_listWidgetItem;
|
||||
p_listWidgetItem = nullptr;
|
||||
|
||||
if (m_inactivatedNetListWidget->count() < 4) {
|
||||
m_inactivatedNetListWidget->setFixedWidth(383);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -457,7 +461,11 @@ void WlanPage::constructWirelessNetArea()
|
|||
|
||||
qDebug() << "[WlanPage] Stopped loading wireless net list! time="
|
||||
<< QDateTime::currentDateTime().toString("hh:mm:ss.zzzz");
|
||||
|
||||
if (m_inactivatedNetListWidget->count() < 4) {
|
||||
m_inactivatedNetListWidget->setFixedWidth(383);
|
||||
} else {
|
||||
m_inactivatedNetListWidget->setFixedWidth(400);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -507,7 +515,9 @@ void WlanPage::onWlanAdded(QString interface, KyWirelessNetItem &item)
|
|||
updateWlanItemState(m_inactivatedNetListWidget, p_listWidgetItem, Deactivated);
|
||||
|
||||
addWlanMoreItem();
|
||||
|
||||
if (m_inactivatedNetListWidget->count() >= 4) {
|
||||
m_inactivatedNetListWidget->setFixedWidth(400);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -826,7 +836,9 @@ void WlanPage::updateActivatedArea(QString uuid, QString ssid, QString devName)
|
|||
m_activateConnectionItemMap.insert(wirelessNetItem.m_NetSsid, p_listWidgetItem);
|
||||
|
||||
m_activatedNetListWidget->setFixedHeight(p_listWidgetItem->sizeHint().height());
|
||||
|
||||
if (m_inactivatedNetListWidget->count() < 4) {
|
||||
m_inactivatedNetListWidget->setFixedWidth(383);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -857,7 +869,11 @@ void WlanPage::updateWirelessNetArea(QString uuid, QString ssid, QString devName
|
|||
|
||||
// 更新‘更多’条目,以保证其处于listwidget的最底部
|
||||
addWlanMoreItem();
|
||||
|
||||
if (m_inactivatedNetListWidget->count() < 4) {
|
||||
m_inactivatedNetListWidget->setFixedWidth(383);
|
||||
} else {
|
||||
m_inactivatedNetListWidget->setFixedWidth(400);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,10 +18,18 @@
|
|||
#include "switchbutton.h"
|
||||
#define SWITCH_WIDTH 48
|
||||
#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)
|
||||
{
|
||||
|
||||
m_colorActive = COLOR_ACTIVE;
|
||||
m_colorInactive = COLOR_INACTIVE;
|
||||
setFixedSize(SWITCH_WIDTH,SWITCH_HEIGHT);
|
||||
m_fWidth = (float)width();
|
||||
m_fHeight = (float)height();
|
||||
|
@ -34,7 +42,6 @@ SwitchButton::SwitchButton(QWidget *parent) : QWidget(parent)
|
|||
else {
|
||||
m_fCurrentValue = 4;
|
||||
}
|
||||
|
||||
connect(m_cTimer, SIGNAL(timeout()), this, SLOT(startAnimation()));
|
||||
|
||||
|
||||
|
@ -49,7 +56,6 @@ void SwitchButton::setSwitchStatus(bool check) {
|
|||
} else {
|
||||
m_bIsOn = 0;
|
||||
}
|
||||
|
||||
emit this->switchStatusChanged();
|
||||
|
||||
m_cTimer->start(); //开始播放动画
|
||||
|
@ -106,6 +112,30 @@ void SwitchButton::mousePressEvent(QMouseEvent *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) {
|
||||
Q_UNUSED(event);
|
||||
|
@ -113,28 +143,28 @@ void SwitchButton::paintEvent(QPaintEvent *event) {
|
|||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
painter.setRenderHint(QPainter::Antialiasing); //抗锯齿效果
|
||||
painter.setPen(Qt::NoPen);
|
||||
QColor colorActive(61,107,229);
|
||||
QColor colorInactive(190,190,190);
|
||||
colorInactive.setAlphaF(0.12);
|
||||
if(m_bIsOn && m_enabled) {
|
||||
painter.save();
|
||||
painter.setBrush(colorActive);
|
||||
painter.setBrush(m_colorActive);
|
||||
QRectF active_rect = QRectF(0,0,m_fWidth,m_fHeight);
|
||||
painter.drawRoundedRect(active_rect, 0.5 * m_fHeight, 0.5 * m_fHeight); //画开启状态
|
||||
} else {
|
||||
painter.save();
|
||||
painter.setBrush(colorInactive);
|
||||
painter.setBrush(m_colorInactive);
|
||||
QRectF inactive_rect = QRectF(0 ,0,m_fWidth,m_fHeight);
|
||||
painter.drawRoundedRect(inactive_rect, 0.5 * m_fHeight, 0.5 * m_fHeight); //画关闭状态
|
||||
}
|
||||
painter.restore();
|
||||
painter.save();
|
||||
if (!m_enabled) {
|
||||
painter.setBrush(Qt::darkGray);
|
||||
painter.setBrush(COLOR_UNABLE);
|
||||
// QRectF enableRect = QRectF(30, 10, 8, 4);
|
||||
// painter.drawRoundedRect(enableRect, 2, 2);
|
||||
} else {
|
||||
painter.setBrush(Qt::white);
|
||||
}
|
||||
painter.drawEllipse(m_fCurrentValue,4, 16, 16);
|
||||
|
||||
painter.restore();
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,8 @@ public:
|
|||
bool getEnabled();
|
||||
|
||||
private:
|
||||
QColor m_colorActive;
|
||||
QColor m_colorInactive;
|
||||
int m_bIsOn = 1;
|
||||
QTimer *m_cTimer;
|
||||
float m_fWidth;
|
||||
|
@ -41,6 +43,8 @@ private:
|
|||
float m_fCurrentValue;
|
||||
void paintEvent(QPaintEvent *event);
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void enterEvent(QEvent *event);
|
||||
void leaveEvent(QEvent *event);
|
||||
bool m_enabled = true;
|
||||
|
||||
Q_SIGNALS:
|
||||
|
|
Loading…
Reference in New Issue