Consolidated viewers into one switchable widget

This commit is contained in:
Mark Long 2016-10-14 17:27:28 -05:00
parent 11670a9a30
commit 40f3c6dcaf
31 changed files with 433 additions and 146 deletions

View File

@ -55,7 +55,9 @@ SOURCES += \
src/ui/widgets/characterwidget.cpp \
src/ui/viewers/applesoftfiledetailviewer.cpp \
src/ui/widgets/hexconverter.cpp \
src/ui/widgets/hrcgcontrolsinfo.cpp
src/ui/widgets/hrcgcontrolsinfo.cpp \
src/ui/viewers/viewerbase.cpp \
src/ui/viewers/fileviewerinterface.cpp
HEADERS += \
@ -91,7 +93,9 @@ HEADERS += \
src/ui/viewers/charsetviewer.h \
src/ui/viewers/applesoftfiledetailviewer.h \
src/ui/widgets/hexconverter.h \
src/ui/widgets/hrcgcontrolsinfo.h
src/ui/widgets/hrcgcontrolsinfo.h \
src/ui/viewers/viewerbase.h \
src/ui/viewers/fileviewerinterface.h
FORMS += \
src/ui/catalogwidget.ui \
@ -102,4 +106,5 @@ FORMS += \
src/ui/viewers/texthexdumpviewer.ui \
src/ui/viewers/applesoftfiledetailviewer.ui \
src/ui/widgets/hexconverter.ui \
src/ui/widgets/hrcgcontrolsinfo.ui
src/ui/widgets/hrcgcontrolsinfo.ui \
src/ui/viewers/viewerbase.ui

View File

@ -29,9 +29,12 @@ DiskFile::~DiskFile()
bool DiskFile::read(QString filename)
{
QFile infile(filename);
QCryptographicHash hash(QCryptographicHash::Md5);
if (infile.open(QIODevice::ReadOnly))
{
QDataStream qds(&infile);
QByteArray contents = infile.readAll();
QDataStream qds(contents);
for (int track = 0; track < 35; track++)
{
for (int sector = 0; sector < 16; sector++)
@ -51,6 +54,10 @@ bool DiskFile::read(QString filename)
}
}
}
hash.addData(contents);
m_hash = hash.result();
qDebug() << "Hash: " << m_hash;
return true;
}

View File

@ -5,6 +5,7 @@
#include <QMap>
#include <QString>
#include <QDebug>
#include <QCryptographicHash>
#include "util.h"
#include "sector.h"
@ -36,11 +37,14 @@ public:
QList<FileDescriptiveEntry> getAllFDEs();
QByteArray fileHash() const { return m_hash; }
private:
QMap< int, QMap< int, Sector> > m_contents;
QMap<FileDescriptiveEntry,GenericFile *> m_files;
QByteArray m_hash;
};

View File

