From f437ad78be9c8ea3b4b8d20a855f1d4fb0de17b4 Mon Sep 17 00:00:00 2001 From: Akiko Date: Tue, 15 Oct 2013 07:06:41 +0200 Subject: [PATCH] - added a generic HEX view widget - updated makefiles for the generic components - the dat viewer component uses the hex one now ! the hex widget is very basic and not suitable for data beyond 40k+ --- common/CMakeLists.txt | 10 +-- common/CodeWidget.cxx | 18 ++--- common/CodeWidget.hxx | 6 +- common/HexWidget.cxx | 197 +++++++++++++++++++++++++++++++++++++++++++++++++ common/HexWidget.hxx | 40 ++++++++++ common/HexWidget.ui | 163 ++++++++++++++++++++++++++++++++++++++++ common/Resources.qrc | 7 ++ common/i18n_english.ts | 12 +++ common/i18n_french.ts | 12 +++ common/i18n_german.ts | 12 +++ editor/DatWindow.cxx | 23 ++++++ editor/DatWindow.ui | 92 ++++++++++++++++++++++- editor/i18n_english.ts | 45 ++++++----- editor/i18n_french.ts | 45 ++++++----- editor/i18n_german.ts | 45 ++++++----- 15 files changed, 657 insertions(+), 70 deletions(-) create mode 100644 common/HexWidget.cxx create mode 100644 common/HexWidget.hxx create mode 100644 common/HexWidget.ui create mode 100644 common/Resources.qrc create mode 100644 common/i18n_english.ts create mode 100644 common/i18n_french.ts create mode 100644 common/i18n_german.ts diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index ac2464f..dc7b864 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -1,9 +1,9 @@ # Qt sources -set (CO_SOURCES CodeWidget.cxx) -set (CO_HEADERS CodeWidget.hxx) -set (CO_UI_FILES ) -set (CO_RES_FILES ) -set (CO_TS_FILES ) +set (CO_SOURCES CodeWidget.cxx HexWidget.cxx) +set (CO_HEADERS CodeWidget.hxx HexWidget.hxx) +set (CO_UI_FILES HexWidget.ui) +set (CO_RES_FILES Resources.qrc) +set (CO_TS_FILES i18n_english.ts i18n_french.ts i18n_german.ts) # wrappers QT5_ADD_TRANSLATION (CO_TS_SOURCES ${CO_TS_FILES}) diff --git a/common/CodeWidget.cxx b/common/CodeWidget.cxx index dd5c93a..2166f5f 100644 --- a/common/CodeWidget.cxx +++ b/common/CodeWidget.cxx @@ -6,7 +6,7 @@ // --- CodeWidget: constructors and deconstructors --- CodeWidget::CodeWidget(QWidget *parent) -: QPlainTextEdit(parent), _area(new Area(this)) +: QPlainTextEdit(parent), _area(new LinesArea(this)) { setupActions(); updateAreaWidth(0); @@ -14,7 +14,7 @@ CodeWidget::CodeWidget(QWidget *parent) } CodeWidget::CodeWidget(const QString& text, QWidget *parent) -: QPlainTextEdit(text, parent), _area(new Area(this)) +: QPlainTextEdit(text, parent), _area(new LinesArea(this)) { setupActions(); updateAreaWidth(0); @@ -126,28 +126,28 @@ void CodeWidget::updateArea(const QRect& rect, qint32 dy) updateAreaWidth(0); } -// --- Area: constructors and deconstructors --- +// --- LinesArea: constructors and deconstructors --- -Area::Area(CodeWidget *parent) +LinesArea::LinesArea(CodeWidget *parent) : QWidget(parent), _parent(parent) { } -Area::~Area() +LinesArea::~LinesArea() { _parent = 0; } -// --- Area: public methods --- +// --- LinesArea: public methods --- -QSize Area::sizeHint() const +QSize LinesArea::sizeHint() const { return QSize(_parent->areaWidth(), 0); } -// --- Area: protected methods --- +// --- LinesArea: protected methods --- -void Area::paintEvent(QPaintEvent *event) +void LinesArea::paintEvent(QPaintEvent *event) { _parent->areaPaintEvent(event); } diff --git a/common/CodeWidget.hxx b/common/CodeWidget.hxx index 804de03..6c3ada2 100644 --- a/common/CodeWidget.hxx +++ b/common/CodeWidget.hxx @@ -26,11 +26,11 @@ private: QWidget *_area; }; -class Area : public QWidget { +class LinesArea : public QWidget { Q_OBJECT public: - explicit Area(CodeWidget *parent); - virtual ~Area(); + explicit LinesArea(CodeWidget *parent); + virtual ~LinesArea(); QSize sizeHint() const; diff --git a/common/HexWidget.cxx b/common/HexWidget.cxx new file mode 100644 index 0000000..300a3c0 --- /dev/null +++ b/common/HexWidget.cxx @@ -0,0 +1,197 @@ +#include +#include +#include +#include "HexWidget.hxx" +#include "ui_HexWidget.h" + +// --- internal typedefs --- + +using QL = QLabel; +using QLE = QLineEdit; +using QTW = QTableWidget; +using QTWI = QTableWidgetItem; + +// --- internal constants --- + +const QChar Null('0'); + +// --- constructors and deconstructors --- + +HexWidget::HexWidget(QWidget *parent) +: QWidget(parent), _ui(new Ui::HexWidget), _width(8) +{ + _ui->setupUi(this); + + setupActions(); +} + +HexWidget::~HexWidget() +{ + delete _ui; +} + +// --- public methods --- + +QByteArray HexWidget::hexData() const +{ + return _data; +} + +void HexWidget::setHexData(const QByteArray& data) +{ + _data = data; + + slotRefreshViews(); +} + +// --- public slots --- + +void HexWidget::slotRefreshViews() +{ + const qint32 max_chars = _data.count(); + const qint32 max_rows = max_chars / _width; + QTW *dline = _ui->wid_decline; + QTW *hex = _ui->wid_hex; + QTW *asc = _ui->wid_asc; + QTW *hline = _ui->wid_hexline; + + dline->setColumnCount(1); + dline->setRowCount(max_rows); + hex->setColumnCount(_width); + hex->setRowCount(max_rows); + asc->setColumnCount(_width); + asc->setRowCount(max_rows); + hline->setColumnCount(1); + hline->setRowCount(max_rows); + + for (qint32 row = 0; row < max_rows; ++row) + { + QTWI *dl = new QTWI(QString("%1").arg(row * _width, 10, 10, Null)); + QTWI *hl = new QTWI((QString("%1").arg(row * _width, 8, 16, Null)).toUpper()); + + dl->setFlags(dl->flags() ^ Qt::ItemIsEditable); + hl->setFlags(dl->flags() ^ Qt::ItemIsEditable); + + dline->setItem(row, 0, dl); + hline->setItem(row, 0, hl); + + for (qint32 col = 0; col < _width; ++col) + { + const qint32 pos = row * _width + col; + + if (pos < max_chars) + { + const unsigned char chr = _data.at(pos); + QTWI *he = new QTWI(QString("%1").arg(chr, 2, 16, Null)); + QTWI *ae = new QTWI(QString(chr)); + + he->setFlags(he->flags() ^ Qt::ItemIsEditable); + ae->setFlags(ae->flags() ^ Qt::ItemIsEditable); + + hex->setItem(row, col, he); + asc->setItem(row, col, ae); + } + } + } + + dline->resizeColumnsToContents(); + dline->resizeRowsToContents(); + + hex->resizeColumnsToContents(); + hex->resizeRowsToContents(); + + asc->resizeColumnsToContents(); + asc->resizeRowsToContents(); + for (qint32 col = 1; col < _width; ++col) + asc->setColumnWidth(col, asc->columnWidth(0)); + + hline->resizeColumnsToContents(); + hline->resizeRowsToContents(); +} + +void HexWidget::slotSelectCellDLine(qint32 row, qint32 col) +{ + _ui->wid_hex->setCurrentCell(row, col); + _ui->wid_asc->setCurrentCell(row, col); + _ui->wid_hexline->setCurrentCell(row, 0); +} + +void HexWidget::slotSelectCellHex(qint32 row, qint32 col) +{ + _ui->wid_decline->setCurrentCell(row, 0); + _ui->wid_asc->setCurrentCell(row, col); + _ui->wid_hexline->setCurrentCell(row, 0); +} + +void HexWidget::slotSelectCellAsc(qint32 row, qint32 col) +{ + _ui->wid_decline->setCurrentCell(row, 0); + _ui->wid_hex->setCurrentCell(row, col); + _ui->wid_hexline->setCurrentCell(row, 0); +} + +void HexWidget::slotSelectCellHLine(qint32 row, qint32 col) +{ + _ui->wid_decline->setCurrentCell(row, 0); + _ui->wid_hex->setCurrentCell(row, col); + _ui->wid_asc->setCurrentCell(row, col); +} + +void HexWidget::slotScrollDLine(qint32 val) +{ + _ui->wid_hex->verticalScrollBar()->setValue(val); + _ui->wid_asc->verticalScrollBar()->setValue(val); + _ui->wid_hexline->verticalScrollBar()->setValue(val); +} + +void HexWidget::slotScrollHex(qint32 val) +{ + _ui->wid_decline->verticalScrollBar()->setValue(val); + _ui->wid_asc->verticalScrollBar()->setValue(val); + _ui->wid_hexline->verticalScrollBar()->setValue(val); +} + +void HexWidget::slotScrollAsc(qint32 val) +{ + _ui->wid_decline->verticalScrollBar()->setValue(val); + _ui->wid_hex->verticalScrollBar()->setValue(val); + _ui->wid_hexline->verticalScrollBar()->setValue(val); +} + +void HexWidget::slotScrollHLine(qint32 val) +{ + _ui->wid_decline->verticalScrollBar()->setValue(val); + _ui->wid_hex->verticalScrollBar()->setValue(val); + _ui->wid_asc->verticalScrollBar()->setValue(val); +} + +// --- protected methods --- + +void HexWidget::changeEvent(QEvent *event) +{ + if (event->type() == QEvent::LanguageChange) + _ui->retranslateUi(this); + else + QWidget::changeEvent(event); +} + +void HexWidget::setupActions() +{ + connect(_ui->wid_decline, SIGNAL(cellClicked(qint32, qint32)), + this, SLOT(slotSelectCellDLine(qint32, qint32))); + connect(_ui->wid_hex, SIGNAL(cellClicked(qint32, qint32)), + this, SLOT(slotSelectCellHex(qint32, qint32))); + connect(_ui->wid_asc, SIGNAL(cellClicked(qint32, qint32)), + this, SLOT(slotSelectCellAsc(qint32, qint32))); + connect(_ui->wid_hexline, SIGNAL(cellClicked(qint32, qint32)), + this, SLOT(slotSelectCellHLine(qint32, qint32))); + + connect(_ui->wid_decline->verticalScrollBar(), SIGNAL(valueChanged(qint32)), + this, SLOT(slotScrollDLine(qint32))); + connect(_ui->wid_hex->verticalScrollBar(), SIGNAL(valueChanged(qint32)), + this, SLOT(slotScrollHex(qint32))); + connect(_ui->wid_asc->verticalScrollBar(), SIGNAL(valueChanged(qint32)), + this, SLOT(slotScrollAsc(qint32))); + connect(_ui->wid_hexline->verticalScrollBar(), SIGNAL(valueChanged(qint32)), + this, SLOT(slotScrollHLine(qint32))); +} diff --git a/common/HexWidget.hxx b/common/HexWidget.hxx new file mode 100644 index 0000000..ca71d69 --- /dev/null +++ b/common/HexWidget.hxx @@ -0,0 +1,40 @@ +#pragma once + +#include + +namespace Ui +{ + class HexWidget; +} + +class HexWidget : public QWidget { + Q_OBJECT +public: + explicit HexWidget(QWidget *parent = 0); + virtual ~HexWidget(); + + QByteArray hexData() const; + void setHexData(const QByteArray& data); + +public slots: + void slotRefreshViews(); + + void slotSelectCellDLine(qint32 row, qint32 col); + void slotSelectCellHex(qint32 row, qint32 col); + void slotSelectCellAsc(qint32 row, qint32 col); + void slotSelectCellHLine(qint32 row, qint32 col); + + void slotScrollDLine(qint32 val); + void slotScrollHex(qint32 val); + void slotScrollAsc(qint32 val); + void slotScrollHLine(qint32 val); + +protected: + virtual void changeEvent(QEvent *event); + void setupActions(); + +private: + Ui::HexWidget *_ui; + QByteArray _data; + qint32 _width; +}; diff --git a/common/HexWidget.ui b/common/HexWidget.ui new file mode 100644 index 0000000..46805c5 --- /dev/null +++ b/common/HexWidget.ui @@ -0,0 +1,163 @@ + + + HexWidget + + + + 0 + 0 + 672 + 416 + + + + Qt::NoContextMenu + + + FRM-HEX + + + + + + + 2 + + + 2 + + + + + + 0 + 0 + + + + + 140 + 16777215 + + + + Qt::NoContextMenu + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + false + + + false + + + 0 + + + 0 + + + false + + + 0 + + + 0 + + + + + + + Qt::NoContextMenu + + + QAbstractItemView::SingleSelection + + + false + + + false + + + false + + + + + + + Qt::NoContextMenu + + + QAbstractItemView::SingleSelection + + + false + + + false + + + false + + + + + + + + 0 + 0 + + + + + 140 + 16777215 + + + + Qt::NoContextMenu + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + false + + + false + + + 0 + + + 0 + + + false + + + 0 + + + 0 + + + + + + + + diff --git a/common/Resources.qrc b/common/Resources.qrc new file mode 100644 index 0000000..41680fc --- /dev/null +++ b/common/Resources.qrc @@ -0,0 +1,7 @@ + + + i18n_english.qm + i18n_french.qm + i18n_german.qm + + diff --git a/common/i18n_english.ts b/common/i18n_english.ts new file mode 100644 index 0000000..93c1d8d --- /dev/null +++ b/common/i18n_english.ts @@ -0,0 +1,12 @@ + + + + + HexWidget + + + FRM-HEX + + + + diff --git a/common/i18n_french.ts b/common/i18n_french.ts new file mode 100644 index 0000000..93c1d8d --- /dev/null +++ b/common/i18n_french.ts @@ -0,0 +1,12 @@ + + + + + HexWidget + + + FRM-HEX + + + + diff --git a/common/i18n_german.ts b/common/i18n_german.ts new file mode 100644 index 0000000..93c1d8d --- /dev/null +++ b/common/i18n_german.ts @@ -0,0 +1,12 @@ + + + + + HexWidget + + + FRM-HEX + + + + diff --git a/editor/DatWindow.cxx b/editor/DatWindow.cxx index 624c9f8..f530a0a 100644 --- a/editor/DatWindow.cxx +++ b/editor/DatWindow.cxx @@ -21,14 +21,37 @@ DatWindow::~DatWindow() void DatWindow::slotDatSave() { + //_entry.setOData(_ui->wid_hex->hexData()); + //_entry.setOSize(_ui->wid_hex->HexData.size()); + //_entry.setCSize(_entry.cData().size()); + //_entry.setName(_ui->ed_name->text()); + //_entry.setNameLength(_entry.name().size() + 1); + //_entry.setHSize(_entry.headerSize() + _entry.nameLength()); + + emit sigDatUpdate(_entry, _num); + + setMode(Mode::Fresh); } void DatWindow::slotDatDiscard() { + _entry = NCFile(); + _num = 0; + //_ui->wid_hex->clear(); + + emit sigDatIgnored(); + + setMode(Mode::Fresh); } void DatWindow::slotDatView(NCFile& entry, quint32 row) { + _entry = entry; + _num = row; + + _ui->ed_name->setText(_entry.name()); + _ui->wid_hex->setHexData(_entry.oData()); + _ui->ed_size->setText(QString::number(_ui->wid_hex->hexData().size())); } // --- protected methods --- diff --git a/editor/DatWindow.ui b/editor/DatWindow.ui index 075d988..04c5407 100644 --- a/editor/DatWindow.ui +++ b/editor/DatWindow.ui @@ -16,14 +16,94 @@ - + + + + 2 + + + 2 + + + + + + + + + 0 + 0 + + + + + + + + 0 + 0 + + + + LAB-STATUS-NAME + + + + + + + + + + + + + + Qt::Horizontal + + + + 213 + 20 + + + + + + + + + 0 + 0 + + + + LAB-STATUS-SIZE + + + + + + + + + + true + + + + + + + + 0 0 800 - 22 + 21 @@ -47,6 +127,14 @@ + + + HexWidget + QWidget +
common/HexWidget.hxx
+ 1 +
+
diff --git a/editor/i18n_english.ts b/editor/i18n_english.ts index 4e912d6..9116c55 100644 --- a/editor/i18n_english.ts +++ b/editor/i18n_english.ts @@ -9,17 +9,28 @@ QTinNS Editor - Dat Viewer - + + LAB-STATUS-NAME + LAB-NAME + Dat name: + + + + LAB-STATUS-SIZE + Dat size: + + + MM-DAT Dat - + ME-DAT-SAVE Save changes - + ME-DAT-CANCEL Discard changes @@ -333,72 +344,72 @@ QTinNS Editor - Text Viewer - + LAB-TEXT-NAME Text name: - + LAB-TEXT-LINES Lines: - + LAB-TEXT-SIZE Size: - + MM-TEXT Text - + MM-EDIT Edit - + ME-TEXT-SAVE Save changes - + ME-TEXT-CANCEL Discard changes - + ME-EDIT-UNDO Undo - + ME-EDIT-REDO Redo - + ME-EDIT-CUT Cut - + ME-EDIT-COPY Copy - + ME-EDIT-INSERT Insert - + ME-EDIT-DELETE Delete - + ME-EDIT-SELALL Select all diff --git a/editor/i18n_french.ts b/editor/i18n_french.ts index ced766a..cd8748e 100644 --- a/editor/i18n_french.ts +++ b/editor/i18n_french.ts @@ -9,17 +9,28 @@ - + + LAB-STATUS-NAME + LAB-NAME + + + + + LAB-STATUS-SIZE + + + + MM-DAT - + ME-DAT-SAVE - + ME-DAT-CANCEL @@ -333,72 +344,72 @@ - + LAB-TEXT-NAME - + LAB-TEXT-LINES - + LAB-TEXT-SIZE - + MM-TEXT - + MM-EDIT - + ME-TEXT-SAVE - + ME-TEXT-CANCEL - + ME-EDIT-UNDO - + ME-EDIT-REDO - + ME-EDIT-CUT - + ME-EDIT-COPY - + ME-EDIT-INSERT - + ME-EDIT-DELETE - + ME-EDIT-SELALL diff --git a/editor/i18n_german.ts b/editor/i18n_german.ts index 6c3d912..7bcf8ae 100644 --- a/editor/i18n_german.ts +++ b/editor/i18n_german.ts @@ -9,17 +9,28 @@ QTinNS Editor - Dat Viewer - + + LAB-STATUS-NAME + LAB-NAME + Datdateiname: + + + + LAB-STATUS-SIZE + Datgröße: + + + MM-DAT Dat - + ME-DAT-SAVE Speichere Änderungen - + ME-DAT-CANCEL Verwerfe Änderungen @@ -333,72 +344,72 @@ QTinNS Editor - Text Viewer - + LAB-TEXT-NAME Textdateiname: - + LAB-TEXT-LINES Zeilen: - + LAB-TEXT-SIZE Größe: - + MM-TEXT Text - + MM-EDIT Bearbeiten - + ME-TEXT-SAVE Speichere Änderungen - + ME-TEXT-CANCEL Verwerfe Änderungen - + ME-EDIT-UNDO Rückgängig - + ME-EDIT-REDO Wiederherstellen - + ME-EDIT-CUT Ausschneiden - + ME-EDIT-COPY Kopieren - + ME-EDIT-INSERT Einfügen - + ME-EDIT-DELETE Löschen - + ME-EDIT-SELALL Alles markieren -- 2.15.1