Updated catalogview with tooltips

This commit is contained in:
Mark Long 2016-02-10 10:10:37 -06:00
parent c707b58f4a
commit cbd6c53803
11 changed files with 109 additions and 20 deletions

View File

@ -1,5 +1,6 @@
QT += core gui
CONFIG += c++11
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

View File

@ -17,6 +17,7 @@ void ApplesoftFile::setData(QByteArray data)
quint8 addhi = m_data.at(1);
m_length = addlo + (addhi * 256);
m_data.remove(0,2);
m_data = m_data.left(m_length);
parse();
}
@ -48,8 +49,11 @@ void ApplesoftFile::parse(quint16 start_address)
m_data_end = idx;
if (idx < m_data.length()) {
qDebug() << QString("%1 byte(s) unaccounted for.").arg(m_data.length() - idx);
// if (idx < m_data.length()) {
// qDebug() << QString("%1 byte(s) unaccounted for.").arg(m_data.length() - idx);
// }
if (idx < m_length) {
qDebug() << QString("%1 byte(s) unaccounted for.").arg(m_length - idx);
}
}

View File

@ -21,6 +21,7 @@ public:
QVector<ApplesoftLine> getLines() const { return m_lines; }
quint16 length() const { return m_length; }
private:
void parse(quint16 start_address = 0x0801);

View File

