X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fgui%2Ffilepicker.cpp;h=06e517d0e2d5235c4a014d6c46f5c46aa0c39c5f;hb=f24ae2128609d5ab8c9a57dfd9dbb46afb7302a9;hp=b30124a54bd271df5df24472023ffc08042fdd0e;hpb=4beff2f35f649bb0befa58c8a89fdd702b3c9b4f;p=virtualjaguar diff --git a/src/gui/filepicker.cpp b/src/gui/filepicker.cpp index b30124a..06e517d 100644 --- a/src/gui/filepicker.cpp +++ b/src/gui/filepicker.cpp @@ -15,6 +15,7 @@ #include "filepicker.h" +#include "file.h" #include "filedb.h" #include "filelistmodel.h" #include "filethread.h" @@ -53,7 +54,8 @@ Data strategy: //could use Window as well... //FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Dialog) -FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Window) +FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt::Window), + currentFile("") { setWindowTitle(tr("Insert Cartridge...")); @@ -64,6 +66,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; @@ -102,13 +133,21 @@ FilePickerWindow::FilePickerWindow(QWidget * parent/*= 0*/): QWidget(parent, Qt: labels->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); dataLayout->addWidget(labels); data = new QLabel(QString(tr( - "4MB Cartridge
" - "FEDCBA98
" - "DOES NOT WORK
" - "Universal Header detected; Requires DSP" + "?MB Cartridge
" + "????????
" + "???
" + "???" ))); data->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); dataLayout->addWidget(data); + +//#warning "!!! Icon size for pushbutton is tiny !!!" + insertCart = new QPushButton(this); + insertCart->setIconSize(QSize(40, 40)); + insertCart->setIcon(QIcon(":/res/insert.png")); + insertCart->setDefault(true); // We want this button to be the default + insertCart->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); + dataLayout->addWidget(insertCart); #else QLabel * text2 = new QLabel(QString(tr( "" @@ -123,8 +162,14 @@ 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 *))); - fileThread->Go(); +// connect(fileThread, SIGNAL(FoundAFile2(unsigned long, QString, QImage *, unsigned long)), this, SLOT(AddFileToList2(unsigned long, QString, QImage *, unsigned long))); + connect(fileThread, SIGNAL(FoundAFile3(unsigned long, QString, QImage *, + unsigned long, bool, unsigned long, unsigned long)), this, + SLOT(AddFileToList3(unsigned long, QString, QImage *, unsigned long, + bool, unsigned long, unsigned long))); + +// Let's defer this to the main window, so we can have some control over when this is done. +// fileThread->Go(); /* New sizes: 373x172 (label), 420x340 (cart) */ @@ -132,6 +177,20 @@ New sizes: 373x172 (label), 420x340 (cart) // QItemSelectionModel * ism = fileList->selectionModel(); // connect(ism, SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(UpdateSelection(const QModelIndex &, const QModelIndex &))); connect(fileList->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(UpdateSelection(const QModelIndex &, const QModelIndex &))); + + connect(insertCart, SIGNAL(clicked()), this, SLOT(LoadButtonPressed())); +} + +QString FilePickerWindow::GetSelectedPrettyName(void) +{ + return prettyFilename; +} + +void FilePickerWindow::ScanSoftwareFolder(bool allow/*= false*/) +{ + // "allow" is whether or not to allow scanning for unknown software. + model->ClearData(); + fileThread->Go(allow); } // @@ -143,16 +202,44 @@ 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, unsigned long size) +{ +if (index != 0xFFFFFFFF) + printf("FilePickerWindow(2): Found match [%s]...\n", romList[index].name); + + if (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(), size); } -void FilePickerWindow::AddFileToList2(unsigned long index, QString str, QImage * img) +void FilePickerWindow::AddFileToList3(unsigned long index, QString str, QImage * img, unsigned long size, bool haveUniversalHeader, unsigned long fileType, unsigned long crc) { -printf("FilePickerWindow(2): Found match [%s]...\n", romList[index].name); +if (index != 0xFFFFFFFF) + printf("FilePickerWindow(3): Found match [%s]...\n", romList[index].name); + if (img) - model->AddData(index, str, *img); + { + model->AddData(index, str, *img, size, haveUniversalHeader, fileType, crc); +//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, haveUniversalHeader, fileType, crc); +} + +void FilePickerWindow::LoadButtonPressed(void) +{ + // TODO: Get the text of the current selection, call the MainWin slot for loading + emit(RequestLoad(currentFile)); + this->hide(); } // @@ -161,23 +248,158 @@ 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(); + currentFile = 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(); + bool haveUniversalHeader = current.model()->data(current, FLM_UNIVERSALHDR).toBool(); + unsigned long fileType = current.model()->data(current, FLM_FILETYPE).toUInt(); + uint32 crc = (uint32)current.model()->data(current, FLM_CRC).toUInt(); +// printf("FPW: %s\n", s.toAscii().data()); + bool haveUnknown = (i == 0xFFFFFFFF ? true : false); +#endif + + // Disallow loading completely unknown files, but allow all others. + insertCart->setEnabled(haveUnknown && (fileType == JST_NONE) ? false : true); +//hm. +//currentFile = s; +//373x172 is label size... +//365x168 now... 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); - painter.drawPixmap(23, 87, QPixmap::fromImage(label)); +//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)); + // Now, looks like it is... +// painter.drawPixmap(23, 87, QPixmap::fromImage(label)); + painter.drawPixmap(27, 89, QPixmap::fromImage(label)); +// painter.drawPixmap(23, 87, 373, 172, QPixmap::fromImage(label)); + +// Well, heck. This should be done to the label *before* we get here. + painter.drawPixmap(27, 89, QPixmap::fromImage(QImage(":/res/upper-left.png"))); + painter.drawPixmap(27+355, 89, QPixmap::fromImage(QImage(":/res/upper-right.png"))); + painter.end(); cartImage->setPixmap(QPixmap::fromImage(cart)); } + else + { + // We should try to be intelligent with our updates here, and only redraw when + // we're going from a selection with a label to a selection without. Now, we + // redraw regardless. + QImage cart; + +// We now have to sources of data for the passed in files: +// - The file DB +// - The file type detection +// This means we have to be mindful of what's passed back by that stuff. +// We can assume that if it wasn't found in the DB, then the fileType +// should be valid. +// The DB takes precedence over the fileType. + if ((!haveUnknown && (romList[i].flags & FF_ROM)) + || (haveUnknown && (fileType == JST_ROM))) + { + cart = QImage(":/res/cart-blank.png"); + QPainter painter(&cart); + painter.drawPixmap(27, 89, QPixmap::fromImage(QImage(":/res/label-blank.png"))); + painter.end(); + } + else if ((!haveUnknown && (romList[i].flags & FF_ALPINE)) + || (haveUnknown && (fileType == JST_ALPINE))) + { + cart = QImage(":/res/alpine-file.png"); + } + else if (haveUnknown && (fileType == JST_ABS_TYPE1 || fileType == JST_ABS_TYPE2 || fileType == JST_JAGSERVER)) + { + cart = QImage(":/res/homebrew-file.png"); + } + else + cart = QImage(":/res/unknown-file.png"); + + cartImage->setPixmap(QPixmap::fromImage(cart)); + } - title->setText(QString("

