ledset走点表增加背景色
This commit is contained in:
parent
d3a7cd2207
commit
d441f6fbc1
|
@ -1,5 +1,4 @@
|
|||
#include "expertsmartpointsetwin.h"
|
||||
#include "gqt.h"
|
||||
#include <QStackedLayout>
|
||||
#include <QLabel>
|
||||
#include <QRadioButton>
|
||||
|
@ -336,17 +335,15 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(ExpertWin *expertWin) : BaseWin{e
|
|||
auto lastIdx = tableRow->columnCount()-1;
|
||||
if(lastIdx==-1) return;
|
||||
auto last = tableRow->item(1, lastIdx);
|
||||
if(last->text()=="×") {
|
||||
virtualCnt--;
|
||||
} else {
|
||||
if(last->text()=="×") virtualCnt--;
|
||||
else {
|
||||
auto point = last->data(Qt::UserRole).toPoint();
|
||||
table->setItem(point.y(), point.x(), 0);
|
||||
table->setText(point.y(), point.x(), "");
|
||||
if(lastIdx==virtualCnt) table->selectionModel()->clearCurrentIndex();
|
||||
else {
|
||||
for(int i=lastIdx-1; i>-1; i--) {
|
||||
auto item = tableRow->item(1, i);
|
||||
if(item->text()=="×") continue;
|
||||
auto point = item->data(Qt::UserRole).toPoint();
|
||||
if(tableRow->text(1, i)=="×") continue;
|
||||
auto point = tableRow->data(1, i).toPoint();
|
||||
table->setCurrentCell(point.y(), point.x());
|
||||
break;
|
||||
}
|
||||
|
@ -362,8 +359,8 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(ExpertWin *expertWin) : BaseWin{e
|
|||
virtualCnt++;
|
||||
auto cnt = tableRow->columnCount();
|
||||
tableRow->setColumnCount(cnt+1);
|
||||
tableRow->setItem(0, cnt, new QTableWidgetItem(QString::number(cnt+1)));
|
||||
tableRow->setItem(1, cnt, new QTableWidgetItem("×"));
|
||||
tableRow->setText(0, cnt, QString::number(cnt+1))->setTextAlignment(Qt::AlignCenter);
|
||||
tableRow->setText(1, cnt, "×")->setTextAlignment(Qt::AlignCenter);
|
||||
});
|
||||
hhh->addWidget(btnAddVoid);
|
||||
|
||||
|
@ -384,27 +381,25 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(ExpertWin *expertWin) : BaseWin{e
|
|||
hhh->addStretch();
|
||||
vBox->addLayout(hhh);
|
||||
|
||||
table = new PointTable;
|
||||
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
table = new NumTable;
|
||||
table->setNoEdit();
|
||||
table->setSelectionMode(QTableWidget::SingleSelection);
|
||||
table->horizontalHeader()->setDefaultSectionSize(40);
|
||||
table->setColWidth(40);
|
||||
table->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter);
|
||||
table->verticalHeader()->setMinimumWidth(40);
|
||||
table->verticalHeader()->setDefaultAlignment(Qt::AlignCenter);
|
||||
connect(table, &QTableWidget::currentCellChanged, this, [=](int row, int col) {
|
||||
if(row < 0) return;
|
||||
auto item = table->item(row, col);
|
||||
if(item) return;
|
||||
auto text = table->text(row, col);
|
||||
if(! text.isEmpty()) return;
|
||||
if(scans.isEmpty()) {
|
||||
auto cnt = tableRow->columnCount() + 1;
|
||||
tableRow->setColumnCount(cnt);
|
||||
tableRow->setItem(0, cnt-1, new QTableWidgetItem(QString::number(cnt)));
|
||||
item = new QTableWidgetItem("√");
|
||||
item->setData(Qt::UserRole, QPoint{col, row});
|
||||
tableRow->setItem(1, cnt-1, item);
|
||||
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});
|
||||
auto realCnt = cnt - virtualCnt;
|
||||
item = new QTableWidgetItem(QString::number(realCnt));
|
||||
table->setItem(row, col, item);
|
||||
table->setText(row, col, QString::number(realCnt))->setTextAlignment(Qt::AlignCenter);
|
||||
if(realCnt==ModuleWidth) {
|
||||
scans.append({col, row});
|
||||
QMessageBox::information(this, tr("提示"), tr("列走完"));
|
||||
|
@ -412,9 +407,7 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(ExpertWin *expertWin) : BaseWin{e
|
|||
} else if(scans.size() < ScanNum) {
|
||||
scans.append({col, row});
|
||||
auto size = scans.size();
|
||||
item = new QTableWidgetItem("S"+QString::number(size));
|
||||
table->setItem(row, col, item);
|
||||
|
||||
table->setText(row, col, "S"+QString::number(size))->setTextAlignment(Qt::AlignCenter);
|
||||
if(size==ScanNum) {
|
||||
QMessageBox::information(this, tr("提示"), tr("行走完"));
|
||||
save();
|
||||
|
@ -425,8 +418,8 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(ExpertWin *expertWin) : BaseWin{e
|
|||
|
||||
vBox->addWidget(table);
|
||||
|
||||
tableRow = new PointTable(2, 0);
|
||||
tableRow->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
tableRow = new NumTable(2, 0);
|
||||
tableRow->setNoEdit();
|
||||
tableRow->setSelectionMode(QTableWidget::NoSelection);
|
||||
tableRow->horizontalHeader()->setDefaultSectionSize(40);
|
||||
tableRow->horizontalHeader()->setVisible(false);
|
||||
|
@ -474,6 +467,11 @@ ExpertSmartPointSetWin::ExpertSmartPointSetWin(ExpertWin *expertWin) : BaseWin{e
|
|||
} else if(idx==2) {
|
||||
table->setColumnCount(ModuleWidth);
|
||||
table->setRowCount(ModuleHeight);
|
||||
QColor altColor(0x445566);
|
||||
for(int r=0; r<ModuleHeight; r++) {
|
||||
if((r&7)!=7) for(int c=7; c<ModuleWidth; c+=8) table->itemValid(r, c)->setBackground(altColor);
|
||||
else for(int c=0; c<ModuleWidth; c++) table->itemValid(r, c)->setBackground(altColor);
|
||||
}
|
||||
}
|
||||
stack->setCurrentIndex(++idx);
|
||||
btnPrev->setEnabled(idx > 0);
|
||||
|
@ -509,7 +507,7 @@ void ExpertSmartPointSetWin::save() {
|
|||
for(int i=0; i<add; i++) points.append(-1);
|
||||
}
|
||||
for(int i=cnt-1; i>=0; i--) {
|
||||
auto data = tableRow->item(1, i)->data(Qt::UserRole);
|
||||
auto data = tableRow->data(1, i);
|
||||
points.append(data.isValid() ? data.toPoint().x() : -1);
|
||||
}
|
||||
obj.insert("Points", points);
|
||||
|
|
|
@ -1,22 +1,11 @@
|
|||
#ifndef EXPERTSMARTPOINTSETWIN_H
|
||||
#define EXPERTSMARTPOINTSETWIN_H
|
||||
|
||||
#include "basewin.h"
|
||||
#include "expertwin.h"
|
||||
#include "gutil/qgui.h"
|
||||
#include <QSpinBox>
|
||||
#include <QTableWidget>
|
||||
#include <QComboBox>
|
||||
|
||||
class PointTable : public QTableWidget {
|
||||
public:
|
||||
explicit PointTable(QWidget *parent = nullptr) : QTableWidget{parent} {}
|
||||
PointTable(int rows, int columns, QWidget *parent = nullptr) : QTableWidget{rows, columns, parent} {}
|
||||
void setItem(int row, int column, QTableWidgetItem *item) {
|
||||
if(item) item->setTextAlignment(Qt::AlignCenter);
|
||||
QTableWidget::setItem(row, column, item);
|
||||
}
|
||||
};
|
||||
|
||||
class ExpertSmartPointSetWin : public BaseWin {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -25,7 +14,7 @@ public:
|
|||
|
||||
ExpertWin *expertWin;
|
||||
|
||||
PointTable *table, *tableRow;
|
||||
NumTable *table, *tableRow;
|
||||
int virtualCnt = 0;
|
||||
QList<QPoint> scans;
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "expertwin.h"
|
||||
#include "gqt.h"
|
||||
#include "table.h"
|
||||
#include "gutil/qgui.h"
|
||||
#include "crc.h"
|
||||
#include "screenunit.h"
|
||||
#include "expertsmartpointsetwin.h"
|
||||
|
@ -118,13 +117,13 @@ QTabBar::tab:selected {margin-top: 0; border-bottom: none; color: #acf; backgrou
|
|||
int idx = 0;
|
||||
for(int rr=0; rr<4; rr++) {
|
||||
QString name = "P"+QString::number(rr+1);
|
||||
table->setValue(rr, "name", name);
|
||||
table->setValue(rr, "x", QString::number(idx));
|
||||
table->setValue(rr, "y", "0");
|
||||
table->setValue(rr, "w", "128");
|
||||
table->setValue(rr, "h", "128");
|
||||
table->setValue(rr, "audio", "0");
|
||||
table->setValue(rr, "backup", "0");
|
||||
table->setText(rr, "name", name);
|
||||
table->setText(rr, "x", QString::number(idx));
|
||||
table->setText(rr, "y", "0");
|
||||
table->setText(rr, "w", "128");
|
||||
table->setText(rr, "h", "128");
|
||||
table->setText(rr, "audio", "0");
|
||||
table->setText(rr, "backup", "0");
|
||||
|
||||
auto unit = new ScreenUnit(this, name, idx, 0, 128, 128, screen);
|
||||
unit->setAutoFillBackground(true);
|
||||
|
@ -319,7 +318,7 @@ QTabBar::tab:selected {margin-top: 0; border-bottom: none; color: #acf; backgrou
|
|||
fdSectorCount->addItem(tr("六开"), 6);
|
||||
fdSectorCount->addItem(tr("七开"), 7);
|
||||
fdSectorCount->addItem(tr("八开"), 8);
|
||||
select(fdSectorCount, mBox["SectorCount"].toInt());
|
||||
setCurrentData(fdSectorCount, mBox["SectorCount"].toInt());
|
||||
vvv->addWidget(fdSectorCount);
|
||||
|
||||
fdDirection = new QComboBox();
|
||||
|
@ -800,25 +799,3 @@ void run() {
|
|||
// pcap_sendqueue_destroy(queue);
|
||||
// }
|
||||
}
|
||||
|
||||
ReceThread::ReceThread(pcap_t *pcap) : pcap(pcap) {
|
||||
connect(this, &QThread::finished, this, &QThread::deleteLater);
|
||||
}
|
||||
void ReceThread::run() {
|
||||
pcap_pkthdr *header;
|
||||
const u_char *data;
|
||||
int res;
|
||||
while((res = pcap_next_ex(pcap, &header, &data)) >= 0) {
|
||||
if(status==2) return;
|
||||
if(status==1 || res == 0 || !showImg) continue; //超时
|
||||
if(header->caplen<24) continue;
|
||||
if(data[0]!=0x55 || data[1]!=0x55) continue;
|
||||
if(data[2]==0x9a && data[3]==0x3d) {
|
||||
// if(data[17]==0xBB) {
|
||||
// emit onMsg(((int)data[24] << 8) + data[25], ((int)data[26] << 8) + data[27]);
|
||||
// } else if(data[17]==0xCC) emit onMsg(img);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
emit onErr(pcap_geterr(pcap));
|
||||
}
|
||||
|
|
|
@ -2,31 +2,11 @@
|
|||
#define EXPERTWIN_H
|
||||
|
||||
#include "basewin.h"
|
||||
#define HAVE_REMOTE
|
||||
#include "pcap.h"
|
||||
#include <QThread>
|
||||
#include <QLabel>
|
||||
#include <QSpinBox>
|
||||
#include <QComboBox>
|
||||
#include <QJsonObject>
|
||||
|
||||
class ReceThread : public QThread {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ReceThread(pcap *pcap);
|
||||
~ReceThread() {
|
||||
pcap_close(pcap);
|
||||
}
|
||||
pcap *pcap;
|
||||
std::atomic<char> status{0};
|
||||
bool showImg{true};
|
||||
protected:
|
||||
void run();
|
||||
signals:
|
||||
void onMsg(QByteArray);
|
||||
void onErr(char *);
|
||||
};
|
||||
|
||||
class ExpertWin : public BaseWin {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "globalfunc.h"
|
||||
#include "table.h"
|
||||
#include "gutil/qgui.h"
|
||||
#include "basewin.h"
|
||||
#define HAVE_REMOTE
|
||||
#include "pcap.h"
|
||||
|
@ -39,22 +39,22 @@ QByteArray getNetDev(QWidget *parent, QByteArray def, bool justReturnIfHave) {
|
|||
}
|
||||
auto rr = table->rowCount();
|
||||
table->setRowCount(rr+1);
|
||||
table->setValue(rr, "name", dev->name);
|
||||
table->setValue(rr, "desc", dev->description);
|
||||
table->setValue(rr, "loopback", (dev->flags & PCAP_IF_LOOPBACK)?"True":"False");
|
||||
table->setText(rr, "name", dev->name);
|
||||
table->setText(rr, "desc", dev->description);
|
||||
table->setText(rr, "loopback", (dev->flags & PCAP_IF_LOOPBACK)?"True":"False");
|
||||
auto ip = (u_char *) &((sockaddr_in *) a->addr)->sin_addr.s_addr;
|
||||
table->setValue(rr, "ip", QString::asprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]));
|
||||
table->setText(rr, "ip", QString::asprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]));
|
||||
if(a->netmask) {
|
||||
ip = (u_char *) &((sockaddr_in *) a->netmask)->sin_addr.s_addr;
|
||||
table->setValue(rr, "netmask", QString::asprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]));
|
||||
table->setText(rr, "netmask", QString::asprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]));
|
||||
}
|
||||
if(a->broadaddr) {
|
||||
ip = (u_char *) &((sockaddr_in *) a->broadaddr)->sin_addr.s_addr;
|
||||
table->setValue(rr, "broadaddr", QString::asprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]));
|
||||
table->setText(rr, "broadaddr", QString::asprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]));
|
||||
}
|
||||
if(a->dstaddr) {
|
||||
ip = (u_char *) &((sockaddr_in *) a->dstaddr)->sin_addr.s_addr;
|
||||
table->setValue(rr, "dstaddr", QString::asprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]));
|
||||
table->setText(rr, "dstaddr", QString::asprintf("%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]));
|
||||
}
|
||||
if(device==0) device = dev;
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
#include "gqt.h"
|
132
ledset/gqt.h
132
ledset/gqt.h
|
@ -1,132 +0,0 @@
|
|||
#ifndef GQT_H
|
||||
#define GQT_H
|
||||
#include <QLayout>
|
||||
#include <QThread>
|
||||
#include <QComboBox>
|
||||
|
||||
inline long long steady_milli() {
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
|
||||
}
|
||||
inline long long system_milli() {
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
||||
}
|
||||
inline long long steady_micro() {
|
||||
return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
|
||||
}
|
||||
inline long long system_micro() {
|
||||
return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
class Wrp {
|
||||
public:
|
||||
T *obj;
|
||||
Wrp(T *obj = nullptr){
|
||||
this->obj = obj;
|
||||
};
|
||||
inline Wrp& operator()(T *obj){
|
||||
this->obj = obj;
|
||||
return *this;
|
||||
}
|
||||
inline Wrp& operator()(T *obj, QLayout *layout){
|
||||
this->obj = obj;
|
||||
layout->addWidget(obj);
|
||||
return *this;
|
||||
}
|
||||
inline Wrp& addTo(QLayout *layout){
|
||||
layout->addWidget(obj);
|
||||
return *this;
|
||||
}
|
||||
inline Wrp& margin(int a){
|
||||
obj->setMargin(a);
|
||||
return *this;
|
||||
}
|
||||
inline Wrp& font(const QFont &font){
|
||||
obj->setFont(font);
|
||||
return *this;
|
||||
}
|
||||
inline Wrp& font(int size){
|
||||
QFont font = obj->font();
|
||||
font.setPointSize(size);
|
||||
obj->setFont(font);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Wrp& width(int w){
|
||||
obj->setFixedWidth(w);
|
||||
return *this;
|
||||
}
|
||||
inline Wrp& height(int h){
|
||||
obj->setFixedHeight(h);
|
||||
return *this;
|
||||
}
|
||||
inline 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());
|
||||
int &rwidth = size.rwidth();
|
||||
rwidth += wAdd;
|
||||
if(rwidth < minW) rwidth = minW;
|
||||
int &rheight = size.rheight();
|
||||
rheight += hAdd;
|
||||
if(rheight < minH) rheight = minH;
|
||||
obj->setFixedSize(size);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Wrp& alignC(){
|
||||
obj->setAlignment(Qt::AlignCenter);
|
||||
return *this;
|
||||
}
|
||||
inline Wrp& alignR(){
|
||||
obj->setAlignment(Qt::AlignRight);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Wrp& connStart(){
|
||||
QObject::connect(obj, &QThread::finished, obj, &QThread::deleteLater);
|
||||
obj->start();
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
class VBox : public QBoxLayout {
|
||||
public:
|
||||
inline VBox(QWidget *parent=nullptr) : QBoxLayout(TopToBottom, parent) {}
|
||||
inline VBox(QBoxLayout *parent) : QBoxLayout(TopToBottom) {
|
||||
parent->addLayout(this);
|
||||
};
|
||||
};
|
||||
class HBox : public QBoxLayout {
|
||||
public:
|
||||
inline HBox(QWidget *parent=nullptr) : QBoxLayout(LeftToRight, parent) {}
|
||||
inline HBox(QBoxLayout *parent) : QBoxLayout(LeftToRight) {
|
||||
parent->addLayout(this);
|
||||
};
|
||||
};
|
||||
|
||||
class ResizeEmitedWgt : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ResizeEmitedWgt(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()) : QWidget{parent, f} {}
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *) override {emit resized();}
|
||||
signals:
|
||||
void resized();
|
||||
};
|
||||
|
||||
template <typename Func>
|
||||
inline QThread *ThreadStart(Func &&f) {
|
||||
QThread* thread = QThread::create(f);
|
||||
QObject::connect(thread, &QThread::finished, thread, &QThread::deleteLater);
|
||||
thread->start();
|
||||
return thread;
|
||||
}
|
||||
|
||||
inline void select(QComboBox *combo, const QVariant &data) {
|
||||
int idx = combo->findData(data);
|
||||
if(idx!=-1) combo->setCurrentIndex(idx);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
|
@ -1,6 +1,8 @@
|
|||
#include "table.h"
|
||||
#include "qgui.h"
|
||||
|
||||
Table::Table(std::initializer_list<ColAttr> colAttrs, QWidget *parent) : QTableWidget{0, (int)colAttrs.size(), parent} {
|
||||
const int AlignRight = Qt::AlignRight | Qt::AlignVCenter;
|
||||
|
||||
Table::Table(std::initializer_list<ColAttr> colAttrs, int rows, QWidget *parent) : NumTable{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);
|
||||
|
@ -8,10 +10,11 @@ Table::Table(std::initializer_list<ColAttr> colAttrs, QWidget *parent) : QTableW
|
|||
item->setText(it->text);
|
||||
item->setData(0x99, it->width);
|
||||
if(it->width > 0) horizontalHeader()->resizeSection(i, it->width);
|
||||
if(it->resizeMode != QHeaderView::Interactive) horizontalHeader()->setSectionResizeMode(i, it->resizeMode);
|
||||
if(it->resizeMode > -1) horizontalHeader()->setSectionResizeMode(i, (QHeaderView::ResizeMode)it->resizeMode);
|
||||
mFieldMap.insert(it->field, i++);
|
||||
}
|
||||
}
|
||||
|
||||
int Table::sizeHintForColumn(int column) const {
|
||||
auto item = horizontalHeaderItem(column);
|
||||
if(item==0) return QTableWidget::sizeHintForColumn(column);
|
|
@ -0,0 +1,289 @@
|
|||
#ifndef QGUI_H
|
||||
#define QGUI_H
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QStackedLayout>
|
||||
#include <QTableWidget>
|
||||
#include <QHeaderView>
|
||||
|
||||
extern const int AlignRight;
|
||||
|
||||
inline int setCurrentData(QComboBox *combo, const QVariant &data) {
|
||||
auto idx = combo->findData(data);
|
||||
if(idx>-1) combo->setCurrentIndex(idx);
|
||||
return idx;
|
||||
}
|
||||
|
||||
class VBox : public QBoxLayout {
|
||||
public:
|
||||
inline VBox(QWidget *parent=nullptr) : QBoxLayout(TopToBottom, parent) {}
|
||||
inline VBox(QBoxLayout *parent) : QBoxLayout(TopToBottom) {
|
||||
parent->addLayout(this);
|
||||
};
|
||||
inline VBox(QStackedLayout *parent) : QBoxLayout(TopToBottom) {
|
||||
setContentsMargins(0,0,0,0);
|
||||
auto wgt = new QWidget;
|
||||
wgt->setLayout(this);
|
||||
parent->addWidget(wgt);
|
||||
};
|
||||
};
|
||||
class HBox : public QBoxLayout {
|
||||
public:
|
||||
inline HBox(QWidget *parent=nullptr) : QBoxLayout(LeftToRight, parent) {}
|
||||
inline HBox(QBoxLayout *parent) : QBoxLayout(LeftToRight) {
|
||||
parent->addLayout(this);
|
||||
};
|
||||
inline HBox(QStackedLayout *parent) : QBoxLayout(LeftToRight) {
|
||||
setContentsMargins(0,0,0,0);
|
||||
auto wgt = new QWidget;
|
||||
wgt->setLayout(this);
|
||||
parent->addWidget(wgt);
|
||||
};
|
||||
};
|
||||
|
||||
class NumTable : public QTableWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NumTable(QWidget *parent = 0) : QTableWidget{parent} {}
|
||||
NumTable(int rows, int columns, QWidget *parent = 0) : QTableWidget{rows, columns, parent} {}
|
||||
|
||||
inline auto setNoEdit() {
|
||||
setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
return this;
|
||||
}
|
||||
inline auto setColWidth(int value) {
|
||||
horizontalHeader()->setDefaultSectionSize(value);
|
||||
return this;
|
||||
}
|
||||
inline auto setRowHeight(int value) {
|
||||
verticalHeader()->setDefaultSectionSize(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
inline auto setHeaderText(int column, QString text) {
|
||||
auto item = horizontalHeaderItem(column);
|
||||
if(item==0) setHorizontalHeaderItem(column, item = new QTableWidgetItem());
|
||||
item->setText(text);
|
||||
return item;
|
||||
}
|
||||
|
||||
inline auto itemValid(int row, int column) {
|
||||
auto item = QTableWidget::item(row, column);
|
||||
if(item==0) setItem(row, column, item = new QTableWidgetItem);
|
||||
return item;
|
||||
}
|
||||
inline auto text(int row, int column) {
|
||||
auto item = QTableWidget::item(row, column);
|
||||
if(item==0) return QString();
|
||||
return item->text();
|
||||
}
|
||||
inline auto setText(int row, int column, const QString &text) {
|
||||
auto item = QTableWidget::item(row, column);
|
||||
if(item) item->setText(text);
|
||||
else setItem(row, column, item = new QTableWidgetItem(text));
|
||||
return item;
|
||||
}
|
||||
|
||||
inline auto data(int row, int col) {
|
||||
auto item = QTableWidget::item(row, col);
|
||||
if(item==0) return QVariant();
|
||||
return item->data(Qt::UserRole);
|
||||
}
|
||||
inline auto setData(int row, int col, const QVariant &value) {
|
||||
auto item = QTableWidget::item(row, col);
|
||||
if(item==0) setItem(row, col, item = new QTableWidgetItem);
|
||||
item->setData(Qt::UserRole, value);
|
||||
return item;
|
||||
}
|
||||
};
|
||||
|
||||
struct ColAttr {
|
||||
QString field;
|
||||
QString text;
|
||||
int width{0};
|
||||
int resizeMode{-1};
|
||||
};
|
||||
class Table : public NumTable {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Table(QWidget *parent = nullptr) : NumTable{parent} {}
|
||||
Table(std::initializer_list<ColAttr> colAttrs, int rows = 0, QWidget *parent = nullptr);
|
||||
|
||||
inline auto setDefs() {
|
||||
setSelectionBehavior(QTableWidget::SelectRows);
|
||||
setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
setAlternatingRowColors(true);
|
||||
return this;
|
||||
}
|
||||
inline auto setColStretch() {
|
||||
horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
return this;
|
||||
}
|
||||
inline auto setRowStretch() {
|
||||
verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
return this;
|
||||
}
|
||||
inline auto setColFit() {
|
||||
horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
return this;
|
||||
}
|
||||
inline auto setRowFit() {
|
||||
verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
return this;
|
||||
}
|
||||
inline auto setColWidth(int value) {
|
||||
horizontalHeader()->setDefaultSectionSize(value);
|
||||
return this;
|
||||
}
|
||||
inline auto setRowHeight(int value) {
|
||||
verticalHeader()->setDefaultSectionSize(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
inline auto setHeaderText(QString column, QString text) {
|
||||
auto col = mFieldMap[column];
|
||||
auto item = horizontalHeaderItem(col);
|
||||
if(item==0) setHorizontalHeaderItem(col, item = new QTableWidgetItem());
|
||||
item->setText(text);
|
||||
return item;
|
||||
}
|
||||
|
||||
inline auto appendRow() {
|
||||
auto value = rowCount();
|
||||
setRowCount(value + 1);
|
||||
return value;
|
||||
}
|
||||
|
||||
inline auto item(int row, QString column) {
|
||||
auto col = mFieldMap[column];
|
||||
return QTableWidget::item(row, col);
|
||||
}
|
||||
inline void setItem(int row, QString column, QTableWidgetItem *item) {
|
||||
auto col = mFieldMap[column];
|
||||
QTableWidget::setItem(row, col, item);
|
||||
}
|
||||
inline auto text(int row, QString column) {
|
||||
auto col = mFieldMap[column];
|
||||
auto item = QTableWidget::item(row, col);
|
||||
if(item==0) return QString();
|
||||
return item->text();
|
||||
}
|
||||
inline auto setText(int row, QString column, const QString &text) {
|
||||
auto col = mFieldMap[column];
|
||||
auto item = QTableWidget::item(row, col);
|
||||
if(item) item->setText(text);
|
||||
else QTableWidget::setItem(row, col, item = new QTableWidgetItem(text));
|
||||
return item;
|
||||
}
|
||||
|
||||
inline auto data(int row, QString column) {
|
||||
auto col = mFieldMap[column];
|
||||
auto item = QTableWidget::item(row, col);
|
||||
if(item==0) return QVariant();
|
||||
return item->data(Qt::UserRole);
|
||||
}
|
||||
inline auto setData(int row, QString column, const QVariant &value) {
|
||||
auto col = mFieldMap[column];
|
||||
auto item = QTableWidget::item(row, col);
|
||||
if(item==0) QTableWidget::setItem(row, col, item = new QTableWidgetItem);
|
||||
item->setData(Qt::UserRole, value);
|
||||
return item;
|
||||
}
|
||||
|
||||
inline auto cellWidget(int row, QString column) {
|
||||
auto col = mFieldMap[column];
|
||||
return QTableWidget::cellWidget(row, col);
|
||||
}
|
||||
inline void setCellWidget(int row, QString column, QWidget *widget) {
|
||||
auto col = mFieldMap[column];
|
||||
QTableWidget::setCellWidget(row, col, widget);
|
||||
}
|
||||
|
||||
QMap<QString,int> mFieldMap;
|
||||
|
||||
public Q_SLOTS:
|
||||
inline void clearRows() {setRowCount(0);}
|
||||
|
||||
protected:
|
||||
int sizeHintForColumn(int column) const override;
|
||||
};
|
||||
|
||||
class ResizeEmitedWgt : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ResizeEmitedWgt(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()) : QWidget{parent, f} {}
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *) override {emit resized();}
|
||||
signals:
|
||||
void resized();
|
||||
};
|
||||
|
||||
|
||||
template<class T>
|
||||
class Wrp {
|
||||
public:
|
||||
T *obj;
|
||||
Wrp(T *obj = nullptr){
|
||||
this->obj = obj;
|
||||
};
|
||||
inline Wrp& operator()(T *obj){
|
||||
this->obj = obj;
|
||||
return *this;
|
||||
}
|
||||
inline Wrp& operator()(T *obj, QLayout *layout){
|
||||
this->obj = obj;
|
||||
layout->addWidget(obj);
|
||||
return *this;
|
||||
}
|
||||
inline Wrp& addTo(QLayout *layout){
|
||||
layout->addWidget(obj);
|
||||
return *this;
|
||||
}
|
||||
inline Wrp& margin(int a){
|
||||
obj->setMargin(a);
|
||||
return *this;
|
||||
}
|
||||
inline Wrp& font(const QFont &font){
|
||||
obj->setFont(font);
|
||||
return *this;
|
||||
}
|
||||
inline Wrp& font(int size){
|
||||
QFont font = obj->font();
|
||||
font.setPointSize(size);
|
||||
obj->setFont(font);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Wrp& width(int w){
|
||||
obj->setFixedWidth(w);
|
||||
return *this;
|
||||
}
|
||||
inline Wrp& height(int h){
|
||||
obj->setFixedHeight(h);
|
||||
return *this;
|
||||
}
|
||||
inline 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());
|
||||
int &rwidth = size.rwidth();
|
||||
rwidth += wAdd;
|
||||
if(rwidth < minW) rwidth = minW;
|
||||
int &rheight = size.rheight();
|
||||
rheight += hAdd;
|
||||
if(rheight < minH) rheight = minH;
|
||||
obj->setFixedSize(size);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Wrp& alignC(){
|
||||
obj->setAlignment(Qt::AlignCenter);
|
||||
return *this;
|
||||
}
|
||||
inline Wrp& alignR(){
|
||||
obj->setAlignment(Qt::AlignRight);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -40,13 +40,12 @@ SOURCES += \
|
|||
expertwin.cpp \
|
||||
fast.cpp \
|
||||
globalfunc.cpp \
|
||||
gqt.cpp \
|
||||
gutil/qgui.cpp \
|
||||
main.cpp \
|
||||
mainwin.cpp \
|
||||
pcaprethread.cpp \
|
||||
pcapwin.cpp \
|
||||
screenunit.cpp \
|
||||
table.cpp \
|
||||
videowin.cpp
|
||||
|
||||
HEADERS += \
|
||||
|
@ -58,12 +57,11 @@ HEADERS += \
|
|||
expertwin.h \
|
||||
fast.h \
|
||||
globalfunc.h \
|
||||
gqt.h \
|
||||
gutil/qgui.h \
|
||||
mainwin.h \
|
||||
pcaprethread.h \
|
||||
pcapwin.h \
|
||||
screenunit.h \
|
||||
table.h \
|
||||
videowin.h
|
||||
|
||||
TRANSLATIONS += \
|
||||
|
|
|
@ -53,7 +53,7 @@ QCheckBox::indicator:checked {border-image: url(:/imgs/checkbox-check.png);}
|
|||
QPushButton[ss="min"]{padding: 0; width: 30px; height: 25px; }
|
||||
QPushButton[ss="close"]{padding: 0; width: 30px; height: 25px; }
|
||||
|
||||
QPushButton[ss="blue"] {background: #07a;}
|
||||
QPushButton[ss="blue"] {background: #069;}
|
||||
)rrr");
|
||||
/*
|
||||
*/
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include <QTimer>
|
||||
#include <QMessageBox>
|
||||
#include <QDebug>
|
||||
#include "table.h"
|
||||
#include "globalfunc.h"
|
||||
#include "basewin.h"
|
||||
#include <QSettings>
|
||||
|
@ -195,13 +194,13 @@ void MainWin::getCard() {
|
|||
auto rr = 0;
|
||||
table->setRowCount(rr+1);
|
||||
uint32_t virtualVCM = data[6]<<8 | data[7] ;
|
||||
table->setValue(rr, "type", tr("虚拟设备"));
|
||||
table->setValue(rr, "name", tr("网口:")+QString::number(virtualVCM));
|
||||
table->setValue(rr, "link", "千兆网直连");
|
||||
table->setText(rr, "type", tr("虚拟设备"));
|
||||
table->setText(rr, "name", tr("网口:")+QString::number(virtualVCM));
|
||||
table->setText(rr, "link", "千兆网直连");
|
||||
uint32_t vcsNum = data[20] << 24 | data[21] <<16 | data[22] <<8 | data[23] ;
|
||||
table->setValue(rr, "vcs", QString::number(vcsNum));
|
||||
table->setValue(rr, "Pinfo", "P:"+QString::number(virtualVCM));
|
||||
table->setValue(rr, "Oinfo", "备注:可直接配屏,无需发送卡");
|
||||
table->setText(rr, "vcs", QString::number(vcsNum));
|
||||
table->setText(rr, "Pinfo", "P:"+QString::number(virtualVCM));
|
||||
table->setText(rr, "Oinfo", "备注:可直接配屏,无需发送卡");
|
||||
}
|
||||
}});
|
||||
if(res) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define MAINWIN_H
|
||||
|
||||
#include "basewin.h"
|
||||
#include "table.h"
|
||||
#include "gutil/qgui.h"
|
||||
|
||||
class MainWin : public BaseWin {
|
||||
Q_OBJECT
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
#ifndef TABLE_H
|
||||
#define TABLE_H
|
||||
|
||||
#include <QTableWidget>
|
||||
#include <QHeaderView>
|
||||
|
||||
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) {}
|
||||
QString field;
|
||||
QString text;
|
||||
int width{0};
|
||||
QHeaderView::ResizeMode resizeMode{QHeaderView::Interactive};
|
||||
};
|
||||
class Table : public QTableWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Table(QWidget *parent = nullptr) : QTableWidget{parent} {}
|
||||
Table(std::initializer_list<ColAttr> colAttrs, QWidget *parent = nullptr);
|
||||
|
||||
inline Table *setDefs() {
|
||||
setSelectionBehavior(QTableWidget::SelectRows);
|
||||
setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
setAlternatingRowColors(true);
|
||||
horizontalHeader()->setBackgroundRole(QPalette::Window);
|
||||
return this;
|
||||
}
|
||||
inline Table *setStretch() {
|
||||
horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
||||
return this;
|
||||
}
|
||||
inline Table *setResizeToContents() {
|
||||
horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
return this;
|
||||
}
|
||||
|
||||
void setHeaderText(QString column, QString text) {
|
||||
auto col = mFieldMap[column];
|
||||
auto item = horizontalHeaderItem(col);
|
||||
if(item==0) setHorizontalHeaderItem(col, item = new QTableWidgetItem());
|
||||
item->setText(text);
|
||||
}
|
||||
|
||||
auto item(int row, QString column) {
|
||||
auto col = mFieldMap[column];
|
||||
return QTableWidget::item(row, col);
|
||||
}
|
||||
void setItem(int row, QString column, QTableWidgetItem *item) {
|
||||
auto col = mFieldMap[column];
|
||||
QTableWidget::setItem(row, col, item);
|
||||
}
|
||||
void setValue(int row, QString column, const QString &text) {
|
||||
auto col = mFieldMap[column];
|
||||
QTableWidget::setItem(row, col, new QTableWidgetItem(text));
|
||||
}
|
||||
|
||||
auto cellWidget(int row, QString column) {
|
||||
auto col = mFieldMap[column];
|
||||
return QTableWidget::cellWidget(row, col);
|
||||
}
|
||||
void setCellWidget(int row, QString column, QWidget *widget) {
|
||||
auto col = mFieldMap[column];
|
||||
QTableWidget::setCellWidget(row, col, widget);
|
||||
}
|
||||
|
||||
QMap<QString,int> mFieldMap;
|
||||
|
||||
protected:
|
||||
int sizeHintForColumn(int column) const override;
|
||||
};
|
||||
|
||||
#endif // TABLE_H
|
Loading…
Reference in New Issue
Block a user