@ -104,108 +104,13 @@ void MainWindow::showLoadDialog()
}
}
void MainWindow::openInHiresViewWidget(BinaryFile *file, QString filename) {
HiresViewWidget *hvwma = new HiresViewWidget(0);
QString title = QString("Image: %1").arg(filename);
hvwma->setWindowTitle(title);
hvwma->show();
hvwma->setData(file->data());
}
void MainWindow::openInDisassemblerViewer(BinaryFile *file) {
DisassemblerViewer *hvwma = new DisassemblerViewer(0);
hvwma->show();
hvwma->setFile(file);
}
void MainWindow::openInMazeViewer(BinaryFile *file) {
MazeViewer *hvwma = new MazeViewer(0);
int cellw = 90;
hvwma->resize(cellw*8,cellw*10);
hvwma->show();
hvwma->setFile(file);
}
void MainWindow::openInCharSetViewer(BinaryFile *file)
{
CharSetViewer *csv = new CharSetViewer(0);
csv->setFile(file);
csv->show();
}
void MainWindow::openInApplesoftFileViewer(ApplesoftFile *file) {
ApplesoftFileViewer *afv = new ApplesoftFileViewer(0);
afv->setFile(file);
afv->show();
}
void MainWindow::handleDiskItemSelectedHexViewOpen(DiskFile *disk, FileDescriptiveEntry fde) {
GenericFile *file = disk->getFile(fde);
file->setFilename(AppleString(fde.filename).printable().trimmed());
HexDumpViewer *hdv = new HexDumpViewer(0);
hdv->setFile(file,file->address());
hdv->show();
}
void MainWindow::handleDiskItemSelectedDefaultOpen(DiskFile *disk, FileDescriptiveEntry fde)
{
GenericFile *file = disk->getFile(fde);
file->setFilename(AppleString(fde.filename).printable().trimmed());
qDebug() << "Default open. Type: " << fde.fileType();
if (dynamic_cast<BinaryFile*>(file)) {
BinaryFile *binfile = dynamic_cast<BinaryFile*>(file);
if (fde.lengthInSectors == 34 && (binfile->address() == 0x2000 || binfile->address() == 0x4000))
{
openInHiresViewWidget(binfile, AppleString(fde.filename).printable().trimmed());
}
else if (file->filename().contains("maze",Qt::CaseInsensitive))
{
openInMazeViewer(binfile);
}
else if (file->filename().contains(".set",Qt::CaseInsensitive))
{
openInCharSetViewer(binfile);
}
else
{
openInDisassemblerViewer(binfile);
}
}
else if (dynamic_cast<ApplesoftFile *>(file))
{
ApplesoftFile *abf = dynamic_cast<ApplesoftFile *>(file);
abf->setFilename(AppleString(fde.filename).printable().trimmed());
openInApplesoftFileViewer(abf);
}
else if (dynamic_cast<TextFile *>(file))
{
TextFile *tf = dynamic_cast<TextFile *>(file);
tf->setFilename(AppleString(fde.filename).printable().trimmed());
TextHexDumpViewer *thdv = new TextHexDumpViewer();
thdv->setFile(tf);
thdv->show();
}
else if (dynamic_cast<RelocatableFile *>(file))
{
RelocatableFile *rf = dynamic_cast<RelocatableFile *>(file);
// HexDumpViewer *hdv = new HexDumpViewer(0);
// hdv->setFile(file,file->address());
// hdv->show();
DisassemblerViewer *hvwma = new DisassemblerViewer(0);
hvwma->show();
hvwma->setFile(rf);
}
else
{
HexDumpViewer *hdv = new HexDumpViewer(0);
hdv->setFile(file,file->address());
hdv->show();
}
ViewerBase *vb = new ViewerBase();
vb->setFile(file);
vb->show();
}

View File

