This commit is contained in:
Gangphon 2023-09-05 10:02:20 +08:00
parent 4dfe9a37b9
commit d5d5984aa5
21 changed files with 1811 additions and 1227 deletions

View File

@ -1,324 +0,0 @@
#include "capthread.h"
#include <QDateTime>
#include <QDebug>
CapThread::CapThread(struct pcap *pcap, QObject *parent) : QThread(parent), pcap(pcap) {
connect(this, &QThread::finished, this, &QThread::deleteLater);
}
void CapThread::run() {
pcap_pkthdr *header;
const u_char *pkt_data;
// qDebug("The program is working......\n");
// qDebug("The capture file is saving as 'data.txt'\n");
// qDebug("You can input 'ctrl + C' to stop the program\n");
int res;
while((res = pcap_next_ex(pcap, &header, &pkt_data)) >= 0) {
if (res == 0) continue; //超时
packet.time = QDateTime::fromSecsSinceEpoch(header->ts.tv_sec).toString("yy-MM-dd HH:mm:ss.")+QString::number(header->ts.tv_usec);
packet.len = header->len;
//输出编号、时间戳和包长度
qDebug("=======================\n");
qDebug()<<packet.time<<" len:"<<header->caplen<<"/"<<header->len;
QString data_str;
char line[LINE_LEN + 1];
int l = 0;
for(uint i=0; i < header->caplen; i++) {
data_str.append(QString::asprintf("%.2x ", pkt_data[i]));
if(i > 13) {
if(isgraph(pkt_data[i]) || pkt_data[i] == ' ') line[l] = pkt_data[i];
else line[l] = '.';
if(l==15) {
line[16] = '\0';
data_str.append(" ");
data_str.append(line);
data_str.append("\n");
memset(line, 0, LINE_LEN);
l = 0;
} else l++;
} else if(i == 13) {
data_str.append("\n");
}
}
packet.data = data_str;
qDebug()<<packet.data.toUtf8().constData();
//分析数据包
//ethernet_protocol_packet_handle(NULL, header, pkt_data);
//packet_list->append(packet);
//emit newPacket();
}
qDebug("Error reading the packets: %s\n", pcap_geterr(pcap));
}
// TCP协议处理
//u_short sport;
//u_short dport;
//u_int sequence; // 序列码
//u_int ack; // 回复码
//u_char hdrLen; // 首部长度保留字
//u_char flags; // 标志
//u_short windows; // 窗口大小
//u_short checksum; // 校验和
//u_short urgent_pointer; // 紧急指针
void CapThread::tcp_protocol_packet_handle(u_char *arg, const struct pcap_pkthdr *pkt_header, const u_char *pkt_content) {
packet.tcp_header = *(TcpHeader*) (pkt_content + 14 + 20);
// qDebug("===================TCP Protocol=================\n");
// qDebug("Source Port: %i\n", ntohs(tcp_protocol->sport));
// qDebug("Destination Port: %i\n", ntohs(tcp_protocol->dport));
// qDebug("Sequence number: %d\n", ntohl(tcp_protocol->sequence));
// qDebug("Acknowledgment number: %d\n", ntohl(tcp_protocol->ack));
// qDebug("Header Length: %d\n", (tcp_protocol->hdrLen >> 4) * 4);
// qDebug("Flags: 0x%.3x ", tcp_protocol->flags);
// if (tcp_protocol->flags & 0x08) qDebug("(PSH)");
// if (tcp_protocol->flags & 0x10) qDebug("(ACK)");
// if (tcp_protocol->flags & 0x02) qDebug("(SYN)");
// if (tcp_protocol->flags & 0x20) qDebug("(URG)");
// if (tcp_protocol->flags & 0x01) qDebug("(FIN)");
// if (tcp_protocol->flags & 0x04) qDebug("(RST)");
// qDebug("\n");
// qDebug("Windows Size: %i\n", ntohs(tcp_protocol->windows));
// qDebug("Checksum: 0x%.4x\n", ntohs(tcp_protocol->checksum));
// qDebug("Urgent Pointer: %i\n", ntohs(tcp_protocol->urgent_pointer));
}
// UDP协议处理
//u_short sport; // 源端口
//u_short dport; // 目标端口
//u_short datalen; // UDP数据长度
//u_short checksum; // 校验和
void CapThread::udp_protocol_packet_handle(u_char *arg, const struct pcap_pkthdr *pkt_header, const u_char *pkt_content) {
packet.udp_header = *(UdpHeader*)(pkt_content + 14 + 20);
// qDebug("===================UDP Protocol=================\n");
// qDebug("Source Port: %i\n", ntohs(udp_protocol->sport));
// qDebug("Destination Port: %i\n", ntohs(udp_protocol->dport));
// qDebug("Datalen: %i\n", ntohs(udp_protocol->datalen));
// qDebug("Checksum: 0x%.4x\n", ntohs(udp_protocol->checksum));
}
// ICMP协议处理
//u_char type; // ICMP类型
//u_char code; // 代码
//u_short checksum; // 校验和
//u_short identification; // 标识
//u_short sequence; // 序列号
//u_long timestamp; // 时间戳
void CapThread::icmp_protocol_packet_handle(u_char *arg, const struct pcap_pkthdr *pkt_header, const u_char *pkt_content) {
packet.icmp_header = *(IcmpHeader*)(pkt_content + 14 + 20);
// qDebug("==================ICMP Protocol=================\n");
// qDebug("Type: %d ", icmp_protocol->type);
// switch (icmp_protocol->type)
// {
// case 8:
// qDebug("(request)\n");
// break;
// case 0:
// qDebug("(reply)\n");
// break;
// default:
// qDebug("\n");
// break;
// }
// qDebug("Code: %d\n", icmp_protocol->code);
// qDebug("CheckSum: 0x%.4x\n", ntohs(icmp_protocol->checksum));
// qDebug("Identification: 0x%.4x\n", ntohs(icmp_protocol->identification));
// qDebug("Sequence: 0x%.4x\n", ntohs(icmp_protocol->sequence));
}
// ARP协议处理
//u_short hardware_type; // 格式化的硬件地址
//u_short protocol_type; // 协议地址格式
//u_char hardware_length; // 硬件地址长度
//u_char protocol_length; // 协议地址长度
//u_short operation_code; // 操作码
//u_char source_ethernet_address[6]; // 发送者硬件地址
//u_char source_ip_address[4]; // 发送者协议地址
//u_char destination_ethernet_address[6]; // 目的方硬件地址
//u_char destination_ip_address[4]; // 目的方协议地址
void CapThread::arp_protocol_packet_handle(u_char *arg, const struct pcap_pkthdr *pkt_header, const u_char *pkt_content) {
packet.arp_header = *(ArpHeader*)(pkt_content + 14);
// qDebug("==================ARP Protocol==================\n");
// qDebug("Hardware Type: ");
// switch (ntohs(arp_protocol->hardware_type))
// {
// case 1:
// qDebug("Ethernet");
// break;
// default:
// break;
// }
// qDebug(" (%d)\n", ntohs(arp_protocol->hardware_type));
// qDebug("Protocol Type: \n");
// switch (ntohs(arp_protocol->protocol_type))
// {
// case 0x0800:
// qDebug("%s", "IP");
// break;
// case 0x0806:
// qDebug("%s", "ARP");
// break;
// case 0x0835:
// qDebug("%s", "RARP");
// break;
// default:
// qDebug("%s", "Unknown Protocol");
// break;
// }
// qDebug(" (0x%04x)\n", ntohs(arp_protocol->protocol_type));
// qDebug("Hardware Length: %d\n", arp_protocol->hardware_length);
// qDebug("Protocol Length: %d\n", arp_protocol->protocol_length);
// qDebug("Operation Code: ");
// switch (ntohs(arp_protocol->operation_code))
// {
// case 1:
// qDebug("request");
// break;
// case 2:
// qDebug("reply");
// break;
// default:
// break;
// }
// qDebug(" (%i)\n", ntohs(arp_protocol->operation_code));
}
// IP协议处理
//u_char version_hlen; // 首部长度 版本
//u_char tos; // 服务质量
//u_short tlen; // 总长度
//u_short identification; // 身份识别
//u_short flags_offset; // 标识 分组偏移
//u_char ttl; // 生命周期
//u_char proto; // 协议类型
//u_short checksum; // 包头测验码
//u_int saddr; // 源IP地址
//u_int daddr; // 目的IP地址
void CapThread::ip_protocol_packet_handle(u_char *arg, const struct pcap_pkthdr *pkt_header, const u_char *pkt_content) {
sockaddr_in source, dest;
char sourceIP[MAX_ADDR_LEN], destIP[MAX_ADDR_LEN];
auto ip_protocol = (IpHeader*)(pkt_content + 14);
source.sin_addr.s_addr = ip_protocol->saddr;
dest.sin_addr.s_addr = ip_protocol->daddr;
strncpy(sourceIP, inet_ntoa(source.sin_addr), MAX_ADDR_LEN);
strncpy(destIP, inet_ntoa(dest.sin_addr), MAX_ADDR_LEN);
packet.ip_header = *ip_protocol;
// qDebug("===================IP Protocol==================\n");
// qDebug("Version: %d\n", ip_protocol->version_hlen >> 4);
// qDebug("Header Length: %d bytes\n", (ip_protocol->version_hlen & 0x0f) * 4);
// qDebug("Tos: %d\n", ip_protocol->tos);
// qDebug("Total Length: %d\n", ntohs(ip_protocol->tlen));
// qDebug("Identification: 0x%.4x (%i)\n", ntohs(ip_protocol->identification), ntohs(ip_protocol->identification));
// qDebug("Flags: %d\n", ntohs(ip_protocol->flags_offset) >> 13);
// qDebug("---Reserved bit: %d\n", (ntohs(ip_protocol->flags_offset) & 0x8000) >> 15);
// qDebug("---Don't fragment: %d\n", (ntohs(ip_protocol->flags_offset) & 0x4000) >> 14);
// qDebug("---More fragment: %d\n", (ntohs(ip_protocol->flags_offset) & 0x2000) >> 13);
// qDebug("Fragment offset: %d\n", ntohs(ip_protocol->flags_offset) & 0x1fff);
// qDebug("Time to live: %d\n", ip_protocol->ttl);
// qDebug("Protocol Type: ");
switch (ip_protocol->proto)
{
case 1:
// qDebug("ICMP");
packet.protocol = "ICMP";
break;
case 6:
// qDebug("TCP");
packet.protocol = "TCP";
break;
case 17:
// qDebug("UDP");
packet.protocol = "UDP";
break;
default:
break;
}
// qDebug(" (%d)\n", ip_protocol->proto);
// qDebug("Header checkSum: 0x%.4x\n", ntohs(ip_protocol->checksum));
// qDebug("Source: %s\n", sourceIP);
// qDebug("Destination: %s\n", destIP);
if (ip_protocol->proto == htons(0x0600))
tcp_protocol_packet_handle(arg, pkt_header, pkt_content);
else if (ip_protocol->proto == htons(0x1100))
udp_protocol_packet_handle(arg, pkt_header, pkt_content);
else if (ip_protocol->proto == htons(0x0100))
icmp_protocol_packet_handle(arg, pkt_header, pkt_content);
}
// Ethernet协议处理
void CapThread::ethernet_protocol_packet_handle(u_char *arg, const struct pcap_pkthdr *pkt_header, const u_char *pkt_content) {
packet.ether_header = *(EtherHeader*)pkt_content;
u_short ethernet_type; //以太网类型
u_char *mac_string; //以太网地址
//获取以太网数据内容
ethernet_type = ntohs(packet.ether_header.ether_type);
// qDebug("==============Ethernet Protocol=================\n");
// //以太网目标地址
// mac_string = ethernet_protocol->ether_dhost;
// qDebug("Destination Mac Address: %02x:%02x:%02x:%02x:%02x:%02x\n",
// *mac_string,
// *(mac_string + 1),
// *(mac_string + 2),
// *(mac_string + 3),
// *(mac_string + 4),
// *(mac_string + 5));
// //以太网源地址
// mac_string = ethernet_protocol->ether_shost;
// qDebug("Source Mac Address: %02x:%02x:%02x:%02x:%02x:%02x\n",
// *mac_string,
// *(mac_string + 1),
// *(mac_string + 2),
// *(mac_string + 3),
// *(mac_string + 4),
// *(mac_string + 5));
// qDebug("Ethernet type: ");
switch (ethernet_type)
{
case 0x0800:
// qDebug("%s", "IP");
break;
case 0x0806:
// qDebug("%s", "ARP");
packet.protocol = "ARP";
break;
case 0x0835:
// qDebug("%s", "RARP");
// packet_data.setRarp_flag(true);
break;
default:
// qDebug("%s", "Unknown Protocol");
packet.protocol = "Unknown Protocol";
break;
}
// qDebug(" (0x%04x)\n", ethernet_type);
switch (ethernet_type)
{
case 0x0800:
ip_protocol_packet_handle(arg, pkt_header, pkt_content);
break;
case 0x0806:
arp_protocol_packet_handle(arg, pkt_header, pkt_content);
break;
// case 0x0835:
// qDebug("==============RARP Protocol=================\n");
// qDebug("RARP\n");
// break;
// default:
// qDebug("==============Unknown Protocol==============\n");
// qDebug("Unknown Protocol\n");
// break;
}
}

View File

