@@ -74,6 +74,11 @@ MaskRomTool::MaskRomTool(QWidget *parent, bool opengl)
7474 : QMainWindow(parent)
7575 , ui(new Ui::MaskRomTool) {
7676
77+ // Set our Qt configuration, needed for settings.
78+ QCoreApplication::setOrganizationName (" TravisGoodspeed" );
79+ QCoreApplication::setOrganizationDomain (" kk4vcz.com" );
80+ QCoreApplication::setApplicationName (" MaskRomTool" );
81+
7782 // Setup caches
7883 QPixmapCache::setCacheLimit (0x100000 ); // 1GB
7984 if (verbose) qDebug ()<<" Cache limit is " <<QPixmapCache::cacheLimit ()<<" kb" ;
@@ -117,6 +122,9 @@ MaskRomTool::MaskRomTool(QWidget *parent, bool opengl)
117122 // Set up the second view.
118123 second.view ->setScene (scene);
119124
125+ // Build a history of past entries.
126+ buildFileHistoryList ();
127+
120128 // Enable OpenGL without antialiasing, now that it's stable.
121129 if (opengl)
122130 enableOpenGL (0 );
@@ -1370,6 +1378,61 @@ void MaskRomTool::getAlignSkipCountThreshold(uint32_t &count){
13701378 count=alignSkipThreshold;
13711379}
13721380
1381+ // Records a file in settings for the history.
1382+ void MaskRomTool::recordFileHistory (QFileInfo file){
1383+ /* What we do here is build a stack of the old filenames,
1384+ * cull the new filename from that stack, and then ensure
1385+ * that the new filename comes first in the new listing.
1386+ */
1387+ QSettings settings;
1388+ QString path=file.absoluteFilePath ();
1389+ QStack<QString> filenames; // Ordered list of filenames.
1390+
1391+ // Build the new list.
1392+ filenames.append (path); // New file always comes first.
1393+ for (int i=0 ; i<10 ; i++){
1394+ QString k=" filename" +QString::number (i);
1395+ QVariant v=settings.value (k);
1396+ if (v.isValid ()){
1397+ if (path!=v.toString ())
1398+ filenames.append (v.toString ());
1399+ }
1400+ }
1401+
1402+ // Write back the new list.
1403+ int i=0 ;
1404+ foreach (QString f, filenames){
1405+ QString k=" filename" +QString::number (i);
1406+ settings.setValue (k, f);
1407+ i++;
1408+ }
1409+ }
1410+
1411+ // Builds the history menu entries.
1412+ void MaskRomTool::buildFileHistoryList (){
1413+ QMenu* recents=ui->menuOpen_Recent ;
1414+ recents->clear ();
1415+
1416+ QSettings settings;
1417+ for (int i=0 ; i<10 ; i++){
1418+ QString k=" filename" +QString::number (i);
1419+ QVariant v=settings.value (k);
1420+ if (v.isValid ()){
1421+ QAction *action=new QAction (recents);
1422+ action->setText (v.toString ());
1423+ recents->addAction (action);
1424+ QObject::connect (action, SIGNAL (triggered (bool )),
1425+ this , SLOT (openHistory ()));
1426+ }
1427+ }
1428+ }
1429+
1430+ // Opens whichever entry in the history was selected.
1431+ void MaskRomTool::openHistory (){
1432+ QAction *action = (QAction*) this ->sender ();
1433+ fileOpen (action->text ());
1434+ }
1435+
13731436// Opens *either* an image or a JSON description of lines.
13741437void MaskRomTool::fileOpen (QString filename){
13751438 // On macOS, each window likes to have a file attached.
@@ -1392,8 +1455,12 @@ void MaskRomTool::fileOpen(QString filename){
13921455
13931456
13941457 // We load the image as a background, so it's not really a part of the scene.
1458+ QFileInfo info (imagefilename);
1459+ recordFileHistory (info);
1460+ buildFileHistoryList ();
13951461 if (verbose)
1396- qDebug ()<<" Loading background image: " <<imagefilename;
1462+ qDebug ()<<" Loading background image: " <<info.absoluteFilePath ();
1463+
13971464 background=QImage (imagefilename);
13981465 backgroundpixmap = scene->addPixmap (QPixmap (imagefilename));
13991466 backgroundpixmap->setZValue (-10 );
0 commit comments