New IntBasic file viewer, various code clean up and bug fixes.

This commit is contained in:
Mark Long 2021-01-22 15:45:10 -06:00
parent e353df7232
commit a30eaec4c0
111 changed files with 19732 additions and 19546 deletions

View File

@ -17,6 +17,7 @@ INCLUDEPATH += src/diskfiles
INCLUDEPATH += src/diskfiles/dos33
INCLUDEPATH += src/util
INCLUDEPATH += src/applesoftfile
INCLUDEPATH += src/intbasic
INCLUDEPATH += src/binaryfile
INCLUDEPATH += src/textfile
INCLUDEPATH += src/ui/viewers
@ -29,6 +30,7 @@ INCLUDEPATH += src/ui
DEFINES += WS_VIDEO
SOURCES += \
src/intbasic/IntBasicFile.cxx \
src/main.cpp \
src/diskfiles/dos33/diskfile.cxx \
src/diskfiles/dos33/sector.cxx \
@ -37,6 +39,7 @@ SOURCES += \
src/diskfiles/dos33/tracksectorlist.cxx \
src/diskfiles/dos33/filedescriptiveentry.cxx \
src/diskfiles/dos33/genericfile.cxx \
src/ui/viewers/intbasicfileviewer.cxx \
src/util/applestring.cxx \
src/applesoftfile/applesoftfile.cxx \
src/applesoftfile/applesofttoken.cxx \
@ -83,6 +86,8 @@ HEADERS += \
src/diskfiles/dos33/tracksectorlist.h \
src/diskfiles/dos33/filedescriptiveentry.h \
src/diskfiles/dos33/genericfile.h \
src/intbasic/IntBasicFile.h \
src/ui/viewers/intbasicfileviewer.h \
src/util/util.h \
src/util/applestring.h \
src/applesoftfile/applesoftfile.h \
@ -132,6 +137,7 @@ FORMS += \
src/ui/viewers/applesoftfileviewer.ui \
src/ui/viewers/disassemblerviewer.ui \
src/ui/viewers/hexdumpviewer.ui \
src/ui/viewers/intbasicfileviewer.ui \
src/ui/viewers/texthexdumpviewer.ui \
src/ui/viewers/applesoftfiledetailviewer.ui \
src/ui/widgets/hexconverter.ui \

View File

@ -4,6 +4,8 @@
#include <QFlag>
#include <QFlags>
#include <QVector>
#include <QList>
enum MemoryUsage {
Unknown = 0x00000000,

View File

@ -34,10 +34,13 @@ FileDescriptiveEntry CatalogSector::makeFDE(int offset)
fde.firstTSListSector.track = m_data->rawData()[offset + 0x00];
fde.firstTSListSector.sector = m_data->rawData()[offset + 0x01];
fde.fileTypeAndFlags = m_data->rawData()[offset + 0x02];
fde.lengthInSectors = makeWord( m_data->rawData()[offset + 0x21], m_data->rawData()[offset + 0x22]);
fde.lengthInSectors = makeWord( m_data->rawData()[offset + 0x21],
m_data->rawData()[offset + 0x22]);
for (int idx = 0x03; idx <= 0x20; idx++) {
fde.filename.append(m_data->rawData()[idx+offset]);
}
if (fde.firstTSListSector.track == 0xFF)
{
//TODO: Double check this stuff. applevision.dsk is a good example.
@ -47,7 +50,7 @@ FileDescriptiveEntry CatalogSector::makeFDE(int offset)
fde.firstTSListSector.track = m_data->rawData()[offset + 0x20];
qDebug() << " New track: " << (quint8) fde.firstTSListSector.track;
qDebug() << " Sector: " << fde.firstTSListSector.sector;
}
return fde;
}

View File

