modified ipv4 and ipv6 ui

This commit is contained in:
zhangyuanyuan1 2022-06-27 15:13:01 +08:00
parent 571f91a479
commit 7f9b8a796e
6 changed files with 210 additions and 26 deletions

View File

@ -2,12 +2,32 @@
#include "netdetail.h"
#include "math.h"
#define LAYOUT_MARGINS 0,0,0,0
#define LAYOUT_SPACING 0
#define HINT_TEXT_MARGINS 8, 1, 0, 3
#define LABEL_HEIGHT 24
Ipv4Page::Ipv4Page(QWidget *parent):QFrame(parent)
{
initUI();
initComponent();
}
bool Ipv4Page::eventFilter(QObject *w, QEvent *e)
{
if (w == ipv4addressEdit) {
if (ipv4addressEdit->text().isEmpty() || getTextEditState(ipv4addressEdit->text())) {
m_addressHintLabel->clear();
}
} else if (w == netMaskEdit) {
if (netMaskEdit->text().isEmpty() || netMaskIsValide(netMaskEdit->text())) {
m_maskHintLabel->clear();
}
}
return QObject::eventFilter(w,e);
}
void Ipv4Page::initUI() {
ipv4ConfigCombox = new QComboBox(this);
ipv4addressEdit = new LineEdit(this);
@ -23,6 +43,24 @@ void Ipv4Page::initUI() {
m_dnsLabel = new QLabel(this);
m_secDnsLabel = new QLabel(this);
m_configEmptyLabel = new QLabel(this);
m_configEmptyLabel->setFixedHeight(LABEL_HEIGHT);
m_addressHintLabel = new QLabel(this);
m_addressHintLabel->setFixedHeight(LABEL_HEIGHT);
m_addressHintLabel->setContentsMargins(HINT_TEXT_MARGINS);
m_maskHintLabel = new QLabel(this);
m_maskHintLabel->setFixedHeight(LABEL_HEIGHT);
m_maskHintLabel->setContentsMargins(HINT_TEXT_MARGINS);
m_gateWayEmptyLabel = new QLabel(this);
m_gateWayEmptyLabel->setFixedHeight(LABEL_HEIGHT);
m_firstDnsEmptyLabel = new QLabel(this);
m_firstDnsEmptyLabel->setFixedHeight(LABEL_HEIGHT);
m_configLabel->setText(tr("Ipv4Config"));
m_addressLabel->setText(tr("Address"));
m_maskLabel->setText(tr("Netmask"));
@ -30,12 +68,36 @@ void Ipv4Page::initUI() {
m_dnsLabel->setText(tr("Prefs DNS"));
m_secDnsLabel->setText(tr("Alternative DNS"));
QPalette hintTextColor;
hintTextColor.setColor(QPalette::WindowText, Qt::red);
m_addressHintLabel->setPalette(hintTextColor);
m_maskHintLabel->setPalette(hintTextColor);
QWidget *addressWidget = new QWidget(this);
QVBoxLayout *addressLayout = new QVBoxLayout(addressWidget);
addressLayout->setContentsMargins(LAYOUT_MARGINS);
addressLayout->setSpacing(LAYOUT_SPACING);
addressLayout->addWidget(ipv4addressEdit);
addressLayout->addWidget(m_addressHintLabel);
QWidget *maskWidget = new QWidget(this);
QVBoxLayout *maskLayout = new QVBoxLayout(maskWidget);
maskLayout->setContentsMargins(LAYOUT_MARGINS);
maskLayout->setSpacing(LAYOUT_SPACING);
maskLayout->addWidget(netMaskEdit);
maskLayout->addWidget(m_maskHintLabel);
m_detailLayout = new QFormLayout(this);
m_detailLayout->setVerticalSpacing(0);
m_detailLayout->setContentsMargins(LAYOUT_MARGINS);
m_detailLayout->addRow(m_configLabel,ipv4ConfigCombox);
m_detailLayout->addRow(m_addressLabel,ipv4addressEdit);
m_detailLayout->addRow(m_maskLabel,netMaskEdit);
m_detailLayout->addRow(m_configEmptyLabel);
m_detailLayout->addRow(m_addressLabel,addressWidget);
m_detailLayout->addRow(m_maskLabel,maskWidget);
m_detailLayout->addRow(m_gateWayLabel,gateWayEdit);
m_detailLayout->addRow(m_gateWayEmptyLabel);
m_detailLayout->addRow(m_dnsLabel,firstDnsEdit);
m_detailLayout->addRow(m_firstDnsEmptyLabel);
m_detailLayout->addRow(m_secDnsLabel,secondDnsEdit);
ipv4ConfigCombox->addItem(tr("Auto(DHCP)")); //"自动(DHCP)"
@ -57,6 +119,9 @@ void Ipv4Page::initUI() {
netMaskEdit->setValidator(new QRegExpValidator(rx, this));
firstDnsEdit->setValidator(new QRegExpValidator(rx, this));
secondDnsEdit->setValidator(new QRegExpValidator(rx, this));
ipv4addressEdit->installEventFilter(this);
netMaskEdit->installEventFilter(this);
}
void Ipv4Page::initComponent() {
@ -166,13 +231,23 @@ bool Ipv4Page::checkConnectBtnIsEnabled()
if (ipv4ConfigCombox->currentIndex() == AUTO_CONFIG) {
return true;
} else {
if (ipv4addressEdit->text().isEmpty() || !getTextEditState(ipv4addressEdit->text())) {
qDebug() << "ipv4address empty or invalid";
if (ipv4addressEdit->text().isEmpty()) {
qDebug() << "ipv4address empty";
return false;
}
if (!getTextEditState(ipv4addressEdit->text())) {
m_addressHintLabel->setText(tr("Invalid address"));
qDebug() << "ipv4address invalid";
return false;
}
if (netMaskEdit->text().isEmpty() || !netMaskIsValide(netMaskEdit->text())) {
qDebug() << "ipv4 netMask empty or invalid";
if (netMaskEdit->text().isEmpty()) {
qDebug() << "ipv4 netMask empty";
return false;
}
if (!netMaskIsValide(netMaskEdit->text())) {
m_maskHintLabel->setText(tr("Invalid subnet mask"));
qDebug() << "ipv4 netMask invalid";
return false;
}
@ -210,19 +285,26 @@ void Ipv4Page::configChanged(int index) {
void Ipv4Page::setLineEnabled(bool check) {
ipv4addressEdit->setEnabled(check);
netMaskEdit->setEnabled(check);
gateWayEdit->setEnabled(check);
firstDnsEdit->setEnabled(check);
secondDnsEdit->setEnabled(check);
if (!check) {
ipv4addressEdit->clear();
netMaskEdit->clear();
gateWayEdit->clear();
firstDnsEdit->clear();
secondDnsEdit->clear();
ipv4addressEdit->setPlaceholderText(" ");
netMaskEdit->setPlaceholderText(" ");
} else {
ipv4addressEdit->setPlaceholderText(tr("Required")); //必填
netMaskEdit->setPlaceholderText(tr("Required")); //必填
}
ipv4addressEdit->setEnabled(check);
netMaskEdit->setEnabled(check);
gateWayEdit->setEnabled(check);
firstDnsEdit->setEnabled(check);
secondDnsEdit->setEnabled(check);
}
void Ipv4Page::setEnableOfSaveBtn() {

View File

@ -28,6 +28,10 @@ public:
void setGateWay(const QString &gateWay);
bool checkIsChanged(const ConInfo info, KyConnectSetting &setting);
protected:
bool eventFilter(QObject *w, QEvent *e);
private:
QComboBox *ipv4ConfigCombox;
LineEdit *ipv4addressEdit;
@ -45,6 +49,12 @@ private:
QLabel *m_gateWayLabel;
QLabel *m_dnsLabel;
QLabel *m_secDnsLabel;
QLabel *m_configEmptyLabel;
QLabel *m_addressHintLabel;
QLabel *m_maskHintLabel;
QLabel *m_gateWayEmptyLabel;
QLabel *m_firstDnsEmptyLabel;
private:
void initUI();
void initComponent();

View File

@ -1,12 +1,32 @@
#include "ipv6page.h"
#include "netdetail.h"
#define LAYOUT_MARGINS 0,0,0,0
#define LAYOUT_SPACING 0
#define HINT_TEXT_MARGINS 8, 1, 0, 3
#define LABEL_HEIGHT 24
Ipv6Page::Ipv6Page(QWidget *parent):QFrame(parent)
{
initUI();
initComponent();
}
bool Ipv6Page::eventFilter(QObject *w, QEvent *e)
{
if (w == ipv6AddressEdit) {
if (ipv6AddressEdit->text().isEmpty() || getIpv6EditState(ipv6AddressEdit->text())) {
m_addressHintLabel->clear();
}
} else if (w == gateWayEdit) {
if (gateWayEdit->text().isEmpty() || getIpv6EditState(gateWayEdit->text())) {
m_gateWayHintLabel->clear();
}
}
return QObject::eventFilter(w,e);
}
void Ipv6Page::setIpv6Config(KyIpConfigType ipv6Config)
{
if (ipv6Config == CONFIG_IP_MANUAL) {
@ -104,6 +124,23 @@ void Ipv6Page::initUI() {
m_dnsLabel = new QLabel(this);
m_secDnsLabel = new QLabel(this);
m_configEmptyLabel = new QLabel(this);
m_configEmptyLabel->setFixedHeight(LABEL_HEIGHT);
m_addressHintLabel = new QLabel(this);
m_addressHintLabel->setFixedHeight(LABEL_HEIGHT);
m_addressHintLabel->setContentsMargins(HINT_TEXT_MARGINS);
m_gateWayHintLabel = new QLabel(this);
m_gateWayHintLabel->setFixedHeight(LABEL_HEIGHT);
m_gateWayHintLabel->setContentsMargins(HINT_TEXT_MARGINS);
m_subnetEmptyLabel = new QLabel(this);
m_subnetEmptyLabel->setFixedHeight(LABEL_HEIGHT);
m_firstDnsEmptyLabel = new QLabel(this);
m_firstDnsEmptyLabel->setFixedHeight(LABEL_HEIGHT);
m_configLabel->setText(tr("Ipv6Config"));
m_addressLabel->setText(tr("Address"));
@ -112,13 +149,36 @@ void Ipv6Page::initUI() {
m_dnsLabel->setText(tr("Prefs DNS"));
m_secDnsLabel->setText(tr("Alternative DNS"));
QPalette hintTextColor;
hintTextColor.setColor(QPalette::WindowText, Qt::red);
m_addressHintLabel->setPalette(hintTextColor);
m_gateWayHintLabel->setPalette(hintTextColor);
QWidget *addressWidget = new QWidget(this);
QVBoxLayout *addressLayout = new QVBoxLayout(addressWidget);
addressLayout->setContentsMargins(LAYOUT_MARGINS);
addressLayout->setSpacing(LAYOUT_SPACING);
addressLayout->addWidget(ipv6AddressEdit);
addressLayout->addWidget(m_addressHintLabel);
QWidget *gateWayWidget = new QWidget(this);
QVBoxLayout *gateWayLayout = new QVBoxLayout(gateWayWidget);
gateWayLayout->setContentsMargins(LAYOUT_MARGINS);
gateWayLayout->setSpacing(LAYOUT_SPACING);
gateWayLayout->addWidget(gateWayEdit);
gateWayLayout->addWidget(m_gateWayHintLabel);
m_detailLayout = new QFormLayout(this);
m_detailLayout->setContentsMargins(0, 0, 0, 0);
m_detailLayout->setVerticalSpacing(0);
m_detailLayout->addRow(m_configLabel,ipv6ConfigCombox);
m_detailLayout->addRow(m_addressLabel,ipv6AddressEdit);
m_detailLayout->addRow(m_configEmptyLabel);
m_detailLayout->addRow(m_addressLabel,addressWidget);
m_detailLayout->addRow(m_subnetLabel,lengthEdit);
m_detailLayout->addRow(m_gateWayLabel,gateWayEdit);
m_detailLayout->addRow(m_subnetEmptyLabel);
m_detailLayout->addRow(m_gateWayLabel,gateWayWidget);
m_detailLayout->addRow(m_dnsLabel,firstDnsEdit);
m_detailLayout->addRow(m_firstDnsEmptyLabel);
m_detailLayout->addRow(m_secDnsLabel,secondDnsEdit);
ipv6ConfigCombox->addItem(tr("Auto(DHCP)")); //"自动(DHCP)"
@ -132,6 +192,9 @@ void Ipv6Page::initUI() {
QRegExp prefix_rx("\\b(?:(?:12[0-8]|1[0-1][0-9]|^[1-9][0-9]?$)\\.){3}(?:12[0-8]|1[0-1][0-9]|^[1-9][0-9]?$)\\b");
lengthEdit->setValidator(new QRegExpValidator(prefix_rx,this));
ipv6AddressEdit->installEventFilter(this);
gateWayEdit->installEventFilter(this);
}
void Ipv6Page::initComponent() {
@ -161,19 +224,27 @@ void Ipv6Page::configChanged(int index) {
void Ipv6Page::setControlEnabled(bool check)
{
ipv6AddressEdit->setEnabled(check);
lengthEdit->setEnabled(check);
gateWayEdit->setEnabled(check);
firstDnsEdit->setEnabled(check);
secondDnsEdit->setEnabled(check);
if (!check) {
ipv6AddressEdit->clear();
lengthEdit->clear();
gateWayEdit->clear();
firstDnsEdit->clear();
secondDnsEdit->clear();
ipv6AddressEdit->setPlaceholderText(" ");
lengthEdit->setPlaceholderText(" ");
gateWayEdit->setPlaceholderText(" ");
} else {
ipv6AddressEdit->setPlaceholderText(tr("Required")); //必填
lengthEdit->setPlaceholderText(tr("Required")); //必填
gateWayEdit->setPlaceholderText(tr("Required")); //必填
}
ipv6AddressEdit->setEnabled(check);
lengthEdit->setEnabled(check);
gateWayEdit->setEnabled(check);
firstDnsEdit->setEnabled(check);
secondDnsEdit->setEnabled(check);
}
void Ipv6Page::setEnableOfSaveBtn()
@ -186,8 +257,13 @@ bool Ipv6Page::checkConnectBtnIsEnabled()
if (ipv6ConfigCombox->currentIndex() == AUTO_CONFIG) {
return true;
} else {
if (ipv6AddressEdit->text().isEmpty() || !getIpv6EditState(ipv6AddressEdit->text())) {
qDebug() << "ipv6address empty or invalid";
if (ipv6AddressEdit->text().isEmpty()) {
qDebug() << "ipv6address empty";
return false;
}
if (!getIpv6EditState(ipv6AddressEdit->text())) {
m_addressHintLabel->setText(tr("Invalid address"));
qDebug() << "ipv6address invalid";
return false;
}
@ -196,8 +272,13 @@ bool Ipv6Page::checkConnectBtnIsEnabled()
return false;
}
if (gateWayEdit->text().isEmpty() || !getIpv6EditState(gateWayEdit->text())) {
qDebug() << "ipv6 gateway empty or invalid";
if (gateWayEdit->text().isEmpty()) {
qDebug() << "ipv6 gateway empty";
return false;
}
if (!getIpv6EditState(gateWayEdit->text())) {
m_gateWayHintLabel->setText(tr("Invalid gateway"));
qDebug() << "ipv6 gateway invalid";
return false;
}

View File

@ -31,6 +31,9 @@ public:
int getPerfixLength(QString text);
protected:
bool eventFilter(QObject *w, QEvent *e);
public:
QComboBox *ipv6ConfigCombox;
LineEdit *ipv6AddressEdit;
@ -46,6 +49,12 @@ private:
QLabel *m_gateWayLabel;
QLabel *m_dnsLabel;
QLabel *m_secDnsLabel;
QLabel *m_configEmptyLabel;
QLabel *m_addressHintLabel;
QLabel *m_subnetEmptyLabel;
QLabel *m_gateWayHintLabel;
QLabel *m_firstDnsEmptyLabel;
private:
void initUI();
void initComponent();

View File

@ -17,7 +17,7 @@
#define WINDOW_HEIGHT 562
#define ICON_SIZE 22,22
#define TITLE_LAYOUT_MARGINS 9,9,0,0
#define LAYOUT_MARGINS 24,0,24,0
#define LAYOUT_MARGINS 0,0,0,0
#define BOTTOM_LAYOUT_SPACING 16
#define PAGE_LAYOUT_SPACING 1
#define DETAIL_PAGE_NUM 0
@ -211,7 +211,7 @@ void NetDetail::centerToScreen()
void NetDetail::initUI()
{
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->setContentsMargins(9,9,14,24);
mainLayout->setContentsMargins(24,9,24,24);
detailPage = new DetailPage(isWlan, m_name.isEmpty(), this);
@ -277,6 +277,7 @@ void NetDetail::initUI()
QVBoxLayout *centerlayout = new QVBoxLayout(centerWidget);
centerlayout->setContentsMargins(LAYOUT_MARGINS);
centerlayout->addWidget(pageFrame);
centerlayout->addSpacing(4);
centerlayout->addWidget(stackWidget);
QHBoxLayout *bottomLayout = new QHBoxLayout(bottomWidget);

View File

@ -52,6 +52,7 @@ void SecurityPage::initUI()
mSecuLayout = new QFormLayout(this);
mSecuLayout->setContentsMargins(0, 0, 0, 0);
mSecuLayout->addRow(secuTypeLabel, secuTypeCombox);
mSecuLayout->addRow(pwdLabel, pwdEdit);
mSecuLayout->addRow(eapTypeLabel, eapTypeCombox);