@ -1,114 +0,0 @@
#ifndef CAPTHREAD_H
#define CAPTHREAD_H
#include <QThread>
#include <winsock2.h>
#include "pcap.h"
#include <QVector>
#pragma comment(lib, "wpcap.lib")
#pragma comment(lib, "Ws2_32.lib")
#define LINE_LEN 16
#define MAX_ADDR_LEN 16
struct EtherHeader {
u_char ether_dhost[6]; // 目标MAC地址
u_char ether_shost[6]; // 源MAC地址
u_short ether_type; // 以太网类型
};
struct IpAddress {
u_char byte1;
u_char byte2;
u_char byte3;
u_char byte4;
};
struct IpHeader {
u_char version_hlen; // 首部长度 版本
u_char tos; // 服务质量
u_short tlen; // 总长度
u_short identification; // 身份识别
u_short flags_offset; // 标识 分组偏移
u_char ttl; // 生命周期
u_char proto; // 协议类型
u_short checksum; // 包头测验码
u_int saddr; // 源IP地址
u_int daddr; // 目的IP地址
};
struct TcpHeader {
u_short sport;
u_short dport;
u_int sequence; // 序列码
u_int ack; // 回复码
u_char hdrLen; // 首部长度保留字
u_char flags; // 标志
u_short windows; // 窗口大小
u_short checksum; // 校验和
u_short urgent_pointer; // 紧急指针
};
struct UdpHeader {
u_short sport; // 源端口
u_short dport; // 目标端口
u_short datalen; // UDP数据长度
u_short checksum; // 校验和
};
struct IcmpHeader {
u_char type; // ICMP类型
u_char code; // 代码
u_short checksum; // 校验和
u_short identification; // 标识
u_short sequence; // 序列号
u_long timestamp; // 时间戳
};
struct ArpHeader {
u_short hardware_type; // 格式化的硬件地址
u_short protocol_type; // 协议地址格式
u_char hardware_length; // 硬件地址长度
u_char protocol_length; // 协议地址长度
u_short operation_code; // 操作码
u_char source_ethernet_address[6]; // 发送者硬件地址
u_char source_ip_address[4]; // 发送者协议地址
u_char destination_ethernet_address[6]; // 目的方硬件地址
u_char destination_ip_address[4]; // 目的方协议地址
};
struct Packet {
QString time;
QString data;
u_int len;
EtherHeader ether_header;
IpHeader ip_header;
TcpHeader tcp_header;
UdpHeader udp_header;
IcmpHeader icmp_header;
ArpHeader arp_header;
QString protocol;
};
class CapThread : public QThread {
Q_OBJECT
public:
explicit CapThread(pcap *pcap, QObject *parent = nullptr);
void setPacketList(QList<Packet> *p){p->clear();packet_list=p;}
pcap *pcap{0};
QList<Packet> *packet_list;
Packet packet;
private:
void tcp_protocol_packet_handle(u_char *arg, const struct pcap_pkthdr *pkt_header, const u_char *pkt_content);
void udp_protocol_packet_handle(u_char *arg, const struct pcap_pkthdr *pkt_header, const u_char *pkt_content);
void icmp_protocol_packet_handle(u_char *arg, const struct pcap_pkthdr *pkt_header, const u_char *pkt_content);
void arp_protocol_packet_handle(u_char *arg, const struct pcap_pkthdr *pkt_header, const u_char *pkt_content);
void ip_protocol_packet_handle(u_char *arg, const struct pcap_pkthdr *pkt_header, const u_char *pkt_content);
void ethernet_protocol_packet_handle(u_char *arg, const struct pcap_pkthdr *pkt_header, const u_char *pkt_content);
protected:
void run();
signals:
void newPacket();
public slots:
};
#endif // CAPTHREAD_H

View File

