ledset
This commit is contained in:
parent
4dfe9a37b9
commit
d5d5984aa5
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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
|
|
@ -557,6 +557,13 @@ void ModuleUnit::drawed() {
|
|||
auto btn = box->boxWin->grpGrp->checkedButton();
|
||||
if(btn==0) return;
|
||||
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));
|
||||
btn->setProperty("mods", mods);
|
||||
name = "G"+QString::number(box->boxWin->grpGrp->id(btn)+1)+"-"+QString::number(mods.size());
|
||||
|
|
|
@ -89,7 +89,7 @@ ExpertScreenConnWin::ExpertScreenConnWin(QWidget *parent) : QSplitter{parent} {
|
|||
|
||||
auto pal = palette();
|
||||
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));
|
||||
bn->setMaximumWidth(30);
|
||||
bn->setMinimumHeight(30);
|
||||
|
@ -156,7 +156,7 @@ ExpertScreenConnWin::ExpertScreenConnWin(QWidget *parent) : QSplitter{parent} {
|
|||
auto bnRefresh = new QPushButton(tr("重新开始"));
|
||||
connect(bnRefresh, &QPushButton::clicked, this, [this] {
|
||||
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);
|
||||
|
||||
|
@ -172,10 +172,8 @@ ExpertScreenConnWin::ExpertScreenConnWin(QWidget *parent) : QSplitter{parent} {
|
|||
table = new CardTable(fdCardRowNum->value(), fdCardColNum->value());
|
||||
table->win = this;
|
||||
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
table->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter);
|
||||
table->horizontalHeader()->setDefaultSectionSize(90);
|
||||
table->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
|
||||
table->verticalHeader()->setDefaultAlignment(Qt::AlignCenter);
|
||||
table->verticalHeader()->setDefaultSectionSize(90);
|
||||
table->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
|
||||
table->verticalHeader()->setMinimumWidth(30);
|
||||
|
@ -195,7 +193,7 @@ void ExpertScreenConnWin::conn(int row, int column) {
|
|||
auto item = table->item(row, column);
|
||||
if(item) return;
|
||||
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()));
|
||||
auto color = cardColors[netIdx % (sizeof(cardColors)/sizeof(cardColors[0]))];
|
||||
item->setForeground(QColor(255,255,255));
|
||||
|
@ -207,9 +205,10 @@ void ExpertScreenConnWin::conn(int row, int column) {
|
|||
}
|
||||
void ExpertScreenConnWin::connBack() {
|
||||
auto netIdx = fdNet->checkedId();
|
||||
if(netss[netIdx].isEmpty()) return;
|
||||
if(netss[netIdx].empty()) return;
|
||||
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->update();
|
||||
}
|
||||
|
@ -217,7 +216,7 @@ void ExpertScreenConnWin::connBack() {
|
|||
void CardTable::paintEvent(QPaintEvent *event) {
|
||||
QTableWidget::paintEvent(event);
|
||||
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();
|
||||
if(size < 2) continue;
|
||||
QColor a=cardColors[i % (sizeof(cardColors)/sizeof(cardColors[0]))];
|
||||
|
|
|
@ -17,7 +17,7 @@ public:
|
|||
QSpinBox *fdCardWidth;
|
||||
QSpinBox *fdCardHeight;
|
||||
CardTable *table;
|
||||
QList<QList<QPoint>> netss{QList<QPoint>{}, QList<QPoint>{}, QList<QPoint>{}, QList<QPoint>{}};
|
||||
std::vector<QPoint> netss[4]{};
|
||||
};
|
||||
|
||||
class CardTable : public QTableWidget {
|
||||
|
|
|
@ -1,17 +1,133 @@
|
|||
#include "screenunit.h"
|
||||
#include "expertwin.h"
|
||||
#include <QDirIterator>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <QLabel>
|
||||
#include <QPainter>
|
||||
#include <QSpinBox>
|
||||
|
||||
#include "expertsendpanel.h"
|
||||
#include "gutil/qgui.h"
|
||||
#include <QLineEdit>
|
||||
#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);
|
||||
setMouseTracking(true);
|
||||
auto font = this->font();
|
||||
|
@ -77,7 +193,7 @@ void ScreenUnit::mousePressEvent(QMouseEvent *e) {
|
|||
foreach(auto item, items) {
|
||||
if(item==this) continue;
|
||||
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;
|
||||
if(dstVer==0) mTBSnap = 1;
|
||||
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()) {
|
||||
dstHor = ele->x();
|
||||
mLRSnap = 1;
|
||||
|
@ -141,7 +257,7 @@ void ScreenUnit::mouseMoveEvent(QMouseEvent *e){
|
|||
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()) {
|
||||
dstVer = ele->y();
|
||||
mTBSnap = 1;
|
||||
|
@ -191,7 +307,7 @@ void ScreenUnit::mouseMoveEvent(QMouseEvent *e){
|
|||
if(dstHor < m_handleLen) dstHor = m_handleLen;
|
||||
if(expertWin->screenWidth>0 && expertWin->screenHeight>0) dstHor = qMin(dstHor, expertWin->screenWidth - x());
|
||||
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) {
|
||||
dstHor = ele->x() - x();
|
||||
mLRSnap = 2;
|
||||
|
@ -214,7 +330,7 @@ void ScreenUnit::mouseMoveEvent(QMouseEvent *e){
|
|||
if(dstVer < m_handleLen) dstVer = m_handleLen;
|
||||
if(expertWin->screenWidth>0 && expertWin->screenHeight>0) dstVer = qMin(dstVer, expertWin->screenHeight - y());
|
||||
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();
|
||||
if(abs(btm - ele->y()) < SnapSpace) {
|
||||
dstVer = ele->y() - y();
|
||||
|
@ -238,7 +354,7 @@ void ScreenUnit::mouseMoveEvent(QMouseEvent *e){
|
|||
if(mFrmSec==Qt::LeftSection) {
|
||||
dstHor = qMin(dstHor, geo.right() - m_handleLen);
|
||||
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) {
|
||||
dstHor = ele->x();
|
||||
mLRSnap = 1;
|
||||
|
@ -259,7 +375,7 @@ void ScreenUnit::mouseMoveEvent(QMouseEvent *e){
|
|||
} else if(mFrmSec==Qt::TopSection) {
|
||||
dstVer = qMin(dstVer, geo.bottom() - m_handleLen);
|
||||
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) {
|
||||
dstVer = ele->y();
|
||||
mTBSnap = 1;
|
|
@ -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
|
|
@ -698,7 +698,7 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(ExpertWin *expertWin) : BaseWin{e
|
|||
table->clearContents();
|
||||
tableRow->setColumnCount(0);
|
||||
virtualCnt = 0;
|
||||
scans.clear();
|
||||
rows.clear();
|
||||
});
|
||||
hhh->addWidget(btnReset);
|
||||
|
||||
|
@ -713,32 +713,28 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(ExpertWin *expertWin) : BaseWin{e
|
|||
table = new Table;
|
||||
table->setEditTriggers(Table::NoEditTriggers);
|
||||
table->setSelectionMode(QTableWidget::SingleSelection);
|
||||
table->setColWidth(35)->setRowHeight(24, QHeaderView::Fixed);
|
||||
table->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter);
|
||||
table->verticalHeader()->setMinimumWidth(35);
|
||||
table->verticalHeader()->setDefaultAlignment(Qt::AlignCenter);
|
||||
table->setColWidth(32)->setRowHeight(24)->setRowResize(QHeaderView::Fixed);
|
||||
connect(table, &QTableWidget::currentCellChanged, this, [=](int row, int col) {
|
||||
if(row < 0) return;
|
||||
auto text = table->text(row, col);
|
||||
if(! text.isEmpty()) return;
|
||||
if(scans.isEmpty()) {
|
||||
if(rows.empty()) {
|
||||
auto cnt = tableRow->columnCount() + 1;
|
||||
tableRow->setColumnCount(cnt);
|
||||
tableRow->setText(0, cnt-1, QString::number(cnt))->setTextAlignment(Qt::AlignCenter);
|
||||
tableRow->setText(1, cnt-1, "√")->setTextAlignment(Qt::AlignCenter);
|
||||
tableRow->setData(1, cnt-1, QPoint{col, row});
|
||||
tableRow->setText(1, cnt-1, "√", QPoint{col, row})->setTextAlignment(Qt::AlignCenter);
|
||||
auto realCnt = cnt - virtualCnt;
|
||||
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);
|
||||
} else {
|
||||
QMessageBox::information(this, tr("提示"), tr("列走完"));
|
||||
scans.append({col, row});
|
||||
rows.emplace_back(tableRow->data(1, 1).toPoint());
|
||||
send(0x11, {0x01400000u | (1<<10)});
|
||||
}
|
||||
} else if(scans.size() < ScanNum) {
|
||||
scans.append({col, row});
|
||||
auto size = scans.size();
|
||||
} else if((int)rows.size() < ScanNum) {
|
||||
rows.emplace_back(QPoint{col, row});
|
||||
auto size = rows.size();
|
||||
table->setText(row, col, "S"+QString::number(size))->setTextAlignment(Qt::AlignCenter);
|
||||
if(size!=ScanNum) {
|
||||
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->setEditTriggers(Table::NoEditTriggers);
|
||||
tableRow->setSelectionMode(QTableWidget::NoSelection);
|
||||
tableRow->setColWidth(35);
|
||||
tableRow->setRowHeight(24);
|
||||
tableRow->setColWidth(32)->setRowHeight(24)->setRowResize(QHeaderView::Fixed);
|
||||
tableRow->horizontalHeader()->setVisible(false);
|
||||
tableRow->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
|
||||
tableRow->verticalHeader()->setMinimumWidth(120);
|
||||
tableRow->setMaximumHeight(50);
|
||||
tableRow->setVHeaderText(0, tr("第一扫灯数:"));
|
||||
|
@ -789,7 +783,7 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(ExpertWin *expertWin) : BaseWin{e
|
|||
ModuleWidth = fdModuleWidth->value();
|
||||
ModuleHeight = fdModuleHeight->value();
|
||||
GroupNum = fdGroupNum->value();
|
||||
ScanNum = (ModuleHeight + 1) / GroupNum;
|
||||
ScanNum = (ModuleHeight + GroupNum - 1) / GroupNum;
|
||||
ChipType = fdChipType->text();
|
||||
DecodeMode = fdDecodeMode->text();
|
||||
GroupMode = fdGroupMode->currentText();
|
||||
|
@ -813,7 +807,7 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(ExpertWin *expertWin) : BaseWin{e
|
|||
auto groupNum = unitptr+modUnitMap.smartsetRes + 1;
|
||||
*groupNum = GroupNum;
|
||||
auto scanNum = unitptr+modUnitMap.smartsetRes + 3;
|
||||
*scanNum = ModuleHeight / GroupNum;
|
||||
*scanNum = ScanNum;
|
||||
auto 走点len = (quint32_be*)(unitptr+modUnitMap.走点len);
|
||||
*走点len = (ModuleWidth+15) / 16 * 16;
|
||||
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;
|
||||
} else if(idx==3) {
|
||||
RowPerScan = fdLightNum->value();
|
||||
ScanNum = (ScanNum + RowPerScan - 1) / RowPerScan;
|
||||
res12 &= ~0xffffu;
|
||||
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;
|
||||
} else if(idx==4) {
|
||||
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");
|
||||
msg.append((data.size()+1)<<2, 0);
|
||||
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 |= data.size()<<2;
|
||||
*plen |= (quint16) data.size()<<2;
|
||||
auto pptr = (quint32_be*)(msg.data()+headMap.ptr);
|
||||
*pptr |= ptr;
|
||||
pptr = (quint32_be*)(msg.data()+headMap.body);
|
||||
|
@ -922,28 +917,49 @@ void ExpertSmartPointSetWin::save() {
|
|||
obj.insert("ModuleWidth", ModuleWidth);
|
||||
obj.insert("ModuleHeight", ModuleHeight);
|
||||
obj.insert("GroupNum", GroupNum);
|
||||
obj.insert("ScanNum", ScanNum);
|
||||
obj.insert("ChipType", ChipType);
|
||||
obj.insert("DecodeMode", DecodeMode);
|
||||
obj.insert("GroupMode", GroupMode);
|
||||
obj.insert("ReverseGroup", ReverseGroup);
|
||||
obj.insert("DataPolarity", DataPolarity);
|
||||
obj.insert("OePolarity", OePolarity);
|
||||
obj.insert("ScanNum", ScanNum);
|
||||
obj.insert("ColorMap", ColorMap);
|
||||
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();
|
||||
if(cnt > ModuleWidth) {
|
||||
auto add = (cnt+ModuleWidth-1) / ModuleWidth * ModuleWidth - cnt;
|
||||
for(int i=0; i<add; i++) points.append(-1);
|
||||
if(cnt > ModuleWidth*RowPerScan) {
|
||||
auto add = cnt % ModuleWidth;
|
||||
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--) {
|
||||
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);
|
||||
JArray Scans;
|
||||
for(QPoint scan : scans) Scans.append(scan.y());
|
||||
obj.insert("Scans", Scans);
|
||||
delete [] cols;
|
||||
JArray pos_item_info;
|
||||
for(int i=cnt-1; i>=0; i--) {
|
||||
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 res = qFile.write(data);
|
||||
qFile.close();
|
||||
|
|
|
@ -20,7 +20,7 @@ public:
|
|||
|
||||
Table *table, *tableRow;
|
||||
int virtualCnt = 0;
|
||||
QList<QPoint> scans;
|
||||
std::vector<QPoint> rows;
|
||||
|
||||
QRadioButton *fdRow, *fdCol;
|
||||
QSpinBox *fdModuleWidth, *fdModuleHeight, *fdGroupNum;
|
||||
|
@ -29,7 +29,7 @@ public:
|
|||
QComboBox *fdGroupMode;
|
||||
int ModuleWidth{32}, ModuleHeight{16}, GroupNum{2}, ScanNum{4};
|
||||
int ChipTypeCode, DecodeModeCode;
|
||||
bool DataPolarity{true}, OePolarity{false};
|
||||
bool ReverseGroup = false, DataPolarity = true, OePolarity = false;
|
||||
int ColorMap;
|
||||
QString ChipType, DecodeMode, GroupMode;
|
||||
|
||||
|
|
1503
ledset/expertwin.cpp
1503
ledset/expertwin.cpp
File diff suppressed because it is too large
Load Diff
|
@ -8,6 +8,7 @@
|
|||
#include <QComboBox>
|
||||
#include <QCheckBox>
|
||||
#include <QRadioButton>
|
||||
#include <QStackedLayout>
|
||||
|
||||
class ExpertWin : public BaseWin {
|
||||
Q_OBJECT
|
||||
|
@ -15,11 +16,9 @@ public:
|
|||
explicit ExpertWin(QWidget *parent, int);
|
||||
|
||||
QByteArray savedData();
|
||||
JObj connSavedData();
|
||||
void addMapData(QByteArray &);
|
||||
|
||||
int screenWidth{1280}, screenHeight{720};
|
||||
double rate{1};
|
||||
|
||||
QLabel *fdModuleWidth, *fdModuleHeight, *fdGroupNum, *fdScanNum, *fdDataGroupColor ,*fdChouDian;
|
||||
QLabel *fdChipType, *fdDecodeMode;
|
||||
JObj cfg;
|
||||
|
@ -39,13 +38,12 @@ public:
|
|||
{"GroupMode", "三线并行"}
|
||||
};
|
||||
|
||||
QStackedLayout *connStack;
|
||||
QSpinBox *fdCardWidth, *fdCardHeight;
|
||||
QComboBox *fdDirection, *fdSectorCount;
|
||||
QRadioButton *fdAdvacned;
|
||||
|
||||
//added by alahover -s 20230830
|
||||
QPushButton *btnReadBack,*btn_OpenCfg,*btn_SaveCfg,*btn_SaveMap,*btn_SendData,*btn_GuhuaData;
|
||||
QTabWidget * m_tab;
|
||||
QPushButton *btnConnReadBack, *btnReceiveReadBack;
|
||||
QSpinBox *spinGclkXw,*spinGclkZkb,*spinLineNs,*spinLineWz,*spinLineXy,*spinPointsOnePort;
|
||||
QComboBox *cbDCLKf,*cbDclkXw, *cbDclkZkb,*freshBeiLv,*cbGCLKf,*cbGryLevel,*cbNoSign,*cbStb,*cbDE,*cbABC,*cbXiaoYinDianPing,*cbSTB,*cbSRowOut;
|
||||
QLabel * m_ctrlFreshRate,*m_ctrlBrightEff,*m_ctrlMinOE;
|
||||
|
@ -55,8 +53,8 @@ public:
|
|||
//added by alahover -o 20230830
|
||||
//added by alahover -s 20230817
|
||||
int m_iRcvCardType;
|
||||
int m_tab1firstClick=0;
|
||||
int m_tab2firstClick=0;
|
||||
bool needInit1 = true;
|
||||
bool needInit2 = true;
|
||||
|
||||
struct St_Rcv_Pos{
|
||||
unsigned char imgXL8 = 0;//接收卡图像列起始低八位
|
||||
|
@ -288,8 +286,6 @@ protected:
|
|||
void closeEvent(QCloseEvent *) override;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define MACRO_FUNC_SEND_PARAM(TIP_MESSAGE,FUNC,SEND_FLASHPAGE_NUM,FLASH_ADDR) \
|
||||
for(int iSendCount=0;iSendCount<SEND_FLASHPAGE_NUM;iSendCount++)\
|
||||
{\
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"普通译码" : 0,
|
||||
"138译码" : 0,
|
||||
"SM5266" : 1,
|
||||
"SM5366" : 2,
|
||||
"ICN2013" : 3,
|
||||
"无译码" : 4,
|
||||
"595译码" : 5,
|
||||
"5958译码" : 6,
|
||||
"ICND2018" : 16,
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -34,7 +34,8 @@ enum enum_rcvCardType{
|
|||
enum_xixun_sync = 0,
|
||||
enum_xixun_async = 1,
|
||||
enum_zrf = 2,
|
||||
enum_mxe
|
||||
enum_mxe,
|
||||
NoCard
|
||||
};
|
||||
struct HeadMap {
|
||||
byte pre = ipp(2);
|
||||
|
|
|
@ -1,44 +1,136 @@
|
|||
#include "qgui.h"
|
||||
#include <QPainter>
|
||||
#include <QResizeEvent>
|
||||
|
||||
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 i = 0;
|
||||
for(typename std::initializer_list<ColAttr>::const_iterator it = colAttrs.begin(); it != colAttrs.end(); ++it) {
|
||||
auto item = horizontalHeaderItem(i);
|
||||
if(item==0) setHorizontalHeaderItem(i, item = new QTableWidgetItem());
|
||||
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++);
|
||||
}
|
||||
int operator*(const QString& key, QTreeView &table) {
|
||||
return ((TreeWidget&)table).fdmap.at(key);
|
||||
}
|
||||
int operator*(const char *key, QTreeView &table) {
|
||||
return ((TreeWidget&)table).fdmap.at(key);
|
||||
}
|
||||
|
||||
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) {
|
||||
QTableWidget::resizeEvent(event);
|
||||
if(noStretch || event->size().width() == event->oldSize().width()) return;
|
||||
resizeSec();
|
||||
adjSections(-1, 0);
|
||||
}
|
||||
|
||||
void Table::resizeSec() {
|
||||
auto header = horizontalHeader();
|
||||
int colCnt = columnCount(), remainWidth = header->width(), stretchWidth = 0, secWidth;
|
||||
void Table::onSectionResized(int logicalIndex, int oldSize, int newSize) {
|
||||
if(blocked || noStretch || newSize==0 || oldSize==0) return;
|
||||
if(! horizontalHeaderItem(logicalIndex)->data(WidthRole).isValid()) return;
|
||||
if(adjSections(logicalIndex, newSize)) isSectionResized = true;
|
||||
}
|
||||
bool Table::adjSections(int index, int size) {
|
||||
QTableWidgetItem *item;
|
||||
for(int cc=0; cc<colCnt; cc++) if((item = horizontalHeaderItem(cc))) {
|
||||
if((secWidth = item->data(0x99).toInt()) > 0) stretchWidth += secWidth;
|
||||
else remainWidth -= header->sectionSize(cc);
|
||||
int remain = horizontalHeader()->width() - size, stretchWidth = 0, width;
|
||||
for(int cc=0; cc<columnCount(); cc++) if(cc!=index && (item = horizontalHeaderItem(cc))) {
|
||||
if((width = item->data(WidthRole).toInt()) > 0) stretchWidth += width;
|
||||
else remain -= horizontalHeader()->sectionSize(cc);
|
||||
}
|
||||
if(remainWidth<=0 || stretchWidth==0) return;
|
||||
for(int cc=0; cc<colCnt; cc++) if((item = horizontalHeaderItem(cc)) && (secWidth = item->data(0x99).toInt()) > 0) header->resizeSection(cc, secWidth * remainWidth / stretchWidth);
|
||||
}
|
||||
|
||||
void Table::updateGeometries() {
|
||||
QTableWidget::updateGeometries();
|
||||
emit updGeos();
|
||||
if(remain<=0 || stretchWidth==0) return false;
|
||||
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));
|
||||
blocked = false;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <QStackedLayout>
|
||||
#include <QTableWidget>
|
||||
#include <QTextEdit>
|
||||
#include <QTreeWidget>
|
||||
|
||||
#define MainMust \
|
||||
#if(QT_VERSION_MAJOR > 5) \
|
||||
|
@ -41,7 +42,7 @@ inline int SetCurData(QComboBox *combo, const QVariant &data) {
|
|||
if(idx>-1) combo->setCurrentIndex(idx);
|
||||
return idx;
|
||||
}
|
||||
inline int SetCurText(QComboBox *combo, const QString &text) {
|
||||
inline int SetCurText(QComboBox *combo, const QString& text) {
|
||||
auto idx = combo->findText(text);
|
||||
if(idx>-1) combo->setCurrentIndex(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);
|
||||
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();
|
||||
ft.setFamily(family);
|
||||
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);
|
||||
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);
|
||||
ft.setPixelSize(pixelSize);
|
||||
if(bold) ft.setBold(true);
|
||||
if(italic) ft.setItalic(true);
|
||||
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();
|
||||
wgt->setTextColor(color);
|
||||
wgt->append(text);
|
||||
|
@ -77,29 +78,29 @@ inline void gAppendText(QTextEdit *wgt, const QString &text, const QColor &color
|
|||
|
||||
class VBox : public QBoxLayout {
|
||||
public:
|
||||
inline VBox(QWidget *parent=nullptr) : QBoxLayout(TopToBottom, parent) {}
|
||||
inline VBox(QBoxLayout *parent) : QBoxLayout(TopToBottom) {
|
||||
VBox(QWidget *parent=nullptr) : QBoxLayout(TopToBottom, parent) {}
|
||||
VBox(QBoxLayout *parent) : QBoxLayout(TopToBottom) {
|
||||
parent->addLayout(this);
|
||||
};
|
||||
inline VBox(QStackedLayout *stack) : QBoxLayout(TopToBottom, new QWidget) {
|
||||
VBox(QStackedLayout *stack) : QBoxLayout(TopToBottom, new QWidget) {
|
||||
stack->addWidget(parentWidget());
|
||||
setContentsMargins(0,0,0,0);
|
||||
};
|
||||
inline VBox(QSplitter *splitter) : QBoxLayout(TopToBottom, new QWidget) {
|
||||
VBox(QSplitter *splitter) : QBoxLayout(TopToBottom, new QWidget) {
|
||||
splitter->addWidget(parentWidget());
|
||||
setContentsMargins(0,0,0,0);
|
||||
};
|
||||
inline QLabel *addLabel() {
|
||||
QLabel *addLabel() {
|
||||
auto lb = new QLabel;
|
||||
addWidget(lb);
|
||||
return lb;
|
||||
}
|
||||
inline QLabel *addLabel(const QString &text) {
|
||||
QLabel *addLabel(const QString& text) {
|
||||
auto lb = new QLabel(text);
|
||||
addWidget(lb);
|
||||
return lb;
|
||||
}
|
||||
inline QDialogButtonBox *addBtnBox(QDialog *dlg = 0) {
|
||||
QDialogButtonBox *addBtnBox(QDialog *dlg = 0) {
|
||||
auto btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
if(dlg) connect(btnBox, &QDialogButtonBox::rejected, dlg, &QDialog::reject);
|
||||
addWidget(btnBox);
|
||||
|
@ -108,24 +109,24 @@ public:
|
|||
};
|
||||
class HBox : public QBoxLayout {
|
||||
public:
|
||||
inline HBox(QWidget *parent=nullptr) : QBoxLayout(LeftToRight, parent) {}
|
||||
inline HBox(QBoxLayout *parent) : QBoxLayout(LeftToRight) {
|
||||
HBox(QWidget *parent=nullptr) : QBoxLayout(LeftToRight, parent) {}
|
||||
HBox(QBoxLayout *parent) : QBoxLayout(LeftToRight) {
|
||||
parent->addLayout(this);
|
||||
};
|
||||
inline HBox(QStackedLayout *stack) : QBoxLayout(LeftToRight, new QWidget) {
|
||||
HBox(QStackedLayout *stack) : QBoxLayout(LeftToRight, new QWidget) {
|
||||
stack->addWidget(parentWidget());
|
||||
setContentsMargins(0,0,0,0);
|
||||
};
|
||||
inline HBox(QSplitter *splitter) : QBoxLayout(LeftToRight, new QWidget) {
|
||||
HBox(QSplitter *splitter) : QBoxLayout(LeftToRight, new QWidget) {
|
||||
splitter->addWidget(parentWidget());
|
||||
setContentsMargins(0,0,0,0);
|
||||
};
|
||||
inline QLabel *addLabel() {
|
||||
QLabel *addLabel() {
|
||||
auto lb = new QLabel;
|
||||
addWidget(lb);
|
||||
return lb;
|
||||
}
|
||||
inline QLabel *addLabel(const QString &text) {
|
||||
QLabel *addLabel(const QString& text) {
|
||||
auto lb = new QLabel(text);
|
||||
addWidget(lb);
|
||||
return lb;
|
||||
|
@ -134,16 +135,16 @@ public:
|
|||
class Grid : public QGridLayout {
|
||||
public:
|
||||
using QGridLayout::QGridLayout;
|
||||
inline Grid(QBoxLayout *parent) {
|
||||
Grid(QBoxLayout *parent) {
|
||||
parent->addLayout(this);
|
||||
};
|
||||
inline Grid(QStackedLayout *stack) : QGridLayout(new QWidget) {
|
||||
Grid(QStackedLayout *stack) : QGridLayout(new QWidget) {
|
||||
stack->addWidget(parentWidget());
|
||||
};
|
||||
inline Grid(QSplitter *splitter) : QGridLayout(new QWidget) {
|
||||
Grid(QSplitter *splitter) : QGridLayout(new QWidget) {
|
||||
splitter->addWidget(parentWidget());
|
||||
};
|
||||
inline QLabel *addLabel(const QString &text) {
|
||||
QLabel *addLabel(const QString& text) {
|
||||
auto lb = new QLabel(text);
|
||||
addWidget(lb);
|
||||
return lb;
|
||||
|
@ -155,7 +156,7 @@ public:
|
|||
using QListWidget::QListWidget;
|
||||
|
||||
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);
|
||||
item->setData(Qt::UserRole, value);
|
||||
insertItem(count(), item);
|
||||
|
@ -164,13 +165,198 @@ public:
|
|||
};
|
||||
|
||||
struct ColAttr {
|
||||
ColAttr(QString field, 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, int width=0, QHeaderView::ResizeMode resizeMode = QHeaderView::Interactive) : field(field), text(text), width(width), resizeMode(resizeMode) {}
|
||||
ColAttr(const QString& field, const QString& text, QHeaderView::ResizeMode resizeMode) : field(field), text(text), resizeMode(resizeMode) {}
|
||||
QString field;
|
||||
QString text;
|
||||
int width{0};
|
||||
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 {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -178,158 +364,166 @@ public:
|
|||
Table() {}
|
||||
Table(std::initializer_list<ColAttr> colAttrs, int rows = 0, QWidget *parent = 0);
|
||||
|
||||
inline auto setDefs() {
|
||||
auto setDefs() {
|
||||
setSelectionBehavior(QTableWidget::SelectRows);
|
||||
setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
setAlternatingRowColors(true);
|
||||
return this;
|
||||
}
|
||||
inline auto setColStretch() {
|
||||
auto setColStretch() {
|
||||
horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
return this;
|
||||
}
|
||||
inline auto setRowStretch() {
|
||||
auto setRowStretch() {
|
||||
verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
return this;
|
||||
}
|
||||
inline auto setColFit() {
|
||||
auto setColFit() {
|
||||
horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
return this;
|
||||
}
|
||||
inline auto setRowFit() {
|
||||
auto setRowFit() {
|
||||
verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
return this;
|
||||
}
|
||||
inline auto setColWidth(int value, QHeaderView::ResizeMode mode = QHeaderView::Interactive) {
|
||||
auto header = horizontalHeader();
|
||||
header->setDefaultSectionSize(value);
|
||||
if(mode!=QHeaderView::Interactive) header->setSectionResizeMode(mode);
|
||||
auto setColWidth(int value) {
|
||||
if(horizontalHeader()->minimumSectionSize() > value) horizontalHeader()->setMinimumSectionSize(value);
|
||||
horizontalHeader()->setDefaultSectionSize(value);
|
||||
return this;
|
||||
}
|
||||
inline auto setRowHeight(int value, QHeaderView::ResizeMode mode = QHeaderView::Interactive) {
|
||||
auto header = verticalHeader();
|
||||
header->setDefaultSectionSize(value);
|
||||
if(mode!=QHeaderView::Interactive) header->setSectionResizeMode(mode);
|
||||
auto setColResize(QHeaderView::ResizeMode mode) {
|
||||
horizontalHeader()->setSectionResizeMode(mode);
|
||||
return this;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
inline auto setHeaderText(int col, QString text) {
|
||||
auto setHeaderText(int col, const QString& text) {
|
||||
auto item = horizontalHeaderItem(col);
|
||||
if(item==0) setHorizontalHeaderItem(col, item = new QTableWidgetItem());
|
||||
item->setText(text);
|
||||
return item;
|
||||
}
|
||||
inline auto setHeaderText(QString column, QString text) {
|
||||
auto col = mFieldMap[column];
|
||||
return setHeaderText(col, text);
|
||||
auto setHeaderText(const QString& column, const QString& text) {
|
||||
return setHeaderText(fdmap.at(column), text);
|
||||
}
|
||||
|
||||
inline auto setVHeaderText(int row, QString text) {
|
||||
auto setVHeaderText(int row, const QString& text) {
|
||||
auto item = verticalHeaderItem(row);
|
||||
if(item==0) setVerticalHeaderItem(row, item = new QTableWidgetItem());
|
||||
item->setText(text);
|
||||
return item;
|
||||
}
|
||||
|
||||
inline auto appendRow() {
|
||||
auto appendRow() {
|
||||
auto value = rowCount();
|
||||
setRowCount(value + 1);
|
||||
return value;
|
||||
}
|
||||
|
||||
using QTableWidget::item;
|
||||
inline auto item(int row, QString column) {
|
||||
auto col = mFieldMap[column];
|
||||
return item(row, col);
|
||||
auto item(int row, const QString& column) {
|
||||
return item(row, fdmap.at(column));
|
||||
}
|
||||
inline auto itemValid(int row, int col) {
|
||||
auto anitem = item(row, col);
|
||||
if(anitem==0) setItem(row, col, anitem = new QTableWidgetItem);
|
||||
return anitem;
|
||||
auto itemValid(int row, int col) {
|
||||
auto itm = item(row, col);
|
||||
if(itm==0) setItem(row, col, itm = new QTableWidgetItem);
|
||||
return itm;
|
||||
}
|
||||
inline auto itemValid(int row, QString column) {
|
||||
auto col = mFieldMap[column];
|
||||
return itemValid(row, col);
|
||||
auto itemValid(int row, const QString& column) {
|
||||
return itemValid(row, fdmap.at(column));
|
||||
}
|
||||
using QTableWidget::setItem;
|
||||
inline void setItem(int row, QString column, QTableWidgetItem *item) {
|
||||
auto col = mFieldMap[column];
|
||||
setItem(row, col, item);
|
||||
void setItem(int row, const QString& column, QTableWidgetItem *item) {
|
||||
setItem(row, fdmap.at(column), item);
|
||||
}
|
||||
|
||||
inline auto text(int row, int col) {
|
||||
auto text(int row, int col) {
|
||||
auto itm = item(row, col);
|
||||
if(itm==0) return QString();
|
||||
return itm->text();
|
||||
}
|
||||
inline auto text(int row, QString column) {
|
||||
auto col = mFieldMap[column];
|
||||
return text(row, col);
|
||||
auto text(int row, const QString& column) {
|
||||
return text(row, fdmap.at(column));
|
||||
}
|
||||
|
||||
inline auto setText(int row, int col, const QString &text) {
|
||||
auto setText(int row, int col, const QString& text) {
|
||||
auto itm = item(row, col);
|
||||
if(itm) itm->setText(text);
|
||||
else setItem(row, col, itm = new QTableWidgetItem(text));
|
||||
return itm;
|
||||
}
|
||||
inline auto setText(int row, QString column, const QString &text) {
|
||||
auto col = mFieldMap[column];
|
||||
return setText(row, col, text);
|
||||
auto setText(int row, const QString& column, const QString& text) {
|
||||
return setText(row, fdmap.at(column), 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);
|
||||
if(itm==0) return QVariant();
|
||||
return itm->data(Qt::UserRole);
|
||||
}
|
||||
inline auto data(int row, QString column) {
|
||||
auto col = mFieldMap[column];
|
||||
return data(row, col);
|
||||
auto data(int row, const QString& column) {
|
||||
return data(row, fdmap.at(column));
|
||||
}
|
||||
|
||||
inline auto setData(int row, int col, const QVariant &value) {
|
||||
auto setData(int row, int col, const QVariant &value) {
|
||||
auto itm = item(row, col);
|
||||
if(itm==0) setItem(row, col, itm = new QTableWidgetItem);
|
||||
itm->setData(Qt::UserRole, value);
|
||||
return itm;
|
||||
}
|
||||
inline auto setData(int row, QString column, const QVariant &value) {
|
||||
auto col = mFieldMap[column];
|
||||
return setData(row, col, value);
|
||||
auto setData(int row, const QString& column, const QVariant &value) {
|
||||
return setData(row, fdmap.at(column), value);
|
||||
}
|
||||
|
||||
using QTableWidget::cellWidget;
|
||||
inline auto cellWidget(int row, QString column) {
|
||||
auto col = mFieldMap[column];
|
||||
return cellWidget(row, col);
|
||||
auto cellWidget(int row, const QString& column) {
|
||||
return cellWidget(row, fdmap.at(column));
|
||||
}
|
||||
using QTableWidget::setCellWidget;
|
||||
inline void setCellWidget(int row, QString column, QWidget *widget) {
|
||||
auto col = mFieldMap[column];
|
||||
setCellWidget(row, col, widget);
|
||||
void setCellWidget(int row, const QString& column, QWidget *widget) {
|
||||
setCellWidget(row, fdmap.at(column), 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:
|
||||
inline void clearRows() {setRowCount(0);}
|
||||
void clearRows() {setRowCount(0);}
|
||||
signals:
|
||||
void updGeos();
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
void updateGeometries() override;
|
||||
void resizeSec();
|
||||
bool noStretch{true};
|
||||
};
|
||||
|
||||
class ResizeEmitedWgt : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
using QWidget::QWidget;
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *) override {emit resized();}
|
||||
signals:
|
||||
void resized();
|
||||
void updateGeometries() override {
|
||||
QTableWidget::updateGeometries();
|
||||
emit updGeos();
|
||||
};
|
||||
void onSectionResized(int logicalIndex, int oldSize, int newSize);
|
||||
bool adjSections(int index, int size);
|
||||
bool noStretch = true;
|
||||
bool isSectionResized = false;
|
||||
bool blocked = false;
|
||||
};
|
||||
|
||||
|
||||
|
@ -340,43 +534,43 @@ public:
|
|||
Wrp(T *obj = nullptr){
|
||||
this->obj = obj;
|
||||
};
|
||||
inline Wrp& operator()(T *obj){
|
||||
Wrp& operator()(T *obj){
|
||||
this->obj = obj;
|
||||
return *this;
|
||||
}
|
||||
inline Wrp& operator()(T *obj, QLayout *layout){
|
||||
Wrp& operator()(T *obj, QLayout *layout){
|
||||
this->obj = obj;
|
||||
layout->addWidget(obj);
|
||||
return *this;
|
||||
}
|
||||
inline Wrp& addTo(QLayout *layout){
|
||||
Wrp& addTo(QLayout *layout){
|
||||
layout->addWidget(obj);
|
||||
return *this;
|
||||
}
|
||||
inline Wrp& margin(int a){
|
||||
Wrp& margin(int a){
|
||||
obj->setMargin(a);
|
||||
return *this;
|
||||
}
|
||||
inline Wrp& font(const QFont &font){
|
||||
Wrp& font(const QFont &font){
|
||||
obj->setFont(font);
|
||||
return *this;
|
||||
}
|
||||
inline Wrp& font(int size){
|
||||
Wrp& font(int size){
|
||||
auto font = obj->font();
|
||||
font.setPixelSize(size);
|
||||
obj->setFont(font);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Wrp& width(int w){
|
||||
Wrp& width(int w){
|
||||
obj->setFixedWidth(w);
|
||||
return *this;
|
||||
}
|
||||
inline Wrp& height(int h){
|
||||
Wrp& height(int h){
|
||||
obj->setFixedHeight(h);
|
||||
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;
|
||||
hAdd+=8;
|
||||
QSize size = obj->fontMetrics().size(Qt::TextShowMnemonic, obj->text());
|
||||
|
@ -390,11 +584,11 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
inline Wrp& alignC(){
|
||||
Wrp& alignC(){
|
||||
obj->setAlignment(Qt::AlignCenter);
|
||||
return *this;
|
||||
}
|
||||
inline Wrp& alignR(){
|
||||
Wrp& alignR(){
|
||||
obj->setAlignment(Qt::AlignRight);
|
||||
return *this;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ class JValue {
|
|||
public:
|
||||
int data[2]{0};
|
||||
enum Type {
|
||||
Null, Bool, Int, Long, Double, Obj, Array, Str
|
||||
Null, Bool, Int, Long, Ulong, Double, Obj, Array, Str
|
||||
};
|
||||
Type type{Null};
|
||||
|
||||
|
@ -21,6 +21,7 @@ public:
|
|||
JValue(bool b) : type(Bool) {data[0] = b;}
|
||||
JValue(int n) : type(Int) {data[0] = 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(const JObj &o) : type(Obj) {new (data) JObj(o);}
|
||||
JValue(const JArray &a) : type(Array) {new (data) JArray(a);}
|
||||
|
@ -61,29 +62,33 @@ public:
|
|||
return type==Null ? def : data[0] || data[1];
|
||||
}
|
||||
int toInt(int def = 0) const {
|
||||
if(type==Bool || type==Int) return data[0];
|
||||
if(type==Long) return *(qint64*) data;
|
||||
if(type==Int || type==Bool) return data[0];
|
||||
if(type==Double) return *(double*) data;
|
||||
if(type==Long) return *(qint64*) data;
|
||||
if(type==Ulong) return *(quint64*) data;
|
||||
return def;
|
||||
}
|
||||
qint64 toLong(qint64 def = 0) const {
|
||||
if(type==Bool || type==Int) return data[0];
|
||||
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;
|
||||
return def;
|
||||
}
|
||||
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==Int || type==Bool) return data[0];
|
||||
if(type==Long) return *(qint64*) data;
|
||||
if(type==Ulong) return *(quint64*) data;
|
||||
return def;
|
||||
}
|
||||
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==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;
|
||||
}
|
||||
JObj toObj() const {
|
||||
|
|
|
@ -32,11 +32,14 @@ win32 {
|
|||
|
||||
|
||||
copydir.files += translations
|
||||
copy.files += $$files(files/*.ic)
|
||||
|
||||
win32 {
|
||||
EXE_SUFFIX = .exe
|
||||
copy.path = $$OUT_PWD
|
||||
copydir.path = $$OUT_PWD
|
||||
CONFIG += file_copies
|
||||
COPIES += copy
|
||||
COPIES += copydir
|
||||
}
|
||||
osx {
|
||||
|
@ -61,6 +64,7 @@ SOURCES += \
|
|||
crc.c \
|
||||
expertboxlayoutwin.cpp \
|
||||
expertscreenconnwin.cpp \
|
||||
expertsendpanel.cpp \
|
||||
expertsmartpointsetwin.cpp \
|
||||
expertwin.cpp \
|
||||
fast.cpp \
|
||||
|
@ -71,7 +75,6 @@ SOURCES += \
|
|||
main.cpp \
|
||||
mainwin.cpp \
|
||||
pcaprethread.cpp \
|
||||
screenunit.cpp \
|
||||
testwin.cpp \
|
||||
videowin.cpp \
|
||||
waitingdlg.cpp
|
||||
|
@ -83,6 +86,7 @@ HEADERS += \
|
|||
efffrefr.h \
|
||||
expertboxlayoutwin.h \
|
||||
expertscreenconnwin.h \
|
||||
expertsendpanel.h \
|
||||
expertsmartpointsetwin.h \
|
||||
expertwin.h \
|
||||
fast.h \
|
||||
|
@ -92,7 +96,6 @@ HEADERS += \
|
|||
gutil/qjson.h \
|
||||
mainwin.h \
|
||||
pcaprethread.h \
|
||||
screenunit.h \
|
||||
testwin.h \
|
||||
videowin.h \
|
||||
waitingdlg.h
|
||||
|
|
|
@ -93,7 +93,9 @@ MainWin::MainWin() {
|
|||
});
|
||||
btnImg = addImg(imgsBar, QPixmap(":/imgs/expert.png").scaledToWidth(128, Qt::SmoothTransformation), tr("专家调屏"));
|
||||
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("亮度控制"));
|
||||
connect(btnImg, &ImgBtn::clicked, this, [=] {
|
||||
|
@ -125,7 +127,8 @@ MainWin::MainWin() {
|
|||
vBox->addSpacing(9);
|
||||
vBox->addWidget(new QLabel(" 硬件信息"));
|
||||
|
||||
table = new Table{
|
||||
table = new TreeWidget{
|
||||
{"_num_", "", 20},
|
||||
{"type", "控制系统类型"},
|
||||
{"name", "名称"},
|
||||
{"link", "连接方式"},
|
||||
|
@ -133,8 +136,10 @@ MainWin::MainWin() {
|
|||
{"netPorts", "网口统计P1~Pn"},
|
||||
{"info", "其他信息", QHeaderView::Stretch},
|
||||
};
|
||||
table->verticalHeader()->setMinimumWidth(20);//added by alahover 20230822
|
||||
table->setDefs();
|
||||
table->setSortingEnabled(true);
|
||||
table->sortItems("name");
|
||||
table->setStyleSheet("TreeWidget::item{height: 26px;}");
|
||||
vBox->addWidget(table);
|
||||
|
||||
auto hBox = new HBox(vBox);
|
||||
|
@ -201,7 +206,6 @@ MainWin::MainWin() {
|
|||
bool ok = true;
|
||||
if(senderAddress.protocol()==QUdpSocket::IPv6Protocol) senderAddress.setAddress(senderAddress.toIPv4Address(&ok));
|
||||
auto addr = ok ? senderAddress.toString() : "";
|
||||
int cnt = table->rowCount();
|
||||
if(data.startsWith("{\"")) {
|
||||
QString error;
|
||||
auto json = JFrom(gram.data(), &error);
|
||||
|
@ -210,56 +214,50 @@ MainWin::MainWin() {
|
|||
continue;
|
||||
}
|
||||
auto cardId = json["cardId"].toStr();
|
||||
for(int rr=0; rr<cnt; rr++) if(table->text(rr, "name")==cardId) {
|
||||
table->setText(rr, "link", addr);
|
||||
TreeWidgetItem *item;
|
||||
for(int rr=0; rr<table->topLevelItemCount(); rr++) if((item = table->item(rr))->text("name")==cardId) {
|
||||
item->setText("link", addr);
|
||||
goto end;
|
||||
}
|
||||
table->setRowCount(cnt+1);
|
||||
table->setData(cnt, "type", enum_xixun_async)->setText(tr("异步卡"));//added by alahover 20230822
|
||||
table->setText(cnt, "name", cardId);
|
||||
table->setText(cnt, "link", addr);
|
||||
item = new TreeWidgetItem(table);
|
||||
item->setText("type", tr("异步卡"), enum_xixun_async);
|
||||
item->setText("name", cardId);
|
||||
item->setText("link", addr);
|
||||
} else {
|
||||
auto bytes = gram.data();
|
||||
auto packet = (UDPPacket *)bytes.data();
|
||||
for(int rr=0; rr<cnt; rr++) if(table->text(rr, "name")==packet->serialCode) {
|
||||
table->setText(rr, "link", addr);
|
||||
TreeWidgetItem *item;
|
||||
for(int rr=0; rr<table->topLevelItemCount(); rr++) if((item = table->item(rr))->text("name")==packet->serialCode) {
|
||||
item->setText("link", addr);
|
||||
goto end;
|
||||
}
|
||||
table->setRowCount(cnt+1);
|
||||
table->setData(cnt, "type", enum_xixun_async)->setText(tr("异步卡"));
|
||||
table->setText(cnt, "name", packet->serialCode);
|
||||
table->setText(cnt, "link", addr);
|
||||
item = new TreeWidgetItem(table);
|
||||
item->setText("type", tr("异步卡"), enum_xixun_async);
|
||||
item->setText("name", packet->serialCode);
|
||||
item->setText("link", addr);
|
||||
}
|
||||
end:;
|
||||
}
|
||||
});
|
||||
reThd->addMultiCallback(0x105B14, [=](int, const QByteArray data) {
|
||||
auto rr = table->rowCount();
|
||||
unsigned short ver = *(quint16_be *)(data.data()+headMap_zrf.protcolFlag);
|
||||
unsigned char pkgType = *(quint8 *)(data.data()+headMap_zrf.pkgType);
|
||||
if(ver!=0x105B || pkgType != 0x14) return;
|
||||
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) {
|
||||
rr = i;
|
||||
goto end;
|
||||
}
|
||||
table->setRowCount(rr+1);
|
||||
TreeWidgetItem *item;
|
||||
for(int i=0; i<table->topLevelItemCount(); i++) if((item = table->item(i))->text("name")==strDeviceName) goto end;
|
||||
item = new TreeWidgetItem(table);
|
||||
end:
|
||||
char cDevicaNameVer[8];
|
||||
memcpy(cDevicaNameVer,(char *)data.data()+headMap_zrf.paramStart+st_zrf_rb_param.deviceVer,8);
|
||||
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;
|
||||
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;
|
||||
table->setData(rr, "type", enum_zrf)->setText(tr("PC虚拟卡V1.0"));
|
||||
table->setText(rr, "name", strDeviceName);
|
||||
table->setText(rr, "link", "千兆网直连");
|
||||
table->setText(rr, "vcsNum", QString::number(maxNetPort_zrf));
|
||||
table->setText(rr, "netPorts", "P:"+QString::number(virtualVCM));
|
||||
table->setText(rr, "info", "版本: "+strDeviceVer+" [备注:可直接配屏,无需发送卡]");
|
||||
if(rr==0) table->selectRow(0);
|
||||
item->setText("type", tr("PC虚拟卡V1.0"), enum_zrf);
|
||||
item->setText("name", strDeviceName);
|
||||
item->setText("link", "千兆网直连");
|
||||
item->setText("vcsNum", QString::number(maxNetPort_zrf));
|
||||
item->setText("netPorts", "P: "+QString::number(virtualVCM));
|
||||
item->setText("info", "版本: "+QLatin1String(data.data()+headMap_zrf.paramStart+st_zrf_rb_param.deviceVer, 8)+" [备注:可直接配屏,无需发送卡]");
|
||||
if(table->selectedItem()==0) item->setSelected(true);
|
||||
});
|
||||
getCard();
|
||||
}
|
||||
|
@ -270,22 +268,22 @@ MainWin::~MainWin() {
|
|||
}
|
||||
|
||||
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 res = sendMsg(msg, 0x1E0, 10000, [=](int, const QByteArray data) {
|
||||
if(*(quint32_be*)(data.data()+headMap.ptr) != 0xA0000000) return;
|
||||
auto rr = table->rowCount();
|
||||
table->setRowCount(rr+1);
|
||||
auto item = new TreeWidgetItem(table);
|
||||
int virtualVCM = *(quint16_be*)(data.data()+headMap.srcAddr);
|
||||
//modified by alahover -s 20230822
|
||||
auto ver = *(byte*)(data.data()+headMap.ver);
|
||||
if(ver==0x01) table->setData(rr, "type", enum_xixun_sync)->setText(tr("PC虚拟卡V0.0"));
|
||||
else if(ver==0x58) table->setData(rr, "type", enum_zrf)->setText(tr("PC虚拟卡V1.0"));
|
||||
table->setText(rr, "name", tr("网口:")+QString::number(virtualVCM));
|
||||
table->setText(rr, "link", "千兆网直连");
|
||||
table->setText(rr, "vcsNum", QString::number(*(quint32_be*)(data.data()+headMap.body)));
|
||||
table->setText(rr, "netPorts", "P:"+QString::number(virtualVCM));
|
||||
table->setText(rr, "info", "备注:可直接配屏,无需发送卡");
|
||||
if(ver==0x01) item->setText("type", tr("PC虚拟卡V0.0"), enum_xixun_sync);
|
||||
else if(ver==0x58) item->setText("type", tr("PC虚拟卡V1.0"), enum_zrf);
|
||||
item->setText("name", QString::number(virtualVCM)+" (网口)");
|
||||
item->setText("link", "千兆网直连");
|
||||
item->setText("vcsNum", QString::number(*(quint32_be*)(data.data()+headMap.body)));
|
||||
item->setText("netPorts", "P: "+QString::number(virtualVCM));
|
||||
item->setText("info", "备注: 可直接配屏,无需发送卡");
|
||||
if(table->selectedItem()==0) item->setSelected(true);
|
||||
});
|
||||
if(res) {
|
||||
QString err = pcap_geterr(pcapSend);
|
||||
|
|
|
@ -12,7 +12,7 @@ public:
|
|||
~MainWin();
|
||||
QWidget *win{0};
|
||||
QByteArray net_name;
|
||||
Table *table{0};
|
||||
TreeWidget *table;
|
||||
QUdpSocket mUdpSocket;
|
||||
int maxNetPort_zrf = 0;
|
||||
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue
Block a user