From 1d8c55ea70b2bf8da49577e0ef5d9e339b773206 Mon Sep 17 00:00:00 2001 From: HwangKC Date: Wed, 13 Nov 2024 17:05:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90QTableview=20pagecontrol=20?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=EF=BC=8C=E6=9B=B4=E6=96=B0=E4=B8=B2=E5=8F=A3?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=9A=84=E4=B8=B2=E5=8F=A3=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=EF=BC=8C=E6=B7=BB=E5=8A=A0=E8=AF=BB=E5=8F=96?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/emsConfigurer/aboutdialog.cpp | 77 +++++++ applications/emsConfigurer/aboutdialog.h | 22 ++ applications/emsConfigurer/aboutdialog.ui | 131 +++++++++++ .../emsConfigurer/devicepropertypage.cpp | 143 +++++++++++- .../emsConfigurer/devicepropertypage.h | 13 ++ applications/emsConfigurer/emsConfigurer.pro | 5 + applications/emsConfigurer/emscfger.conf | 3 + .../formserialportsettingdialog.cpp | 46 ++++ .../formserialportsettingdialog.h | 5 + .../formserialportsettingdialog.ui | 47 ++-- .../emsConfigurer/globalparameters.cpp | 14 +- applications/emsConfigurer/globalparameters.h | 6 + applications/emsConfigurer/ipaddress.cpp | 217 ++++++++++++++++++ applications/emsConfigurer/ipaddress.h | 72 ++++++ applications/emsConfigurer/main.cpp | 6 + applications/emsConfigurer/maindialog.cpp | 20 +- applications/emsConfigurer/maindialog.ui | 2 +- applications/emsConfigurer/mainwindow.cpp | 30 ++- applications/emsConfigurer/mainwindow.ui | 66 +++--- 19 files changed, 847 insertions(+), 78 deletions(-) create mode 100644 applications/emsConfigurer/aboutdialog.cpp create mode 100644 applications/emsConfigurer/aboutdialog.h create mode 100644 applications/emsConfigurer/aboutdialog.ui create mode 100644 applications/emsConfigurer/emscfger.conf create mode 100644 applications/emsConfigurer/ipaddress.cpp create mode 100644 applications/emsConfigurer/ipaddress.h diff --git a/applications/emsConfigurer/aboutdialog.cpp b/applications/emsConfigurer/aboutdialog.cpp new file mode 100644 index 0000000..23faa30 --- /dev/null +++ b/applications/emsConfigurer/aboutdialog.cpp @@ -0,0 +1,77 @@ +#include "aboutdialog.h" +#include "ui_aboutdialog.h" + +#include +#include +#include +#include +#include +#include + +#define MAJOR_VERSION 1 +#define MINOR_VERSION 0 +#define BUILD_VERSION 0 + +AboutDialog::AboutDialog(QWidget *parent) + : QDialog(parent) + , ui(new Ui::AboutDialog) +{ + ui->setupUi(this); + + this->setWindowIcon(QIcon(":/images/icon.png")); + this->setWindowTitle(tr("About EMU Configurer Kit")); + + QPixmap pixmap(":/images/hj-net.png"); + pixmap = pixmap.scaled(250, 75, Qt::KeepAspectRatio, Qt::SmoothTransformation); // 按比例缩放 + ui->label_logo->setPixmap(pixmap); + + ui->buttonBox->clear(); + QPushButton *okButton = ui->buttonBox->addButton(QDialogButtonBox::Ok); + okButton->setFixedSize(100, 30); + + QFont font("Arial", 14, QFont::Bold); + ui->productName->setFont(font); + ui->productName->setText(QString(tr("Configurer Kit for EMU Host"))); + + QStandardItemModel *model = new QStandardItemModel(this); + + QString version = QString(tr("Version %1.%2.%3")).arg(MAJOR_VERSION).arg(MINOR_VERSION).arg(BUILD_VERSION); + + QString formattedDate; + QDate date = QDate::fromString(__DATE__, "MMM dd yyyy"); + if (date.isValid()) + { + formattedDate = date.toString("yyyy-MM-dd"); // 输出格式: 2024-11-12 + formattedDate += QString(" %1").arg(__TIME__); + } + else + { + formattedDate = "Invalid Date"; + } + + QString compileDate = QString(tr("Compiled on %1")) + .arg(formattedDate); + + // 添加一些字符串到模型中 + QStringList stringList; + stringList << version + << compileDate; + + // 将每个字符串作为 QStandardItem 添加到模型中 + for (const QString &str : stringList) + { + QStandardItem *item = new QStandardItem(str); + model->appendRow(item); + } + + // 将模型设置到 QListView + ui->listView->setModel(model); + + setFixedSize(640, 480); + +} + +AboutDialog::~AboutDialog() +{ + delete ui; +} diff --git a/applications/emsConfigurer/aboutdialog.h b/applications/emsConfigurer/aboutdialog.h new file mode 100644 index 0000000..4474ece --- /dev/null +++ b/applications/emsConfigurer/aboutdialog.h @@ -0,0 +1,22 @@ +#ifndef ABOUTDIALOG_H +#define ABOUTDIALOG_H + +#include + +namespace Ui { +class AboutDialog; +} + +class AboutDialog : public QDialog +{ + Q_OBJECT + +public: + explicit AboutDialog(QWidget *parent = nullptr); + ~AboutDialog(); + +private: + Ui::AboutDialog *ui; +}; + +#endif // ABOUTDIALOG_H diff --git a/applications/emsConfigurer/aboutdialog.ui b/applications/emsConfigurer/aboutdialog.ui new file mode 100644 index 0000000..cb642e5 --- /dev/null +++ b/applications/emsConfigurer/aboutdialog.ui @@ -0,0 +1,131 @@ + + + AboutDialog + + + Qt::WindowModal + + + + 0 + 0 + 640 + 480 + + + + Qt::NoContextMenu + + + About Configurer ... + + + true + + + + + 260 + 420 + 341 + 32 + + + + + 0 + 0 + + + + Qt::Horizontal + + + QDialogButtonBox::Ok + + + + + + 10 + 10 + 261 + 61 + + + + WWW.HJ-NET.COM + + + + + + 10 + 120 + 621 + 271 + + + + Qt::NoContextMenu + + + QFrame::Panel + + + QAbstractItemView::NoEditTriggers + + + Qt::IgnoreAction + + + + + + 30 + 70 + 601 + 41 + + + + TextLabel + + + + + + + buttonBox + accepted() + AboutDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AboutDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/applications/emsConfigurer/devicepropertypage.cpp b/applications/emsConfigurer/devicepropertypage.cpp index 7f6b5ec..51c78c4 100644 --- a/applications/emsConfigurer/devicepropertypage.cpp +++ b/applications/emsConfigurer/devicepropertypage.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include "globalparameters.h" #include "mytablemodel.h" @@ -16,13 +18,19 @@ #define PER_PAGE_SIZE (30) DevicePropertyPage::DevicePropertyPage(QWidget *parent) : - QWidget(parent),m_pTableView(nullptr),m_pButton(nullptr) + QWidget(parent),m_nDownCounter(0),m_pTableView(nullptr),m_pButton(nullptr),m_totalPageCount(0),m_currentPage(0) { InitializeTable(); m_pTimer = new QTimer(this); connect(m_pTimer, SIGNAL(timeout()), this, SLOT(handleTimeout())); //m_pTimer->start(AppData::getInstance()->nTimeOut); + + m_pDownCounterTimer = new QTimer(this); + connect(m_pDownCounterTimer, SIGNAL(timeout()), this, SLOT(handleDownCounter())); + + updatePageButtonState(); + updatePageLabel(); } DevicePropertyPage::~DevicePropertyPage() @@ -33,15 +41,18 @@ void DevicePropertyPage::handleTimeout() { if(m_pTimer->isActive()) { - m_pTimer->stop(); - Refresh(); - - int nInterval = 5000; - m_pTimer->start(nInterval*1000); } } +void DevicePropertyPage::handleDownCounter() +{ + m_nDownCounter--; + m_pDownCounterLabel->setText(QString("%1").arg(m_nDownCounter)); + if (m_nDownCounter == 0) + m_nDownCounter = m_pTimerIntervalSpinBox->value(); +} + void DevicePropertyPage::InitializeTableView(MyTableModel *model, QTableView *tableView) { //设置tableview的model @@ -56,6 +67,8 @@ void DevicePropertyPage::InitializeTableView(MyTableModel *model, QTableView *ta pHeaderView->setHidden(false); //false 显示行号列 true Hide + pHeaderView->setStretchLastSection(true); //设置充满表宽度 + //pHeaderView->setVisible(true); //pHeaderView->setFixedHeight(40); @@ -103,6 +116,7 @@ void DevicePropertyPage::InitializeTableView(MyTableModel *model, QTableView *ta tableView->setColumnWidth(2,base); tableView->setColumnWidth(3,base-40); tableView->setColumnWidth(4,base+60); + tableView->setColumnWidth(5,base+60); #endif tableView->show(); @@ -114,13 +128,21 @@ void DevicePropertyPage::InitializeTable() m_myModel->setHeadData(AppData::getInstance()->lstDataTableHeaderText); m_pTableView = new QTableView(this); - m_pButton = new QPushButton(tr("Refresh"), this); + + //m_pButton = new QPushButton(tr("Refresh"), this); + // 设置固定大小和位置的按钮 + //m_pButton->setFixedSize(100, 30); // 设置按钮的固定大小 m_pFirstButton = new QPushButton(tr("First"), this); m_pForwardButton = new QPushButton(tr("Forward"), this); m_pNextButton = new QPushButton(tr("Next"), this); m_pLastButton = new QPushButton(tr("Last"), this); + m_pFirstButton->setFixedSize(80, 30); // 设置按钮的固定大小 + m_pForwardButton->setFixedSize(80, 30); // 设置按钮的固定大小 + m_pNextButton->setFixedSize(80, 30); // 设置按钮的固定大小 + m_pLastButton->setFixedSize(80, 30); // 设置按钮的固定大小 + m_pGotoPageNumberLineEdit = new QLineEdit(tr("1"), this); m_pGotoPageNumberLineEdit->setFixedWidth(40); m_pValidator = new QIntValidator(this); @@ -128,10 +150,26 @@ void DevicePropertyPage::InitializeTable() m_pValidator->setRange(0, 100); m_pGotoPageNumberLabel = new QLabel(tr("Page"), this); - m_pGotoPageNumberButton = new QPushButton(tr("Goto"), this); + m_pGotoPageNumberButton = new QPushButton(tr("Go"), this); + m_pGotoPageNumberButton->setFixedSize(40, 30); m_pPagesLabel = new QLabel(tr("Total %d Pages, Current No.%d Page"), this); + // 设置字体为粗体 + QFont font = m_pPagesLabel->font(); + font.setBold(true); // 设置为粗体 + m_pPagesLabel->setFont(font); + + // 创建一个QSpinBox,范围为10到100 + m_pTimerIntervalSpinBox = new QSpinBox(this); + m_pTimerIntervalSpinBox->setRange(15, 300); // 设置范围为10到100 + m_pTimerIntervalSpinBox->setValue(15); // 默认值设为10 + + m_pRefreshCheckBox = new QCheckBox(tr("Auto Refresh"), this); + m_pDownCounterLabel = new QLabel(tr("0"), this); + + m_pDownCounterLabel->setFont(font); + // 创建主布局 QVBoxLayout *mainLayout = new QVBoxLayout(this); @@ -139,9 +177,25 @@ void DevicePropertyPage::InitializeTable() mainLayout->addWidget(m_pTableView); + // 创建一个水平布局来包含按钮 + QHBoxLayout *buttonLayout0 = new QHBoxLayout(); + //buttonLayout0->addStretch(); // 让按钮保持在右侧 + buttonLayout0->setContentsMargins(0, 0, 0, 0); // 取消按钮的边距 + + // 添加标签、QSpinBox到布局 + buttonLayout0->addWidget(new QLabel(tr("Interval(Sec.)"), this)); + buttonLayout0->addWidget(m_pTimerIntervalSpinBox); + buttonLayout0->addWidget(m_pRefreshCheckBox); + buttonLayout0->addWidget(m_pDownCounterLabel); + m_pDownCounterLabel->setVisible(false); + + + QSpacerItem *spacer2 = new QSpacerItem(10, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); + buttonLayout0->addItem(spacer2); + // 创建一个水平布局来包含按钮 QHBoxLayout *buttonLayout = new QHBoxLayout(); - buttonLayout->addStretch(); // 让按钮保持在右侧 + //buttonLayout->addStretch(); // 让按钮保持在右侧 buttonLayout->addWidget(m_pPagesLabel); QSpacerItem *spacer0 = new QSpacerItem(10, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); @@ -160,23 +214,24 @@ void DevicePropertyPage::InitializeTable() buttonLayout->addWidget(m_pGotoPageNumberLineEdit); buttonLayout->addWidget(m_pGotoPageNumberButton); - buttonLayout->addWidget(m_pButton); + //buttonLayout->addWidget(m_pButton); buttonLayout->setContentsMargins(0, 0, 0, 0); // 取消按钮的边距 // 将表格视图和按钮布局添加到主布局 + mainLayout->addLayout(buttonLayout0); mainLayout->addLayout(buttonLayout); mainLayout->setContentsMargins(0, 0, 0, 0); // 取消主布局的边距 mainLayout->setSpacing(10); // 取消布局间的间距 - // 设置固定大小和位置的按钮 - m_pButton->setFixedSize(100, 30); // 设置按钮的固定大小 // 连接信号和槽 connect(m_pTableView, &QTableView::doubleClicked, this, &DevicePropertyPage::onTableViewDoubleClicked); connect(m_pButton, &QPushButton::clicked, this, &DevicePropertyPage::onButtonClicked); + connect(m_pRefreshCheckBox, &QCheckBox::stateChanged, this, &DevicePropertyPage::CheckRefresh); + connect(m_pFirstButton, &QPushButton::clicked, this, &DevicePropertyPage::onFirstButtonClicked); connect(m_pLastButton, &QPushButton::clicked, this, &DevicePropertyPage::onLastButtonClicked); connect(m_pForwardButton, &QPushButton::clicked, this, &DevicePropertyPage::onForwardButtonClicked); @@ -186,6 +241,46 @@ void DevicePropertyPage::InitializeTable() setLayout(mainLayout); } +void DevicePropertyPage::CheckRefresh(int state) +{ + if (state == Qt::Checked) + { + qDebug() << "Checkbox is checked"; + + Refresh(); + + pageTo(1); + + int nInterver = m_pTimerIntervalSpinBox->value() * 1000; + m_pTimer->start(nInterver); + + m_nDownCounter = m_pTimerIntervalSpinBox->value(); + m_pDownCounterLabel->setText(QString("%1").arg(m_nDownCounter)); + + m_pDownCounterTimer->start(1000); + m_pDownCounterLabel->setVisible(true); + + } + else if (state == Qt::Unchecked) + { + qDebug() << "Checkbox is unchecked"; + if (m_pTimer->isActive()) + { + m_pTimer->stop(); + } + if (m_pDownCounterTimer->isActive()) + { + m_pDownCounterTimer->stop(); + }; + + m_pDownCounterLabel->setVisible(false); + m_pDownCounterLabel->setText("0"); + } + else + { + qDebug() << "Checkbox is in an indeterminate state"; + } +} void DevicePropertyPage::setBaseType(unsigned int base, unsigned int mask) { filterBaseType = base; @@ -213,6 +308,30 @@ void DevicePropertyPage::Refresh() QGuiApplication::restoreOverrideCursor(); } +void DevicePropertyPage::keyPressEvent(QKeyEvent *event) +{ + // 检查是否按下特定按键 + switch(event->key()) + { + case Qt::Key_PageDown: + { + if (m_currentPage < m_totalPageCount) + onNextButtonClicked(); + break; + } + + case Qt::Key_PageUp: + { + if (m_currentPage > 1) + onForwardButtonClicked(); + break; + } + } + + // 处理其他按键,调用基类的 keyPressEvent + QWidget::keyPressEvent(event); +} + int DevicePropertyPage::PageDataProcess() { //获取数据总数 diff --git a/applications/emsConfigurer/devicepropertypage.h b/applications/emsConfigurer/devicepropertypage.h index 67a0301..741c9fc 100644 --- a/applications/emsConfigurer/devicepropertypage.h +++ b/applications/emsConfigurer/devicepropertypage.h @@ -7,6 +7,9 @@ #include #include #include +#include +#include +#include #include "datafetcher.h" @@ -27,9 +30,12 @@ public: public slots: void handleTimeout(); //超时处理函数 + void handleDownCounter(); //倒计时 private: QTimer *m_pTimer; + QTimer *m_pDownCounterTimer; + int m_nDownCounter; private: MyTableModel* m_myModel; @@ -53,6 +59,9 @@ protected: //翻倒第i页 void pageTo(int page); +protected: + void keyPressEvent(QKeyEvent *event) override; + private slots: void onButtonClicked(); @@ -63,6 +72,7 @@ private slots: void onForwardButtonClicked(); void onNextButtonClicked(); void onGotoButtonClicked(); + void CheckRefresh(int state); private: unsigned int filterBaseType; @@ -80,6 +90,9 @@ private: QLineEdit* m_pGotoPageNumberLineEdit; QPushButton* m_pGotoPageNumberButton; + QCheckBox *m_pRefreshCheckBox; + QSpinBox* m_pTimerIntervalSpinBox; + QLabel* m_pDownCounterLabel; QLabel* m_pPagesLabel; QVector columnWidths; // 存储初始列宽 diff --git a/applications/emsConfigurer/emsConfigurer.pro b/applications/emsConfigurer/emsConfigurer.pro index 31ce512..eb92c85 100644 --- a/applications/emsConfigurer/emsConfigurer.pro +++ b/applications/emsConfigurer/emsConfigurer.pro @@ -74,10 +74,12 @@ win32:LIBS += Ws2_32.lib #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ + aboutdialog.cpp \ datafetcher.cpp \ devicepropertypage.cpp \ formserialportsettingdialog.cpp \ globalparameters.cpp \ + ipaddress.cpp \ kutilities.cpp \ main.cpp \ maindialog.cpp \ @@ -87,10 +89,12 @@ SOURCES += \ ziputils.cpp HEADERS += \ + aboutdialog.h \ datafetcher.h \ devicepropertypage.h \ formserialportsettingdialog.h \ globalparameters.h \ + ipaddress.h \ kutilities.h \ maindialog.h \ mainwindow.h \ @@ -103,6 +107,7 @@ HEADERS += \ frame_define.h FORMS += \ + aboutdialog.ui \ formserialportsettingdialog.ui \ maindialog.ui \ mainwindow.ui diff --git a/applications/emsConfigurer/emscfger.conf b/applications/emsConfigurer/emscfger.conf new file mode 100644 index 0000000..5f0a9fe --- /dev/null +++ b/applications/emsConfigurer/emscfger.conf @@ -0,0 +1,3 @@ +[serialport] +number=10 +prefix=/dev/ttymxc diff --git a/applications/emsConfigurer/formserialportsettingdialog.cpp b/applications/emsConfigurer/formserialportsettingdialog.cpp index f63a16c..12aea25 100644 --- a/applications/emsConfigurer/formserialportsettingdialog.cpp +++ b/applications/emsConfigurer/formserialportsettingdialog.cpp @@ -3,6 +3,8 @@ #include #include +#include +#include #include "globalparameters.h" @@ -152,4 +154,48 @@ void FormSerialPortSettingDialog::InitializeUi() } ui->cb_type->setModel(model_type); + + ui->toolButton->setFixedSize(40, 30); + + ui->buttonBox->clear(); + QPushButton *okButton = ui->buttonBox->addButton(QDialogButtonBox::Ok); + QPushButton *cancelButton = ui->buttonBox->addButton(QDialogButtonBox::Cancel); + okButton->setFixedSize(100, 30); + cancelButton->setFixedSize(100, 30); + + //设置串口号 + ui->cb_serialport->setView(new QListView(this)); + + QStandardItemModel* model_serialport = new QStandardItemModel(this); + + for (int i=0; i < AppData::getInstance()->SerialPortCount ; i++) + { + QString name = AppData::getInstance()->SerialPortPrefix + QString("%1").arg(i); + + QStandardItem* item = new QStandardItem(name); + //QVariant var = QVariant::fromValue(data); + item->setData(name); + model_serialport->appendRow(item); + } + + ui->cb_serialport->setModel(model_serialport); + + connect(okButton, &QPushButton::clicked, this, &FormSerialPortSettingDialog::onOkClicked); + connect(cancelButton, &QPushButton::clicked, this, &FormSerialPortSettingDialog::onCancelClicked); + connect(ui->toolButton, &QPushButton::clicked, this, &FormSerialPortSettingDialog::onToolButtonClicked); +} + +void FormSerialPortSettingDialog::onOkClicked() +{ + QMessageBox::information(this, "onOkClicked", "Refresh"); +} + +void FormSerialPortSettingDialog::onCancelClicked() +{ + QMessageBox::information(this, "onCancelClicked", "Refresh"); +} + +void FormSerialPortSettingDialog::onToolButtonClicked() +{ + QMessageBox::information(this, "onToolButtonClicked", "Refresh"); } diff --git a/applications/emsConfigurer/formserialportsettingdialog.h b/applications/emsConfigurer/formserialportsettingdialog.h index ceec42d..5011d2c 100644 --- a/applications/emsConfigurer/formserialportsettingdialog.h +++ b/applications/emsConfigurer/formserialportsettingdialog.h @@ -21,6 +21,11 @@ private: protected: void InitializeUi(); + +private slots: + void onOkClicked(); + void onCancelClicked(); + void onToolButtonClicked(); }; #endif // FORMSERIALPORTSETTINGDIALOG_H diff --git a/applications/emsConfigurer/formserialportsettingdialog.ui b/applications/emsConfigurer/formserialportsettingdialog.ui index fba4237..da76240 100644 --- a/applications/emsConfigurer/formserialportsettingdialog.ui +++ b/applications/emsConfigurer/formserialportsettingdialog.ui @@ -2,14 +2,29 @@ FormSerialPortSettingDialog + + Qt::WindowModal + 0 0 - 706 + 726 526 + + + 726 + 526 + + + + + 726 + 526 + + 设备串口设置 @@ -29,9 +44,6 @@ Qt::Horizontal - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - @@ -149,19 +161,6 @@ 串口号 - - port - - - - - - 130 - 160 - 181 - 30 - - @@ -488,6 +487,16 @@ + + + + 130 + 160 + 181 + 25 + + + device_id @@ -495,7 +504,7 @@ device_manufature cb_type slave_id - port + cb_serialport cb_baund cb_data cb_parity @@ -506,8 +515,8 @@ checkBox_DTS checkBox_CTS checkBox_DTR - toolButton so_file + toolButton diff --git a/applications/emsConfigurer/globalparameters.cpp b/applications/emsConfigurer/globalparameters.cpp index 140af8a..abf4659 100644 --- a/applications/emsConfigurer/globalparameters.cpp +++ b/applications/emsConfigurer/globalparameters.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -13,6 +14,8 @@ #include "mytablemodel.h" #include "kutilities.h" +#define INI_SETTING_FILE "emscfger.conf" + AppData::~AppData() { } @@ -23,7 +26,8 @@ AppData::AppData(token) << ("Parameter") << ("Value") << ("Unit") - << ("Time"); + << ("Time") + << (""); nTimeOut = 5000; qsDestinationIp = "127.0.0.1"; @@ -32,6 +36,14 @@ AppData::AppData(token) } +bool AppData::readConfiguration(QString iniFile) +{ + QSettings settings(iniFile, QSettings::IniFormat); + SerialPortCount = settings.value("serialport/number", "10").toInt(); + SerialPortPrefix = settings.value("serialport/prefix", "/dev/ttymxc").toString(); + return false; +} + AppCommon::AppCommon(token) { } diff --git a/applications/emsConfigurer/globalparameters.h b/applications/emsConfigurer/globalparameters.h index 1bb3e4d..e5cf64d 100644 --- a/applications/emsConfigurer/globalparameters.h +++ b/applications/emsConfigurer/globalparameters.h @@ -105,6 +105,7 @@ public: AppData(const AppData &other) = delete; AppData& operator=(const AppData &other) = delete; + bool readConfiguration(QString iniFile); public: //数据表格的表头 QStringList lstDataTableHeaderText; @@ -117,6 +118,11 @@ public: //最后的错误信息 QString qsLastErrorString; + + //串口数量 + int SerialPortCount; + //串口字符串前缀 + QString SerialPortPrefix; }; diff --git a/applications/emsConfigurer/ipaddress.cpp b/applications/emsConfigurer/ipaddress.cpp new file mode 100644 index 0000000..7b52474 --- /dev/null +++ b/applications/emsConfigurer/ipaddress.cpp @@ -0,0 +1,217 @@ +#pragma execution_character_set("utf-8") + +#include "ipaddress.h" +#include "qlabel.h" +#include "qlineedit.h" +#include "qboxlayout.h" +#include "qregexp.h" +#include "qvalidator.h" +#include "qevent.h" + +IPAddress::IPAddress(QWidget *parent) : QWidget(parent) +{ + this->initForm(); +} + +bool IPAddress::eventFilter(QObject *watched, QEvent *event) +{ + if (event->type() == QEvent::KeyPress) + { + QLineEdit *txt = (QLineEdit *)watched; + if (txt == txtIP1 || txt == txtIP2 || txt == txtIP3 || txt == txtIP4) + { + QKeyEvent *key = (QKeyEvent *)event; + + //如果当前按下了小数点则移动焦点到下一个输入框 + if (key->text() == ".") + { + this->focusNextChild(); + } + + //如果按下了退格键并且当前文本框已经没有了内容则焦点往前移 + if (key->key() == Qt::Key_Backspace) + { + if (txt->text().length() <= 1) + { + this->focusNextPrevChild(false); + } + } + } + } + + return QWidget::eventFilter(watched, event); +} + +void IPAddress::initForm() +{ + bgColor = "#FFFFFF"; + borderColor = "#A6B5B8"; + borderRadius = 3; + + //用于显示小圆点的标签,居中对齐 + labDot1 = new QLabel; + labDot1->setAlignment(Qt::AlignCenter); + labDot1->setText("."); + + labDot2 = new QLabel; + labDot2->setAlignment(Qt::AlignCenter); + labDot2->setText("."); + + labDot3 = new QLabel; + labDot3->setAlignment(Qt::AlignCenter); + labDot3->setText("."); + + //用于输入IP地址的文本框,居中对齐 + txtIP1 = new QLineEdit; + txtIP1->setObjectName("txtIP1"); + txtIP1->setAlignment(Qt::AlignCenter); + txtIP1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + connect(txtIP1, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString))); + + txtIP2 = new QLineEdit; + txtIP2->setObjectName("txtIP2"); + txtIP2->setAlignment(Qt::AlignCenter); + txtIP2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + connect(txtIP2, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString))); + + txtIP3 = new QLineEdit; + txtIP3->setObjectName("txtIP3"); + txtIP3->setAlignment(Qt::AlignCenter); + txtIP3->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + connect(txtIP3, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString))); + + txtIP4 = new QLineEdit; + txtIP4->setObjectName("txtIP4"); + txtIP4->setAlignment(Qt::AlignCenter); + txtIP4->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + connect(txtIP4, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString))); + + //设置IP地址校验过滤 + QRegExp regExp("(2[0-5]{2}|2[0-4][0-9]|1?[0-9]{1,2})"); + txtIP1->setValidator(new QRegExpValidator(regExp, this)); + txtIP2->setValidator(new QRegExpValidator(regExp, this)); + txtIP3->setValidator(new QRegExpValidator(regExp, this)); + txtIP4->setValidator(new QRegExpValidator(regExp, this)); + + //绑定事件过滤器,识别键盘按下 + txtIP1->installEventFilter(this); + txtIP2->installEventFilter(this); + txtIP3->installEventFilter(this); + txtIP4->installEventFilter(this); + + QFrame *frame = new QFrame; + frame->setObjectName("frameIP"); + + QStringList qss; + qss.append(QString("QFrame#frameIP{border:1px solid %1;border-radius:%2px;}").arg(borderColor).arg(borderRadius)); + qss.append(QString("QLabel{min-width:15px;background-color:%1;}").arg(bgColor)); + qss.append(QString("QLineEdit{background-color:%1;border:none;}").arg(bgColor)); + qss.append(QString("QLineEdit#txtIP1{border-top-left-radius:%1px;border-bottom-left-radius:%1px;}").arg(borderRadius)); + qss.append(QString("QLineEdit#txtIP4{border-top-right-radius:%1px;border-bottom-right-radius:%1px;}").arg(borderRadius)); + frame->setStyleSheet(qss.join("")); + + QVBoxLayout *verticalLayout = new QVBoxLayout(this); + verticalLayout->setMargin(0); + verticalLayout->setSpacing(0); + verticalLayout->addWidget(frame); + + //将控件按照横向布局排列 + QHBoxLayout *layout = new QHBoxLayout(frame); + layout->setMargin(0); + layout->setSpacing(0); + layout->addWidget(txtIP1); + layout->addWidget(labDot1); + layout->addWidget(txtIP2); + layout->addWidget(labDot2); + layout->addWidget(txtIP3); + layout->addWidget(labDot3); + layout->addWidget(txtIP4); +} + +void IPAddress::textChanged(const QString &text) +{ + int len = text.length(); + int value = text.toInt(); + + //判断当前是否输入完成一个网段,是的话则自动移动到下一个输入框 + if (len == 3) + { + if (value >= 100 && value <= 255) + { + this->focusNextChild(); + } + } + + //拼接成完整IP地址 + ip = QString("%1.%2.%3.%4").arg(txtIP1->text()).arg(txtIP2->text()).arg(txtIP3->text()).arg(txtIP4->text()); +} + +QString IPAddress::getIP() const +{ + return this->ip; +} + +QSize IPAddress::sizeHint() const +{ + return QSize(250, 20); +} + +QSize IPAddress::minimumSizeHint() const +{ + return QSize(30, 10); +} + +void IPAddress::setIP(const QString &ip) +{ + //先检测IP地址是否合法 + QRegExp regExp("((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)"); + if (!regExp.exactMatch(ip)) + { + return; + } + + if (this->ip != ip) + { + this->ip = ip; + + //将IP地址填入各个网段 + QStringList list = ip.split("."); + txtIP1->setText(list.at(0)); + txtIP2->setText(list.at(1)); + txtIP3->setText(list.at(2)); + txtIP4->setText(list.at(3)); + } +} + +void IPAddress::clear() +{ + txtIP1->clear(); + txtIP2->clear(); + txtIP3->clear(); + txtIP4->clear(); + txtIP1->setFocus(); +} + +void IPAddress::setBgColor(const QString &bgColor) +{ + if (this->bgColor != bgColor) + { + this->bgColor = bgColor; + } +} + +void IPAddress::setBorderColor(const QString &borderColor) +{ + if (this->borderColor != borderColor) + { + this->borderColor = borderColor; + } +} + +void IPAddress::setBorderRadius(int borderRadius) +{ + if (this->borderRadius != borderRadius) + { + this->borderRadius = borderRadius; + } +} diff --git a/applications/emsConfigurer/ipaddress.h b/applications/emsConfigurer/ipaddress.h new file mode 100644 index 0000000..adea4e4 --- /dev/null +++ b/applications/emsConfigurer/ipaddress.h @@ -0,0 +1,72 @@ +#ifndef IPADDRESS_H +#define IPADDRESS_H + +/** + * IP地址输入框控件 作者:feiyangqingyun(QQ:517216493) 2017-8-11 + * 1:可设置IP地址,自动填入框 + * 2:可清空IP地址 + * 3:支持按下小圆点自动切换 + * 4:支持退格键自动切换 + * 5:支持IP地址过滤 + * 6:可设置背景色/边框颜色/边框圆角角度 + */ + +#include +#include + +class QLabel; +class QLineEdit; + +class IPAddress : public QWidget +{ + Q_OBJECT + Q_PROPERTY(QString ip READ getIP WRITE setIP) + +public: + explicit IPAddress(QWidget *parent = 0); + +protected: + bool eventFilter(QObject *watched, QEvent *event); + +private: + QLabel *labDot1; //第一个小圆点 + QLabel *labDot2; //第二个小圆点 + QLabel *labDot3; //第三个小圆点 + + QLineEdit *txtIP1; //IP地址网段输入框1 + QLineEdit *txtIP2; //IP地址网段输入框2 + QLineEdit *txtIP3; //IP地址网段输入框3 + QLineEdit *txtIP4; //IP地址网段输入框4 + + QString ip; //IP地址 + QString bgColor; //背景颜色 + QString borderColor;//边框颜色 + int borderRadius; //边框圆角角度 + +private slots: + void initForm(); + void textChanged(const QString &text); + +public: + //获取IP地址 + QString getIP() const; + + QSize sizeHint() const; + QSize minimumSizeHint() const; + +public Q_SLOTS: + //设置IP地址 + void setIP(const QString &ip); + //清空 + void clear(); + + //设置背景颜色 + void setBgColor(const QString &bgColor); + //设置边框颜色 + void setBorderColor(const QString &borderColor); + //设置边框圆角角度 + void setBorderRadius(int borderRadius); + +}; + +#endif // IPADDRESS_H diff --git a/applications/emsConfigurer/main.cpp b/applications/emsConfigurer/main.cpp index 7ee9029..32e4cc1 100644 --- a/applications/emsConfigurer/main.cpp +++ b/applications/emsConfigurer/main.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -20,6 +21,7 @@ #include #include +#include "globalparameters.h" int main(int argc, char *argv[]) { @@ -85,6 +87,10 @@ int main(int argc, char *argv[]) } } + //读取配置 + QString iniFilePath = QDir(appDir).filePath("emscfger.conf"); + AppData::getInstance()->readConfiguration(iniFilePath); + MainWindow w; //隐藏(不显示)最大化最小化按钮 w.setWindowFlags(w.windowFlags()&~Qt::WindowMinMaxButtonsHint); diff --git a/applications/emsConfigurer/maindialog.cpp b/applications/emsConfigurer/maindialog.cpp index 31b1a85..085a5bf 100644 --- a/applications/emsConfigurer/maindialog.cpp +++ b/applications/emsConfigurer/maindialog.cpp @@ -19,6 +19,7 @@ #include "kutilities.h" #include "devicepropertypage.h" #include "formserialportsettingdialog.h" +#include "aboutdialog.h" MainDialog::MainDialog(QWidget *parent) : QMainWindow (parent), @@ -27,6 +28,7 @@ MainDialog::MainDialog(QWidget *parent) : //ui->setupUi(this); this->setWindowIcon(QIcon(":/images/icon.png")); + this->setWindowTitle(tr("EMU Configurer Kit")); InitializeUI(); @@ -102,9 +104,6 @@ void MainDialog::InitializeUI() // Set central widget setCentralWidget(centralWidget); - // Set initial size of the dialog - setWindowTitle(tr("EMS Configurer ")); - //resize(800, 600); setMinimumSize(1024, 768); @@ -222,9 +221,11 @@ void MainDialog::loadWindowState() //增加设备 void MainDialog::onToolButton1Clicked() { - FormSerialPortSettingDialog dlg; - dlg.setModal(true); - if(dlg.exec() == QDialog::Accepted) + FormSerialPortSettingDialog* dlg = new FormSerialPortSettingDialog(this); + dlg->setWindowFlags(dlg->windowFlags()&~(Qt::WindowMinMaxButtonsHint|Qt::WindowContextHelpButtonHint)); + //dlg.setModal(true); + dlg->show(); + if(dlg->exec() == QDialog::Accepted) QMessageBox::information(this, "OK Clicked", "Button 1 was clicked!"); else QMessageBox::information(this, "Cancel Clicked", "Cancel was clicked!"); @@ -239,7 +240,12 @@ void MainDialog::onToolButton2Clicked() //关于 void MainDialog::onAboutButtonClicked() { - QMessageBox::information(this, "Button Clicked", "About"); + AboutDialog *aboutDlg = new AboutDialog(this); + aboutDlg->setWindowFlags(aboutDlg->windowFlags()&~(Qt::WindowMinMaxButtonsHint|Qt::WindowContextHelpButtonHint)); + //aboutDlg->setWindowFlags(aboutDlg->windowFlags() | Qt::WindowStaysOnTopHint); + + aboutDlg->setStyleSheet("border-radius: 4px;"); // 定制圆角 + aboutDlg->show(); } //刷新 diff --git a/applications/emsConfigurer/maindialog.ui b/applications/emsConfigurer/maindialog.ui index 314ebaf..bcbf593 100644 --- a/applications/emsConfigurer/maindialog.ui +++ b/applications/emsConfigurer/maindialog.ui @@ -17,7 +17,7 @@ Qt::NoContextMenu - Dialog + diff --git a/applications/emsConfigurer/mainwindow.cpp b/applications/emsConfigurer/mainwindow.cpp index 71b835a..5dc286d 100644 --- a/applications/emsConfigurer/mainwindow.cpp +++ b/applications/emsConfigurer/mainwindow.cpp @@ -2,13 +2,12 @@ #include "ui_mainwindow.h" #include #include -#include -#include #include #include "MainDialog.h" #include "mysqlutils.h" #include "kutilities.h" +#include "ipaddress.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) @@ -16,7 +15,9 @@ MainWindow::MainWindow(QWidget *parent) , m_pMainDialog(nullptr) { ui->setupUi(this); + this->setWindowIcon(QIcon(":/images/icon.png")); + this->setWindowTitle(tr("EMU Configurer Kit")); QPixmap pixmap(":/images/hj-net.png"); pixmap = pixmap.scaled(250, 75, Qt::KeepAspectRatio, Qt::SmoothTransformation); // 按比例缩放 @@ -24,13 +25,20 @@ MainWindow::MainWindow(QWidget *parent) QString qsLineEditStyle("QLineEdit { min-height: 20px; min-width: 120px; }"); ui->userToken->setStyleSheet(qsLineEditStyle); - ui->serverIp->setStyleSheet(qsLineEditStyle); - QRegularExpression rx("^((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)$"); - QRegularExpressionValidator* ipValidator = new QRegularExpressionValidator(rx, this); - ui->serverIp->setValidator(ipValidator); - setIp("127.0.0.1"); - //setIp("192.168.0.155"); + ui->serverIP->setIP("127.0.0.1"); + + ui->pb_Logon->setFixedSize(100, 30); + ui->pb_Close->setFixedSize(100, 30); + ui->pb_Test->setFixedSize(45, 25); + + QFont font("Arial", 24, QFont::Bold); + ui->productName1->setText(tr("Configurer Kit")); + ui->productName1->setFont(font); + + QFont font2("Arial", 12, QFont::Bold); + ui->productName2->setText(tr("for EMU Host")); + ui->productName2->setFont(font2); } MainWindow::~MainWindow() @@ -45,13 +53,13 @@ MainWindow::~MainWindow() void MainWindow::setIp(const QString &ip) { - ui->serverIp->setText(ip); + ui->serverIP->setIP(ip); } bool MainWindow::testDatabase() { CWaitorCursor wait; - QString svr = ui->serverIp->text(); + QString svr = ui->serverIP->getIP(); std::string dbserver = svr.toStdString(); //"tcp://192.168.4.254"; int dbport = 3306; std::string dbuser = "root"; @@ -78,7 +86,7 @@ bool MainWindow::testServerEcho() { using namespace hv; - QString svr = ui->serverIp->text(); + QString svr = ui->serverIP->getIP(); int connfd = AppTcpClient::getInstance()->Initialize(svr,DEVICE_SERVER_PORT); if (connfd <= 0) diff --git a/applications/emsConfigurer/mainwindow.ui b/applications/emsConfigurer/mainwindow.ui index 2c8b207..b59f656 100644 --- a/applications/emsConfigurer/mainwindow.ui +++ b/applications/emsConfigurer/mainwindow.ui @@ -10,7 +10,7 @@ 0 0 615 - 362 + 375 @@ -27,7 +27,7 @@ 120 - 183 + 173 101 21 @@ -36,11 +36,11 @@ Host IP - + 100 - 50 + 70 391 61 @@ -58,20 +58,7 @@ Qt::AlignCenter - - - - 250 - 180 - 121 - 23 - - - - - - - + 400 @@ -96,10 +83,10 @@ - 380 - 180 + 440 + 170 51 - 21 + 30 @@ -123,7 +110,7 @@ 170 - 287 + 300 251 31 @@ -162,9 +149,9 @@ 250 - 240 - 181 - 23 + 250 + 180 + 30 @@ -197,7 +184,7 @@ 120 - 240 + 250 101 21 @@ -211,13 +198,38 @@ 250 210 + 180 + 30 + + + + + + + 250 + 170 181 - 23 + 30 + + + IPAddress + QWidget +
ipaddress.h
+ 1 +
+
+ + pb_Test + userName + userToken + pb_Logon + pb_Close +