@ -7,16 +7,16 @@
QList<QStringList> Disassembler::disassemble(quint16 from, quint16 to) {
QList<QStringList> retval;
// qDebug() << "From: " << from << " To: " << to;
quint16 next = 0;
for (int idx = from; idx <= to; )
{
QStringList line = disassembleOp(quint16(idx), &next);
retval.append(line);
// qDebug() << idx << line.join(" ");
idx = next ;
if (idx > 0xffff || (next < from)) { qDebug() << "Breaking." ; break; }
if (idx > 0xffff || (next < from)) {
qDebug() << "Breaking.";
break;
}
}
return retval;

View File

@ -1,7 +1,13 @@
#include "catalogwidget.h"
#include "ui_catalogwidget.h"
#include "filedescriptiveentry.h"
#include "binaryfile.h"
#include "applesoftfile.h"
#include "genericfile.h"
#include <QUrl>
#include <QDebug>
#include <QMenu>
#include <QAction>
CatalogWidget::CatalogWidget(QWidget *parent) :
QWidget(parent),
@ -13,6 +19,26 @@ CatalogWidget::CatalogWidget(QWidget *parent) :
connect(ui->catalog_list, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
SLOT(itemClicked(QListWidgetItem*)));
ui->catalog_list->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->catalog_list, SIGNAL(customContextMenuRequested(const QPoint &)),
SLOT(showContextMenuForWidget(const QPoint &)));
}
void CatalogWidget::showContextMenuForWidget(const QPoint &point) {
QListWidgetItem *selectedItem = ui->catalog_list->itemAt(point);
QMenu contextMenu("Context menu",this);
QAction *viewAction = new QAction("View",this);
connect(viewAction, &QAction::triggered,
[=](){ this->itemClicked(selectedItem); viewAction->deleteLater();});
contextMenu.addAction(viewAction);
QAction *viewWithAction = new QAction("View With...",this);
connect(viewWithAction, &QAction::triggered,
[=](){ this->itemClicked(selectedItem); viewWithAction->deleteLater();});
contextMenu.addAction(viewWithAction);
contextMenu.exec(mapToGlobal(point));
}
CatalogWidget::~CatalogWidget()
@ -26,6 +52,43 @@ void CatalogWidget::prepForNewDisk(QString filename, DiskFile *disk)
m_diskname = filename;
}
QString CatalogWidget::createToolTip(FileDescriptiveEntry &fde) {
QString retval;
retval += AppleString(fde.filename).printable().trimmed() + "\n";
retval += QString("Type: %1\n").arg(fde.fileType());
retval += QString("Sectors: %1 (%2 bytes)\n").arg(fde.lengthInSectors).arg(fde.lengthInSectors*256);
retval += QString("%1\n").arg(fde.isLocked()?"Locked":"Unlocked");
GenericFile *file = m_disk->getFile(fde);
if (dynamic_cast<BinaryFile*>(file)) {
BinaryFile *binfile = dynamic_cast<BinaryFile*>(file);
quint16 address = binfile->address();
quint16 length = binfile->length();
retval += QString("Address: $%1 (%2)\n").arg((quint16) (address),4,16,QChar('0'))
.arg(address);
retval += QString("Length: $%1 (%2)\n").arg((quint16) (length),4,16,QChar('0'))
.arg(length);
} else if (dynamic_cast<ApplesoftFile*>(file)) {
ApplesoftFile *asfile = dynamic_cast<ApplesoftFile*>(file);
quint16 length = asfile->length();
retval += QString("Length: $%1 (%2)\n").arg((quint16) (length),4,16,QChar('0'))
.arg(length);
quint16 uabytes = asfile->extraData().length();
if (uabytes) {
retval += QString("Unaccounted Bytes: $%1 (%2)\n").arg((quint16) (uabytes),4,16,QChar('0'))
.arg(uabytes);
}
} else {
retval += QString("Data Length: $%1 (%2)\n").arg((quint16) (file->data().length()),4,16,QChar('0'))
.arg(file->data().length());
}
return retval;
}
void CatalogWidget::processNewlyLoadedDisk(QString diskfilename, DiskFile *disk)
{
if (m_disk == disk) {
@ -43,6 +106,7 @@ void CatalogWidget::processNewlyLoadedDisk(QString diskfilename, DiskFile *disk)
QString sizeStr = QString("%1").arg(size,5,10,QChar(' ')).toUpper();
QString text = QString("%1 %2 %3 %4").arg(locked?"*":" ").arg(sizeStr).arg(filetype).arg(filename);
QListWidgetItem *item = new QListWidgetItem(text);
item->setToolTip(createToolTip(fde));
item->setData(0x0100,idx);
ui->catalog_list->addItem(item);
QRect rect = fm->boundingRect(text);
@ -65,6 +129,8 @@ void CatalogWidget::unloadDisk(DiskFile *disk)
ui->volume_label->clear();
}
void CatalogWidget::itemClicked(QListWidgetItem *item)
{
int idx = item->data(0x0100).toInt();

View File

@ -25,10 +25,13 @@ public slots:
void processNewlyLoadedDisk(QString filename, DiskFile *disk);
void unloadDisk(DiskFile *disk);
void showContextMenuForWidget(const QPoint &);
signals:
void newFileSelected(FileDescriptiveEntry *entry);
void itemSelected(DiskFile *disk, FileDescriptiveEntry fde);
protected:
QString createToolTip(FileDescriptiveEntry &fde);
private slots:
void itemClicked(QListWidgetItem *item);

View File

@ -90,6 +90,14 @@ void MainWindow::openInHiresViewWidget(BinaryFile *file, QString filename) {
hvwma->setData(file->data());
}
void MainWindow::openInDisassemblerViewer(BinaryFile *file) {
DisassemblerViewer *hvwma = new DisassemblerViewer(0);
hvwma->show();
hvwma->setFile(file);
}
void MainWindow::handleDiskItemSelectedDefaultOpen(DiskFile *disk, FileDescriptiveEntry fde)
{
GenericFile *file = disk->getFile(fde);
@ -104,19 +112,8 @@ void MainWindow::handleDiskItemSelectedDefaultOpen(DiskFile *disk, FileDescripti
}
else
{
DisassemblerViewer *hvwma = new DisassemblerViewer(0);
openInDisassemblerViewer(binfile);
// QString title = QString("Image: %1").arg(AppleString(fde.filename).printable().trimmed());
// hvwma->setWindowTitle(title);
hvwma->show();
hvwma->setFile(binfile);
// quint16 address = binfile->address();
// Memory mem;
// mem.addFile(binfile->data(), address);
// Disassembler dis(mem.values());
// dis.disassemble(binfile->address(), binfile->address()+binfile->length());
}
}
else if (dynamic_cast<ApplesoftFile *>(file))

View File

@ -36,6 +36,7 @@ signals:
protected:
void openInHiresViewWidget(BinaryFile *file, QString filename);
void openInDisassemblerViewer(BinaryFile *file);
private:
Ui::MainWindow *ui;

View File

@ -40,7 +40,6 @@ void DisassemblerViewer::setFile(BinaryFile *file) {
QByteArray joinedlines = qPrintable(formattedLines.join("\n"));
setData(joinedlines);
}
void DisassemblerViewer::setData(QByteArray data)

View File

@ -1,4 +1,6 @@
#include "hiresviewwidget.h"
#include "binaryfile.h"
#include <QPainter>
#include <QMap>
#include <QDebug>
@ -282,8 +284,17 @@ void HiresViewWidget::drawPixmap() {
}
}
void HiresViewWidget::setFile(BinaryFile *file) {
m_file = file;
QString title = QString("Image: %1").arg(m_file->filename());
setWindowTitle(title);
setData(file->data());
}
void HiresViewWidget::setData(QByteArray data) {
qDebug() << "setData";
m_data = data;
drawPixmap();

View File

@ -1,6 +1,8 @@
#ifndef HIRESVIEWWIDGET_H
#define HIRESVIEWWIDGET_H
#include "binaryfile.h"
#include <QWidget>
#include <QPixmap>
#include <QByteArray>
@ -47,9 +49,11 @@ public:
static QBitArray byteToBits(quint8 byte);
void contextMenuEvent(QContextMenuEvent *);
signals:
public slots:
void setFile(BinaryFile *file);
void setData(QByteArray data);
void setMode(ViewMode);
@ -84,6 +88,8 @@ private:
bool m_showScanLines;
void drawPixmap();
BinaryFile *m_file;
};