@ -9,6 +9,7 @@
#include "tracksectorlist.h"
#include "applesoftfile.h"
#include "binaryfile.h"
#include "IntBasicFile.h"
#include "relocatablefile.h"
#include "textfile.h"
@ -128,6 +129,10 @@ GenericFile *DiskFile::getFile(FileDescriptiveEntry fde)
{
retval = new TextFile(data);
}
else if ((fde.fileType() == "I"))
{
retval = new IntBasicFile(data);
}
else
{
retval = new GenericFile(data);

View File

@ -12,17 +12,20 @@ class GenericFile
public:
GenericFile(QByteArray data = QByteArray());
virtual ~GenericFile() { }
virtual void setData(QByteArray data);
virtual void setData(QByteArray data);
virtual QByteArray data() { return m_data; }
void setFilename(QString filename) { m_filename = filename; }
QString filename() const { return m_filename; }
virtual void setAddress(quint16 location) { m_address = location; }
virtual quint16 address() { return m_address; }
virtual QByteArray rawData() { return m_data; }
virtual void setLength(quint16 length) { m_length = length; }
virtual quint16 length() { return m_length; }
virtual quint16 length() const { return m_length; }
DiskFile *diskFile() const { return m_diskfile; }
void setDiskFile(DiskFile *diskfile) { m_diskfile = diskfile; }

View File

@ -54,7 +54,8 @@ bool VTOC::isSectorInUse(TSPair ts) {
quint8 baseaddr = (track * 4) + 0x38;
//quint16 word = (((quint16) m_data->rawData()[baseaddr]) *256) + (quint8) m_data->rawData()[baseaddr+1];
quint16 word = makeWord(m_data->rawData()[baseaddr+1],m_data->rawData()[baseaddr]);
quint16 word = makeWord(m_data->rawData()[baseaddr+1],
m_data->rawData()[baseaddr]);
quint16 bitpos = (quint16) 0x01 << (quint16) sec;
return !(word & bitpos);

View File

@ -26,6 +26,10 @@ quint16 IntBasicFile::get16(quint8 v1, quint8 v2)
QByteArray IntBasicFile::dumpBufferAsIntBasicFile(QByteArray origdata)
/*
* THIS CODE IS MODIFIED FROM PAUL SCHYLTER'S SAMPLE CODE AVAILABLE AT:
* https://macgui.com/usenet/?group=1&start=14720&id=184603
*
*
* Integer Basic file format:
*
* <Length_of_file> (16-bit little endian)

View File

@ -12,8 +12,8 @@
int main(int argc, char** argv)
{
QApplication a(argc, argv);
QCoreApplication::setOrganizationName("AppleSAWS");
QCoreApplication::setOrganizationDomain("ml.com");
QCoreApplication::setOrganizationName("LydianScaleSoftware");
QCoreApplication::setOrganizationDomain("lydianscale.com");
QCoreApplication::setApplicationName("AppleSAWS");
DiskExplorer w;
QSettings settings;

View File

@ -4,6 +4,7 @@
#include "binaryfile.h"
#include "applesoftfile.h"
#include "genericfile.h"
#include "IntBasicFile.h"
#include <QUrl>
#include <QDebug>
#include <QMenu>
@ -15,7 +16,9 @@ CatalogWidget::CatalogWidget(QWidget *parent) :
ui(new Ui::CatalogWidget)
{
ui->setupUi(this);
ui->catalog_list->setFont(QFont("monospace"));
QFont catalogFont;
catalogFont.setStyleHint(QFont::Monospace);
ui->catalog_list->setFont(catalogFont);
ui->noteButton->setText(QChar(0x270d));
ui->noteButton->setFont(QFont("sans",16,QFont::Bold));

View File

@ -5,13 +5,16 @@
#include <QString>
#include <QStringList>
#include <QTableWidgetItem>
#include <QFile>
ApplesoftFileDetailViewer::ApplesoftFileDetailViewer(ApplesoftFile *file, QWidget *parent) :
QWidget(parent),
ui(new Ui::ApplesoftFileDetailViewer)
{
ui->setupUi(this);
ui->m_varView->setSortingEnabled(true);
m_file = file;
load();
@ -121,7 +124,8 @@ void ApplesoftFileDetailViewer::process()
QStringList keys = vardata.keys();
ui->m_varView->setRowCount(keys.count());
qSort(keys);
keys.sort();
int idx = 0;
foreach (QString key, keys)
{

View File

@ -39,12 +39,12 @@
</attribute>
<column>
<property name="text">
<string>Variable</string>
<string>Type</string>
</property>
</column>
<column>
<property name="text">
<string>Type</string>
<string>Variable</string>
</property>
</column>
<column>

View File

@ -1,11 +1,13 @@
#include "applesoftfileviewer.h"
#include "ui_applesoftfileviewer.h"
#include "applesoftformatter.h"
#include "util.h"
#include <QDebug>
#include <QSettings>
#include <QPrinter>
#include <QPrintDialog>
#include <QCloseEvent>
#include <QFontDialog>
ApplesoftFileViewer::ApplesoftFileViewer(QWidget *parent) :
@ -15,6 +17,11 @@ ApplesoftFileViewer::ApplesoftFileViewer(QWidget *parent) :
ui->setupUi(this);
m_afdv = Q_NULLPTR;
QFont textAreaFont;
textAreaFont.setStyleHint(QFont::Monospace);
textAreaFont.setPointSize(12);
QSettings settings;
QString title = QString("Applesoft Viewer");
m_title = title;
@ -34,6 +41,7 @@ ApplesoftFileViewer::ApplesoftFileViewer(QWidget *parent) :
m_showVarExplorerAction = Q_NULLPTR;
m_wordWrapAction = Q_NULLPTR;
m_showCtrlCharsAction = Q_NULLPTR;
m_setFontAction = Q_NULLPTR;
toggleWordWrap(settings.value("ASViewer.WordWrap",true).toBool());
@ -42,6 +50,8 @@ ApplesoftFileViewer::ApplesoftFileViewer(QWidget *parent) :
setBreakAfterReturn(settings.value("ASViewer.breakAfterReturn",false).toBool(), NoReformat);
setSyntaxHighlighting(settings.value("ASViewer.syntaxHighlighting",true).toBool(), NoReformat);
setShowCtrlChars(settings.value("ASViewer.showCtrlChars",true).toBool(), NoReformat);
setTextFont(fontFromSettings("ASViewer.textFont", textAreaFont), NoReformat);
}
ApplesoftFileViewer::~ApplesoftFileViewer()
@ -149,6 +159,26 @@ bool ApplesoftFileViewer::makeMenuOptions(QMenu *menu)
}
menu->addAction(m_showVarExplorerAction);
menu->addSeparator();
if (!m_setFontAction)
{
m_setFontAction = new QAction("Set &Font...",this);
connect(m_setFontAction, &QAction::triggered, this, [this] {
bool ok;
QFont font = QFontDialog::getFont(&ok,
ui->textArea->font(),
this, "Set Font",
QFontDialog::MonospacedFonts);
if (ok) {
setTextFont(font,ForceReformat);
fontToSettings("ASViewer.textFont",font);
}
});
}
menu->addAction(m_setFontAction);
return true;
}
@ -257,6 +287,15 @@ void ApplesoftFileViewer::setIntsAsHex(bool enabled, ReformatRule reformat)
reformatText();
}
void ApplesoftFileViewer::setTextFont(const QFont &font, ReformatRule reformat)
{
ui->textArea->setFont(font);
if (reformat == ForceReformat)
{
reformatText();
}
}
void ApplesoftFileViewer::reformatText()
{
QTextDocument *doc = ui->textArea->document();
@ -373,7 +412,9 @@ void ApplesoftFileViewer::doPrint()
}
QTextDocument printDoc;
QFont printFont("Courier",10);
QFont printFont;
printFont.setStyleHint(QFont::Monospace);
printFont.setPointSize(10);
printDoc.setDefaultFont(printFont);
QTextOption printOptions;
printOptions.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);

View File

@ -60,6 +60,8 @@ protected slots:
void setShowCtrlChars(bool enabled) { setShowCtrlChars(enabled,ForceReformat); }
void setShowCtrlChars(bool enabled, ReformatRule reformat);
void setTextFont(const QFont &font, ReformatRule reformat);
void launchVarBrowser();
void reformatText();
@ -78,6 +80,7 @@ private:
QAction *m_showVarExplorerAction;
QAction *m_wordWrapAction;
QAction *m_showCtrlCharsAction;
QAction *m_setFontAction;
};
#endif // APPLESOFTFILEVIEWER_H

View File

@ -51,15 +51,6 @@
</item>
<item row="1" column="0">
<widget class="QTextBrowser" name="textArea">
<property name="font">
<font>
<family>Misc Fixed</family>
<pointsize>14</pointsize>
<weight>50</weight>
<bold>false</bold>
<stylestrategy>PreferAntialias</stylestrategy>
</font>
</property>
<property name="acceptDrops">
<bool>false</bool>
</property>

File diff suppressed because it is too large Load Diff

View File

@ -45,6 +45,8 @@ public slots:
void doPrint();
void doExport();
void handleDisassembleRequest(QList<quint16> addresses);
protected:
void setTextFont(const QFont &font);
protected slots:
void showMetadataDialog();
private:
@ -55,6 +57,7 @@ private:
QAction *m_wordWrapAction;
QAction *m_showMetadataAction;
QAction *m_setFontAction;
BinaryFileMetadata *m_bfm;

View File

@ -16,12 +16,6 @@
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="FlowLineTextBrowser" name="textArea">
<property name="font">
<font>
<family>Courier</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="acceptRichText">
<bool>false</bool>
</property>

View File

@ -17,7 +17,7 @@ class FileViewerInterface : public QWidget
Q_OBJECT
public:
FileViewerInterface(QWidget *parent = Q_NULLPTR) : QWidget(parent) { }
FileViewerInterface(QWidget *parent = Q_NULLPTR) : QWidget(parent) { setFont(QFont("courier")); }
virtual bool optionsMenuItems(QMenu *) = 0;

View File

@ -1,20 +1,31 @@
#include "hexdumpviewer.h"
#include "ui_hexdumpviewer.h"
#include "util.h"
#include <QDebug>
#include <QScrollBar>
#include <QSettings>
#include <QAction>
#include <QMenu>
#include <QFontDialog>
#include "applestring.h"
#include <QChar>
HexDumpViewer::HexDumpViewer(QWidget *parent) :
FileViewerInterface(parent),
ui(new Ui::HexDumpViewer)
{
QFont textAreaFont;
textAreaFont.setStyleHint(QFont::Monospace);
m_file = Q_NULLPTR;
ui->setupUi(this);
setTextFont(fontFromSettings("HexDumpViewer.textFont", textAreaFont));
m_offset = 0;
QString title = QString("Hex Viewer");
setWindowTitle(title);
@ -86,33 +97,34 @@ void HexDumpViewer::showHexAndAsciiValues()
QString HexDumpViewer::valToAppleAscii(quint8 val)
{
typedef enum {
Inverse,
Flash,
Normal,
AltUC
} Zone;
// typedef enum {
// Inverse,
// Flash,
// Normal,
// AltUC
// } Zone;
Zone zone;
TextAttribute attribute = AppleChar::getAttribute(val);
QString charval = AppleChar::printable(val);
if (val == 0xff) { charval = "?"; } // QChar(0x25a0); }
QString charval;
if (val <= 0x1F) { val += 0x40; charval = QString("%1").arg(QChar(val)); zone = Inverse; } //INV UC
else if (val <= 0x3F) { val = val; charval = QString("%1").arg(QChar(val)); zone = Inverse; } // INV SP
else if (val <= 0x5F) { val = val; charval = QString("%1").arg(QChar(val)); zone = Flash; } // FL UC
else if (val <= 0x7F) { val -= 0x40; charval = QString("%1").arg(QChar(val)); zone = Flash; } // FL SP
else if (val <= 0x9F) { val -= 0x40; charval = QString("%1").arg(QChar(val)); zone = AltUC; } // NORMx UC
else if (val <= 0xBF) { val -= 0x40; charval = QString("%1").arg(QChar(val)); zone = Normal; } // NORM SP
else if (val <= 0xDF) { val -= 0x80; charval = QString("%1").arg(QChar(val)); zone = Normal; } // NORM UC
else if (val < 0xFF) { val -= 0x80; charval = QString("%1").arg(QChar(val)); zone = Normal; } // NORM LC
else if (val == 0xFF) { val = val; charval = QString("\u25a0"); zone = Normal; }
// if (val <= 0x1F) { val += 0x40; charval = QString("%1").arg(QChar(val)); zone = Inverse; } //INV UC
// else if (val <= 0x3F) { charval = QString("%1").arg(QChar(val)); zone = Inverse; } // INV SP
// else if (val <= 0x5F) { charval = QString("%1").arg(QChar(val)); zone = Flash; } // FL UC
// else if (val <= 0x7F) { val -= 0x40; charval = QString("%1").arg(QChar(val)); zone = Flash; } // FL SP
// else if (val <= 0x9F) { val -= 0x40; charval = QString("%1").arg(QChar(val)); zone = AltUC; } // NORMx UC
// else if (val <= 0xBF) { val -= 0x80; charval = QString("%1").arg(QChar(val)); zone = Normal; } // NORM SP
// else if (val <= 0xDF) { val -= 0x80; charval = QString("%1").arg(QChar(val)); zone = Normal; } // NORM UC
// else if (val < 0xFF) { val -= 0x80; charval = QString("%1").arg(QChar(val)); zone = Normal; } // NORM LC
// else /* (val == 0xFF)*/ { charval = QString("\u25a0"); zone = Normal; }
QString htmlstr = charval.toHtmlEscaped();
QString retval;
if (zone == Inverse) { retval = QString("<font color=\"blue\"><b>%1</b></font>").arg(htmlstr); }
else if (zone == Flash) { retval = QString("<font color=\"green\"><b><i>%1</i></b></font>").arg(htmlstr);}
else if (zone == AltUC) { retval = QString("<font color=\"red\"><i>%1</i></font>").arg(htmlstr);}
else /* zone == Normal */ { retval = QString("%1").arg(htmlstr);}
if (attribute == Inverse) { retval = QString("<font color=\"blue\"><b>%1</b></font>").arg(htmlstr); }
else if (attribute == Flash) { retval = QString("<font color=\"green\"><b><i>%1</i></b></font>").arg(htmlstr);}
else if (attribute == NormalLow) { retval = QString("<font color=\"red\"><i>%1</i></font>").arg(htmlstr);}
else { retval = QString("%1").arg(htmlstr);}
return retval;
}
@ -148,9 +160,35 @@ bool HexDumpViewer::optionsMenuItems(QMenu *menu)
this, &HexDumpViewer::toggleWordWrap);
menu->addAction(action);
menu->addSeparator();
if (m_setFontAction) {
m_setFontAction = new QAction("Set &Font...");
}
menu->addAction(m_setFontAction);
connect(m_setFontAction, &QAction::triggered,
this, [this] {
bool ok;
QFont font = QFontDialog::getFont(&ok,
ui->textArea->font(),
this, "Set Font",
QFontDialog::MonospacedFonts);
if (ok) {
setTextFont(font);
fontToSettings("HexDumpViewer.textFont", font);
}
});
return true;
}
void HexDumpViewer::setTextFont(const QFont &font)
{
ui->textArea->setFont(font);
}
void HexDumpViewer::setData(QByteArray data)
{
ui->textArea->setHtml(data);

View File

@ -35,11 +35,15 @@ public slots:
void doPrint();
void doExport();
protected:
void setTextFont(const QFont &font);
private:
void setText(QString text);
void setData(QByteArray data);
QString valToAppleAscii(quint8 val);
QAction *m_setFontAction;
Ui::HexDumpViewer *ui;
quint16 m_offset;

View File

@ -24,14 +24,7 @@
<number>1</number>
</property>
<item row="0" column="0" colspan="2">
<widget class="QTextBrowser" name="textArea">
<property name="font">
<font>
<family>Courier 10 Pitch</family>
<pointsize>10</pointsize>
</font>
</property>
</widget>
<widget class="QTextBrowser" name="textArea"/>
</item>
</layout>
</widget>

View File

@ -14,6 +14,11 @@ TextHexDumpViewer::TextHexDumpViewer(QWidget *parent) :
{
m_file = Q_NULLPTR;
ui->setupUi(this);
QFont textAreaFont;
textAreaFont.setStyleHint(QFont::Monospace);
ui->textArea->setFont(textAreaFont);
m_offset = 0;
QString title = QString("Text/Hex File Viewer");

View File

@ -15,14 +15,7 @@
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QTextBrowser" name="textArea">
<property name="font">
<font>
<family>Courier</family>
<pointsize>12</pointsize>
</font>
</property>
</widget>
<widget class="QTextBrowser" name="textArea"/>
</item>
</layout>
</widget>

View File

@ -12,6 +12,8 @@
#include "hexdumpviewer.h"
#include "texthexdumpviewer.h"
#include "charsetviewer.h"
#include "IntBasicFile.h"
#include "intbasicfileviewer.h"
#include "hiresviewwidget.h"
#include "disassemblerviewer.h"
#include "textfile.h"
@ -71,6 +73,17 @@ void ViewerBase::setFile(GenericFile *file)
descriptor="Applesoft File Viewer";
addViewer(descriptor,afv);
defaultViewerDescriptor = descriptor;
}
else if (dynamic_cast<IntBasicFile*>(file))
{
IntBasicFileViewer *ibf = new IntBasicFileViewer(0);
ibf->setFile(file);
descriptor="Integer Basic File Viewer";
addViewer(descriptor, ibf);
defaultViewerDescriptor = descriptor;
}
else if (dynamic_cast<BinaryFile*>(file))
{

View File

@ -18,7 +18,6 @@ FlowLineTextBrowser::FlowLineTextBrowser(QWidget *parent) : QTextBrowser(parent)
int FlowLineTextBrowser::getFirstVisibleBlock(QTextBlock *firstBlock) const
{
QTextCursor curs = QTextCursor(this->document());
curs.movePosition(QTextCursor::Start);
for(int i=0; i < this->document()->blockCount(); ++i)
@ -44,8 +43,8 @@ int FlowLineTextBrowser::getFirstVisibleBlock(QTextBlock *firstBlock) const
if (firstBlock)
*firstBlock = QTextBlock();
return 0;
return 0;
}
void FlowLineTextBrowser::showEvent(QShowEvent *)

View File

@ -2,7 +2,6 @@
#define ASCIIINFODIALOG_H
#include <QDialog>
#include "asciiinfodialog.h"
#include "ui_asciiinfodialog.h"
namespace Ui {

View File

@ -1,6 +1,7 @@
#include "hexconverter.h"
#include "ui_hexconverter.h"
#include <QString>
#include <QIntValidator>
HexConverter::HexConverter(QWidget *parent) :
QDialog(parent),

View File

@ -25,56 +25,71 @@ QVector<TextAttribute> AppleString::attributes() const
}
QChar AppleChar::printable() const
QChar AppleChar::printable(quint8 val)
{
quint8 newval;
switch (getTextSet()) {
case SetInvUC:
newval = m_val+0x40;
break;
case SetInvSp:
newval = m_val;
break;
case SetFlUC:
newval = m_val;
break;
case SetFlSp:
newval = m_val-0x40;
break;
case SetNormUC:
newval = m_val-0x40;
break;
case SetNormSp:
newval = m_val-0x80;
break;
case SetNormAltUC:
newval = m_val-0x80;
break;
case SetNormLC:
default:
newval = m_val-0x80;
break;
switch (getTextSet(val)) {
case SetInvUC:
newval = val+0x40;
break;
case SetInvSp:
newval = val;
break;
case SetFlUC:
newval = val;
break;
case SetFlSp:
newval = val-0x40;
break;
case SetNormUC:
newval = val-0x40;
break;
case SetNormSp:
newval = val-0x80;
break;
case SetNormAltUC:
newval = val-0x80;
break;
case SetNormLC:
default:
newval = val-0x80;
break;
}
return QChar(newval);
}
TextAttribute AppleChar::getAttribute() const
TextAttribute AppleChar::getAttribute(quint8 val)
{
if (m_val <= 0x3f) { return Inverse; }
if (m_val <= 0x7f) { return Flash; }
if (m_val <= 0xbf) { return Normal; }
if (m_val <= 0xdf) { return NormalHigh; }
return Normal;
if (val <= 0x3f) { return Inverse; }
if (val <= 0x7f) { return Flash; }
if (val <= 0xbf) { return NormalLow; }
if (val <= 0xdf) { return NormalHigh; }
return NormalHigh;
}
TextSet AppleChar::getTextSet() const {
if (m_val < 0x20) { return SetInvUC; }
if (m_val < 0x40) { return SetInvSp; }
if (m_val < 0x60) { return SetFlUC; }
if (m_val < 0x80) { return SetFlSp; }
if (m_val < 0xA0) { return SetNormUC; }
if (m_val < 0xC0) { return SetNormSp; }
if (m_val < 0xE0) { return SetNormAltUC; }
TextSet AppleChar::getTextSet(quint8 val) {
if (val < 0x20) { return SetInvUC; }
if (val < 0x40) { return SetInvSp; }
if (val < 0x60) { return SetFlUC; }
if (val < 0x80) { return SetFlSp; }
if (val < 0xA0) { return SetNormUC; }
if (val < 0xC0) { return SetNormSp; }
if (val < 0xE0) { return SetNormAltUC; }
return SetNormLC;
}
QString AppleChar::getHtmlString(quint8 val)
{
TextAttribute attribute = getAttribute(val);
QString htmlstring = printable(val);
htmlstring = htmlstring.toHtmlEscaped();
QString retval;
if (attribute == Inverse) { retval = QString("<font color=\"blue\"><b>%1</b></font>").arg(htmlstring); }
else if (attribute == Flash) { retval = QString("<font color=\"green\"><b><i>%1</i></b></font>").arg(htmlstring);}
else if (attribute == NormalLow) { retval = QString("<font color=\"red\"><i>%1</i></font>").arg(htmlstring);}
else { retval = QString("%1").arg(htmlstring);}
return retval;
}

View File

@ -13,10 +13,16 @@ public:
AppleChar() { m_val = 0; }
AppleChar(quint8 ch) { m_val = ch; }
QChar printable() const;
QChar printable() const { return printable(m_val); }
TextAttribute getAttribute() const { return getAttribute(m_val); }
TextSet getTextSet() const { return getTextSet(m_val); }
static TextAttribute getAttribute(quint8 val) ;
static TextSet getTextSet(quint8 val) ;
static QChar printable(quint8 val) ;
static QString getHtmlString(quint8 val);
TextAttribute getAttribute() const;
TextSet getTextSet() const;
private:
quint8 m_val;
@ -31,3 +37,4 @@ public:
};
#endif // APPLESTRING_H

View File

@ -13,7 +13,10 @@ void CharSetCharacter::setData(QByteArray bytes)
m_data = bytes;
}
void CharSetCharacter::setData(quint8 b0, quint8 b1, quint8 b2, quint8 b3, quint8 b4, quint8 b5, quint8 b6, quint8 b7)
void CharSetCharacter::setData(quint8 b0, quint8 b1,
quint8 b2, quint8 b3,
quint8 b4, quint8 b5,
quint8 b6, quint8 b7)
{
QByteArray data;
data.append(b0);

View File

@ -5,6 +5,8 @@
#include <QByteArray>
#include <QDebug>
#include <QColor>
#include <QFont>
#include <QSettings>
typedef enum {
DOSTextFile = 0x00,
@ -21,7 +23,7 @@ typedef enum {
typedef enum {
Inverse = 0x00, // 0x00 -- 0x3F
Flash = 0x01, // 0x40 -- 0x7F
Normal = 0x02, // 0x80 -- 0xBF
NormalLow = 0x02, // 0x80 -- 0xBF
NormalHigh = 0x04 // 0xC0 -- 0xFF
} TextAttribute;
@ -74,6 +76,20 @@ inline quint16 makeWord(quint8 lo, quint8 hi)
return hi*256 + lo;
}
inline QFont fontFromSettings(QString key, QFont &defaultfont)
{
QSettings settings;
QString result = settings.value(key, defaultfont.toString()).toString();
QFont retval;
retval.fromString(result);
return retval;
}
inline void fontToSettings(const QString &key, const QFont &font)
{
QSettings settings;
settings.setValue(key, font.toString());
}
#endif // UTIL_H