Add some tools.

This commit is contained in:
zhangjiaping 2021-08-13 11:15:48 +08:00
parent 81f4a0100d
commit df6d30e66f
8 changed files with 266 additions and 2 deletions

View File

@ -5,10 +5,12 @@ FORMS += \
$$PWD/onelancform.ui
HEADERS += \
$$PWD/listitem.h \
$$PWD/oneconnform.h \
$$PWD/onelancform.h
SOURCES += \
$$PWD/listitem.cpp \
$$PWD/oneconnform.cpp \
$$PWD/onelancform.cpp

View File

@ -0,0 +1,6 @@
#include "listitem.h"
ListItem::ListItem()
{
}

View File

@ -0,0 +1,12 @@
#ifndef LISTITEM_H
#define LISTITEM_H
#include <QFrame>
class ListItem : public QFrame
{
Q_OBJECT
public:
ListItem();
};
#endif // LISTITEM_H

View File

@ -1,6 +1,121 @@
#include "wlanpage.h"
#include <QEvent>
#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 LAN_LAYOUT_MARGINS 8,8,8,8
#define LAN_LAYOUT_SPACING 8
#define LAN_LIST_SPACING 2
#define TEXT_MARGINS 16,0,0,0
//#define SCROLL_AREA_HEIGHT 200
#define SETTINGS_LAYOUT_MARGINS 24,16,24,16
WlanPage::WlanPage(QWidget *parent) : QWidget(parent)
{
initUI();
}
WlanPage::~WlanPage()
{
delete m_title_divider;
delete m_activated_wlan_divider;
delete m_inactivated_wlan_divider;
}
bool WlanPage::eventFilter(QObject *w, QEvent *e)
{
if (e->type() == QEvent::MouseButtonPress) {
if (w == m_hidden_wlan_label) {
//ZJP_TODO 打开隐藏WiFi添加弹窗
} else if (w == m_settings_label) {
//ZJP_TODO 打开控制面板
}
}
return QWidget::eventFilter(w,e);
}
void WlanPage::initUI()
{
m_main_layout = new QVBoxLayout(this);
m_main_layout->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_main_layout->setSpacing(MAIN_LAYOUT_SPACING);
this->setLayout(m_main_layout);
m_title_frame = new QFrame(this);
m_title_frame->setFixedHeight(TITLE_FRAME_HEIGHT);
m_title_layout = new QHBoxLayout(m_title_frame);
m_title_layout->setContentsMargins(TITLE_LAYOUT_MARGINS);
m_title_label = new QLabel(m_title_frame);
m_title_label->setText(tr("WLAN"));
m_lan_switch = new SwitchButton(m_title_frame);
m_title_layout->addWidget(m_title_label);
m_title_layout->addStretch();
m_title_layout->addWidget(m_lan_switch);
m_title_divider = new Divider(this);
m_activated_wlan_frame = new QFrame(this);
m_activated_wlan_layout = new QVBoxLayout(m_activated_wlan_frame);
m_activated_wlan_layout->setContentsMargins(LAN_LAYOUT_MARGINS);
m_activated_wlan_layout->setSpacing(LAN_LAYOUT_SPACING);
m_activated_wlan_label = new QLabel(m_activated_wlan_frame);
m_activated_wlan_label->setContentsMargins(TEXT_MARGINS);
m_activated_wlan_label->setText(tr("Activated WLAN"));
m_activated_wlan_list_widget = new QListWidget(m_activated_wlan_frame);
m_activated_wlan_list_widget->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_activated_wlan_list_widget->setSpacing(LAN_LIST_SPACING);
m_activated_wlan_layout->addWidget(m_activated_wlan_label);
m_activated_wlan_layout->addWidget(m_activated_wlan_list_widget);
m_activated_wlan_divider = new Divider(this);
m_inactivated_wlan_frame = new QFrame(this);
m_inactivated_wlan_layout = new QVBoxLayout(m_inactivated_wlan_frame);
m_inactivated_wlan_layout->setContentsMargins(LAN_LAYOUT_MARGINS);
m_inactivated_wlan_layout->setSpacing(LAN_LAYOUT_SPACING);
m_inactivated_wlan_frame->setLayout(m_inactivated_wlan_layout);
m_inactivated_wlan_label = new QLabel(m_inactivated_wlan_frame);
m_inactivated_wlan_label->setContentsMargins(TEXT_MARGINS);
m_inactivated_wlan_label->setText(tr("Inactivated WLAN"));
m_inactivated_wlan_list_area = new QScrollArea(m_inactivated_wlan_frame);
m_inactivated_wlan_list_area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_inactivated_wlan_list_area->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
m_inactivated_wlan_list_area_central_widget = new QFrame(m_inactivated_wlan_list_area);
m_inactivated_wlan_list_area->setWidget(m_inactivated_wlan_list_area_central_widget);
m_inactivated_wlan_list_area_layout = new QVBoxLayout(m_inactivated_wlan_list_area_central_widget);
m_inactivated_wlan_list_area_central_widget->setLayout(m_inactivated_wlan_list_area_layout);
m_inactivated_wlan_list_area_layout->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_inactivated_wlan_list_widget = new QListWidget(m_inactivated_wlan_list_area_central_widget);
m_inactivated_wlan_list_widget->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_inactivated_wlan_list_widget->setSpacing(LAN_LIST_SPACING);
m_hidden_wlan_widget = new QFrame(m_inactivated_wlan_list_area_central_widget);
m_hidden_wlan_layout = new QHBoxLayout(m_hidden_wlan_widget);
m_hidden_wlan_layout->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_hidden_wlan_label = new QLabel(m_hidden_wlan_widget);
m_hidden_wlan_label->setText(tr("More..."));
m_hidden_wlan_layout->addWidget(m_hidden_wlan_label);
m_hidden_wlan_layout->addStretch();
m_inactivated_wlan_list_area_layout->addWidget(m_inactivated_wlan_list_widget);
m_inactivated_wlan_list_area_layout->addWidget(m_hidden_wlan_widget);
// m_inactivated_lan_list_area->setFixedHeight(SCROLL_AREA_HEIGHT);
m_inactivated_wlan_layout->addWidget(m_inactivated_wlan_label);
m_inactivated_wlan_layout->addWidget(m_inactivated_wlan_list_area);
m_inactivated_wlan_divider = new Divider(this);
m_settings_frame = new QFrame(this);
m_settings_layout = new QHBoxLayout(m_settings_frame);
m_settings_layout->setContentsMargins(SETTINGS_LAYOUT_MARGINS);
m_settings_label = new QLabel(m_settings_frame);
m_settings_label->setText(tr("Settings"));
m_settings_layout->addWidget(m_settings_label);
m_settings_frame->setLayout(m_settings_layout);
m_main_layout->addWidget(m_title_frame);
m_main_layout->addWidget(m_title_divider);
m_main_layout->addWidget(m_activated_wlan_frame);
m_main_layout->addWidget(m_activated_wlan_divider);
m_main_layout->addWidget(m_inactivated_wlan_frame);
m_main_layout->addWidget(m_inactivated_wlan_divider);
m_main_layout->addWidget(m_settings_frame);
}

