Added HexConverter utility

This commit is contained in:
Mark Long 2016-10-13 11:18:18 -05:00
parent dede70bfb9
commit f26af738c4
8 changed files with 245 additions and 7 deletions

View File

@ -53,7 +53,8 @@ SOURCES += \
src/binaryfile/binaryfilemetadata.cpp \
src/util/charset.cpp \
src/ui/widgets/characterwidget.cpp \
src/ui/viewers/applesoftfiledetailviewer.cpp
src/ui/viewers/applesoftfiledetailviewer.cpp \
src/ui/widgets/hexconverter.cpp
HEADERS += \
@ -87,7 +88,8 @@ HEADERS += \
src/ui/widgets/characterwidget.h \
src/util/charset.h \
src/ui/viewers/charsetviewer.h \
src/ui/viewers/applesoftfiledetailviewer.h
src/ui/viewers/applesoftfiledetailviewer.h \
src/ui/widgets/hexconverter.h
FORMS += \
src/ui/catalogwidget.ui \
@ -96,4 +98,5 @@ FORMS += \
src/ui/viewers/disassemblerviewer.ui \
src/ui/viewers/hexdumpviewer.ui \
src/ui/viewers/texthexdumpviewer.ui \
src/ui/viewers/applesoftfiledetailviewer.ui
src/ui/viewers/applesoftfiledetailviewer.ui \
src/ui/widgets/hexconverter.ui

View File

@ -44,6 +44,10 @@ MainWindow::MainWindow(QWidget *parent) :
ui->catalogWidget, SLOT(processNewlyLoadedDisk(QString,DiskFile*)));
connect(this, SIGNAL(diskFileUnloading(DiskFile*)),
ui->catalogWidget, SLOT(unloadDisk(DiskFile*)));
m_hexConverter = new HexConverter(this);
connect(ui->action_Hex_Converter, SIGNAL(triggered()), m_hexConverter, SLOT(show()));
}
MainWindow::~MainWindow()

View File

@ -7,6 +7,7 @@
#include "binaryfile.h"
#include "applesoftfile.h"
//#include "relocatablefile.h"
#include "hexconverter.h"
namespace Ui {
@ -46,6 +47,7 @@ protected:
void openInCharSetViewer(BinaryFile *file);
private:
Ui::MainWindow *ui;
HexConverter *m_hexConverter;
DiskFile *m_disk;
};

View File

@ -45,7 +45,7 @@
<x>0</x>
<y>0</y>
<width>273</width>
<height>20</height>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menu_File">
@ -57,7 +57,14 @@
<addaction name="separator"/>
<addaction name="action_Quit"/>
</widget>
<widget class="QMenu" name="menu_Util">
<property name="title">
<string>&amp;Util</string>
</property>
<addaction name="action_Hex_Converter"/>
</widget>
<addaction name="menu_File"/>
<addaction name="menu_Util"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<widget class="QToolBar" name="toolBar">
@ -86,6 +93,11 @@
<string>&amp;Unload Disk Image</string>
</property>
</action>
<action name="action_Hex_Converter">
<property name="text">
<string>&amp;Hex Converter...</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@ -4,6 +4,7 @@
#include <QMap>
#include <QString>
#include <QStringList>
#include <QTableWidgetItem>
ApplesoftFileDetailViewer::ApplesoftFileDetailViewer(QWidget *parent) :
@ -66,9 +67,17 @@ void ApplesoftFileDetailViewer::process()
default: vtname = "Unknown";
}
ui->m_varView->setItem(idx,0,new QTableWidgetItem(vtname));
ui->m_varView->setItem(idx,1,new QTableWidgetItem(key));
ui->m_varView->setItem(idx,2,new QTableWidgetItem(linenums));
QTableWidgetItem *twi = new QTableWidgetItem(vtname);
twi->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
ui->m_varView->setItem(idx,0,twi);
twi = new QTableWidgetItem(key);
twi->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
ui->m_varView->setItem(idx,1,twi);
twi = new QTableWidgetItem(linenums);
twi->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
ui->m_varView->setItem(idx,2,twi);
idx++;
}

View File

