📄 hexview.cpp
字号:
#include "hexview.h"#include <qlistview.h>#include <qlayout.h>#include <qfont.h>#include <cstring>HexView::HexView(QWidget *parent, const char *name, const char *title, const char *data) : QDialog(parent, name){ QVBoxLayout *vbox = new QVBoxLayout(this); listView = new QListView(this); listView->addColumn("Offset"); listView->addColumn("Bytes"); listView->addColumn("ASCII"); listView->setSorting(-1); listView->setSelectionMode(QListView::NoSelection); listView->setFont(QFont("Courier", 14)); vbox->addWidget(listView); resize(675, 500); display(title, data);}int HexView::exec(){ return QDialog::exec();}void HexView::display(const char *title, const char *data){ QString hexit = "", offsetline = "", hexline = "", asciiline = "", pad = ""; int charcnt = 0, offset = 0; unsigned len = strlen(data), j = 0; QListViewItem *item = 0; setCaption((QString) title + " (Hex View)"); listView->clear(); for (unsigned i=0; i < len; i++) { charcnt++; hexit = (QString) hexit.sprintf("%x", data[i]); if (hexit.length() == 1) hexit = (QString) "0" + hexit; hexline += (QString) " " + hexit; if ((data[i] < '\x20') || (data[i] > '\x7e')) asciiline += " "; else asciiline += data[i]; if (charcnt == 16) { offsetline = offsetline.sprintf("%x", offset); for (j=0; j < (8 - offsetline.length()); j++) pad += (QString) "0"; offsetline = (QString) "0x" + pad + offsetline; hexline += " "; item = new QListViewItem(listView, listView->lastItem()); item->setText(0, offsetline); item->setText(1, hexline); item->setText(2, asciiline); charcnt = 0; hexline = asciiline = pad = ""; offset += 16; } } if (charcnt) { offsetline = offsetline.sprintf("%x", offset); for (j=0; j < (8 - offsetline.length()); j++) pad += "0"; offsetline = (QString) "0x" + pad + offsetline; hexline += " "; item = new QListViewItem(listView, listView->lastItem()); item->setText(0, offsetline); item->setText(1, hexline); item->setText(2, asciiline); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -