From caf1236884015695c52910a75b8420be7c63d574 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Thu, 4 Mar 2010 19:35:39 +0000 Subject: [PATCH] Successfully integrated ZIP file fishing of images & software --- src/gui/filelistmodel.cpp | 32 +++++++++++++++++++++++++++++--- src/gui/filelistmodel.h | 14 ++++++++++++++ src/gui/filepicker.cpp | 13 ++++++++++++- src/gui/filepicker.h | 1 + src/gui/filethread.cpp | 16 ++++++++++++++-- src/gui/filethread.h | 1 + src/gui/imagedelegate.cpp | 20 +++++++++++++++++++- 7 files changed, 90 insertions(+), 7 deletions(-) diff --git a/src/gui/filelistmodel.cpp b/src/gui/filelistmodel.cpp index a975b82..c35bd35 100644 --- a/src/gui/filelistmodel.cpp +++ b/src/gui/filelistmodel.cpp @@ -27,17 +27,26 @@ FileListModel::FileListModel(QObject * parent/*= 0*/): QAbstractListModel(parent int FileListModel::rowCount(const QModelIndex & parent/*= QModelIndex()*/) const { // return pixList.size(); - return dbIndex.size(); +// return dbIndex.size(); + return list.size(); } QVariant FileListModel::data(const QModelIndex & index, int role) const { // return QVariant(); // return pixList.at(index.row()); - return (uint)dbIndex.at(index.row()); +// return (uint)dbIndex.at(index.row()); + 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 + return QVariant(); } -QVariant FileListModel::headerData(int section, Qt::Orientation orientation, int role/*= Qt::DisplayRole*/) const +QVariant FileListModel::headerData(int/* section*/, Qt::Orientation/* orientation*/, int role/*= Qt::DisplayRole*/) const { #if 0 // Not sure that this is necessary for our purposes... @@ -70,6 +79,23 @@ void FileListModel::AddData(unsigned long index) reset(); } +void FileListModel::AddData(unsigned long index, QString str, QImage img) +{ + // Assuming that both QString and QImage have copy constructors, this should work. + FileListData data; + + data.dbIndex = index; + data.filename = str; + data.label = img; + + list.push_back(data); + reset(); +} + +//FileListData FileListModel::GetData(const QModelIndex & index) const +//{ +// return list.at(index.row()); +//} #if 0 diff --git a/src/gui/filelistmodel.h b/src/gui/filelistmodel.h index 1599ca5..b2006a8 100644 --- a/src/gui/filelistmodel.h +++ b/src/gui/filelistmodel.h @@ -11,6 +11,16 @@ #include #include +struct FileListData +{ +// FileListData(unsigned long ul=0, QString str="", QImage img=QImage()): dbIndex(ul), filename(str), label(img) {} +// FileListData(unsigned long ul=0, QString str, QImage img): dbIndex(ul), filename(str), label(img) {} + + unsigned long dbIndex; + QString filename; + QImage label; +}; + class FileListModel: public QAbstractListModel { public: @@ -22,10 +32,14 @@ class FileListModel: public QAbstractListModel void AddData(QIcon pix); void AddData(unsigned long); + void AddData(unsigned long, QString, QImage); + +// FileListData GetData(const QModelIndex & index) const; private: std::vector pixList; std::vector dbIndex; + std::vector list; }; #endif // __FILELISTMODEL_H__ diff --git a/src/gui/filepicker.cpp b/src/gui/filepicker.cpp index 9f85885..f642571 100644 --- a/src/gui/filepicker.cpp +++ b/src/gui/filepicker.cpp @@ -57,7 +57,8 @@ FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt: layout->addWidget(fileList); fileThread = new FileThread(this); - connect(fileThread, SIGNAL(FoundAFile(unsigned long)), this, SLOT(AddFileToList(unsigned long))); +// 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 *))); fileThread->Go(); } @@ -72,3 +73,13 @@ printf("FilePickerWindow: Found match [%s]...\n", romList[index].name); // model->AddData(QIcon(":/res/generic.png")); model->AddData(index); } + +void FilePickerWindow::AddFileToList2(unsigned long index, QString str, QImage * img) +{ +printf("FilePickerWindow(2): Found match [%s]...\n", romList[index].name); + if (img) + model->AddData(index, str, *img); + else + model->AddData(index, str, QImage()); +} + diff --git a/src/gui/filepicker.h b/src/gui/filepicker.h index f0b5143..447162e 100644 --- a/src/gui/filepicker.h +++ b/src/gui/filepicker.h @@ -21,6 +21,7 @@ class FilePickerWindow: public QWidget public slots: void AddFileToList(unsigned long index); + void AddFileToList2(unsigned long index, QString, QImage *); protected: // void PopulateList(void); diff --git a/src/gui/filethread.cpp b/src/gui/filethread.cpp index dec070f..22bf3b7 100644 --- a/src/gui/filethread.cpp +++ b/src/gui/filethread.cpp @@ -10,6 +10,7 @@ // --- ---------- ------------------------------------------------------------- // JLH 01/28/2010 Created this file // JLH 02/16/2010 Moved RomIdentifier stuff to its own file +// JLH 03/02/2010 Added .ZIP file fishing // #include "filethread.h" @@ -83,6 +84,9 @@ printf("FileThread: Aborting!!!\n"); QFileInfo fileInfo = list.at(i); + // ZIP files are special: They contain more than just the software now... ;-) + // So now we fish around inside them to pull out the stuff we want. + // Probably also need more stringent error checking as well... :-O if (fileInfo.suffix().compare("zip", Qt::CaseInsensitive) == 0) { uint8 * buffer = NULL; @@ -96,6 +100,12 @@ printf("FileThread: Aborting!!!\n"); delete[] buffer; // Mebbe we should pass a index AND a QImage here??? +/* +Let's think about this... What *do* we need to send out? +we need the filename for sure. image file if it exists. +do we need the index? I think we're only using it to pull the label from the subdir... +we might need it if we want to pull ROM flags from the fileDB... +*/ if (index != 0xFFFFFFFF && !(romList[index].flags & FF_BIOS)) { QImage img; @@ -108,7 +118,8 @@ printf("FileThread: Aborting!!!\n"); } //printf("FileThread: Attempted to load image. Size: %u x %u...\n", img.width(), img.height()); - emit FoundAFile(index); +// emit FoundAFile(index); + emit FoundAFile2(index, fileInfo.canonicalFilePath(), &img); } } } @@ -127,7 +138,8 @@ printf("FileThread: Aborting!!!\n"); // Mebbe we should pass a index AND a QImage here??? if (index != 0xFFFFFFFF && !(romList[index].flags & FF_BIOS)) - emit FoundAFile(index); +// emit FoundAFile(index); + emit FoundAFile2(index, fileInfo.canonicalFilePath(), 0); } } } diff --git a/src/gui/filethread.h b/src/gui/filethread.h index 0065f51..533ddfb 100644 --- a/src/gui/filethread.h +++ b/src/gui/filethread.h @@ -19,6 +19,7 @@ class FileThread: public QThread signals: void FoundAFile(unsigned long index); + void FoundAFile2(unsigned long index, QString filename, QImage * label); protected: void run(void); diff --git a/src/gui/imagedelegate.cpp b/src/gui/imagedelegate.cpp index d148c2c..f7dfa9b 100644 --- a/src/gui/imagedelegate.cpp +++ b/src/gui/imagedelegate.cpp @@ -17,6 +17,7 @@ #include "imagedelegate.h" #include "filedb.h" +//#include "filelistmodel.h" ImageDelegate::ImageDelegate(QObject * parent): QAbstractItemDelegate(parent), pixelSize(12) @@ -75,9 +76,22 @@ The foreground of the item (the circle representing a pixel) must be rendered us // painter->drawPixmap(option.rect.x()+13, option.rect.y()+51, 433/2, 203/2, QPixmap(":/res/labels/rayman.jpg")); // painter->drawPixmap(option.rect.x(), option.rect.y(), 488/2, 395/2, QPixmap(":/res/cart-blank.png")); painter->drawPixmap(option.rect.x(), option.rect.y(), 488/4, 395/4, QPixmap(":/res/cart-blank.png")); +// unsigned long i = index.model()->data(index, Qt::DisplayRole).toUInt(); 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(); - if (romList[i].file[0] == 0) +#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; +#endif + +// if (romList[i].file[0] == 0) + if (label.isNull()) { // painter->drawPixmap(option.rect.x()+14, option.rect.y()+50, 433/2, 203/2, QPixmap(":/res/label-blank.png")); painter->drawPixmap(option.rect.x()+7, option.rect.y()+25, 433/4, 203/4, QPixmap(":/res/label-blank.png")); @@ -90,10 +104,14 @@ The foreground of the item (the circle representing a pixel) must be rendered us } else { +#if 0 QString filename(romList[i].file); filename.prepend("./label/"); QImage img(filename); painter->drawImage(QRect(option.rect.x()+7, option.rect.y()+25, 433/4, 203/4), img); +#else + painter->drawImage(QRect(option.rect.x()+7, option.rect.y()+25, 433/4, 203/4), label); +#endif } //26x100 #endif -- 2.37.2