@ -0,0 +1,100 @@
#include "hexconverter.h"
#include "ui_hexconverter.h"
#include <QString>
HexConverter::HexConverter(QWidget *parent) :
QDialog(parent),
ui(new Ui::HexConverter)
{
ui->setupUi(this);
ui->uint8LineEdit->setValidator(new QIntValidator(0,255));
ui->int8LineEdit->setValidator(new QIntValidator(-128,127));
ui->uint16LineEdit->setValidator(new QIntValidator(0,65535));
ui->int16LineEdit->setValidator(new QIntValidator(-32768,32767));
connect(ui->hexLineEdit, SIGNAL(textEdited(QString)), SLOT(calcFromNewHex(QString)));
connect(ui->uint8LineEdit, SIGNAL(textEdited(QString)), SLOT(calcFromNewUint8(QString)));
connect(ui->int8LineEdit, SIGNAL(textEdited(QString)), SLOT(calcFromNewInt8(QString)));
connect(ui->uint16LineEdit, SIGNAL(textEdited(QString)), SLOT(calcFromNewUint16(QString)));
connect(ui->int16LineEdit, SIGNAL(textEdited(QString)), SLOT(calcFromNewInt16(QString)));
}
HexConverter::~HexConverter()
{
delete ui;
}
void HexConverter::calcFromNewHex(QString value)
{
bool ok = true;
quint16 ui16 = value.toInt(&ok,16);
qint16 i16 = ui16;
quint8 ui8 = ui16;
qint8 i8 = ui16;
ui->uint16LineEdit->setText(QString::number(ui16));
ui->int16LineEdit->setText(QString::number(i16));
ui->uint8LineEdit->setText(QString::number(ui8));
ui->int8LineEdit->setText(QString::number(i8));
}
void HexConverter::calcFromNewUint16(QString value)
{
bool ok = true;
quint16 ui16 = value.toInt(&ok);
qint16 i16 = ui16;
quint8 ui8 = ui16;
qint8 i8 = ui16;
QString hex = QString::number(ui16,16);
ui->int16LineEdit->setText(QString::number(i16));
ui->uint8LineEdit->setText(QString::number(ui8));
ui->int8LineEdit->setText(QString::number(i8));
ui->hexLineEdit->setText(hex);
}
void HexConverter::calcFromNewInt16(QString value)
{
bool ok = true;
qint16 i16 = value.toInt(&ok);
quint16 ui16 = i16;
quint8 ui8 = i16;
qint8 i8 = i16;
QString hex = QString::number(ui16,16);
ui->uint16LineEdit->setText(QString::number(ui16));
ui->uint8LineEdit->setText(QString::number(ui8));
ui->int8LineEdit->setText(QString::number(i8));
ui->hexLineEdit->setText(hex);
}
void HexConverter::calcFromNewUint8(QString value)
{
bool ok = true;
quint8 ui8 = value.toInt(&ok);
quint16 ui16 = ui8;
qint16 i16 = ui16;
qint8 i8 = ui16;
QString hex = QString::number(ui16,16);
ui->uint16LineEdit->setText(QString::number(ui16));
ui->int16LineEdit->setText(QString::number(i16));
ui->int8LineEdit->setText(QString::number(i8));
ui->hexLineEdit->setText(hex);
}
void HexConverter::calcFromNewInt8(QString value)
{
bool ok = true;
qint8 i8 = value.toInt(&ok);
quint8 ui8 = i8;
quint16 ui16 = ui8;
qint16 i16 = ui16;
QString hex = QString::number(ui16,16);
ui->uint16LineEdit->setText(QString::number(ui16));
ui->int16LineEdit->setText(QString::number(i16));
ui->uint8LineEdit->setText(QString::number(ui8));
ui->hexLineEdit->setText(hex);
}

View File

@ -0,0 +1,29 @@
#ifndef HEXCONVERTER_H
#define HEXCONVERTER_H
#include <QDialog>
namespace Ui {
class HexConverter;
}
class HexConverter : public QDialog
{
Q_OBJECT
public:
explicit HexConverter(QWidget *parent = 0);
~HexConverter();
public slots:
void calcFromNewUint16(QString value);
void calcFromNewInt16(QString value);
void calcFromNewHex(QString value);
void calcFromNewUint8(QString value);
void calcFromNewInt8(QString value);
protected slots:
private:
Ui::HexConverter *ui;
};
#endif // HEXCONVERTER_H

View File

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>HexConverter</class>
<widget class="QDialog" name="HexConverter">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>247</width>
<height>113</height>
</rect>
</property>
<property name="windowTitle">
<string>HexConverter</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="hexLabel">
<property name="text">
<string>Hex</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="uint16Label">
<property name="text">
<string>UInt16</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="int16Label">
<property name="text">
<string>Int16</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="hexLineEdit">
<property name="inputMask">
<string>HHHH</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="uint16LineEdit"/>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="int16LineEdit"/>
</item>
<item row="2" column="1">
<widget class="QLabel" name="uint8Label">
<property name="text">
<string>Uint8</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="int8Label">
<property name="text">
<string>Int8</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="uint8LineEdit"/>
</item>
<item row="3" column="2">
<widget class="QLineEdit" name="int8LineEdit"/>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>