From b79e71ad6d2f71a2c1ccacb3d37ff02be60f2538 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Tue, 1 Feb 2011 03:00:48 +0000 Subject: [PATCH] Fixed random crashes due to QImage corruption. --- Makefile | 162 ++++++++++++++++++++++++++------------ src/gui/app.cpp | 17 +++- src/gui/filelistmodel.cpp | 21 ++++- src/gui/filelistmodel.h | 18 +++-- src/gui/filepicker.cpp | 78 +++++++++++++++--- src/gui/filepicker.h | 2 +- src/gui/filethread.cpp | 35 ++++++-- src/gui/filethread.h | 2 +- src/gui/imagedelegate.cpp | 8 +- src/gui/mainwin.cpp | 4 +- 10 files changed, 268 insertions(+), 79 deletions(-) diff --git a/Makefile b/Makefile index c191bf4..895a0ab 100644 --- a/Makefile +++ b/Makefile @@ -8,63 +8,72 @@ # # NOTE: zlib and OpenGL libs are a dependency, but are not checked for. -# same goes for libcdio +# same goes for libcdio, Qt # Figure out which system we're compiling for, and set the appropriate variables -ifeq "$(OSTYPE)" "msys" # Win32 +OSTYPE := $(shell uname -a) -SYSTYPE = __GCCWIN32__ -EXESUFFIX = .exe -GLLIB = -lopengl32 -ICON = obj/icon.o -SDLLIBTYPE = --libs -MSG = Win32 on MinGW +ifeq "$(findstring Msys,$(OSTYPE))" "Msys" # Win32 -else -#ifeq "$(OSTYPE)" "darwin" -ifeq "darwin" "$(findstring darwin,$(OSTYPE))" # Should catch both 'darwin' and 'darwin7.0' +SYSTYPE := __GCCWIN32__ +EXESUFFIX := .exe +GLLIB := -lopengl32 +ICON := obj/icon.o +SDLLIBTYPE := --libs +MSG := Win32 on MinGW + +else ifeq "$(findstring Darwin,$(OSTYPE))" "Darwin" # Should catch both 'darwin' and 'darwin7.0' + +SYSTYPE := __GCCUNIX__ -D_OSX_ +EXESUFFIX := +GLLIB := +ICON := +SDLLIBTYPE := --static-libs +MSG := Mac OS X -SYSTYPE = __GCCUNIX__ -D_OSX_ -EXESUFFIX = -GLLIB = -ICON = -SDLLIBTYPE = --static-libs -MSG = Mac OS X +else ifeq "$(findstring Linux,$(OSTYPE))" "Linux" # Linux + +SYSTYPE := __GCCUNIX__ +EXESUFFIX := +GLLIB := -lGL -lGLU +ICON := +SDLLIBTYPE := --libs +MSG := GNU/Linux else # *nix -SYSTYPE = __GCCUNIX__ -EXESUFFIX = -GLLIB = -lGL -lGLU -ICON = -SDLLIBTYPE = --libs -MSG = generic Unix/Linux +$(error OS TYPE UNDETECTED) endif + +# Set vars for libcdio +ifneq "$(shell pkg-config --silence-errors --libs libcdio)" "" +HAVECDIO := -DHAVE_LIB_CDIO +CDIOLIB := -lcdio +else +HAVECDIO := +CDIOLIB := endif -CC = gcc -LD = gcc -TARGET = virtualjaguar +CC := gcc +LD := gcc +TARGET := virtualjaguar # Note that we use optimization level 2 instead of 3--3 doesn't seem to gain much over 2 -CFLAGS = -MMD -Wall -Wno-switch -O2 -D$(SYSTYPE) -ffast-math -fomit-frame-pointer `sdl-config --cflags` -CPPFLAGS = -MMD -Wall -Wno-switch -Wno-non-virtual-dtor -O2 -D$(SYSTYPE) -Wno-trigraphs \ - -DHAVE_LIB_CDIO -ffast-math -fomit-frame-pointer `sdl-config --cflags` -g +CFLAGS := -MMD -Wall -Wno-switch -O2 -D$(SYSTYPE) -ffast-math -fomit-frame-pointer `sdl-config --cflags` +CPPFLAGS := -MMD -Wall -Wno-switch -Wno-non-virtual-dtor -O2 -D$(SYSTYPE) -Wno-trigraphs \ + $(HAVECDIO) -ffast-math -fomit-frame-pointer `sdl-config --cflags` -g # -fomit-frame-pointer `sdl-config --cflags` -g # -fomit-frame-pointer `sdl-config --cflags` -DLOG_UNMAPPED_MEMORY_ACCESSES -LDFLAGS = +LDFLAGS := -LIBS = -L/usr/local/lib -L/usr/lib `sdl-config $(SDLLIBTYPE)` -lstdc++ -lz $(GLLIB) -lcdio `pkg-config --libs QtGui QtOpenGL` -# Comment out the above and uncomment below if you don't have libcdio. -# Also, remove the "-DHAVE_LIB_CDIO" from CPPFLAGS above. -#LIBS = -L/usr/local/lib -L/usr/lib `sdl-config $(SDLLIBTYPE)` -lstdc++ -lz $(GLLIB) +LIBS := -L/usr/local/lib -L/usr/lib `sdl-config $(SDLLIBTYPE)` -lstdc++ -lz $(GLLIB) $(CDIOLIB) `pkg-config --libs QtGui QtOpenGL` -INCS = -I. -I./src -I./src/gui -I/usr/local/include -I/usr/include +INCS := -I. -I./src -I./src/gui -I/usr/local/include -I/usr/include -OBJS = \ +OBJS := \ obj/m68kcpu.o \ obj/m68kops.o \ obj/m68kopac.o \ @@ -117,30 +126,81 @@ OBJS = \ obj/wavetable.o \ $(ICON) -all: checkenv message obj $(TARGET)$(EXESUFFIX) +# Targets for convenience sake, not "real" targets +.PHONY: clean + +all: checkenv message2 obj $(TARGET)$(EXESUFFIX) @echo @echo -e "\033[01;33m***\033[00;32m Looks like it compiled OK... Give it a whirl!\033[00m" # Check the compilation environment, barf if not appropriate -checkenv: - @echo - @echo -en "\033[01;33m***\033[00;32m Checking compilation environment... \033[00m" -ifeq "" "$(shell which sdl-config)" - @echo +checkenv: msg-check-env check-sdl check-zlib check-cdio check-gl check-qt ; + +#check-sdl: msg-ck-sdl $(if $(strip ),,msg-no-sdl stop-on-error) +check-sdl: msg-ck-sdl $(if $(shell which sdl-config),,msg-no-sdl stop-on-error) + @echo -e "\033[01;37mOK\033[00m" + +msg-ck-sdl: + @echo -en " \033[00;32mSDL... \033[00m" + +msg-no-sdl: + @echo -e "\033[01;37mNOT FOUND\033[00m" @echo @echo -e "\033[01;33mIt seems that you don't have the SDL development libraries installed. If you" @echo -e "have installed them, make sure that the sdl-config file is somewhere in your" @echo -e "path and is executable.\033[00m" @echo -#Is there a better way to break out of the makefile? - @breaky -else + +check-zlib: msg-ck-zlib $(if $(shell pkg-config --silence-errors --libs zlib),,msg-no-zlib stop-on-error) @echo -e "\033[01;37mOK\033[00m" -endif -# !!! NOTE !!! Need to put a check here for libcdio, GL, zlib, Qt -message: +msg-ck-zlib: + @echo -en " \033[00;32mZLIB... \033[00m" + +msg-no-zlib: + @echo -e "\033[01;37mNOT FOUND\033[00m" + @echo + @echo -e "\033[01;33mIt seems that you don't have ZLIB installed. If you have installed it, make" + @echo -e "sure that the pkg-config file is somewhere in your path and is executable.\033[00m" + @echo + +#NOTE that this check shouldn't be fatal, we can bounce back from it by excluding CD support +check-cdio: msg-ck-cdio $(if $(CDIOLIB),msg-cdio,msg-no-cdio) ; + +msg-ck-cdio: + @echo -en " \033[00;32mLIBCDIO... \033[00m" + +msg-cdio: + @echo -e "\033[01;37mOK\033[00m" + +msg-no-cdio: + @echo -e "\033[01;37mNOT FOUND\033[00m" + @echo + @echo -e "\033[01;33mIt seems that you don't have LIBCDIO installed. Since this is not fatal," + @echo -e "Virtual Jaguar will be built WITHOUT CD support.\033[00m" + @echo + +check-gl: msg-ck-gl + @echo -e "*** GL CHECK NOT IMPLEMENTED ***" + +msg-ck-gl: + @echo -en " \033[00;32mOpenGL... \033[00m" + +check-qt: msg-ck-qt + @echo -e "*** QT CHECK NOT IMPLEMENTED ***" + +msg-ck-qt: + @echo -en " \033[00;32mQt... \033[00m" + +stop-on-error: ; $(error COMPILATION ENVIRONMENT) + +msg-check-env: + @echo + @echo -e "\033[01;33m***\033[00;32m Checking compilation environment: \033[00m" + @echo + +message2: @echo @echo -e "\033[01;33m***\033[00;32m Building Virtual Jaguar for $(MSG)...\033[00m" @echo @@ -163,7 +223,7 @@ $(ICON): res/$(TARGET).rc res/$(TARGET).ico @windres -i res/$(TARGET).rc -o $(ICON) --include-dir=./res endif -# Main source compilation... +# Main source compilation (implicit rules)... obj/%.o: src/%.c @echo -e "\033[01;33m***\033[00;32m Compiling $<...\033[00m" @@ -204,7 +264,7 @@ QT_CFLAGS = -MMD `pkg-config --cflags QtGui` #QT_DEFINES = -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED QT_DEFINES = -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED #QT_INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I./src/gui -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I./obj -QT_INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I./src -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I/usr/X11R6/include -I./obj +QT_INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I./src -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtOpenGL -I/usr/include/qt4 -I/usr/X11R6/include -I./obj `sdl-config --cflags` QT_CXXFLAGS = -MMD -pipe -O2 -march=pentium-m -pipe -D_REENTRANT -Wall -W $(QT_DEFINES) -D$(SYSTYPE) -g obj/moc_%.cpp: src/gui/%.h @@ -216,7 +276,7 @@ obj/moc_%.o: obj/moc_%.cpp @$(CC) -c $(QT_CXXFLAGS) $(QT_INCPATH) -o $@ $< obj/qrc_virtualjaguar.cpp: src/gui/virtualjaguar.qrc res/vj.xpm - @echo -e "\033[01;33m***\033[00;32m Creating qrc_vj.cpp...\033[00m" + @echo -e "\033[01;33m***\033[00;32m Creating qrc_virtualjaguar.cpp...\033[00m" @/usr/bin/rcc -name virtualjaguar src/gui/virtualjaguar.qrc -o obj/qrc_virtualjaguar.cpp obj/qrc_%.o: obj/qrc_%.cpp diff --git a/src/gui/app.cpp b/src/gui/app.cpp index e878edf..1e36fe4 100644 --- a/src/gui/app.cpp +++ b/src/gui/app.cpp @@ -9,10 +9,12 @@ // Who When What // --- ---------- ------------------------------------------------------------- // JLH 12/23/2009 Created this file +// JLH 01/21/2011 Added SDL initialization // #include "app.h" +#include #include #include "log.h" #include "mainwin.h" @@ -38,9 +40,20 @@ int main(int argc, char * argv[]) //ick int id = qRegisterMetaType(); LogInit("virtualjaguar.log"); // Init logfile - App app(argc, argv); // Declare an instance of the application + int retVal = -1; // Default is failure + + // Set up SDL library + if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) < 0) + { + WriteLog("VJ: Could not initialize the SDL library: %s\n", SDL_GetError()); + } + else + { + WriteLog("VJ: SDL (joystick, audio) successfully initialized.\n"); + App app(argc, argv); // Declare an instance of the application + retVal = app.exec(); // And run it! + } - int retVal = app.exec(); // And run it! LogDone(); // Close logfile return retVal; } diff --git a/src/gui/filelistmodel.cpp b/src/gui/filelistmodel.cpp index c35bd35..09389b8 100644 --- a/src/gui/filelistmodel.cpp +++ b/src/gui/filelistmodel.cpp @@ -36,14 +36,30 @@ QVariant FileListModel::data(const QModelIndex & index, int role) const // return QVariant(); // return pixList.at(index.row()); // return (uint)dbIndex.at(index.row()); +//It could be that this is fucking things up... +#if 0 if (role == Qt::DecorationRole) return list.at(index.row()).label; else if (role == Qt::DisplayRole) return (uint)list.at(index.row()).dbIndex; else if (role == Qt::EditRole) return list.at(index.row()).filename; + else if (role == Qt::WhatsThisRole) + return (uint)list.at(index.row()).fileSize; else return QVariant(); +#else + if (role == FLM_LABEL) + return list.at(index.row()).label; + else if (role == FLM_INDEX) + return (uint)list.at(index.row()).dbIndex; + else if (role == FLM_FILENAME) + return list.at(index.row()).filename; + else if (role == FLM_FILESIZE) + return (uint)list.at(index.row()).fileSize; + + return QVariant(); +#endif } QVariant FileListModel::headerData(int/* section*/, Qt::Orientation/* orientation*/, int role/*= Qt::DisplayRole*/) const @@ -67,6 +83,7 @@ QVariant FileListModel::headerData(int/* section*/, Qt::Orientation/* orientatio #endif } +/* void FileListModel::AddData(QIcon pix) { pixList.push_back(pix); @@ -78,13 +95,15 @@ void FileListModel::AddData(unsigned long index) dbIndex.push_back(index); reset(); } +*/ -void FileListModel::AddData(unsigned long index, QString str, QImage img) +void FileListModel::AddData(unsigned long index, QString str, QImage img, unsigned long size) { // Assuming that both QString and QImage have copy constructors, this should work. FileListData data; data.dbIndex = index; + data.fileSize = size; data.filename = str; data.label = img; diff --git a/src/gui/filelistmodel.h b/src/gui/filelistmodel.h index b2006a8..78d73e9 100644 --- a/src/gui/filelistmodel.h +++ b/src/gui/filelistmodel.h @@ -17,10 +17,17 @@ struct FileListData // FileListData(unsigned long ul=0, QString str, QImage img): dbIndex(ul), filename(str), label(img) {} unsigned long dbIndex; + unsigned long fileSize; QString filename; QImage label; }; +//hm. +#define FLM_INDEX (Qt::UserRole + 1) +#define FLM_FILESIZE (Qt::UserRole + 2) +#define FLM_FILENAME (Qt::UserRole + 3) +#define FLM_LABEL (Qt::UserRole + 4) + class FileListModel: public QAbstractListModel { public: @@ -30,16 +37,17 @@ class FileListModel: public QAbstractListModel QVariant data(const QModelIndex & index, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; - void AddData(QIcon pix); - void AddData(unsigned long); - void AddData(unsigned long, QString, QImage); +// void AddData(QIcon pix); +// void AddData(unsigned long); + void AddData(unsigned long, QString, QImage, unsigned long); // FileListData GetData(const QModelIndex & index) const; private: - std::vector pixList; - std::vector dbIndex; +// std::vector pixList; +// std::vector dbIndex; std::vector list; +// std::vector size; }; #endif // __FILELISTMODEL_H__ diff --git a/src/gui/filepicker.cpp b/src/gui/filepicker.cpp index b30124a..150a275 100644 --- a/src/gui/filepicker.cpp +++ b/src/gui/filepicker.cpp @@ -64,6 +64,35 @@ FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt: fileList->setModel(model); // fileList->setItemDelegate(new ImageDelegate(this)); fileList->setItemDelegate(new ImageDelegate()); +#if 0 + //nope. +// fileList->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); +// fileList->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); +//small problem with this is that it doesn't take scrollbar into account... +QSize sbSize = fileList->verticalScrollBar()->minimumSizeHint(); +printf("VSB minimumSizeHint: %u, %u\n", sbSize.width(), sbSize.height()); +QSize sbSize2 = fileList->verticalScrollBar()->sizeHint(); +printf("VSB sizeHint: %u, %u\n", sbSize2.width(), sbSize2.height()); +QRect sbRect = fileList->verticalScrollBar()->normalGeometry(); +printf("VSB normalGeometry: %u, %u\n", sbRect.width(), sbRect.height()); +QSize sbSize3 = fileList->verticalScrollBar()->size(); +printf("VSB size: %u, %u\n", sbSize3.width(), sbSize3.height()); +// int sbWidth = fileList->verticalScrollBar()->width(); + int sbWidth = fileList->verticalScrollBar()->size().width(); + fileList->setFixedWidth((488/4) + 4 + sbWidth);//ick +#else + // This sets it to the "too large size" as the minimum! + QScrollBar * vsb = new QScrollBar(Qt::Vertical, this); + int sbWidth = vsb->size().width(); + printf("VSB size width: %u\n", sbWidth); + int sbWidth2 = vsb->sizeHint().width(); + printf("VSB sizeHint width: %u\n", sbWidth2); + delete vsb; + +// fileList->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); +// fileList->verticalScrollBar()->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); + fileList->setFixedWidth((488/4) + 4 + sbWidth);//ick +#endif // QVBoxLayout * layout = new QVBoxLayout; QHBoxLayout * layout = new QHBoxLayout; @@ -123,7 +152,7 @@ FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt: fileThread = new FileThread(this); // connect(fileThread, SIGNAL(FoundAFile(unsigned long)), this, SLOT(AddFileToList(unsigned long))); - connect(fileThread, SIGNAL(FoundAFile2(unsigned long, QString, QImage *)), this, SLOT(AddFileToList2(unsigned long, QString, QImage *))); + connect(fileThread, SIGNAL(FoundAFile2(unsigned long, QString, QImage *, unsigned long)), this, SLOT(AddFileToList2(unsigned long, QString, QImage *, unsigned long))); fileThread->Go(); /* New sizes: 373x172 (label), 420x340 (cart) @@ -143,16 +172,20 @@ void FilePickerWindow::AddFileToList(unsigned long index) printf("FilePickerWindow: Found match [%s]...\n", romList[index].name); // NOTE: The model *ignores* what you send it, so this is crap. !!! FIX !!! [DONE, somewhat] // model->AddData(QIcon(":/res/generic.png")); - model->AddData(index); +// model->AddData(index); } -void FilePickerWindow::AddFileToList2(unsigned long index, QString str, QImage * img) +void FilePickerWindow::AddFileToList2(unsigned long index, QString str, QImage * img, unsigned long size) { printf("FilePickerWindow(2): Found match [%s]...\n", romList[index].name); if (img) - model->AddData(index, str, *img); + { + model->AddData(index, str, *img, size); +//It would be better to pass the pointer into the model though... + delete img; + } else - model->AddData(index, str, QImage()); + model->AddData(index, str, QImage(), size); } // @@ -161,23 +194,52 @@ printf("FilePickerWindow(2): Found match [%s]...\n", romList[index].name); // void FilePickerWindow::UpdateSelection(const QModelIndex & current, const QModelIndex &/*previous*/) { +#if 0 QString s = current.model()->data(current, Qt::EditRole).toString(); unsigned long i = current.model()->data(current, Qt::DisplayRole).toUInt(); QImage label = current.model()->data(current, Qt::DecorationRole).value(); // printf("FPW: %s\n", s.toAscii().data()); - + unsigned long fileSize = current.model()->data(current, Qt::WhatsThisRole).toUInt(); +#else + QString s = current.model()->data(current, FLM_FILENAME).toString(); + unsigned long i = current.model()->data(current, FLM_INDEX).toUInt(); + QImage label = current.model()->data(current, FLM_LABEL).value(); + unsigned long fileSize = current.model()->data(current, FLM_FILESIZE).toUInt(); +// printf("FPW: %s\n", s.toAscii().data()); +#endif +//373x172 is label size... if (!label.isNull()) { +/* + QImage cartImg(":/res/cart-blank.png"); + QPainter painter(&cartImg); + painter.drawPixmap(23, 87, QPixmap(":/res/label-blank.png")); + painter.end(); + cartSmall = cartImg.scaled(488/4, 395/4, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); +*/ QImage cart(":/res/cart-blank.png"); QPainter painter(&cart); +//Though this should probably be done when this is loaded, instead of every time here... +//QImage scaledImg = label.scaled(373, 172, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); +//painter.drawPixmap(23, 87, QPixmap::fromImage(scaledImg)); painter.drawPixmap(23, 87, QPixmap::fromImage(label)); +// painter.drawPixmap(23, 87, 373, 172, QPixmap::fromImage(label)); painter.end(); cartImage->setPixmap(QPixmap::fromImage(cart)); } +//1048576 +//2097152 +//4194304 title->setText(QString("