@ -557,6 +557,13 @@ void ModuleUnit::drawed() {
auto btn = box->boxWin->grpGrp->checkedButton(); auto btn = box->boxWin->grpGrp->checkedButton();
if(btn==0) return; if(btn==0) return;
auto mods = btn->property("mods").toList(); auto mods = btn->property("mods").toList();
if(! mods.isEmpty() && ((ExpertWin*)box->boxWin->parentWidget())->m_iRcvCardType==enum_zrf) {
auto last = (ModuleUnit*) mods.last().value<void*>();
if(last->mY!=mY || last->mX+last->mW!=mX) {
QMessageBox::warning(this, "注意", "模组要紧跟着前一个");
return;
}
}
mods.append(QVariant::fromValue((void*)this)); mods.append(QVariant::fromValue((void*)this));
btn->setProperty("mods", mods); btn->setProperty("mods", mods);
name = "G"+QString::number(box->boxWin->grpGrp->id(btn)+1)+"-"+QString::number(mods.size()); name = "G"+QString::number(box->boxWin->grpGrp->id(btn)+1)+"-"+QString::number(mods.size());

View File

@ -89,7 +89,7 @@ ExpertScreenConnWin::ExpertScreenConnWin(QWidget *parent) : QSplitter{parent} {
auto pal = palette(); auto pal = palette();
fdNet = new QButtonGroup(gBox); fdNet = new QButtonGroup(gBox);
for(int i=0; i<netss.size(); i++) { for(int i=0; i<sizeof(netss)/sizeof(netss[0]); i++) {
auto bn = new QPushButton(QString::number(i+1)); auto bn = new QPushButton(QString::number(i+1));
bn->setMaximumWidth(30); bn->setMaximumWidth(30);
bn->setMinimumHeight(30); bn->setMinimumHeight(30);
@ -156,7 +156,7 @@ ExpertScreenConnWin::ExpertScreenConnWin(QWidget *parent) : QSplitter{parent} {
auto bnRefresh = new QPushButton(tr("重新开始")); auto bnRefresh = new QPushButton(tr("重新开始"));
connect(bnRefresh, &QPushButton::clicked, this, [this] { connect(bnRefresh, &QPushButton::clicked, this, [this] {
table->clearContents(); table->clearContents();
for(int i=0; i<netss.size(); i++) if(! netss[i].isEmpty()) netss[i].clear(); for(int i=0; i<sizeof(netss)/sizeof(netss[0]); i++) if(! netss[i].empty()) netss[i].clear();
}); });
hBox->addWidget(bnRefresh); hBox->addWidget(bnRefresh);
@ -172,10 +172,8 @@ ExpertScreenConnWin::ExpertScreenConnWin(QWidget *parent) : QSplitter{parent} {
table = new CardTable(fdCardRowNum->value(), fdCardColNum->value()); table = new CardTable(fdCardRowNum->value(), fdCardColNum->value());
table->win = this; table->win = this;
table->setEditTriggers(QAbstractItemView::NoEditTriggers); table->setEditTriggers(QAbstractItemView::NoEditTriggers);
table->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter);
table->horizontalHeader()->setDefaultSectionSize(90); table->horizontalHeader()->setDefaultSectionSize(90);
table->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); table->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
table->verticalHeader()->setDefaultAlignment(Qt::AlignCenter);
table->verticalHeader()->setDefaultSectionSize(90); table->verticalHeader()->setDefaultSectionSize(90);
table->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed); table->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
table->verticalHeader()->setMinimumWidth(30); table->verticalHeader()->setMinimumWidth(30);
@ -195,7 +193,7 @@ void ExpertScreenConnWin::conn(int row, int column) {
auto item = table->item(row, column); auto item = table->item(row, column);
if(item) return; if(item) return;
auto netIdx = fdNet->checkedId(); auto netIdx = fdNet->checkedId();
netss[netIdx].append(QPoint(column, row)); netss[netIdx].emplace_back(QPoint(column, row));
item = new QTableWidgetItem("网口: "+QString::number(netIdx+1)+"\n"+tr("接收卡: ")+QString::number(netss[netIdx].size())+"\n"+tr("宽度: ")+QString::number(fdCardWidth->value())+"\n高度: "+QString::number(fdCardHeight->value())); item = new QTableWidgetItem("网口: "+QString::number(netIdx+1)+"\n"+tr("接收卡: ")+QString::number(netss[netIdx].size())+"\n"+tr("宽度: ")+QString::number(fdCardWidth->value())+"\n高度: "+QString::number(fdCardHeight->value()));
auto color = cardColors[netIdx % (sizeof(cardColors)/sizeof(cardColors[0]))]; auto color = cardColors[netIdx % (sizeof(cardColors)/sizeof(cardColors[0]))];
item->setForeground(QColor(255,255,255)); item->setForeground(QColor(255,255,255));
@ -207,9 +205,10 @@ void ExpertScreenConnWin::conn(int row, int column) {
} }
void ExpertScreenConnWin::connBack() { void ExpertScreenConnWin::connBack() {
auto netIdx = fdNet->checkedId(); auto netIdx = fdNet->checkedId();
if(netss[netIdx].isEmpty()) return; if(netss[netIdx].empty()) return;
table->selectionModel()->clearCurrentIndex(); table->selectionModel()->clearCurrentIndex();
auto point = netss[netIdx].takeLast(); auto point = netss[netIdx].back();
netss[netIdx].pop_back();
table->setItem(point.y(), point.x(), 0); table->setItem(point.y(), point.x(), 0);
table->update(); table->update();
} }
@ -217,7 +216,7 @@ void ExpertScreenConnWin::connBack() {
void CardTable::paintEvent(QPaintEvent *event) { void CardTable::paintEvent(QPaintEvent *event) {
QTableWidget::paintEvent(event); QTableWidget::paintEvent(event);
QPainter painter(viewport()); QPainter painter(viewport());
for(int i=0; i<win->netss.size(); i++) { for(int i=0; i<sizeof(win->netss)/sizeof(win->netss[0]); i++) {
auto size = win->netss[i].size(); auto size = win->netss[i].size();
if(size < 2) continue; if(size < 2) continue;
QColor a=cardColors[i % (sizeof(cardColors)/sizeof(cardColors[0]))]; QColor a=cardColors[i % (sizeof(cardColors)/sizeof(cardColors[0]))];

View File

@ -17,7 +17,7 @@ public:
QSpinBox *fdCardWidth; QSpinBox *fdCardWidth;
QSpinBox *fdCardHeight; QSpinBox *fdCardHeight;
CardTable *table; CardTable *table;
QList<QList<QPoint>> netss{QList<QPoint>{}, QList<QPoint>{}, QList<QPoint>{}, QList<QPoint>{}}; std::vector<QPoint> netss[4]{};
}; };
class CardTable : public QTableWidget { class CardTable : public QTableWidget {

View File

@ -1,17 +1,133 @@
#include "screenunit.h" #include "expertsendpanel.h"
#include "expertwin.h" #include "gutil/qgui.h"
#include <QDirIterator> #include <QLineEdit>
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <QJsonArray>
#include <QJsonObject>
#include <QLabel>
#include <QPainter>
#include <QSpinBox>
#include <QMouseEvent> #include <QMouseEvent>
#include <QPainter>
ScreenUnit::ScreenUnit(ExpertWin *expertWin, const QString &name, int x, int y, int w, int h, QWidget *parent) : QWidget{parent}, expertWin{expertWin}, name{name}, mX{x}, mY{y}, mW{w}, mH{h} { QColor colors[] {QColor(0xdd0000), QColor(0xdd6600), QColor(0x008800), QColor(0x008888), QColor(0x0000ff), QColor(0x777777), QColor(0xaaaaaa)};
ExpertSendPanel::ExpertSendPanel(QWidget *parent) : QWidget{parent} {
auto vBox = new VBox(this);
vBox->setContentsMargins(4, 4, 4, 4);
auto splitter = new QSplitter;
vBox->addWidget(splitter);
auto vLeft = new VBox(splitter);
auto hBox = new HBox(vLeft);
hBox->addWidget(new QLabel("分辨率: "));
auto fdW = new QLineEdit(QString::number(screenWidth));
hBox->addWidget(fdW);
hBox->addWidget(new QLabel("X"));
auto fdH = new QLineEdit(QString::number(screenHeight));
hBox->addWidget(fdH);
hBox = new HBox(vLeft);
hBox->addStretch();
auto btnGet = new QPushButton("刷新");
btnGet->setMinimumWidth(80);
hBox->addWidget(btnGet);
hBox->addSpacing(40);
auto btnSet = new QPushButton("设置");
btnSet->setMinimumWidth(80);
hBox->addWidget(btnSet);
hBox->addStretch();
auto table = new TreeWidget{
{"face", "网口", 32},
{"x", "X", 32},
{"y", "Y", 32},
{"w", "宽度", 32},
{"h", "高度", 32},
{"audio", "音频开关", QHeaderView::Stretch},
{"backup", "备份开关", QHeaderView::Stretch}
};
table->setDefs();
table->setStyleSheet("TreeWidget::item{height: 24px;}");
vLeft->addWidget(table);
auto canvas = new ResizeEmitedWgt;
auto screen = new QWidget(canvas);
screen->setGeometry(0, 0, screenWidth, screenHeight);
screen->setAutoFillBackground(true);
auto pal = palette();
pal.setColor(QPalette::Window, QColor(0, 0, 0));
screen->setPalette(pal);
connect(canvas, &ResizeEmitedWgt::resized, this, [this, canvas, screen] {
rate = qMin(canvas->width()/(double)screenWidth, canvas->height()/(double)screenHeight);
if(rate==0) return;
screen->resize(qRound(screenWidth*rate), qRound(screenHeight*rate));
auto children = screen->children();
foreach(auto childObj, children) {
auto unit = static_cast<ScreenUnit*>(childObj);
unit->setGeometry(qRound(unit->mX*rate), qRound(unit->mY*rate), qRound(unit->mW*rate), qRound(unit->mH*rate));
}
});
splitter->addWidget(canvas);
splitter->setStretchFactor(0,0);
splitter->setStretchFactor(1,1);
splitter->setSizes({280, 1});
hBox = new HBox(vBox);
auto btn = new QPushButton(tr("保存到文件"));
btn->setProperty("ss","blue");
connect(btn, &QPushButton::clicked, this, [=] {
});
hBox->addWidget(btn);
hBox->addStretch();
btn = new QPushButton(tr("发送发送卡参数"));
btn->setProperty("ss","blue");
connect(btn, &QPushButton::clicked, this, [=] {
});
hBox->addWidget(btn);
btn = new QPushButton(tr("固化发送卡参数"));
btn->setProperty("ss","blue");
connect(btn, &QPushButton::clicked, this, [=] {
});
hBox->addWidget(btn);
btnSendReadBack = new QPushButton(tr("回读发送卡参数"));
btnSendReadBack->setProperty("ss","blue");
connect(btnSendReadBack, &QPushButton::clicked, this, [=] {
});
hBox->addWidget(btnSendReadBack);
for(int rr=0; rr<4; rr++) {
auto item = new TreeWidgetItem(table);
QString name = "P"+QString::number(rr+1);
item->setText("face", name);
item->setText("x", QString::number(rr*128));
item->setText("y", "0");
item->setText("w", "128");
item->setText("h", "128");
item->setText("audio", "0");
item->setText("backup", "0");
auto unit = new ScreenUnit(this, name, rr*128, 0, 128, 128, screen);
unit->setAutoFillBackground(true);
pal.setColor(QPalette::Window, colors[rr]);
unit->setPalette(pal);
}
}
ScreenUnit::ScreenUnit(ExpertSendPanel *expertWin, const QString &name, int x, int y, int w, int h, QWidget *parent) : QWidget{parent}, expertWin{expertWin}, name{name}, mX{x}, mY{y}, mW{w}, mH{h} {
setGeometry(x, y, w, h); setGeometry(x, y, w, h);
setMouseTracking(true); setMouseTracking(true);
auto font = this->font(); auto font = this->font();
@ -77,7 +193,7 @@ void ScreenUnit::mousePressEvent(QMouseEvent *e) {
foreach(auto item, items) { foreach(auto item, items) {
if(item==this) continue; if(item==this) continue;
auto ele = static_cast<ScreenUnit*>(item); auto ele = static_cast<ScreenUnit*>(item);
mOtherEles.append(ele); mOtherEles.emplace_back(ele);
} }
} }
} }
@ -109,7 +225,7 @@ void ScreenUnit::mouseMoveEvent(QMouseEvent *e){
else if(dstHor==expertWin->screenWidth - width()) mLRSnap = 2; else if(dstHor==expertWin->screenWidth - width()) mLRSnap = 2;
if(dstVer==0) mTBSnap = 1; if(dstVer==0) mTBSnap = 1;
else if(dstVer==expertWin->screenHeight - height()) mTBSnap = 2; else if(dstVer==expertWin->screenHeight - height()) mTBSnap = 2;
if(mLRSnap==0) foreach(ScreenUnit *ele, mOtherEles) {//左右 if(mLRSnap==0) for(ScreenUnit *ele : mOtherEles) {//左右
if(abs(dstHor - ele->x()) < SnapSpace && ele->x() <= expertWin->screenWidth - width()) { if(abs(dstHor - ele->x()) < SnapSpace && ele->x() <= expertWin->screenWidth - width()) {
dstHor = ele->x(); dstHor = ele->x();
mLRSnap = 1; mLRSnap = 1;
@ -141,7 +257,7 @@ void ScreenUnit::mouseMoveEvent(QMouseEvent *e){
break; break;
} }
} }
if(mTBSnap==0) foreach(ScreenUnit *ele, mOtherEles) {//上下 if(mTBSnap==0) for(ScreenUnit *ele : mOtherEles) {//上下
if(abs(dstVer-ele->y()) < SnapSpace && ele->y() <= expertWin->screenHeight - height()) { if(abs(dstVer-ele->y()) < SnapSpace && ele->y() <= expertWin->screenHeight - height()) {
dstVer = ele->y(); dstVer = ele->y();
mTBSnap = 1; mTBSnap = 1;
@ -191,7 +307,7 @@ void ScreenUnit::mouseMoveEvent(QMouseEvent *e){
if(dstHor < m_handleLen) dstHor = m_handleLen; if(dstHor < m_handleLen) dstHor = m_handleLen;
if(expertWin->screenWidth>0 && expertWin->screenHeight>0) dstHor = qMin(dstHor, expertWin->screenWidth - x()); if(expertWin->screenWidth>0 && expertWin->screenHeight>0) dstHor = qMin(dstHor, expertWin->screenWidth - x());
auto right = x() + dstHor; auto right = x() + dstHor;
if(right < expertWin->screenWidth-8) foreach(ScreenUnit *ele, mOtherEles) {//左右 if(right < expertWin->screenWidth-8) for(ScreenUnit *ele : mOtherEles) {//左右
if(abs(right - ele->x()) < SnapSpace) { if(abs(right - ele->x()) < SnapSpace) {
dstHor = ele->x() - x(); dstHor = ele->x() - x();
mLRSnap = 2; mLRSnap = 2;
@ -214,7 +330,7 @@ void ScreenUnit::mouseMoveEvent(QMouseEvent *e){
if(dstVer < m_handleLen) dstVer = m_handleLen; if(dstVer < m_handleLen) dstVer = m_handleLen;
if(expertWin->screenWidth>0 && expertWin->screenHeight>0) dstVer = qMin(dstVer, expertWin->screenHeight - y()); if(expertWin->screenWidth>0 && expertWin->screenHeight>0) dstVer = qMin(dstVer, expertWin->screenHeight - y());
auto btm = y() + dstVer; auto btm = y() + dstVer;
if(btm < expertWin->screenHeight-8) foreach(ScreenUnit *ele, mOtherEles) {//上下 if(btm < expertWin->screenHeight-8) for(ScreenUnit *ele : mOtherEles) {//上下
auto eleBtm = ele->y() + ele->height(); auto eleBtm = ele->y() + ele->height();
if(abs(btm - ele->y()) < SnapSpace) { if(abs(btm - ele->y()) < SnapSpace) {
dstVer = ele->y() - y(); dstVer = ele->y() - y();
@ -238,7 +354,7 @@ void ScreenUnit::mouseMoveEvent(QMouseEvent *e){
if(mFrmSec==Qt::LeftSection) { if(mFrmSec==Qt::LeftSection) {
dstHor = qMin(dstHor, geo.right() - m_handleLen); dstHor = qMin(dstHor, geo.right() - m_handleLen);
if(dstHor < 0) dstHor = 0; if(dstHor < 0) dstHor = 0;
if(dstHor > 8) foreach(ScreenUnit *ele, mOtherEles) {//左右 if(dstHor > 8) for(ScreenUnit *ele : mOtherEles) {//左右
if(abs(dstHor - ele->x()) < SnapSpace) { if(abs(dstHor - ele->x()) < SnapSpace) {
dstHor = ele->x(); dstHor = ele->x();
mLRSnap = 1; mLRSnap = 1;
@ -259,7 +375,7 @@ void ScreenUnit::mouseMoveEvent(QMouseEvent *e){
} else if(mFrmSec==Qt::TopSection) { } else if(mFrmSec==Qt::TopSection) {
dstVer = qMin(dstVer, geo.bottom() - m_handleLen); dstVer = qMin(dstVer, geo.bottom() - m_handleLen);
if(dstVer < 0) dstVer = 0; if(dstVer < 0) dstVer = 0;
if(dstVer > 8) foreach(ScreenUnit *ele, mOtherEles) {//上下 if(dstVer > 8) for(ScreenUnit *ele : mOtherEles) {//上下
if(abs(dstVer - ele->y()) < SnapSpace) { if(abs(dstVer - ele->y()) < SnapSpace) {
dstVer = ele->y(); dstVer = ele->y();
mTBSnap = 1; mTBSnap = 1;

56
ledset/expertsendpanel.h Normal file
View File

@ -0,0 +1,56 @@
#ifndef EXPERTSENDPANEL_H
#define EXPERTSENDPANEL_H
#include <QPushButton>
#include <QPen>
class ExpertSendPanel : public QWidget {
Q_OBJECT
public:
explicit ExpertSendPanel(QWidget *parent = nullptr);
int screenWidth{1280}, screenHeight{720};
double rate{1};
QPushButton *btnSendReadBack;
};
class ResizeEmitedWgt : public QWidget {
Q_OBJECT
public:
using QWidget::QWidget;
protected:
void resizeEvent(QResizeEvent *) override {emit resized();}
signals:
void resized();
};
#define m_handleLen 10
class ScreenUnit : public QWidget {
Q_OBJECT
public:
explicit ScreenUnit(ExpertSendPanel *, const QString &name, int x, int y, int w, int h, QWidget *parent = nullptr);
ExpertSendPanel *expertWin{0};
QString name;
int mX, mY, mW, mH;
protected:
void paintEvent(QPaintEvent *) override;
void mousePressEvent(QMouseEvent *) override;
void mouseReleaseEvent(QMouseEvent *) override;
void mouseMoveEvent(QMouseEvent *) override;
void leaveEvent(QEvent *) override;
void setFrmSec(const QPoint &);
void setFrmSecIfNeed(Qt::WindowFrameSection frmSec, Qt::CursorShape cursor);
void clearSnap();
QPen mSidePen{Qt::white};
QPoint mPressRel{INT_MIN, INT_MIN};
Qt::WindowFrameSection mFrmSec{Qt::NoSection};
char mLRSnap{0}, mTBSnap{0};
std::vector<ScreenUnit *> mOtherEles;
};
#endif // EXPERTSENDPANEL_H

View File

@ -698,7 +698,7 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(ExpertWin *expertWin) : BaseWin{e
table->clearContents(); table->clearContents();
tableRow->setColumnCount(0); tableRow->setColumnCount(0);
virtualCnt = 0; virtualCnt = 0;
scans.clear(); rows.clear();
}); });
hhh->addWidget(btnReset); hhh->addWidget(btnReset);
@ -713,32 +713,28 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(ExpertWin *expertWin) : BaseWin{e
table = new Table; table = new Table;
table->setEditTriggers(Table::NoEditTriggers); table->setEditTriggers(Table::NoEditTriggers);
table->setSelectionMode(QTableWidget::SingleSelection); table->setSelectionMode(QTableWidget::SingleSelection);
table->setColWidth(35)->setRowHeight(24, QHeaderView::Fixed); table->setColWidth(32)->setRowHeight(24)->setRowResize(QHeaderView::Fixed);
table->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter);
table->verticalHeader()->setMinimumWidth(35);
table->verticalHeader()->setDefaultAlignment(Qt::AlignCenter);
connect(table, &QTableWidget::currentCellChanged, this, [=](int row, int col) { connect(table, &QTableWidget::currentCellChanged, this, [=](int row, int col) {
if(row < 0) return; if(row < 0) return;
auto text = table->text(row, col); auto text = table->text(row, col);
if(! text.isEmpty()) return; if(! text.isEmpty()) return;
if(scans.isEmpty()) { if(rows.empty()) {
auto cnt = tableRow->columnCount() + 1; auto cnt = tableRow->columnCount() + 1;
tableRow->setColumnCount(cnt); tableRow->setColumnCount(cnt);
tableRow->setText(0, cnt-1, QString::number(cnt))->setTextAlignment(Qt::AlignCenter); tableRow->setText(0, cnt-1, QString::number(cnt))->setTextAlignment(Qt::AlignCenter);
tableRow->setText(1, cnt-1, "")->setTextAlignment(Qt::AlignCenter); tableRow->setText(1, cnt-1, "", QPoint{col, row})->setTextAlignment(Qt::AlignCenter);
tableRow->setData(1, cnt-1, QPoint{col, row});
auto realCnt = cnt - virtualCnt; auto realCnt = cnt - virtualCnt;
table->setText(row, col, QString::number(realCnt))->setTextAlignment(Qt::AlignCenter); table->setText(row, col, QString::number(realCnt))->setTextAlignment(Qt::AlignCenter);
if(realCnt!=ModuleWidth) { if(realCnt < ModuleWidth*RowPerScan) {
if(send(0x11, {0x01400000u | cnt}) == 0) qDebug()<<"resp back. col:"<<QString::number(cnt, 16); if(send(0x11, {0x01400000u | cnt}) == 0) qDebug()<<"resp back. col:"<<QString::number(cnt, 16);
} else { } else {
QMessageBox::information(this, tr("提示"), tr("列走完")); QMessageBox::information(this, tr("提示"), tr("列走完"));
scans.append({col, row}); rows.emplace_back(tableRow->data(1, 1).toPoint());
send(0x11, {0x01400000u | (1<<10)}); send(0x11, {0x01400000u | (1<<10)});
} }
} else if(scans.size() < ScanNum) { } else if((int)rows.size() < ScanNum) {
scans.append({col, row}); rows.emplace_back(QPoint{col, row});
auto size = scans.size(); auto size = rows.size();
table->setText(row, col, "S"+QString::number(size))->setTextAlignment(Qt::AlignCenter); table->setText(row, col, "S"+QString::number(size))->setTextAlignment(Qt::AlignCenter);
if(size!=ScanNum) { if(size!=ScanNum) {
if(send(0x11, {0x01400000u | (size<<10)}) == 0) qDebug()<<"resp back. row:"<<QString::number(size, 16); if(send(0x11, {0x01400000u | (size<<10)}) == 0) qDebug()<<"resp back. row:"<<QString::number(size, 16);
@ -755,10 +751,8 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(ExpertWin *expertWin) : BaseWin{e
tableRow = new Table(2, 0); tableRow = new Table(2, 0);
tableRow->setEditTriggers(Table::NoEditTriggers); tableRow->setEditTriggers(Table::NoEditTriggers);
tableRow->setSelectionMode(QTableWidget::NoSelection); tableRow->setSelectionMode(QTableWidget::NoSelection);
tableRow->setColWidth(35); tableRow->setColWidth(32)->setRowHeight(24)->setRowResize(QHeaderView::Fixed);
tableRow->setRowHeight(24);
tableRow->horizontalHeader()->setVisible(false); tableRow->horizontalHeader()->setVisible(false);
tableRow->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
tableRow->verticalHeader()->setMinimumWidth(120); tableRow->verticalHeader()->setMinimumWidth(120);
tableRow->setMaximumHeight(50); tableRow->setMaximumHeight(50);
tableRow->setVHeaderText(0, tr("第一扫灯数:")); tableRow->setVHeaderText(0, tr("第一扫灯数:"));
@ -789,7 +783,7 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(ExpertWin *expertWin) : BaseWin{e
ModuleWidth = fdModuleWidth->value(); ModuleWidth = fdModuleWidth->value();
ModuleHeight = fdModuleHeight->value(); ModuleHeight = fdModuleHeight->value();
GroupNum = fdGroupNum->value(); GroupNum = fdGroupNum->value();
ScanNum = (ModuleHeight + 1) / GroupNum; ScanNum = (ModuleHeight + GroupNum - 1) / GroupNum;
ChipType = fdChipType->text(); ChipType = fdChipType->text();
DecodeMode = fdDecodeMode->text(); DecodeMode = fdDecodeMode->text();
GroupMode = fdGroupMode->currentText(); GroupMode = fdGroupMode->currentText();
@ -813,7 +807,7 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(ExpertWin *expertWin) : BaseWin{e
auto groupNum = unitptr+modUnitMap.smartsetRes + 1; auto groupNum = unitptr+modUnitMap.smartsetRes + 1;
*groupNum = GroupNum; *groupNum = GroupNum;
auto scanNum = unitptr+modUnitMap.smartsetRes + 3; auto scanNum = unitptr+modUnitMap.smartsetRes + 3;
*scanNum = ModuleHeight / GroupNum; *scanNum = ScanNum;
auto len = (quint32_be*)(unitptr+modUnitMap.len); auto len = (quint32_be*)(unitptr+modUnitMap.len);
*len = (ModuleWidth+15) / 16 * 16; *len = (ModuleWidth+15) / 16 * 16;
auto check = (quint32_be*)(msg.data()+headMap.end+modMap.check); auto check = (quint32_be*)(msg.data()+headMap.end+modMap.check);
@ -839,9 +833,10 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(ExpertWin *expertWin) : BaseWin{e
if(send(0x11, {0x01300000u, res12})) return; if(send(0x11, {0x01300000u, res12})) return;
} else if(idx==3) { } else if(idx==3) {
RowPerScan = fdLightNum->value(); RowPerScan = fdLightNum->value();
ScanNum = (ScanNum + RowPerScan - 1) / RowPerScan;
res12 &= ~0xffffu; res12 &= ~0xffffu;
res12 |= (uint)(RowPerScan - 1)<<8; //折返次数 res12 |= (uint)(RowPerScan - 1)<<8; //折返次数
res12 |= (uint)(ModuleHeight / (RowPerScan*GroupNum)); //扫描类型 res12 |= (uint)ScanNum; //扫描类型
if(send(0x11, {0x01200000u | fdRGBStat->checkedId(), res12, ((uint)ModuleWidth+15) / 16 * 16 * RowPerScan})) return; if(send(0x11, {0x01200000u | fdRGBStat->checkedId(), res12, ((uint)ModuleWidth+15) / 16 * 16 * RowPerScan})) return;
} else if(idx==4) { } else if(idx==4) {
bool hases[4]{true,true,true,true}; bool hases[4]{true,true,true,true};
@ -886,9 +881,9 @@ int ExpertSmartPointSetWin::send(uint ptr, const std::initializer_list<uint> &da
auto msg = QByteArray::fromHex("5555 01AD 0000 FFFFFFFF 0000ABCD B1000000 0000 00000000 AD000000 0000"); auto msg = QByteArray::fromHex("5555 01AD 0000 FFFFFFFF 0000ABCD B1000000 0000 00000000 AD000000 0000");
msg.append((data.size()+1)<<2, 0); msg.append((data.size()+1)<<2, 0);
auto plen = (quint16_be*)(msg.data()+headMap.len); auto plen = (quint16_be*)(msg.data()+headMap.len);
*plen |= (data.size()<<2)+6; *plen |= (quint16) (data.size()<<2)+6;
plen = (quint16_be*)(msg.data()+headMap.bodylen); plen = (quint16_be*)(msg.data()+headMap.bodylen);
*plen |= data.size()<<2; *plen |= (quint16) data.size()<<2;
auto pptr = (quint32_be*)(msg.data()+headMap.ptr); auto pptr = (quint32_be*)(msg.data()+headMap.ptr);
*pptr |= ptr; *pptr |= ptr;
pptr = (quint32_be*)(msg.data()+headMap.body); pptr = (quint32_be*)(msg.data()+headMap.body);
@ -922,28 +917,49 @@ void ExpertSmartPointSetWin::save() {
obj.insert("ModuleWidth", ModuleWidth); obj.insert("ModuleWidth", ModuleWidth);
obj.insert("ModuleHeight", ModuleHeight); obj.insert("ModuleHeight", ModuleHeight);
obj.insert("GroupNum", GroupNum); obj.insert("GroupNum", GroupNum);
obj.insert("ScanNum", ScanNum);
obj.insert("ChipType", ChipType); obj.insert("ChipType", ChipType);
obj.insert("DecodeMode", DecodeMode); obj.insert("DecodeMode", DecodeMode);
obj.insert("GroupMode", GroupMode); obj.insert("GroupMode", GroupMode);
obj.insert("ReverseGroup", ReverseGroup);
obj.insert("DataPolarity", DataPolarity); obj.insert("DataPolarity", DataPolarity);
obj.insert("OePolarity", OePolarity); obj.insert("OePolarity", OePolarity);
obj.insert("ScanNum", ScanNum);
obj.insert("ColorMap", ColorMap); obj.insert("ColorMap", ColorMap);
obj.insert("RowPerScan", RowPerScan); obj.insert("RowPerScan", RowPerScan);
JArray points; JArray RowMap;
for(QPoint row : rows) RowMap.append(row.y());
obj.insert("RowMap", RowMap);
JArray ColumnMap;
auto cnt = tableRow->columnCount(); auto cnt = tableRow->columnCount();
if(cnt > ModuleWidth) { if(cnt > ModuleWidth*RowPerScan) {
auto add = (cnt+ModuleWidth-1) / ModuleWidth * ModuleWidth - cnt; auto add = cnt % ModuleWidth;
for(int i=0; i<add; i++) points.append(-1); if(add) add = ModuleWidth - add;
for(int i=0; i<add; i++) ColumnMap.append(-1);
} }
int *cols = new int[ModuleWidth]{0};
for(int i=cnt-1; i>=0; i--) { for(int i=cnt-1; i>=0; i--) {
auto data = tableRow->data(1, i); auto data = tableRow->data(1, i);
points.append(data.isValid() ? data.toPoint().x() : -1); int col = -1;
if(data.isValid()) {
col = data.toPoint().x();
cols[col]++;
col += (RowPerScan-cols[col])*ModuleWidth;
}
ColumnMap.append(col);
} }
obj.insert("Points", points); delete [] cols;
JArray Scans; JArray pos_item_info;
for(QPoint scan : scans) Scans.append(scan.y()); for(int i=cnt-1; i>=0; i--) {
obj.insert("Scans", Scans); auto data = tableRow->data(1, i);
auto pos = data.isValid() ? data.toPoint() : QPoint{-1, -1};
pos_item_info.append(JObj{
{"col", pos_item_info.size()},
{"x", pos.x()},
{"y", pos.y()}
});
}
obj.insert("ColumnMap", ColumnMap);
obj.insert("pos_item_info", pos_item_info);
auto data = JToBytes(obj, " "); auto data = JToBytes(obj, " ");
auto res = qFile.write(data); auto res = qFile.write(data);
qFile.close(); qFile.close();

View File

@ -20,7 +20,7 @@ public:
Table *table, *tableRow; Table *table, *tableRow;
int virtualCnt = 0; int virtualCnt = 0;
QList<QPoint> scans; std::vector<QPoint> rows;
QRadioButton *fdRow, *fdCol; QRadioButton *fdRow, *fdCol;
QSpinBox *fdModuleWidth, *fdModuleHeight, *fdGroupNum; QSpinBox *fdModuleWidth, *fdModuleHeight, *fdGroupNum;
@ -29,7 +29,7 @@ public:
QComboBox *fdGroupMode; QComboBox *fdGroupMode;
int ModuleWidth{32}, ModuleHeight{16}, GroupNum{2}, ScanNum{4}; int ModuleWidth{32}, ModuleHeight{16}, GroupNum{2}, ScanNum{4};
int ChipTypeCode, DecodeModeCode; int ChipTypeCode, DecodeModeCode;
bool DataPolarity{true}, OePolarity{false}; bool ReverseGroup = false, DataPolarity = true, OePolarity = false;
int ColorMap; int ColorMap;
QString ChipType, DecodeMode, GroupMode; QString ChipType, DecodeMode, GroupMode;

File diff suppressed because it is too large Load Diff

View File

@ -8,6 +8,7 @@
#include <QComboBox> #include <QComboBox>
#include <QCheckBox> #include <QCheckBox>
#include <QRadioButton> #include <QRadioButton>
#include <QStackedLayout>
class ExpertWin : public BaseWin { class ExpertWin : public BaseWin {
Q_OBJECT Q_OBJECT
@ -15,11 +16,9 @@ public:
explicit ExpertWin(QWidget *parent, int); explicit ExpertWin(QWidget *parent, int);
QByteArray savedData(); QByteArray savedData();
JObj connSavedData();
void addMapData(QByteArray &); void addMapData(QByteArray &);
int screenWidth{1280}, screenHeight{720};
double rate{1};
QLabel *fdModuleWidth, *fdModuleHeight, *fdGroupNum, *fdScanNum, *fdDataGroupColor ,*fdChouDian; QLabel *fdModuleWidth, *fdModuleHeight, *fdGroupNum, *fdScanNum, *fdDataGroupColor ,*fdChouDian;
QLabel *fdChipType, *fdDecodeMode; QLabel *fdChipType, *fdDecodeMode;
JObj cfg; JObj cfg;
@ -39,13 +38,12 @@ public:
{"GroupMode", "三线并行"} {"GroupMode", "三线并行"}
}; };
QStackedLayout *connStack;
QSpinBox *fdCardWidth, *fdCardHeight; QSpinBox *fdCardWidth, *fdCardHeight;
QComboBox *fdDirection, *fdSectorCount; QComboBox *fdDirection, *fdSectorCount;
QRadioButton *fdAdvacned; QRadioButton *fdAdvacned;
//added by alahover -s 20230830 QPushButton *btnConnReadBack, *btnReceiveReadBack;
QPushButton *btnReadBack,*btn_OpenCfg,*btn_SaveCfg,*btn_SaveMap,*btn_SendData,*btn_GuhuaData;
QTabWidget * m_tab;
QSpinBox *spinGclkXw,*spinGclkZkb,*spinLineNs,*spinLineWz,*spinLineXy,*spinPointsOnePort; QSpinBox *spinGclkXw,*spinGclkZkb,*spinLineNs,*spinLineWz,*spinLineXy,*spinPointsOnePort;
QComboBox *cbDCLKf,*cbDclkXw, *cbDclkZkb,*freshBeiLv,*cbGCLKf,*cbGryLevel,*cbNoSign,*cbStb,*cbDE,*cbABC,*cbXiaoYinDianPing,*cbSTB,*cbSRowOut; QComboBox *cbDCLKf,*cbDclkXw, *cbDclkZkb,*freshBeiLv,*cbGCLKf,*cbGryLevel,*cbNoSign,*cbStb,*cbDE,*cbABC,*cbXiaoYinDianPing,*cbSTB,*cbSRowOut;
QLabel * m_ctrlFreshRate,*m_ctrlBrightEff,*m_ctrlMinOE; QLabel * m_ctrlFreshRate,*m_ctrlBrightEff,*m_ctrlMinOE;
@ -55,8 +53,8 @@ public:
//added by alahover -o 20230830 //added by alahover -o 20230830
//added by alahover -s 20230817 //added by alahover -s 20230817
int m_iRcvCardType; int m_iRcvCardType;
int m_tab1firstClick=0; bool needInit1 = true;
int m_tab2firstClick=0; bool needInit2 = true;
struct St_Rcv_Pos{ struct St_Rcv_Pos{
unsigned char imgXL8 = 0;//接收卡图像列起始低八位 unsigned char imgXL8 = 0;//接收卡图像列起始低八位
@ -288,8 +286,6 @@ protected:
void closeEvent(QCloseEvent *) override; void closeEvent(QCloseEvent *) override;
}; };
#define MACRO_FUNC_SEND_PARAM(TIP_MESSAGE,FUNC,SEND_FLASHPAGE_NUM,FLASH_ADDR) \ #define MACRO_FUNC_SEND_PARAM(TIP_MESSAGE,FUNC,SEND_FLASHPAGE_NUM,FLASH_ADDR) \
for(int iSendCount=0;iSendCount<SEND_FLASHPAGE_NUM;iSendCount++)\ for(int iSendCount=0;iSendCount<SEND_FLASHPAGE_NUM;iSendCount++)\
{\ {\

11
ledset/files/decoder.ic Normal file
View File

@ -0,0 +1,11 @@
{
"普通译码" : 0,
"138译码" : 0,
"SM5266" : 1,
"SM5366" : 2,
"ICN2013" : 3,
"无译码" : 4,
"595译码" : 5,
"5958译码" : 6,
"ICND2018" : 16,
}

36
ledset/files/driver.ic Normal file
View File

@ -0,0 +1,36 @@
{
"通用" : 0,
"MBI5042" : 1,
"MBI5041" : 1,
"MY9268" : 2,
"MBI5050" : 3,
"SD16749" : 4,
"SM16136" : 5,
"APA101" : 6,
"MY9266" : 7,
"MY9868" : 8,
"MBI5052" : 9,
"SUM2017" : 10,
"MY9862" : 11,
"SUM2032" : 12,
"MBI5153" : 13,
"ICN2053" : 15,
"ICN2038S" : 16,
"MBI5124" : 17,
"SM16017" : 18,
"SM16207" : 19,
"SM16159" : 20,
"LS9929IP" : 21,
"ICND2110" : 22,
"LS9918IP" : 23,
"SM16237" : 24,
"SUM2028" : 25,
"SUM2017TD" : 26,
"SM16259" : 27,
"ICND2065" : 28,
"ICND2055" : 28,
"SM16359" : 29,
"RT5965" : 30,
"RT5966" : 30,
"MBI5264" : 31
}

View File

@ -34,7 +34,8 @@ enum enum_rcvCardType{
enum_xixun_sync = 0, enum_xixun_sync = 0,
enum_xixun_async = 1, enum_xixun_async = 1,
enum_zrf = 2, enum_zrf = 2,
enum_mxe enum_mxe,
NoCard
}; };
struct HeadMap { struct HeadMap {
byte pre = ipp(2); byte pre = ipp(2);

View File

@ -1,44 +1,136 @@
#include "qgui.h" #include "qgui.h"
#include <QPainter>
#include <QResizeEvent> #include <QResizeEvent>
const int AlignRight = Qt::AlignRight | Qt::AlignVCenter; const int AlignRight = Qt::AlignRight | Qt::AlignVCenter;
Table::Table(std::initializer_list<ColAttr> colAttrs, int rows, QWidget *parent) : QTableWidget{rows, (int)colAttrs.size(), parent} { int operator*(const QString& key, QTreeView &table) {
int i = 0; return ((TreeWidget&)table).fdmap.at(key);
for(typename std::initializer_list<ColAttr>::const_iterator it = colAttrs.begin(); it != colAttrs.end(); ++it) { }
auto item = horizontalHeaderItem(i); int operator*(const char *key, QTreeView &table) {
if(item==0) setHorizontalHeaderItem(i, item = new QTableWidgetItem()); return ((TreeWidget&)table).fdmap.at(key);
item->setText(it->text);
if(it->width > 0) horizontalHeader()->resizeSection(i, it->width);
if(it->resizeMode != QHeaderView::Interactive) {
if(it->resizeMode==QHeaderView::Stretch && it->width>0) {
item->setData(0x99, it->width > 0 ? it->width : 100);
noStretch = false;
} else horizontalHeader()->setSectionResizeMode(i, (QHeaderView::ResizeMode)it->resizeMode);
}
mFieldMap.emplace(it->field, i++);
}
} }
TreeWidget::TreeWidget(std::initializer_list<ColAttr> colAttrs, QWidget *parent) : QTreeWidget{parent} {
header()->setMinimumSectionSize(16);
int i = 0;
auto item = headerItem();
for(auto attr = colAttrs.begin(); attr < colAttrs.end(); ++attr) {
item->setText(i, attr->text);
item->setData(i, FieldRole, attr->field);
if(attr->width > 0) header()->resizeSection(i, attr->width);
if(attr->resizeMode != QHeaderView::Interactive) {
if(attr->resizeMode==QHeaderView::Stretch && attr->width > 0) {
item->setData(i, WidthRole, attr->width);
noStretch = false;
} else header()->setSectionResizeMode(i, attr->resizeMode);
}
fdmap.emplace(attr->field, i++);
}
hasRowNum = i && colAttrs.begin()->field=="_num_";
connect(header(), &QHeaderView::sectionResized, this, &TreeWidget::onSectionResized);
header()->installEventFilter(this);
}
bool TreeWidget::eventFilter(QObject *watched, QEvent *event) {
if(isSectionResized && event->type()==QEvent::Leave && watched==header()) {
isSectionResized = false;
auto item = headerItem();
for(int cc=0; cc<columnCount(); cc++) if(item->data(cc, WidthRole).isValid()) item->setData(cc, WidthRole, header()->sectionSize(cc));
}
return QTreeWidget::eventFilter(watched, event);
}
void TreeWidget::resizeEvent(QResizeEvent *event) {
QTreeWidget::resizeEvent(event);
if(noStretch || event->size().width() == event->oldSize().width()) return;
adjSections(-1, 0);
}
void TreeWidget::drawRow(QPainter *painter, const QStyleOptionViewItem &options, const QModelIndex &index) const {
QTreeWidget::drawRow(painter, options, index);
if(columnWidth(0)>40) return;
if(hasRowNum) {
QRect rect(options.rect.left(), options.rect.top(), columnWidth(0), options.rect.height());
painter->fillRect(rect, QColor(128, 128, 128, 32));
painter->drawText(rect, Qt::AlignCenter, QString::number(index.row()+1));
}
if(hasGrid) {
QBrush color({128, 128, 128, 128});
painter->fillRect(options.rect.left(), options.rect.bottom(), options.rect.width(), 1, color);
QRect rec(options.rect.left()-1, options.rect.top(), 1, options.rect.height());
auto end = columnCount() - 1;
for(int i=0; i<end; i++) {
rec.translate(columnWidth(i), 0);
painter->fillRect(rec, color);
}
}
}
void TreeWidget::onSectionResized(int logicalIndex, int oldSize, int newSize) {
if(blocked || noStretch || newSize==0 || oldSize==0) return;
if(! headerItem()->data(logicalIndex, WidthRole).isValid()) return;
if(adjSections(logicalIndex, newSize)) isSectionResized = true;
}
bool TreeWidget::adjSections(int index, int size) {
auto item = headerItem();
int remain = header()->width() - size, stretchWidth = 0, width;
for(int cc=0; cc<columnCount(); cc++) if(cc!=index) {
if((width = item->data(cc, WidthRole).toInt()) > 0) stretchWidth += width;
else remain -= header()->sectionSize(cc);
}
if(remain<=0 || stretchWidth==0) return false;
auto min = header()->minimumSectionSize();
blocked = true;
for(int cc=0; cc<columnCount(); cc++) if(cc!=index && (width = item->data(cc, WidthRole).toInt()) > 0) header()->resizeSection(cc, qMax(min, width * remain / stretchWidth));
blocked = false;
return true;
}
Table::Table(std::initializer_list<ColAttr> colAttrs, int rows, QWidget *parent) : QTableWidget{rows, (int)colAttrs.size(), parent} {
int i = 0;
for(auto attr = colAttrs.begin(); attr < colAttrs.end(); ++attr) {
auto item = horizontalHeaderItem(i);
if(item==0) setHorizontalHeaderItem(i, item = new QTableWidgetItem);
item->setText(attr->text);
item->setData(FieldRole, attr->field);
if(attr->width > 0) horizontalHeader()->resizeSection(i, attr->width);
if(attr->resizeMode != QHeaderView::Interactive) {
if(attr->resizeMode==QHeaderView::Stretch && attr->width > 0) {
item->setData(WidthRole, attr->width);
noStretch = false;
} else horizontalHeader()->setSectionResizeMode(i, attr->resizeMode);
}
fdmap.emplace(attr->field, i++);
}
connect(horizontalHeader(), &QHeaderView::sectionResized, this, &Table::onSectionResized);
horizontalHeader()->installEventFilter(this);
}
bool Table::eventFilter(QObject *watched, QEvent *event) {
if(isSectionResized && event->type()==QEvent::Leave && watched==horizontalHeader()) {
isSectionResized = false;
QTableWidgetItem *item;
for(int cc=0; cc<columnCount(); cc++) if((item = horizontalHeaderItem(cc)) && item->data(WidthRole).isValid()) item->setData(WidthRole, horizontalHeader()->sectionSize(cc));
}
return QTableWidget::eventFilter(watched, event);
}
void Table::resizeEvent(QResizeEvent *event) { void Table::resizeEvent(QResizeEvent *event) {
QTableWidget::resizeEvent(event); QTableWidget::resizeEvent(event);
if(noStretch || event->size().width() == event->oldSize().width()) return; if(noStretch || event->size().width() == event->oldSize().width()) return;
resizeSec(); adjSections(-1, 0);
} }
void Table::onSectionResized(int logicalIndex, int oldSize, int newSize) {
void Table::resizeSec() { if(blocked || noStretch || newSize==0 || oldSize==0) return;
auto header = horizontalHeader(); if(! horizontalHeaderItem(logicalIndex)->data(WidthRole).isValid()) return;
int colCnt = columnCount(), remainWidth = header->width(), stretchWidth = 0, secWidth; if(adjSections(logicalIndex, newSize)) isSectionResized = true;
}
bool Table::adjSections(int index, int size) {
QTableWidgetItem *item; QTableWidgetItem *item;
for(int cc=0; cc<colCnt; cc++) if((item = horizontalHeaderItem(cc))) { int remain = horizontalHeader()->width() - size, stretchWidth = 0, width;
if((secWidth = item->data(0x99).toInt()) > 0) stretchWidth += secWidth; for(int cc=0; cc<columnCount(); cc++) if(cc!=index && (item = horizontalHeaderItem(cc))) {
else remainWidth -= header->sectionSize(cc); if((width = item->data(WidthRole).toInt()) > 0) stretchWidth += width;
else remain -= horizontalHeader()->sectionSize(cc);
} }
if(remainWidth<=0 || stretchWidth==0) return; if(remain<=0 || stretchWidth==0) return false;
for(int cc=0; cc<colCnt; cc++) if((item = horizontalHeaderItem(cc)) && (secWidth = item->data(0x99).toInt()) > 0) header->resizeSection(cc, secWidth * remainWidth / stretchWidth); auto min = horizontalHeader()->minimumSectionSize();
} blocked = true;
for(int cc=0; cc<columnCount(); cc++) if(cc!=index && (item = horizontalHeaderItem(cc)) && (width = item->data(WidthRole).toInt()) > 0) horizontalHeader()->resizeSection(cc, qMax(min, width * remain / stretchWidth));
void Table::updateGeometries() { blocked = false;
QTableWidget::updateGeometries(); return true;
emit updGeos();
} }

View File

@ -11,6 +11,7 @@
#include <QStackedLayout> #include <QStackedLayout>
#include <QTableWidget> #include <QTableWidget>
#include <QTextEdit> #include <QTextEdit>
#include <QTreeWidget>
#define MainMust \ #define MainMust \
#if(QT_VERSION_MAJOR > 5) \ #if(QT_VERSION_MAJOR > 5) \
@ -41,7 +42,7 @@ inline int SetCurData(QComboBox *combo, const QVariant &data) {
if(idx>-1) combo->setCurrentIndex(idx); if(idx>-1) combo->setCurrentIndex(idx);
return idx; return idx;
} }
inline int SetCurText(QComboBox *combo, const QString &text) { inline int SetCurText(QComboBox *combo, const QString& text) {
auto idx = combo->findText(text); auto idx = combo->findText(text);
if(idx>-1) combo->setCurrentIndex(idx); if(idx>-1) combo->setCurrentIndex(idx);
return idx; return idx;
@ -53,7 +54,7 @@ inline void gFont(QWidget *wgt, int size, bool bold = false, bool italic = false
if(italic) ft.setItalic(true); if(italic) ft.setItalic(true);
wgt->setFont(ft); wgt->setFont(ft);
} }
inline void gFont(QWidget *wgt, const QString &family, int size = 0, bool bold = false, bool italic = false) { inline void gFont(QWidget *wgt, const QString& family, int size = 0, bool bold = false, bool italic = false) {
auto ft = wgt->font(); auto ft = wgt->font();
ft.setFamily(family); ft.setFamily(family);
if(size) ft.setPixelSize(size); if(size) ft.setPixelSize(size);
@ -61,14 +62,14 @@ inline void gFont(QWidget *wgt, const QString &family, int size = 0, bool bold =
if(italic) ft.setItalic(true); if(italic) ft.setItalic(true);
wgt->setFont(ft); wgt->setFont(ft);
} }
inline QFont qfont(const QString &family, int pixelSize, bool bold = false, bool italic = false) { inline QFont qfont(const QString& family, int pixelSize, bool bold = false, bool italic = false) {
QFont ft(family); QFont ft(family);
ft.setPixelSize(pixelSize); ft.setPixelSize(pixelSize);
if(bold) ft.setBold(true); if(bold) ft.setBold(true);
if(italic) ft.setItalic(true); if(italic) ft.setItalic(true);
return ft; return ft;
} }
inline void gAppendText(QTextEdit *wgt, const QString &text, const QColor &color) { inline void gAppendText(QTextEdit *wgt, const QString& text, const QColor &color) {
auto c0 = wgt->textColor(); auto c0 = wgt->textColor();
wgt->setTextColor(color); wgt->setTextColor(color);
wgt->append(text); wgt->append(text);
@ -77,29 +78,29 @@ inline void gAppendText(QTextEdit *wgt, const QString &text, const QColor &color
class VBox : public QBoxLayout { class VBox : public QBoxLayout {
public: public:
inline VBox(QWidget *parent=nullptr) : QBoxLayout(TopToBottom, parent) {} VBox(QWidget *parent=nullptr) : QBoxLayout(TopToBottom, parent) {}
inline VBox(QBoxLayout *parent) : QBoxLayout(TopToBottom) { VBox(QBoxLayout *parent) : QBoxLayout(TopToBottom) {
parent->addLayout(this); parent->addLayout(this);
}; };
inline VBox(QStackedLayout *stack) : QBoxLayout(TopToBottom, new QWidget) { VBox(QStackedLayout *stack) : QBoxLayout(TopToBottom, new QWidget) {
stack->addWidget(parentWidget()); stack->addWidget(parentWidget());
setContentsMargins(0,0,0,0); setContentsMargins(0,0,0,0);
}; };
inline VBox(QSplitter *splitter) : QBoxLayout(TopToBottom, new QWidget) { VBox(QSplitter *splitter) : QBoxLayout(TopToBottom, new QWidget) {
splitter->addWidget(parentWidget()); splitter->addWidget(parentWidget());
setContentsMargins(0,0,0,0); setContentsMargins(0,0,0,0);
}; };
inline QLabel *addLabel() { QLabel *addLabel() {
auto lb = new QLabel; auto lb = new QLabel;
addWidget(lb); addWidget(lb);
return lb; return lb;
} }
inline QLabel *addLabel(const QString &text) { QLabel *addLabel(const QString& text) {
auto lb = new QLabel(text); auto lb = new QLabel(text);
addWidget(lb); addWidget(lb);
return lb; return lb;
} }
inline QDialogButtonBox *addBtnBox(QDialog *dlg = 0) { QDialogButtonBox *addBtnBox(QDialog *dlg = 0) {
auto btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); auto btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
if(dlg) connect(btnBox, &QDialogButtonBox::rejected, dlg, &QDialog::reject); if(dlg) connect(btnBox, &QDialogButtonBox::rejected, dlg, &QDialog::reject);
addWidget(btnBox); addWidget(btnBox);
@ -108,24 +109,24 @@ public:
}; };
class HBox : public QBoxLayout { class HBox : public QBoxLayout {
public: public:
inline HBox(QWidget *parent=nullptr) : QBoxLayout(LeftToRight, parent) {} HBox(QWidget *parent=nullptr) : QBoxLayout(LeftToRight, parent) {}
inline HBox(QBoxLayout *parent) : QBoxLayout(LeftToRight) { HBox(QBoxLayout *parent) : QBoxLayout(LeftToRight) {
parent->addLayout(this); parent->addLayout(this);
}; };
inline HBox(QStackedLayout *stack) : QBoxLayout(LeftToRight, new QWidget) { HBox(QStackedLayout *stack) : QBoxLayout(LeftToRight, new QWidget) {
stack->addWidget(parentWidget()); stack->addWidget(parentWidget());
setContentsMargins(0,0,0,0); setContentsMargins(0,0,0,0);
}; };
inline HBox(QSplitter *splitter) : QBoxLayout(LeftToRight, new QWidget) { HBox(QSplitter *splitter) : QBoxLayout(LeftToRight, new QWidget) {
splitter->addWidget(parentWidget()); splitter->addWidget(parentWidget());
setContentsMargins(0,0,0,0); setContentsMargins(0,0,0,0);
}; };
inline QLabel *addLabel() { QLabel *addLabel() {
auto lb = new QLabel; auto lb = new QLabel;
addWidget(lb); addWidget(lb);
return lb; return lb;
} }
inline QLabel *addLabel(const QString &text) { QLabel *addLabel(const QString& text) {
auto lb = new QLabel(text); auto lb = new QLabel(text);
addWidget(lb); addWidget(lb);
return lb; return lb;
@ -134,16 +135,16 @@ public:
class Grid : public QGridLayout { class Grid : public QGridLayout {
public: public:
using QGridLayout::QGridLayout; using QGridLayout::QGridLayout;
inline Grid(QBoxLayout *parent) { Grid(QBoxLayout *parent) {
parent->addLayout(this); parent->addLayout(this);
}; };
inline Grid(QStackedLayout *stack) : QGridLayout(new QWidget) { Grid(QStackedLayout *stack) : QGridLayout(new QWidget) {
stack->addWidget(parentWidget()); stack->addWidget(parentWidget());
}; };
inline Grid(QSplitter *splitter) : QGridLayout(new QWidget) { Grid(QSplitter *splitter) : QGridLayout(new QWidget) {
splitter->addWidget(parentWidget()); splitter->addWidget(parentWidget());
}; };
inline QLabel *addLabel(const QString &text) { QLabel *addLabel(const QString& text) {
auto lb = new QLabel(text); auto lb = new QLabel(text);
addWidget(lb); addWidget(lb);
return lb; return lb;
@ -155,7 +156,7 @@ public:
using QListWidget::QListWidget; using QListWidget::QListWidget;
using QListWidget::addItem; using QListWidget::addItem;
inline auto addItem(const QString &text, const QVariant &value) { auto addItem(const QString& text, const QVariant &value) {
auto item = new QListWidgetItem(text); auto item = new QListWidgetItem(text);
item->setData(Qt::UserRole, value); item->setData(Qt::UserRole, value);
insertItem(count(), item); insertItem(count(), item);
@ -164,13 +165,198 @@ public:
}; };
struct ColAttr { struct ColAttr {
ColAttr(QString field, QString text, int width=0, QHeaderView::ResizeMode resizeMode = QHeaderView::Interactive) : field(field), text(text), width(width), resizeMode(resizeMode) {} ColAttr(const QString& field, const QString& text, int width=0, QHeaderView::ResizeMode resizeMode = QHeaderView::Interactive) : field(field), text(text), width(width), resizeMode(resizeMode) {}
ColAttr(QString field, QString text, QHeaderView::ResizeMode resizeMode) : field(field), text(text), resizeMode(resizeMode) {} ColAttr(const QString& field, const QString& text, QHeaderView::ResizeMode resizeMode) : field(field), text(text), resizeMode(resizeMode) {}
QString field; QString field;
QString text; QString text;
int width{0}; int width{0};
QHeaderView::ResizeMode resizeMode; QHeaderView::ResizeMode resizeMode;
}; };
enum TableItemDataRole {
FieldRole = 0xfe,
WidthRole
};
int operator*(const QString& key, QTreeView &table);
int operator*(const char *key, QTreeView &table);
class TreeWidgetItem : public QTreeWidgetItem {
public:
using QTreeWidgetItem::QTreeWidgetItem;
using QTreeWidgetItem::checkState;
auto checkState(const QString& column) {
return checkState(column**treeWidget());
}
using QTreeWidgetItem::setCheckState;
auto setCheckState(const QString& column, Qt::CheckState state) {
setCheckState(column**treeWidget(), state);
return this;
}
using QTreeWidgetItem::text;
auto text(const QString& column) {
return text(column**treeWidget());
}
using QTreeWidgetItem::setText;
auto setText(const QString& column, const QString& text) {
setText(column**treeWidget(), text);
return this;
}
auto setText(const QString& column, const QString& text, const QVariant &value) {
auto idx = column**treeWidget();
setText(idx, text);
setData(idx, Qt::UserRole, value);
return this;
}
using QTreeWidgetItem::background;
auto background(const QString& column) {
return background(column**treeWidget());
}
using QTreeWidgetItem::setBackground;
auto setBackground(const QString& column, const QBrush &brush) {
setBackground(column**treeWidget(), brush);
return this;
}
using QTreeWidgetItem::foreground;
auto foreground(const QString& column) {
return foreground(column**treeWidget());
}
using QTreeWidgetItem::setForeground;
auto setForeground(const QString& column, const QBrush &brush) {
setForeground(column**treeWidget(), brush);
return this;
}
using QTreeWidgetItem::data;
auto data(int col) {
return data(col, Qt::UserRole);
}
auto data(const QString& column, int role = Qt::UserRole) {
return data(column**treeWidget(), role);
}
using QTreeWidgetItem::setData;
auto setData(int col, const QVariant &value) {
setData(col, Qt::UserRole, value);
return this;
}
auto setData(const QString& column, const QVariant &value) {
setData(column**treeWidget(), Qt::UserRole, value);
return this;
}
auto setData(const QString& column, int role, const QVariant &value) {
setData(column**treeWidget(), role, value);
return this;
}
auto itemWidget(int column) {
return treeWidget()->itemWidget(this, column);
}
auto itemWidget(const QString& column) {
return treeWidget()->itemWidget(this, column**treeWidget());
}
auto setItemWidget(int column, QWidget *widget) {
treeWidget()->setItemWidget(this, column, widget);
return this;
}
auto setItemWidget(const QString& column, QWidget *widget) {
treeWidget()->setItemWidget(this, column**treeWidget(), widget);
return this;
}
};
class TreeWidget : public QTreeWidget {
Q_OBJECT
public:
using QTreeWidget::QTreeWidget;
TreeWidget(std::initializer_list<ColAttr> colAttrs, QWidget *parent = 0);
auto setDefs() {
setIndentation(0);
setAlternatingRowColors(true);
header()->setStretchLastSection(false);
return this;
}
auto setColFit() {
header()->setSectionResizeMode(QHeaderView::ResizeToContents);
return this;
}
auto setColWidth(int value, QHeaderView::ResizeMode mode = QHeaderView::Interactive) {
header()->setDefaultSectionSize(value);
if(mode!=QHeaderView::Interactive) header()->setSectionResizeMode(mode);
return this;
}
auto setHeaderText(const QString& column, const QString& text) {
headerItem()->setText(fdmap.at(column), text);
return this;
}
using QTreeWidget::showColumn;
auto showColumn(const QString& column) {
showColumn(fdmap.at(column));
return this;
}
using QTreeWidget::hideColumn;
auto hideColumn(const QString& column) {
hideColumn(fdmap.at(column));
return this;
}
TreeWidgetItem *item(int idx) const {
return (TreeWidgetItem*) topLevelItem(idx);
}
TreeWidgetItem *selectedItem() const {
auto is = selectedItems();
return is.isEmpty() ? 0 : (TreeWidgetItem*) is.at(0);
}
TreeWidgetItem *curItem() const {
return (TreeWidgetItem*) currentItem();
}
using QTreeWidget::itemWidget;
auto itemWidget(QTreeWidgetItem *item, const QString& column) {
return itemWidget(item, fdmap.at(column));
}
using QTreeWidget::setItemWidget;
auto setItemWidget(QTreeWidgetItem *item, const QString& column, QWidget *widget) {
setItemWidget(item, fdmap.at(column), widget);
return this;
}
QString field(int column) const {
return headerItem()->data(column, FieldRole).toString();
}
QString sortField() const {
return field(sortColumn());
}
using QTreeWidget::sortItems;
void sortItems(const QString& column, Qt::SortOrder order = Qt::AscendingOrder) {
sortItems(fdmap.at(column), order);
}
std::unordered_map<QString, int> fdmap;
bool hasRowNum = false;
bool hasGrid = true;
signals:
void updGeos();
protected:
bool eventFilter(QObject *watched, QEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
void updateGeometries() override {
QTreeWidget::updateGeometries();
emit updGeos();
};
void drawRow(QPainter *painter, const QStyleOptionViewItem &options, const QModelIndex &index) const override;
void onSectionResized(int logicalIndex, int oldSize, int newSize);
bool adjSections(int index, int size);
bool noStretch = true;
bool isSectionResized = false;
bool blocked = false;
};
class Table : public QTableWidget { class Table : public QTableWidget {
Q_OBJECT Q_OBJECT
public: public:
@ -178,158 +364,166 @@ public:
Table() {} Table() {}
Table(std::initializer_list<ColAttr> colAttrs, int rows = 0, QWidget *parent = 0); Table(std::initializer_list<ColAttr> colAttrs, int rows = 0, QWidget *parent = 0);
inline auto setDefs() { auto setDefs() {
setSelectionBehavior(QTableWidget::SelectRows); setSelectionBehavior(QTableWidget::SelectRows);
setEditTriggers(QAbstractItemView::NoEditTriggers); setEditTriggers(QAbstractItemView::NoEditTriggers);
setAlternatingRowColors(true); setAlternatingRowColors(true);
return this; return this;
} }
inline auto setColStretch() { auto setColStretch() {
horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
return this; return this;
} }
inline auto setRowStretch() { auto setRowStretch() {
verticalHeader()->setSectionResizeMode(QHeaderView::Stretch); verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
return this; return this;
} }
inline auto setColFit() { auto setColFit() {
horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
return this; return this;
} }
inline auto setRowFit() { auto setRowFit() {
verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
return this; return this;
} }
inline auto setColWidth(int value, QHeaderView::ResizeMode mode = QHeaderView::Interactive) { auto setColWidth(int value) {
auto header = horizontalHeader(); if(horizontalHeader()->minimumSectionSize() > value) horizontalHeader()->setMinimumSectionSize(value);
header->setDefaultSectionSize(value); horizontalHeader()->setDefaultSectionSize(value);
if(mode!=QHeaderView::Interactive) header->setSectionResizeMode(mode);
return this; return this;
} }
inline auto setRowHeight(int value, QHeaderView::ResizeMode mode = QHeaderView::Interactive) { auto setColResize(QHeaderView::ResizeMode mode) {
auto header = verticalHeader(); horizontalHeader()->setSectionResizeMode(mode);
header->setDefaultSectionSize(value); return this;
if(mode!=QHeaderView::Interactive) header->setSectionResizeMode(mode); }
auto setRowHeight(int value) {
if(verticalHeader()->minimumSectionSize() > value) verticalHeader()->setMinimumSectionSize(value);
verticalHeader()->setDefaultSectionSize(value);
return this;
}
auto setRowResize(QHeaderView::ResizeMode mode) {
verticalHeader()->setSectionResizeMode(mode);
return this; return this;
} }
inline auto setHeaderText(int col, QString text) { auto setHeaderText(int col, const QString& text) {
auto item = horizontalHeaderItem(col); auto item = horizontalHeaderItem(col);
if(item==0) setHorizontalHeaderItem(col, item = new QTableWidgetItem()); if(item==0) setHorizontalHeaderItem(col, item = new QTableWidgetItem());
item->setText(text); item->setText(text);
return item; return item;
} }
inline auto setHeaderText(QString column, QString text) { auto setHeaderText(const QString& column, const QString& text) {
auto col = mFieldMap[column]; return setHeaderText(fdmap.at(column), text);
return setHeaderText(col, text);
} }
inline auto setVHeaderText(int row, QString text) { auto setVHeaderText(int row, const QString& text) {
auto item = verticalHeaderItem(row); auto item = verticalHeaderItem(row);
if(item==0) setVerticalHeaderItem(row, item = new QTableWidgetItem()); if(item==0) setVerticalHeaderItem(row, item = new QTableWidgetItem());
item->setText(text); item->setText(text);
return item; return item;
} }
inline auto appendRow() { auto appendRow() {
auto value = rowCount(); auto value = rowCount();
setRowCount(value + 1); setRowCount(value + 1);
return value; return value;
} }
using QTableWidget::item; using QTableWidget::item;
inline auto item(int row, QString column) { auto item(int row, const QString& column) {
auto col = mFieldMap[column]; return item(row, fdmap.at(column));
return item(row, col);
} }
inline auto itemValid(int row, int col) { auto itemValid(int row, int col) {
auto anitem = item(row, col); auto itm = item(row, col);
if(anitem==0) setItem(row, col, anitem = new QTableWidgetItem); if(itm==0) setItem(row, col, itm = new QTableWidgetItem);
return anitem; return itm;
} }
inline auto itemValid(int row, QString column) { auto itemValid(int row, const QString& column) {
auto col = mFieldMap[column]; return itemValid(row, fdmap.at(column));
return itemValid(row, col);
} }
using QTableWidget::setItem; using QTableWidget::setItem;
inline void setItem(int row, QString column, QTableWidgetItem *item) { void setItem(int row, const QString& column, QTableWidgetItem *item) {
auto col = mFieldMap[column]; setItem(row, fdmap.at(column), item);
setItem(row, col, item);
} }
inline auto text(int row, int col) { auto text(int row, int col) {
auto itm = item(row, col); auto itm = item(row, col);
if(itm==0) return QString(); if(itm==0) return QString();
return itm->text(); return itm->text();
} }
inline auto text(int row, QString column) { auto text(int row, const QString& column) {
auto col = mFieldMap[column]; return text(row, fdmap.at(column));
return text(row, col);
} }
inline auto setText(int row, int col, const QString &text) { auto setText(int row, int col, const QString& text) {
auto itm = item(row, col); auto itm = item(row, col);
if(itm) itm->setText(text); if(itm) itm->setText(text);
else setItem(row, col, itm = new QTableWidgetItem(text)); else setItem(row, col, itm = new QTableWidgetItem(text));
return itm; return itm;
} }
inline auto setText(int row, QString column, const QString &text) { auto setText(int row, const QString& column, const QString& text) {
auto col = mFieldMap[column]; return setText(row, fdmap.at(column), text);
return setText(row, col, text); }
auto setText(int row, int col, const QString& text, const QVariant &value) {
auto itm = item(row, col);
if(itm) itm->setText(text);
else setItem(row, col, itm = new QTableWidgetItem(text));
itm->setData(Qt::UserRole, value);
return itm;
}
auto setText(int row, const QString& column, const QString& text, const QVariant &value) {
return setText(row, fdmap.at(column), text, value);
} }
inline auto data(int row, int col) { auto data(int row, int col) {
auto itm = item(row, col); auto itm = item(row, col);
if(itm==0) return QVariant(); if(itm==0) return QVariant();
return itm->data(Qt::UserRole); return itm->data(Qt::UserRole);
} }
inline auto data(int row, QString column) { auto data(int row, const QString& column) {
auto col = mFieldMap[column]; return data(row, fdmap.at(column));
return data(row, col);
} }
inline auto setData(int row, int col, const QVariant &value) { auto setData(int row, int col, const QVariant &value) {
auto itm = item(row, col); auto itm = item(row, col);
if(itm==0) setItem(row, col, itm = new QTableWidgetItem); if(itm==0) setItem(row, col, itm = new QTableWidgetItem);
itm->setData(Qt::UserRole, value); itm->setData(Qt::UserRole, value);
return itm; return itm;
} }
inline auto setData(int row, QString column, const QVariant &value) { auto setData(int row, const QString& column, const QVariant &value) {
auto col = mFieldMap[column]; return setData(row, fdmap.at(column), value);
return setData(row, col, value);
} }
using QTableWidget::cellWidget; using QTableWidget::cellWidget;
inline auto cellWidget(int row, QString column) { auto cellWidget(int row, const QString& column) {
auto col = mFieldMap[column]; return cellWidget(row, fdmap.at(column));
return cellWidget(row, col);
} }
using QTableWidget::setCellWidget; using QTableWidget::setCellWidget;
inline void setCellWidget(int row, QString column, QWidget *widget) { void setCellWidget(int row, const QString& column, QWidget *widget) {
auto col = mFieldMap[column]; setCellWidget(row, fdmap.at(column), widget);
setCellWidget(row, col, widget);
} }
std::map<QString, int> mFieldMap; using QTableWidget::sortItems;
void sortItems(const QString& column, Qt::SortOrder order) {
sortItems(fdmap.at(column), order);
}
std::unordered_map<QString, int> fdmap;
public Q_SLOTS: public Q_SLOTS:
inline void clearRows() {setRowCount(0);} void clearRows() {setRowCount(0);}
signals: signals:
void updGeos(); void updGeos();
protected: protected:
bool eventFilter(QObject *watched, QEvent *event) override;
void resizeEvent(QResizeEvent *event) override; void resizeEvent(QResizeEvent *event) override;
void updateGeometries() override; void updateGeometries() override {
void resizeSec(); QTableWidget::updateGeometries();
bool noStretch{true}; emit updGeos();
}; };
void onSectionResized(int logicalIndex, int oldSize, int newSize);
class ResizeEmitedWgt : public QWidget { bool adjSections(int index, int size);
Q_OBJECT bool noStretch = true;
public: bool isSectionResized = false;
using QWidget::QWidget; bool blocked = false;
protected:
void resizeEvent(QResizeEvent *) override {emit resized();}
signals:
void resized();
}; };
@ -340,43 +534,43 @@ public:
Wrp(T *obj = nullptr){ Wrp(T *obj = nullptr){
this->obj = obj; this->obj = obj;
}; };
inline Wrp& operator()(T *obj){ Wrp& operator()(T *obj){
this->obj = obj; this->obj = obj;
return *this; return *this;
} }
inline Wrp& operator()(T *obj, QLayout *layout){ Wrp& operator()(T *obj, QLayout *layout){
this->obj = obj; this->obj = obj;
layout->addWidget(obj); layout->addWidget(obj);
return *this; return *this;
} }
inline Wrp& addTo(QLayout *layout){ Wrp& addTo(QLayout *layout){
layout->addWidget(obj); layout->addWidget(obj);
return *this; return *this;
} }
inline Wrp& margin(int a){ Wrp& margin(int a){
obj->setMargin(a); obj->setMargin(a);
return *this; return *this;
} }
inline Wrp& font(const QFont &font){ Wrp& font(const QFont &font){
obj->setFont(font); obj->setFont(font);
return *this; return *this;
} }
inline Wrp& font(int size){ Wrp& font(int size){
auto font = obj->font(); auto font = obj->font();
font.setPixelSize(size); font.setPixelSize(size);
obj->setFont(font); obj->setFont(font);
return *this; return *this;
} }
inline Wrp& width(int w){ Wrp& width(int w){
obj->setFixedWidth(w); obj->setFixedWidth(w);
return *this; return *this;
} }
inline Wrp& height(int h){ Wrp& height(int h){
obj->setFixedHeight(h); obj->setFixedHeight(h);
return *this; return *this;
} }
inline Wrp& padding(int wAdd, int hAdd, int minW = 32, int minH = 16){ Wrp& padding(int wAdd, int hAdd, int minW = 32, int minH = 16){
wAdd+=8; wAdd+=8;
hAdd+=8; hAdd+=8;
QSize size = obj->fontMetrics().size(Qt::TextShowMnemonic, obj->text()); QSize size = obj->fontMetrics().size(Qt::TextShowMnemonic, obj->text());
@ -390,11 +584,11 @@ public:
return *this; return *this;
} }
inline Wrp& alignC(){ Wrp& alignC(){
obj->setAlignment(Qt::AlignCenter); obj->setAlignment(Qt::AlignCenter);
return *this; return *this;
} }
inline Wrp& alignR(){ Wrp& alignR(){
obj->setAlignment(Qt::AlignRight); obj->setAlignment(Qt::AlignRight);
return *this; return *this;
} }

View File

@ -13,7 +13,7 @@ class JValue {
public: public:
int data[2]{0}; int data[2]{0};
enum Type { enum Type {
Null, Bool, Int, Long, Double, Obj, Array, Str Null, Bool, Int, Long, Ulong, Double, Obj, Array, Str
}; };
Type type{Null}; Type type{Null};
@ -21,6 +21,7 @@ public:
JValue(bool b) : type(Bool) {data[0] = b;} JValue(bool b) : type(Bool) {data[0] = b;}
JValue(int n) : type(Int) {data[0] = n;} JValue(int n) : type(Int) {data[0] = n;}
JValue(qint64 n) : type(Long) {*(qint64*) data = n;} JValue(qint64 n) : type(Long) {*(qint64*) data = n;}
JValue(quint64 n) : type(Ulong) {*(quint64*) data = n;}
JValue(double d) : type(Double) {*(double*) data = d;} JValue(double d) : type(Double) {*(double*) data = d;}
JValue(const JObj &o) : type(Obj) {new (data) JObj(o);} JValue(const JObj &o) : type(Obj) {new (data) JObj(o);}
JValue(const JArray &a) : type(Array) {new (data) JArray(a);} JValue(const JArray &a) : type(Array) {new (data) JArray(a);}
@ -61,29 +62,33 @@ public:
return type==Null ? def : data[0] || data[1]; return type==Null ? def : data[0] || data[1];
} }
int toInt(int def = 0) const { int toInt(int def = 0) const {
if(type==Bool || type==Int) return data[0]; if(type==Int || type==Bool) return data[0];
if(type==Long) return *(qint64*) data;
if(type==Double) return *(double*) data; if(type==Double) return *(double*) data;
if(type==Long) return *(qint64*) data;
if(type==Ulong) return *(quint64*) data;
return def; return def;
} }
qint64 toLong(qint64 def = 0) const { qint64 toLong(qint64 def = 0) const {
if(type==Bool || type==Int) return data[0];
if(type==Long) return *(qint64*) data; if(type==Long) return *(qint64*) data;
if(type==Ulong) return *(quint64*) data;
if(type==Int || type==Bool) return data[0];
if(type==Double) return *(double*) data; if(type==Double) return *(double*) data;
return def; return def;
} }
double toDouble(double def = 0) const { double toDouble(double def = 0) const {
if(type==Bool || type==Int) return data[0];
if(type==Long) return *(qint64*) data;
if(type==Double) return *(double*) data; if(type==Double) return *(double*) data;
if(type==Int || type==Bool) return data[0];
if(type==Long) return *(qint64*) data;
if(type==Ulong) return *(quint64*) data;
return def; return def;
} }
QString toStr(const QString &def = "") const { QString toStr(const QString &def = "") const {
if(type==Bool) return data[0] ? "true" : "false";
if(type==Int) return QString::number(data[0]);
if(type==Long) return QString::number(*(qint64*) data);
if(type==Double) return QString::number(*(double*) data);
if(type==Str) return (*(SharedData<QString>**) data)->data; if(type==Str) return (*(SharedData<QString>**) data)->data;
if(type==Int) return QString::number(data[0]);
if(type==Double) return QString::number(*(double*) data);
if(type==Bool) return data[0] ? "true" : "false";
if(type==Long) return QString::number(*(qint64*) data);
if(type==Ulong) return QString::number(*(quint64*) data);
return def; return def;
} }
JObj toObj() const { JObj toObj() const {

View File

@ -32,11 +32,14 @@ win32 {
copydir.files += translations copydir.files += translations
copy.files += $$files(files/*.ic)
win32 { win32 {
EXE_SUFFIX = .exe EXE_SUFFIX = .exe
copy.path = $$OUT_PWD
copydir.path = $$OUT_PWD copydir.path = $$OUT_PWD
CONFIG += file_copies CONFIG += file_copies
COPIES += copy
COPIES += copydir COPIES += copydir
} }
osx { osx {
@ -61,6 +64,7 @@ SOURCES += \
crc.c \ crc.c \
expertboxlayoutwin.cpp \ expertboxlayoutwin.cpp \
expertscreenconnwin.cpp \ expertscreenconnwin.cpp \
expertsendpanel.cpp \
expertsmartpointsetwin.cpp \ expertsmartpointsetwin.cpp \
expertwin.cpp \ expertwin.cpp \
fast.cpp \ fast.cpp \
@ -71,7 +75,6 @@ SOURCES += \
main.cpp \ main.cpp \
mainwin.cpp \ mainwin.cpp \
pcaprethread.cpp \ pcaprethread.cpp \
screenunit.cpp \
testwin.cpp \ testwin.cpp \
videowin.cpp \ videowin.cpp \
waitingdlg.cpp waitingdlg.cpp
@ -83,6 +86,7 @@ HEADERS += \
efffrefr.h \ efffrefr.h \
expertboxlayoutwin.h \ expertboxlayoutwin.h \
expertscreenconnwin.h \ expertscreenconnwin.h \
expertsendpanel.h \
expertsmartpointsetwin.h \ expertsmartpointsetwin.h \
expertwin.h \ expertwin.h \
fast.h \ fast.h \
@ -92,7 +96,6 @@ HEADERS += \
gutil/qjson.h \ gutil/qjson.h \
mainwin.h \ mainwin.h \
pcaprethread.h \ pcaprethread.h \
screenunit.h \
testwin.h \ testwin.h \
videowin.h \ videowin.h \
waitingdlg.h waitingdlg.h

View File

@ -93,7 +93,9 @@ MainWin::MainWin() {
}); });
btnImg = addImg(imgsBar, QPixmap(":/imgs/expert.png").scaledToWidth(128, Qt::SmoothTransformation), tr("专家调屏")); btnImg = addImg(imgsBar, QPixmap(":/imgs/expert.png").scaledToWidth(128, Qt::SmoothTransformation), tr("专家调屏"));
connect(btnImg, &ImgBtn::clicked, this, [=] { connect(btnImg, &ImgBtn::clicked, this, [=] {
(new ExpertWin(this, (enum_rcvCardType) table->data(table->currentRow(), "type").toInt()))->show(); auto item = table->selectedItem();
if(item) (new ExpertWin(this, (enum_rcvCardType) item->data("type").toInt()))->show();
else if(QMessageBox::question(this, "Info", tr("未选择卡, 是否继续?"))==QMessageBox::Yes) (new ExpertWin(this, NoCard))->show();
}); });
btnImg = addImg(imgsBar, QPixmap(":/imgs/bright.png").scaledToWidth(128, Qt::SmoothTransformation), tr("亮度控制")); btnImg = addImg(imgsBar, QPixmap(":/imgs/bright.png").scaledToWidth(128, Qt::SmoothTransformation), tr("亮度控制"));
connect(btnImg, &ImgBtn::clicked, this, [=] { connect(btnImg, &ImgBtn::clicked, this, [=] {
@ -125,7 +127,8 @@ MainWin::MainWin() {
vBox->addSpacing(9); vBox->addSpacing(9);
vBox->addWidget(new QLabel(" 硬件信息")); vBox->addWidget(new QLabel(" 硬件信息"));
table = new Table{ table = new TreeWidget{
{"_num_", "", 20},
{"type", "控制系统类型"}, {"type", "控制系统类型"},
{"name", "名称"}, {"name", "名称"},
{"link", "连接方式"}, {"link", "连接方式"},
@ -133,8 +136,10 @@ MainWin::MainWin() {
{"netPorts", "网口统计P1~Pn"}, {"netPorts", "网口统计P1~Pn"},
{"info", "其他信息", QHeaderView::Stretch}, {"info", "其他信息", QHeaderView::Stretch},
}; };
table->verticalHeader()->setMinimumWidth(20);//added by alahover 20230822
table->setDefs(); table->setDefs();
table->setSortingEnabled(true);
table->sortItems("name");
table->setStyleSheet("TreeWidget::item{height: 26px;}");
vBox->addWidget(table); vBox->addWidget(table);
auto hBox = new HBox(vBox); auto hBox = new HBox(vBox);
@ -201,7 +206,6 @@ MainWin::MainWin() {
bool ok = true; bool ok = true;
if(senderAddress.protocol()==QUdpSocket::IPv6Protocol) senderAddress.setAddress(senderAddress.toIPv4Address(&ok)); if(senderAddress.protocol()==QUdpSocket::IPv6Protocol) senderAddress.setAddress(senderAddress.toIPv4Address(&ok));
auto addr = ok ? senderAddress.toString() : ""; auto addr = ok ? senderAddress.toString() : "";
int cnt = table->rowCount();
if(data.startsWith("{\"")) { if(data.startsWith("{\"")) {
QString error; QString error;
auto json = JFrom(gram.data(), &error); auto json = JFrom(gram.data(), &error);
@ -210,56 +214,50 @@ MainWin::MainWin() {
continue; continue;
} }
auto cardId = json["cardId"].toStr(); auto cardId = json["cardId"].toStr();
for(int rr=0; rr<cnt; rr++) if(table->text(rr, "name")==cardId) { TreeWidgetItem *item;
table->setText(rr, "link", addr); for(int rr=0; rr<table->topLevelItemCount(); rr++) if((item = table->item(rr))->text("name")==cardId) {
item->setText("link", addr);
goto end; goto end;
} }
table->setRowCount(cnt+1); item = new TreeWidgetItem(table);
table->setData(cnt, "type", enum_xixun_async)->setText(tr("异步卡"));//added by alahover 20230822 item->setText("type", tr("异步卡"), enum_xixun_async);
table->setText(cnt, "name", cardId); item->setText("name", cardId);
table->setText(cnt, "link", addr); item->setText("link", addr);
} else { } else {
auto bytes = gram.data(); auto bytes = gram.data();
auto packet = (UDPPacket *)bytes.data(); auto packet = (UDPPacket *)bytes.data();
for(int rr=0; rr<cnt; rr++) if(table->text(rr, "name")==packet->serialCode) { TreeWidgetItem *item;
table->setText(rr, "link", addr); for(int rr=0; rr<table->topLevelItemCount(); rr++) if((item = table->item(rr))->text("name")==packet->serialCode) {
item->setText("link", addr);
goto end; goto end;
} }
table->setRowCount(cnt+1); item = new TreeWidgetItem(table);
table->setData(cnt, "type", enum_xixun_async)->setText(tr("异步卡")); item->setText("type", tr("异步卡"), enum_xixun_async);
table->setText(cnt, "name", packet->serialCode); item->setText("name", packet->serialCode);
table->setText(cnt, "link", addr); item->setText("link", addr);
} }
end:; end:;
} }
}); });
reThd->addMultiCallback(0x105B14, [=](int, const QByteArray data) { reThd->addMultiCallback(0x105B14, [=](int, const QByteArray data) {
auto rr = table->rowCount();
unsigned short ver = *(quint16_be *)(data.data()+headMap_zrf.protcolFlag); unsigned short ver = *(quint16_be *)(data.data()+headMap_zrf.protcolFlag);
unsigned char pkgType = *(quint8 *)(data.data()+headMap_zrf.pkgType); unsigned char pkgType = *(quint8 *)(data.data()+headMap_zrf.pkgType);
if(ver!=0x105B || pkgType != 0x14) return; if(ver!=0x105B || pkgType != 0x14) return;
auto strDeviceName = QString(QLatin1String(data.data()+headMap_zrf.paramStart+st_zrf_rb_param.deviceName, 9)); auto strDeviceName = QString(QLatin1String(data.data()+headMap_zrf.paramStart+st_zrf_rb_param.deviceName, 9));
for(int i=0;i<rr;i++) if(table->text(i,1)==strDeviceName) { TreeWidgetItem *item;
rr = i; for(int i=0; i<table->topLevelItemCount(); i++) if((item = table->item(i))->text("name")==strDeviceName) goto end;
goto end; item = new TreeWidgetItem(table);
}
table->setRowCount(rr+1);
end: end:
char cDevicaNameVer[8]; int virtualVCM = *(quint8*)(data.data()+headMap_zrf.netPort) + 1;
memcpy(cDevicaNameVer,(char *)data.data()+headMap_zrf.paramStart+st_zrf_rb_param.deviceVer,8); int rcvIdex = *(quint8*)(data.data()+headMap_zrf.rcvIndex) + 1;
QString strDeviceVer = QString(QLatin1String(cDevicaNameVer));
strDeviceVer=strDeviceVer.left(8);
int virtualVCM = *(quint8*)(data.data()+headMap_zrf.netPort)+1;
int rcvIdex = *(quint8*)(data.data()+headMap_zrf.rcvIndex)+1;
if(rcvIdex > maxNetPort_zrf) maxNetPort_zrf = rcvIdex; if(rcvIdex > maxNetPort_zrf) maxNetPort_zrf = rcvIdex;
table->setData(rr, "type", enum_zrf)->setText(tr("PC虚拟卡V1.0")); item->setText("type", tr("PC虚拟卡V1.0"), enum_zrf);
table->setText(rr, "name", strDeviceName); item->setText("name", strDeviceName);
table->setText(rr, "link", "千兆网直连"); item->setText("link", "千兆网直连");
table->setText(rr, "vcsNum", QString::number(maxNetPort_zrf)); item->setText("vcsNum", QString::number(maxNetPort_zrf));
table->setText(rr, "netPorts", "P:"+QString::number(virtualVCM)); item->setText("netPorts", "P: "+QString::number(virtualVCM));
table->setText(rr, "info", "版本: "+strDeviceVer+" [备注:可直接配屏,无需发送卡]"); item->setText("info", "版本: "+QLatin1String(data.data()+headMap_zrf.paramStart+st_zrf_rb_param.deviceVer, 8)+" [备注:可直接配屏,无需发送卡]");
if(rr==0) table->selectRow(0); if(table->selectedItem()==0) item->setSelected(true);
}); });
getCard(); getCard();
} }
@ -270,22 +268,22 @@ MainWin::~MainWin() {
} }
void MainWin::getCard() { void MainWin::getCard() {
table->setRowCount(0); table->clear();
auto msg = QByteArray::fromHex("5555 01 0D 0008 FFFFFFFF 0000ABCD A0000000 0000 38CB847E 00000000 0000ABCD CD040446"); auto msg = QByteArray::fromHex("5555 01 0D 0008 FFFFFFFF 0000ABCD A0000000 0000 38CB847E 00000000 0000ABCD CD040446");
auto res = sendMsg(msg, 0x1E0, 10000, [=](int, const QByteArray data) { auto res = sendMsg(msg, 0x1E0, 10000, [=](int, const QByteArray data) {
if(*(quint32_be*)(data.data()+headMap.ptr) != 0xA0000000) return; if(*(quint32_be*)(data.data()+headMap.ptr) != 0xA0000000) return;
auto rr = table->rowCount(); auto item = new TreeWidgetItem(table);
table->setRowCount(rr+1);
int virtualVCM = *(quint16_be*)(data.data()+headMap.srcAddr); int virtualVCM = *(quint16_be*)(data.data()+headMap.srcAddr);
//modified by alahover -s 20230822 //modified by alahover -s 20230822
auto ver = *(byte*)(data.data()+headMap.ver); auto ver = *(byte*)(data.data()+headMap.ver);
if(ver==0x01) table->setData(rr, "type", enum_xixun_sync)->setText(tr("PC虚拟卡V0.0")); if(ver==0x01) item->setText("type", tr("PC虚拟卡V0.0"), enum_xixun_sync);
else if(ver==0x58) table->setData(rr, "type", enum_zrf)->setText(tr("PC虚拟卡V1.0")); else if(ver==0x58) item->setText("type", tr("PC虚拟卡V1.0"), enum_zrf);
table->setText(rr, "name", tr("网口:")+QString::number(virtualVCM)); item->setText("name", QString::number(virtualVCM)+" (网口)");
table->setText(rr, "link", "千兆网直连"); item->setText("link", "千兆网直连");
table->setText(rr, "vcsNum", QString::number(*(quint32_be*)(data.data()+headMap.body))); item->setText("vcsNum", QString::number(*(quint32_be*)(data.data()+headMap.body)));
table->setText(rr, "netPorts", "P:"+QString::number(virtualVCM)); item->setText("netPorts", "P: "+QString::number(virtualVCM));
table->setText(rr, "info", "备注:可直接配屏,无需发送卡"); item->setText("info", "备注: 可直接配屏,无需发送卡");
if(table->selectedItem()==0) item->setSelected(true);
}); });
if(res) { if(res) {
QString err = pcap_geterr(pcapSend); QString err = pcap_geterr(pcapSend);

View File

@ -12,7 +12,7 @@ public:
~MainWin(); ~MainWin();
QWidget *win{0}; QWidget *win{0};
QByteArray net_name; QByteArray net_name;
Table *table{0}; TreeWidget *table;
QUdpSocket mUdpSocket; QUdpSocket mUdpSocket;
int maxNetPort_zrf = 0; int maxNetPort_zrf = 0;

View File

@ -1,37 +0,0 @@
#ifndef SCREENUNIT_H
#define SCREENUNIT_H
#include <QWidget>
#include <QVBoxLayout>
#include <QPen>
#define m_handleLen 10
class ExpertWin;
class ScreenUnit : public QWidget {
Q_OBJECT
public:
explicit ScreenUnit(ExpertWin *, const QString &name, int x, int y, int w, int h, QWidget *parent = nullptr);
ExpertWin *expertWin{0};
QString name;
int mX, mY, mW, mH;
protected:
void paintEvent(QPaintEvent *) override;
void mousePressEvent(QMouseEvent *) override;
void mouseReleaseEvent(QMouseEvent *) override;
void mouseMoveEvent(QMouseEvent *) override;
void leaveEvent(QEvent *) override;
void setFrmSec(const QPoint &);
void setFrmSecIfNeed(Qt::WindowFrameSection frmSec, Qt::CursorShape cursor);
void clearSnap();
QPen mSidePen{Qt::white};
QPoint mPressRel{INT_MIN, INT_MIN};
Qt::WindowFrameSection mFrmSec{Qt::NoSection};
char mLRSnap{0}, mTBSnap{0};
QList<ScreenUnit *> mOtherEles;
};
#endif // SCREENUNIT_H