View File

@ -1,16 +1,56 @@
#ifndef WLANPAGE_H
#define WLANPAGE_H
#include <QWidget>
#include "divider.h"
#include "switchbutton.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QScrollArea>
#include <QListWidget>
class WlanPage : public QWidget
{
Q_OBJECT
public:
explicit WlanPage(QWidget *parent = nullptr);
~WlanPage();
signals:
protected:
bool eventFilter(QObject *, QEvent *);
private:
void initUI();
QVBoxLayout * m_main_layout = nullptr;
QFrame * m_title_frame = nullptr;
QHBoxLayout * m_title_layout = nullptr;
QLabel * m_title_label = nullptr;
SwitchButton * m_lan_switch = nullptr;
Divider * m_title_divider = nullptr;
QFrame * m_activated_wlan_frame = nullptr;
QVBoxLayout * m_activated_wlan_layout = nullptr;
QLabel * m_activated_wlan_label = nullptr;
QListWidget * m_activated_wlan_list_widget = nullptr;
Divider * m_activated_wlan_divider = nullptr;
QFrame * m_inactivated_wlan_frame = nullptr;
QVBoxLayout * m_inactivated_wlan_layout = nullptr;
QLabel * m_inactivated_wlan_label = nullptr;
QScrollArea * m_inactivated_wlan_list_area = nullptr;
QFrame * m_inactivated_wlan_list_area_central_widget = nullptr;
QVBoxLayout * m_inactivated_wlan_list_area_layout = nullptr;
QListWidget * m_inactivated_wlan_list_widget = nullptr;
QFrame * m_hidden_wlan_widget = nullptr;
QHBoxLayout * m_hidden_wlan_layout = nullptr;
QLabel * m_hidden_wlan_label = nullptr;
Divider * m_inactivated_wlan_divider = nullptr;
QFrame * m_settings_frame = nullptr;
QHBoxLayout * m_settings_layout = nullptr;
QLabel * m_settings_label = nullptr;
};
#endif // WLANPAGE_H

View File

@ -0,0 +1,53 @@
#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_is_activated = isActivated;
this->setAutoFillBackground(false);
m_icon_label = new QLabel(this);
m_icon_label->setScaledContents(true);
}
void NetButton::startLoading()
{
emit this->requestStartLoading();
}
void NetButton::stopLoading()
{
emit this->requestStopLoading();
}
void NetButton::setPressed()
{
//ZJP_TODO 设置颜色为点击颜色,注意区分已连接/未连接
if (m_is_activated)
;
;
}
void NetButton::setReleased()
{
//ZJP_TODO 设置颜色为未点击颜色,注意区分已连接/未连接
if (m_is_activated)
;
;
}
void NetButton::setButtonIcon(QIcon *icon)
{
if (!icon) return;
m_icon_label->setPixmap(icon->pixmap(this->size()));
}
void NetButton::onLoadingStarted()
{
//ZJP_TODO 开始播放转圈动画
}
void NetButton::onLoadingStopped()
{
//ZJP_TODO 停止播放转圈动画
}

View File

@ -0,0 +1,34 @@
#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_is_activated = INACTIVATED;
QLabel * m_icon_label = nullptr;
private slots:
void onLoadingStarted();
void onLoadingStopped();
};
#endif // NETBUTTON_H

View File

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