1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
| #include <QRegExpValidator> #include <QLabel>
#include "ippartlineedit.h" #include "ipaddredit.h"
CIpAddrEdit::CIpAddrEdit(QWidget *parent) : QWidget(parent) { m_pIpPart1 = new CIpPartLineEdit(this); m_pIpPart2 = new CIpPartLineEdit(this); m_pIpPart3 = new CIpPartLineEdit(this); m_pIpPart4 = new CIpPartLineEdit(this);
m_pDot1 = new QLabel(this); m_pDot2 = new QLabel(this); m_pDot3 = new QLabel(this);
m_pIpPart1->setGeometry(QRect(0, 0, 42, 27)); m_pIpPart2->setGeometry(QRect(70, 0, 42, 27)); m_pIpPart3->setGeometry(QRect(140, 0, 42, 27)); m_pIpPart4->setGeometry(QRect(210, 0, 42, 27));
m_pDot1->setText("-"); m_pDot1->setGeometry(QRect(48, 5, 16, 16)); m_pDot1->setAlignment(Qt::AlignCenter);
m_pDot2->setText("-"); m_pDot2->setGeometry(QRect(118, 5, 16, 16)); m_pDot2->setAlignment(Qt::AlignCenter);
m_pDot3->setText("-"); m_pDot3->setGeometry(QRect(188, 5, 16, 16)); m_pDot3->setAlignment(Qt::AlignCenter);
QWidget::setTabOrder(m_pIpPart1, m_pIpPart2); QWidget::setTabOrder(m_pIpPart2, m_pIpPart3); QWidget::setTabOrder(m_pIpPart3, m_pIpPart4);
m_pIpPart1->m_vSetNextEdit(m_pIpPart2); m_pIpPart2->m_vSetNextEdit(m_pIpPart3); m_pIpPart3->m_vSetNextEdit(m_pIpPart4);
m_pIpPart2->m_vSetPreEdit(m_pIpPart1); m_pIpPart3->m_vSetPreEdit(m_pIpPart2); m_pIpPart4->m_vSetPreEdit(m_pIpPart3);
connect(m_pIpPart1, SIGNAL(textChanged(const QString&)), this, SLOT(slot_text_Changed(const QString&))); connect(m_pIpPart2, SIGNAL(textChanged(const QString&)), this, SLOT(slot_text_Changed(const QString&))); connect(m_pIpPart3, SIGNAL(textChanged(const QString&)), this, SLOT(slot_text_Changed(const QString&))); connect(m_pIpPart4, SIGNAL(textChanged(const QString&)), this, SLOT(slot_text_Changed(const QString&)));
connect(m_pIpPart1, SIGNAL(textEdited(const QString&)), this, SLOT(slot_text_Edited(const QString&))); connect(m_pIpPart2, SIGNAL(textEdited(const QString&)), this, SLOT(slot_text_Edited(const QString&))); connect(m_pIpPart3, SIGNAL(textEdited(const QString&)), this, SLOT(slot_text_Edited(const QString&))); connect(m_pIpPart4, SIGNAL(textEdited(const QString&)), this, SLOT(slot_text_Edited(const QString&))); }
CIpAddrEdit::~CIpAddrEdit() {
}
void CIpAddrEdit::slot_text_Changed(const QString &) { QString strIpPart1 = m_pIpPart1->text(); QString strIpPart2 = m_pIpPart1->text(); QString strIpPart3 = m_pIpPart1->text(); QString strIpPart4 = m_pIpPart1->text();
QString strIpAddr = QString("%1.%2.%3.%4") .arg(strIpPart1) .arg(strIpPart2) .arg(strIpPart3) .arg(strIpPart4);
emit sigTextChanged(strIpAddr); }
void CIpAddrEdit::slot_text_Edited(const QString &) { QString strIpPart1 = m_pIpPart1->text(); QString strIpPart2 = m_pIpPart1->text(); QString strIpPart3 = m_pIpPart1->text(); QString strIpPart4 = m_pIpPart1->text();
QString strIpAddr = QString("%1.%2.%3.%4") .arg(strIpPart1) .arg(strIpPart2) .arg(strIpPart3) .arg(strIpPart4);
emit sigTextEdited(strIpAddr); }
void CIpAddrEdit::m_vSetText(const QString &text) { QString strIpAddr = text;
QRegExp regexp("((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)"); QRegExpValidator regexp_validator(regexp, this);
int iPos = 0;
QValidator::State state = regexp_validator.validate(strIpAddr, iPos); if(state != QValidator::Acceptable) { return ; }
QStringList ipAddrList = text.split(".");
QString strIpPart1 = ipAddrList.at(0); QString strIpPart2 = ipAddrList.at(1); QString strIpPart3 = ipAddrList.at(2); QString strIpPart4 = ipAddrList.at(3);
m_pIpPart1->setText(strIpPart1); m_pIpPart2->setText(strIpPart2); m_pIpPart3->setText(strIpPart3); m_pIpPart4->setText(strIpPart4); }
QString CIpAddrEdit::m_strGetText() { QString strIpPart1 = m_pIpPart1->text(); QString strIpPart2 = m_pIpPart2->text(); QString strIpPart3 = m_pIpPart3->text(); QString strIpPart4 = m_pIpPart4->text();
return QString("%1.%2.%3.%4") .arg(strIpPart1) .arg(strIpPart2) .arg(strIpPart3) .arg(strIpPart4); }
void CIpAddrEdit::m_vSetStyleSheet(const QString &styleSheet) { m_pIpPart1->setStyleSheet(styleSheet); m_pIpPart2->setStyleSheet(styleSheet); m_pIpPart3->setStyleSheet(styleSheet); m_pIpPart4->setStyleSheet(styleSheet); }
|