1 /* hexviewdialog.cpp 2 3 Copyright (c) 2016, Nikolaj Schlej. All rights reserved. 4 This program and the accompanying materials 5 are licensed and made available under the terms and conditions of the BSD License 6 which accompanies this distribution. The full text of the license may be found at 7 http://opensource.org/licenses/bsd-license.php 8 9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 12 */ 13 14 #include "hexviewdialog.h" 15 HexViewDialog(QWidget * parent)16HexViewDialog::HexViewDialog(QWidget *parent) : 17 QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint), 18 ui(new Ui::HexViewDialog), 19 hexView(NULL) 20 { 21 // Create UI 22 ui->setupUi(this); 23 hexView = new QHexEdit(this); 24 hexView->setReadOnly(true); 25 hexView->setUpperCase(true); 26 ui->layout->addWidget(hexView); 27 } 28 ~HexViewDialog()29HexViewDialog::~HexViewDialog() 30 { 31 delete hexView; 32 delete ui; 33 } 34 setFont(const QFont & font)35void HexViewDialog::setFont(const QFont &font) 36 { 37 hexView->setFont(font); 38 } 39 setItem(const UModelIndex & index,bool bodyOnly)40void HexViewDialog::setItem(const UModelIndex & index, bool bodyOnly) 41 { 42 const TreeModel * model = (const TreeModel*)index.model(); 43 44 // Set dialog title 45 UString itemName = model->name(index); 46 UString itemText = model->text(index); 47 setWindowTitle(UString("Hex view: ") + (itemText.isEmpty() ? itemName : itemName + " | " + itemText)); 48 49 // Set hex data 50 QByteArray hexdata; 51 if (bodyOnly) hexdata = model->body(index); 52 else hexdata = model->header(index) + model->body(index) + model->tail(index); 53 hexView->setData(hexdata); 54 }