Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Commit

Permalink
beauty UI, set background color for table item
Browse files Browse the repository at this point in the history
  • Loading branch information
Wang Xin committed Dec 25, 2022
1 parent 7538839 commit c2fcce1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Binary file modified build/bin/sniffer
Binary file not shown.
27 changes: 27 additions & 0 deletions src/view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,22 +163,49 @@ void View::add_pkt(const packet_struct *packet, bool flag) {
QStandardItem *item;
item = new QStandardItem(QString::number(packet->no));
TableModel->setItem(index, 0, item);
setColor(packet, item);
item = new QStandardItem(QString::fromStdString(packet->time));
TableModel->setItem(index, 1, item);
setColor(packet, item);
item = new QStandardItem(src);
TableModel->setItem(index, 2, item);
setColor(packet, item);
item = new QStandardItem(dst);
TableModel->setItem(index, 3, item);
setColor(packet, item);
item = new QStandardItem(prot);
TableModel->setItem(index, 4, item);
setColor(packet, item);
item = new QStandardItem(QString::number(packet->len));
TableModel->setItem(index, 5, item);
setColor(packet, item);
item = new QStandardItem(info);
TableModel->setItem(index, 6, item);
setColor(packet, item);

index++;
}

/* set different color according to protocal */
void View::setColor(const packet_struct* packet, QStandardItem *item) {
if(packet->trs_type != Utrs) {
switch(packet->trs_type) {
case TCP: item->setBackground(QBrush(QColor(255, 240, 245))); break;
case UDP: item->setBackground(QBrush(QColor(255, 255, 240))); break;
case ICMP:item->setBackground(QBrush(QColor(64 , 224, 208))); break;
case IGMP:item->setBackground(QBrush(QColor(135, 206, 250))); break;
case Utrs:break;
}
}else {
switch(packet->net_type) {
case IPv4:item->setBackground(QBrush(QColor(250, 128, 114))); break;
case IPv6:item->setBackground(QBrush(QColor(152, 251, 152))); break;
case ARP: item->setBackground(QBrush(QColor(238, 130, 238))); break;
case Unet:break;
}
}
}

void View::onTableClicked(const QModelIndex &item) {
auto idx = item.row();
if (!item.isValid()) {
Expand Down
4 changes: 3 additions & 1 deletion src/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class View : public QObject {
~View();
void add_pkt(const packet_struct *packete, bool flag=false);

void clearView();
void clearView();

private slots:
void onTableClicked(const QModelIndex &);
Expand All @@ -29,6 +29,8 @@ private slots:
int index;
QStandardItemModel *TableModel;
QStandardItemModel *TreeModel;

void setColor(const packet_struct* packet, QStandardItem *item);
};

#endif // VIEW_H

0 comments on commit c2fcce1

Please sign in to comment.