@ -9,7 +9,7 @@
//#include "relocatablefile.h"
#include "hexconverter.h"
#include "hrcgcontrolsinfo.h"
#include "viewerbase.h"
namespace Ui {
class MainWindow;
@ -30,7 +30,6 @@ public slots:
void showLoadDialog();
private slots:
void handleDiskItemSelectedHexViewOpen(DiskFile *disk, FileDescriptiveEntry fde);
void handleDiskItemSelectedDefaultOpen(DiskFile *disk, FileDescriptiveEntry fde);
signals:
@ -40,12 +39,6 @@ signals:
void diskFileUnloading(DiskFile *file);
void diskFileUnloaded();
protected:
void openInApplesoftFileViewer(ApplesoftFile *file);
void openInHiresViewWidget(BinaryFile *file, QString filename);
void openInDisassemblerViewer(BinaryFile *file);
void openInMazeViewer(BinaryFile *file);
void openInCharSetViewer(BinaryFile *file);
private:
Ui::MainWindow *ui;
HRCGControlsInfo *m_hrcgDialog;

View File

@ -21,6 +21,12 @@ ApplesoftFileDetailViewer::~ApplesoftFileDetailViewer()
delete ui;
}
void ApplesoftFileDetailViewer::setLineData(QVector<ApplesoftLine> lineData)
{
m_lines = lineData;
process();
}
void ApplesoftFileDetailViewer::process()
{
QMap<QString,QStringList> vardata;
@ -32,12 +38,12 @@ void ApplesoftFileDetailViewer::process()
foreach(ApplesoftToken token, line.tokens)
{
quint16 tid = token.getTokenId();
if (tid == ApplesoftToken::IntVarTokenVal ||
tid == ApplesoftToken::IntAryVarTokenVal ||
tid == ApplesoftToken::FloatVarTokenVal ||
tid == ApplesoftToken::FloatAryVarTokenVal ||
tid == ApplesoftToken::StringVarTokenVal ||
tid == ApplesoftToken::StringAryVarTokenVal)
if (tid == ApplesoftToken::IntVarTokenVal ||
tid == ApplesoftToken::IntAryVarTokenVal ||
tid == ApplesoftToken::FloatVarTokenVal ||
tid == ApplesoftToken::FloatAryVarTokenVal ||
tid == ApplesoftToken::StringVarTokenVal ||
tid == ApplesoftToken::StringAryVarTokenVal)
{
QString varname = token.getStringValue();
if (varname.contains("(")) { varname.append(")"); }

View File

@ -17,7 +17,7 @@ public:
explicit ApplesoftFileDetailViewer(QWidget *parent = 0);
~ApplesoftFileDetailViewer();
void setLineData(QVector<ApplesoftLine> lineData) { m_lines = lineData; process(); }
void setLineData(QVector<ApplesoftLine> lineData);
private:
void process();

View File

@ -3,13 +3,18 @@
#include "applesoftformatter.h"
#include "applesoftfiledetailviewer.h"
#include <QDebug>
#include <QSettings>
ApplesoftFileViewer::ApplesoftFileViewer(QWidget *parent) :
QWidget(parent),
FileViewerInterface(parent),
ui(new Ui::ApplesoftFileViewer)
{
ui->setupUi(this);
QSettings settings;
QString title = QString("AppleSoft Viewer");
m_title = title;
emit setTitle(title);
setWindowTitle(title);
m_formatter = new ApplesoftFormatter(this);
@ -20,6 +25,11 @@ ApplesoftFileViewer::ApplesoftFileViewer(QWidget *parent) :
ui->textArea->setUndoRedoEnabled(false);
ui->textArea->setUndoRedoEnabled(true);
setIntsAsHex(settings.value("ASViewer.intsAsHex",false).toBool());
ui->intHexCB->setChecked(settings.value("ASViewer.intsAsHex",false).toBool());
setIndentCode(settings.value("ASViewer.indentCode",false).toBool());
ui->indentCode->setChecked(settings.value("ASViewer.indentCode",false).toBool());
connect(ui->intHexCB, SIGNAL(toggled(bool)), SLOT(setIntsAsHex(bool)));
connect(ui->intHexCB, SIGNAL(toggled(bool)), ui->findText,SLOT(clear()));
@ -27,6 +37,7 @@ ApplesoftFileViewer::ApplesoftFileViewer(QWidget *parent) :
connect(ui->indentCode, SIGNAL(toggled(bool)), ui->findText,SLOT(clear()));
connect(ui->varBrowserButton, SIGNAL(clicked(bool)), SLOT(launchVarBrowser()));
}
ApplesoftFileViewer::~ApplesoftFileViewer()
@ -34,6 +45,11 @@ ApplesoftFileViewer::~ApplesoftFileViewer()
delete ui;
}
QMenu *ApplesoftFileViewer::optionsMenuItems() const
{
return Q_NULLPTR;
}
void ApplesoftFileViewer::setIndentCode(bool enabled)
{
if (enabled)
@ -44,6 +60,8 @@ void ApplesoftFileViewer::setIndentCode(bool enabled)
{
m_formatter->setFlags(m_formatter->flags() & ~ApplesoftFormatter::ReindentCode);
}
QSettings settings;
settings.setValue("ASViewer.indentCode",enabled);
reformatText();
}
@ -57,6 +75,8 @@ void ApplesoftFileViewer::setIntsAsHex(bool enabled)
{
m_formatter->setFlags(m_formatter->flags() & ~ApplesoftFormatter::ShowIntsAsHex);
}
QSettings settings;
settings.setValue("ASViewer.intsAsHex",enabled);
reformatText();
}
@ -65,11 +85,21 @@ void ApplesoftFileViewer::reformatText()
ui->textArea->setText(m_formatter->formatText());
}
void ApplesoftFileViewer::setFile(GenericFile *file) {
ApplesoftFile *af = dynamic_cast<ApplesoftFile*>(file);
if (af)
{
setFile(af);
}
}
void ApplesoftFileViewer::setFile(ApplesoftFile *file) {
m_file = file;
m_formatter->setFile(file);
QString title = QString("AppleSoft Viewer: %1").arg(m_file->filename());
m_title = title;
emit setTitle(title);
setWindowTitle(title);
ui->textArea->setText(m_formatter->formatText());

View File

@ -4,22 +4,26 @@
#include <QWidget>
#include "applesoftfile.h"
#include "applesoftformatter.h"
#include "viewerbase.h"
namespace Ui {
class ApplesoftFileViewer;
}
class ApplesoftFileViewer : public QWidget
class ApplesoftFileViewer : public FileViewerInterface
{
Q_OBJECT
public:
explicit ApplesoftFileViewer(QWidget *parent = 0);
ApplesoftFileViewer(QWidget *parent = 0);
~ApplesoftFileViewer();
// void setFormatter(ApplesoftFormatter *formatter);
virtual QMenu* optionsMenuItems() const;
public slots:
void setFile(GenericFile *file);
void setFile(ApplesoftFile *m_file);
void setData(QByteArray data);
void setText(QString text);

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ApplesoftFileViewer</class>
<widget class="QWidget" name="ApplesoftFileViewer">
<widget class="FileViewerInterface" name="ApplesoftFileViewer">
<property name="geometry">
<rect>
<x>0</x>

View File

@ -1,14 +1,26 @@
#include "charsetviewer.h"
#include <QGridLayout>
CharSetViewer::CharSetViewer(QWidget *parent) : QWidget(parent)
CharSetViewer::CharSetViewer(QWidget *parent) : FileViewerInterface(parent)
{
m_file = Q_NULLPTR;
QGridLayout *qgl = new QGridLayout(this);
setLayout(qgl);
QString title = QString("Character Set Viewer");
setWindowTitle(title);
}
void CharSetViewer::setFile(GenericFile *file)
{
if (dynamic_cast<BinaryFile*>(file))
{
BinaryFile *bf = dynamic_cast<BinaryFile*>(file);
setFile(bf);
}
}
void CharSetViewer::setFile(BinaryFile *file)
{
m_file = file;
@ -27,8 +39,12 @@ void CharSetViewer::setFile(BinaryFile *file)
cw->enableBitShift(true);
cw->setBgColor(Qt::white);
cw->setFgColor(Qt::black);
cw->move(xpos,ypos);
QGridLayout *qgl = qobject_cast<QGridLayout*>(this->layout());
qgl->addWidget(cw,ypos,xpos);
//cw->move(xpos,ypos);
cw->show();
xpos+= cw->width();
if (xpos/cw->width() > 11) {
xpos = 0;

View File

@ -3,15 +3,17 @@
#include "binaryfile.h"
#include "characterwidget.h"
#include "fileviewerinterface.h"
#include <QWidget>
class CharSetViewer : public QWidget
class CharSetViewer : public FileViewerInterface
{
Q_OBJECT
public:
explicit CharSetViewer(QWidget *parent = 0);
void setFile(GenericFile *file);
void setFile(BinaryFile *file);
signals:

View File

@ -2,11 +2,12 @@
#include "ui_disassemblerviewer.h"
#include "disassembler.h"
#include "memory.h"
#include "relocatablefile.h"
#include <QDebug>
DisassemblerViewer::DisassemblerViewer(QWidget *parent) :
QWidget(parent),
FileViewerInterface(parent),
ui(new Ui::DisassemblerViewer)
{
ui->setupUi(this);
@ -20,6 +21,18 @@ DisassemblerViewer::~DisassemblerViewer()
delete ui;
}
void DisassemblerViewer::setFile(GenericFile *file)
{
if (dynamic_cast<RelocatableFile*>(file))
{
setFile(dynamic_cast<RelocatableFile*>(file));
}
if (dynamic_cast<BinaryFile*>(file))
{
setFile(dynamic_cast<BinaryFile*>(file));
}
}
void DisassemblerViewer::setFile(BinaryFile *file) {
m_file = file;

View File

@ -6,12 +6,13 @@
#include "binaryfile.h"
#include "relocatablefile.h"
#include "fileviewerinterface.h"
namespace Ui {
class DisassemblerViewer;
}
class DisassemblerViewer : public QWidget
class DisassemblerViewer : public FileViewerInterface
{
Q_OBJECT
@ -25,6 +26,10 @@ public:
void setText(QString text);
QString getPotentialLabel(quint16 address);
public slots:
void setFile(GenericFile *file);
private:
Ui::DisassemblerViewer *ui;

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DisassemblerViewer</class>
<widget class="QWidget" name="DisassemblerViewer">
<widget class="FileViewerInterface" name="DisassemblerViewer">
<property name="geometry">
<rect>
<x>0</x>

View File

@ -0,0 +1,7 @@
#include "fileviewerinterface.h"
void FileViewerInterface::activate()
{
}

View File

@ -0,0 +1,36 @@
#ifndef FILEVIEWERINTERFACE_H
#define FILEVIEWERINTERFACE_H
#include <QWidget>
#include <QString>
class GenericFile;
class QMenu;
class FileViewerInterface : public QWidget
{
Q_OBJECT
public:
FileViewerInterface(QWidget *parent = Q_NULLPTR) : QWidget(parent) { }
virtual QMenu *optionsMenuItems() const { return Q_NULLPTR; }
bool canPrint() const { return false; }
public slots:
virtual void activate();
virtual void setFile(GenericFile *file) = 0;
void doPrint() { }
QString title() const { return m_title; }
signals:
void setTitle(QString title);
protected:
QString m_title;
};
#endif // FILEVIEWERINTERFACE_H

View File

@ -5,7 +5,7 @@
#include <QScrollBar>
HexDumpViewer::HexDumpViewer(QWidget *parent) :
QWidget(parent),
FileViewerInterface(parent),
ui(new Ui::HexDumpViewer)
{
ui->setupUi(this);

View File

@ -2,6 +2,7 @@
#define HEXDUMPVIEWER_H
#include "genericfile.h"
#include "fileviewerinterface.h"
#include <QString>
#include <QByteArray>
@ -12,7 +13,7 @@ namespace Ui {
class HexDumpViewer;
}
class HexDumpViewer : public QWidget
class HexDumpViewer : public FileViewerInterface
{
Q_OBJECT
@ -20,7 +21,10 @@ public:
explicit HexDumpViewer(QWidget *parent = 0);
~HexDumpViewer();
void setFile(GenericFile *file, quint16 offset = 0);
void setFile(GenericFile *file) { setFile(file,0); }
void setFile(GenericFile *file, quint16 offset);
public slots:
void showHexAndAsciiValues();

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>HexDumpViewer</class>
<widget class="QWidget" name="HexDumpViewer">
<widget class="FileViewerInterface" name="HexDumpViewer">
<property name="geometry">
<rect>
<x>0</x>

View File

@ -10,7 +10,7 @@
HiresViewWidget::HiresViewWidget(QWidget *parent) :
QWidget(parent)
FileViewerInterface(parent)
{
resize(561,384);
m_viewMode = Color2;
@ -18,9 +18,7 @@ HiresViewWidget::HiresViewWidget(QWidget *parent) :
if (m_rowTable == 0) { makeOffsetTable(); }
qDebug() << "ctor";
m_pixmap = QPixmap(561,384);
qDebug() << "Pixmap size: " << m_pixmap.size();
QPainter painter(&m_pixmap);
painter.setBrush(Qt::black);
painter.drawRect(0,0,this->width(),this->height());
@ -83,7 +81,6 @@ void HiresViewWidget::handleShowScanLinesAction(bool toggled) {
void HiresViewWidget::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
qDebug() << "paintEvent";
// if (m_pixmap.size() != this->size()) {
// m_pixmap = m_pixmap.scaled(this->size(),Qt::KeepAspectRatio);
@ -94,14 +91,13 @@ void HiresViewWidget::paintEvent(QPaintEvent *event)
QPainter painter(this);
QPixmap tmppixmap = m_pixmap;
tmppixmap = tmppixmap.scaled(this->size(), Qt::KeepAspectRatio);
// tmppixmap = tmppixmap.scaled(this->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
painter.drawPixmap(0,0,tmppixmap);
}
void HiresViewWidget::resizeEvent(QResizeEvent *)
{
qDebug() << "resizeEvent";
}
@ -515,5 +511,14 @@ void HiresViewWidget::contextMenuEvent(QContextMenuEvent *event) {
menu.exec(event->globalPos());
}
void HiresViewWidget::setFile(GenericFile *file)
{
BinaryFile *af = dynamic_cast<BinaryFile*>(file);
if (af)
{
setFile(af);
}
}
QMap<int,int> *HiresViewWidget::m_rowTable = 0;

View File

@ -2,6 +2,7 @@
#define HIRESVIEWWIDGET_H
#include "binaryfile.h"
#include "fileviewerinterface.h"
#include <QWidget>
#include <QPixmap>
@ -30,7 +31,7 @@ static const QColor lightBlueColor = QColor(208,195,255);
static const QColor whiteColor = QColor(255,255,255);
class HiresViewWidget : public QWidget
class HiresViewWidget : public FileViewerInterface
{
Q_OBJECT
public:
@ -53,7 +54,9 @@ public:
signals:
public slots:
void setFile(GenericFile *file);
void setFile(BinaryFile *file);
void setData(QByteArray data);
void setMode(ViewMode);

View File

@ -5,7 +5,7 @@
#include "memory.h"
MazeViewer::MazeViewer(QWidget *parent) : QWidget(parent)
MazeViewer::MazeViewer(QWidget *parent) : FileViewerInterface(parent)
{
setMinimumSize(480,600);
m_maze = QPixmap(width(),height());
@ -28,6 +28,14 @@ void MazeViewer::paintEvent(QPaintEvent *event)
painter.drawPixmap(0,0,m_maze);
}
void MazeViewer::setFile(GenericFile *file)
{
if (dynamic_cast<BinaryFile*>(file))
{
setFile(dynamic_cast<BinaryFile*>(file));
}
}
void MazeViewer::setFile(BinaryFile *file)
{
m_file = file;

View File

@ -7,11 +7,12 @@
#include "binaryfile.h"
#include "memory.h"
#include "fileviewerinterface.h"
/// A class for viewing maze files in "The Missing Ring" by DataMost.
class MazeViewer : public QWidget
class MazeViewer : public FileViewerInterface
{
Q_OBJECT
public:
@ -21,6 +22,8 @@ public:
void resizeEvent(QResizeEvent *event);
void paintEvent(QPaintEvent *event);
void setFile(GenericFile *file);
void setFile(BinaryFile *file);
private:

View File

@ -6,7 +6,7 @@
#include <QByteArray>
TextHexDumpViewer::TextHexDumpViewer(QWidget *parent) :
QWidget(parent),
FileViewerInterface(parent),
ui(new Ui::TextHexDumpViewer)
{
ui->setupUi(this);

View File

@ -2,6 +2,7 @@
#define TEXTHEXDUMPVIEWER_H
#include "genericfile.h"
#include "fileviewerinterface.h"
#include <QString>
#include <QByteArray>
@ -12,7 +13,7 @@ namespace Ui {
class TextHexDumpViewer;
}
class TextHexDumpViewer : public QWidget
class TextHexDumpViewer : public FileViewerInterface
{
Q_OBJECT
@ -20,7 +21,8 @@ public:
explicit TextHexDumpViewer(QWidget *parent = 0);
~TextHexDumpViewer();
void setFile(GenericFile *file, quint16 offset = 0);
void setFile(GenericFile *file) { setFile(file,0); }
void setFile(GenericFile *file, quint16 offset);
void setData(QByteArray data);
void setText(QString text);

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TextHexDumpViewer</class>
<widget class="QWidget" name="TextHexDumpViewer">
<widget class="FileViewerInterface" name="TextHexDumpViewer">
<property name="geometry">
<rect>
<x>0</x>

View File

@ -0,0 +1,135 @@
#include "viewerbase.h"
#include "ui_viewerbase.h"
#include <QCloseEvent>
#include <QToolBar>
#include <QComboBox>
#include <QLabel>
#include "applesoftfileviewer.h"
#include "hexdumpviewer.h"
#include "texthexdumpviewer.h"
#include "charsetviewer.h"
#include "hiresviewwidget.h"
#include "disassemblerviewer.h"
#include "textfile.h"
#include "mazeviewer.h"
ViewerBase::ViewerBase(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::ViewerBase)
{
setMinimumWidth(1024);
m_stack = new QStackedWidget(this);
ui->setupUi(this);
setCentralWidget(m_stack);
m_toolbar = new QToolBar(this);
addToolBar(m_toolbar);
QLabel *label = new QLabel("View With: ");
m_toolbar->addWidget(label);
m_viewercombo = new QComboBox(m_toolbar);
m_toolbar->addWidget(m_viewercombo);
connect(m_viewercombo, SIGNAL(currentIndexChanged(QString)), SLOT(showViewer(QString)));
}
ViewerBase::~ViewerBase()
{
delete ui;
}
void ViewerBase::setFile(GenericFile *file)
{
m_file = file;
QString descriptor;
HexDumpViewer *hdv = new HexDumpViewer(0);
hdv->setFile(file);
descriptor = ("Hex Dump Viewer");
addViewer(descriptor,hdv);
if (dynamic_cast<ApplesoftFile*>(file))
{
ApplesoftFileViewer *afv = new ApplesoftFileViewer(0);
afv->setFile(file);
descriptor="Applesoft File Viewer";
addViewer(descriptor,afv);
m_stack->setCurrentWidget(afv);
showViewer(descriptor);
}
else if (dynamic_cast<BinaryFile*>(file))
{
BinaryFile *bf = dynamic_cast<BinaryFile*>(file);
CharSetViewer *csv = new CharSetViewer();
csv->setFile(bf);
descriptor ="HRCG Character Set Viewer";
addViewer(descriptor,csv);
HiresViewWidget *hrvw = new HiresViewWidget();
hrvw->setFile(bf);
descriptor = "HiRes Image Viewer";
addViewer(descriptor,hrvw);
MazeViewer *mv = new MazeViewer();
mv->setFile(file);
descriptor = "MissingRing Maze Viewer";
addViewer(descriptor,mv);
DisassemblerViewer *dv = new DisassemblerViewer();
dv->setFile(bf);
descriptor = "Disassembler Viewer";
addViewer(descriptor,dv);
showViewer(descriptor);
}
else if (dynamic_cast<TextFile*>(file))
{
BinaryFile *bf = dynamic_cast<BinaryFile*>(file);
TextHexDumpViewer *thdv = new TextHexDumpViewer();
thdv->setFile(bf);
descriptor = QString("Text/Hex Dump Viewer");
addViewer(descriptor,thdv);
showViewer(descriptor);
}
else if (dynamic_cast<RelocatableFile*>(file))
{
DisassemblerViewer *dv = new DisassemblerViewer();
dv->setFile(file);
descriptor = "Relocatable Disassembler Viewer";
addViewer(descriptor,dv);
}
else
{
showViewer(descriptor);
}
}
void ViewerBase::closeEvent(QCloseEvent *event)
{
event->accept();
}
void ViewerBase::addViewer(QString descriptor, FileViewerInterface *viewer)
{
if (!m_viewers.contains(descriptor))
{
m_viewers[descriptor] = viewer;
m_viewercombo->addItem(descriptor);
m_stack->addWidget(viewer);
}
}
void ViewerBase::showViewer(QString descriptor)
{
m_viewercombo->setCurrentText(descriptor);
FileViewerInterface *fvi = m_viewers[descriptor];
m_stack->setCurrentWidget(fvi);
setWindowTitle(fvi->windowTitle());
}

View File

@ -0,0 +1,43 @@
#ifndef VIEWERBASE_H
#define VIEWERBASE_H
#include <QMainWindow>
#include <QStackedWidget>
#include <QToolBar>
#include <QComboBox>
#include "fileviewerinterface.h"
#include "genericfile.h"
namespace Ui {
class ViewerBase;
}
class ViewerBase : public QMainWindow
{
Q_OBJECT
public:
explicit ViewerBase(QWidget *parent = 0);
~ViewerBase();
void setFile(GenericFile *file);
public slots:
void showViewer(QString descriptor);
protected:
void closeEvent(QCloseEvent *event);
void addViewer(QString descriptor, FileViewerInterface *viewer);
private:
Ui::ViewerBase *ui;
QStackedWidget *m_stack;
QToolBar *m_toolbar;
QComboBox *m_viewercombo;
QMap<QString,FileViewerInterface *> m_viewers;
GenericFile *m_file;
};
#endif // VIEWERBASE_H

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ViewerBase</class>
<widget class="QMainWindow" name="ViewerBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>818</width>
<height>614</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget"/>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>818</width>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menu_File">
<property name="title">
<string>&amp;File</string>
</property>
<addaction name="action_Print"/>
<addaction name="separator"/>
<addaction name="action_Close"/>
</widget>
<addaction name="menu_File"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="action_Print">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>&amp;Print</string>
</property>
</action>
<action name="action_Close">
<property name="text">
<string>&amp;Close</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -65,7 +65,6 @@ void CharacterWidget::doRepaint()
m_scale*2, m_scale*2);
}
}
}
if (m_showgrid)
@ -85,7 +84,6 @@ void CharacterWidget::doRepaint()
painter.drawLine(0,m_pixmap.height(), m_pixmap.width(), m_pixmap.height());
painter.drawLine(m_pixmap.width(), m_pixmap.height(), m_pixmap.width(),0);
painter.drawLine(m_pixmap.width(),0, 0,0);
}
repaint();