%1

").arg(romList[i].name)); +//Kludge for now, we'll have to fix this later... + QString fileType = QString(romList[i].flags & FF_ROM ? "%1MB Cartridge" : "%1*** UNKNOWN ***") + .arg(fileSize / 1048576); QString crcString = QString("%1").arg(romList[i].crc32, 8, 16, QChar('0')).toUpper(); - data->setText(QString("%1
%2
%3
%4").arg("Cart").arg(crcString).arg("100%").arg("Requires BIOS")); + QString notes = +/* (romList[i].flags & FF_ROM ? "Jaguar ROM " : "")*/ + QString(romList[i].flags & FF_BAD_DUMP ? "BAD DUMP" : ""); + data->setText(QString("%1
%2
%3
%4").arg(fileType).arg(crcString).arg("???%").arg(notes)); } /* @@ -206,5 +268,3 @@ Compatibility: 80% (or ****) */ - - diff --git a/src/gui/filepicker.h b/src/gui/filepicker.h index a8c5888..16edee9 100644 --- a/src/gui/filepicker.h +++ b/src/gui/filepicker.h @@ -21,7 +21,7 @@ class FilePickerWindow: public QWidget public slots: void AddFileToList(unsigned long index); - void AddFileToList2(unsigned long index, QString, QImage *); + void AddFileToList2(unsigned long index, QString, QImage *, unsigned long size); void UpdateSelection(const QModelIndex &, const QModelIndex &); protected: diff --git a/src/gui/filethread.cpp b/src/gui/filethread.cpp index 22bf3b7..dd1a540 100644 --- a/src/gui/filethread.cpp +++ b/src/gui/filethread.cpp @@ -94,10 +94,13 @@ printf("FileThread: Aborting!!!\n"); if (size > 0) { + uint32_t fileSize = size; //printf("FileThread: About to calc checksum on file with size %u... (buffer=%08X)\n", size, buffer); uint32 crc = crc32_calcCheckSum(buffer, size); uint32 index = FindCRCIndexInFileList(crc); - delete[] buffer; +// These two are NOT interchangeable! +// delete[] buffer; + free(buffer); // Mebbe we should pass a index AND a QImage here??? /* @@ -108,18 +111,38 @@ we might need it if we want to pull ROM flags from the fileDB... */ if (index != 0xFFFFFFFF && !(romList[index].flags & FF_BIOS)) { - QImage img; +//Here's a little problem. When we create the image here and pass it off to FilePicker, +//we can clobber this image before we have a chance to copy it out in the FilePicker function +//because we can be back here before FilePicker can respond. +//So we need to fix this so that this does not happen. :-/ +//And now it is. :-) +/* +So I guess we can create an image on the heap and pass *that* to FilePicker. But then, would +it be worthwhile to just pass the pointer into the FileListModel instead of a copy of an object? +Maybe. We'd do like so: +QImage * imageCopy = new QImage(); +*/ + QImage * img = NULL; size = GetFileFromZIP(fileInfo.canonicalFilePath().toAscii(), FT_LABEL, buffer); +//printf("FT: Label size = %u bytes.\n", size); if (size > 0) { - img.loadFromData(buffer, size); - delete[] buffer; +//#warning "!!!" +//Not sure if this will work properly... Seems to. + QImage label; + bool success = label.loadFromData(buffer, size); + img = new QImage(); + *img = label.scaled(373, 172, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); +//printf("FT: Label %s: %ux%u.\n", (success ? "succeeded" : "did not succeed"), img->width(), img->height()); +// These two are NOT interchangeable! +// delete[] buffer; + free(buffer); } //printf("FileThread: Attempted to load image. Size: %u x %u...\n", img.width(), img.height()); // emit FoundAFile(index); - emit FoundAFile2(index, fileInfo.canonicalFilePath(), &img); + emit FoundAFile2(index, fileInfo.canonicalFilePath(), img, fileSize); } } } @@ -139,7 +162,7 @@ we might need it if we want to pull ROM flags from the fileDB... // Mebbe we should pass a index AND a QImage here??? if (index != 0xFFFFFFFF && !(romList[index].flags & FF_BIOS)) // emit FoundAFile(index); - emit FoundAFile2(index, fileInfo.canonicalFilePath(), 0); + emit FoundAFile2(index, fileInfo.canonicalFilePath(), 0, fileInfo.size()); } } } diff --git a/src/gui/filethread.h b/src/gui/filethread.h index 533ddfb..67c8d5e 100644 --- a/src/gui/filethread.h +++ b/src/gui/filethread.h @@ -19,7 +19,7 @@ class FileThread: public QThread signals: void FoundAFile(unsigned long index); - void FoundAFile2(unsigned long index, QString filename, QImage * label); + void FoundAFile2(unsigned long index, QString filename, QImage * label, unsigned long); protected: void run(void); diff --git a/src/gui/imagedelegate.cpp b/src/gui/imagedelegate.cpp index eaae05f..e9069da 100644 --- a/src/gui/imagedelegate.cpp +++ b/src/gui/imagedelegate.cpp @@ -17,7 +17,7 @@ #include "imagedelegate.h" #include "filedb.h" - +#include "filelistmodel.h" //ImageDelegate::ImageDelegate(QObject * parent): QAbstractItemDelegate(parent)//, pixelSize(12) //{ @@ -89,9 +89,15 @@ The foreground of the item (the circle representing a pixel) must be rendered us // don't get Qt's default ugly looking fast scaling... #warning "!!! FIX !!! Need to create properly scaled down cart/label images!" // unsigned long i = index.model()->data(index, Qt::DisplayRole).toUInt(); +#if 0 unsigned long i = index.model()->data(index, Qt::DisplayRole).toUInt(); QString filename = index.model()->data(index, Qt::EditRole).toString(); QImage label = index.model()->data(index, Qt::DecorationRole).value(); +#else + unsigned long i = index.model()->data(index, FLM_INDEX).toUInt(); + QString filename = index.model()->data(index, FLM_FILENAME).toString(); + QImage label = index.model()->data(index, FLM_LABEL).value(); +#endif #if 0 if (role == Qt::DecorationRole) diff --git a/src/gui/mainwin.cpp b/src/gui/mainwin.cpp index bfdbf0b..8e2060c 100644 --- a/src/gui/mainwin.cpp +++ b/src/gui/mainwin.cpp @@ -207,9 +207,9 @@ WriteLog("About to attempt to load BIOSes...\n"); SET32(jaguarMainRAM, 0, 0x00200000); // Set top of stack... //Let's try this... -// JaguarLoadFile("./software/Rayman (World).j64"); + JaguarLoadFile("./software/Rayman (World).j64"); // JaguarLoadFile("./software/I-War (World).j64"); - JaguarLoadFile("./software/Alien vs Predator (World).j64"); +// JaguarLoadFile("./software/Alien vs Predator (World).j64"); //This is crappy!!! !!! FIX !!! //Is this even needed any more? Hmm. Maybe. Dunno. -- 2.37.2