]> Shamusworld >> Repos - virtualjaguar/blobdiff - src/gui/filepicker.cpp
First attempt at configuration dialog.
[virtualjaguar] / src / gui / filepicker.cpp
index 150a2753c66101fddd5009d239a4808e2bdbf4ea..d7f1507293885e82c4910a6b6967b0bd6390f2ec 100644 (file)
@@ -53,7 +53,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..."));
 
@@ -138,6 +139,14 @@ printf("VSB size: %u, %u\n", sbSize3.width(), sbSize3.height());
        )));
        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(
                "<table>"
@@ -161,6 +170,13 @@ 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;
 }
 
 //
@@ -188,6 +204,13 @@ printf("FilePickerWindow(2): Found match [%s]...\n", romList[index].name);
                model->AddData(index, str, QImage(), size);
 }
 
+void FilePickerWindow::LoadButtonPressed(void)
+{
+       // TODO: Get the text of the current selection, call the MainWin slot for loading
+       emit(RequestLoad(currentFile));
+       this->hide();
+}
+
 //
 // This slot gets called when the QListView gets clicked on. Updates
 // the cart graphic and accompanying text.
@@ -201,13 +224,19 @@ void FilePickerWindow::UpdateSelection(const QModelIndex & current, const QModel
 //     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();
+//     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<QImage>();
        unsigned long fileSize = current.model()->data(current, FLM_FILESIZE).toUInt();
 //     printf("FPW: %s\n", s.toAscii().data());
 #endif
+
+//hm.
+//currentFile = s;
+
 //373x172 is label size...
+//365x168 now...
        if (!label.isNull())
        {
 /*
@@ -222,8 +251,27 @@ void FilePickerWindow::UpdateSelection(const QModelIndex & current, const QModel
 //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));
+               // 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(":/res/cart-blank.png");
+               QPainter painter(&cart);
+//             painter.drawPixmap(23, 87, QPixmap::fromImage(QImage(":/res/label-blank.png")));
+               painter.drawPixmap(27, 89, QPixmap::fromImage(QImage(":/res/label-blank.png")));
                painter.end();
                cartImage->setPixmap(QPixmap::fromImage(cart));
        }
@@ -231,6 +279,7 @@ void FilePickerWindow::UpdateSelection(const QModelIndex & current, const QModel
 //1048576
 //2097152
 //4194304
+       prettyFilename = romList[i].name;
        title->setText(QString("<h2>%1</h2>").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 ***")