%1

").arg(romList[i].name)); - 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")); +//1048576 +//2097152 +//4194304 + if (!haveUnknown) + prettyFilename = romList[i].name; + else + { + int lastSlashPos = currentFile.lastIndexOf('/'); + prettyFilename = "\"" + currentFile.mid(lastSlashPos + 1) + "\""; + } + + title->setText(QString("

%1

").arg(prettyFilename)); + +//Kludge for now, we'll have to fix this later... +// So let's fix it now! + QString fileTypeString, crcString, notes, compatibility; + +#if 0 + if (!haveUnknown) + { + if (romList[i].flags & FF_ROM) + fileTypeString = QString(tr("%1MB Cartridge")).arg(fileSize / 1048576); + else if (romList[i].flags & FF_ALPINE) + fileTypeString = QString(tr("%1MB Alpine ROM")).arg(fileSize / 1048576); + else + fileTypeString = QString(tr("*** UNKNOWN *** (%1 bytes)")).arg(fileSize); + } +#else + if ((!haveUnknown && (romList[i].flags & FF_ROM)) || (haveUnknown && (fileType == JST_ROM))) + fileTypeString = QString(tr("%1MB Cartridge")).arg(fileSize / 1048576); + else if ((!haveUnknown && (romList[i].flags & FF_ALPINE)) || (haveUnknown && (fileType == JST_ALPINE))) + fileTypeString = QString(tr("%1MB Alpine ROM")).arg(fileSize / 1048576); + else if (haveUnknown && (fileType == JST_ABS_TYPE1 || fileType == JST_ABS_TYPE2)) + fileTypeString = QString(tr("ABS/COF Executable (%1 bytes)")).arg(fileSize); + else if (haveUnknown && (fileType == JST_JAGSERVER)) + fileTypeString = QString(tr("Jaguar Server Executable (%1 bytes)")).arg(fileSize); + else + fileTypeString = QString(tr("*** UNKNOWN *** (%1 bytes)")).arg(fileSize); +#endif + +// crcString = QString("%1").arg(romList[i].crc32, 8, 16, QChar('0')).toUpper(); + crcString = QString("%1").arg(crc, 8, 16, QChar('0')).toUpper(); + + if (!haveUnknown && (romList[i].flags & FF_NON_WORKING)) + compatibility = "DOES NOT WORK"; + else + compatibility = "Unknown"; + + // This is going to need some formatting love before long... + if (!haveUnknown && (romList[i].flags & FF_BAD_DUMP)) + notes = "BAD DUMP"; + + if (haveUniversalHeader) + notes += " Universal Header detected"; + + if (!haveUnknown && (romList[i].flags & FF_REQ_DSP)) + notes += " Requires DSP"; + + if (!haveUnknown && (romList[i].flags & FF_VERIFIED)) + notes += " (Verified)"; + + data->setText(QString("%1
%2
%3
%4") + .arg(fileTypeString).arg(crcString).arg(compatibility).arg(notes)); } /* @@ -203,8 +425,4 @@ Compatibility: Unknown CRC32: 44889921 Compatibility: 80% (or ****) Notes: EEPROM available - - */ - -