From ef19a7a94f983b366c47d052e4ce454c6fa383a6 Mon Sep 17 00:00:00 2001 From: Dagen Brock Date: Fri, 28 Dec 2018 09:52:41 -0600 Subject: [PATCH] add the palette code and clean/fix project for qt 5.7 -> 5.12 - the 5.12 release seems to introduce some bugs on my mac, when you hit preview, rthe code ran but the UI wwouldn't update. i've added repaint() calls, but this is quite frustrating and could be an issue with qt that might be mitigated otherwise in the future. sorry future me. :`( --- buckshot/buckshot.pro | 7 ++ buckshot/buckshot.pro.user | 90 ++++++++--------- buckshot/mainwindow.cpp | 118 +++++++++++++++------- buckshot/mainwindow.h | 7 +- buckshot/mainwindow.ui | 202 ++++++++++++++++++++++--------------- 5 files changed, 257 insertions(+), 167 deletions(-) diff --git a/buckshot/buckshot.pro b/buckshot/buckshot.pro index 1783ee9..f81f020 100644 --- a/buckshot/buckshot.pro +++ b/buckshot/buckshot.pro @@ -11,6 +11,13 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = buckshot TEMPLATE = app +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +CONFIG += c++11 SOURCES += main.cpp\ mainwindow.cpp diff --git a/buckshot/buckshot.pro.user b/buckshot/buckshot.pro.user index 76653a2..1735e71 100644 --- a/buckshot/buckshot.pro.user +++ b/buckshot/buckshot.pro.user @@ -1,10 +1,10 @@ - + EnvironmentId - {604923ac-6650-4c69-8172-ab5bd4c4d88b} + {30a1729f-a912-4116-992a-f04331cbb1d0} ProjectExplorer.Project.ActiveTarget @@ -54,19 +54,27 @@ ProjectExplorer.Project.PluginSettings - + + + true + false + + + + true + ProjectExplorer.Project.Target.0 - Desktop Qt 5.7.0 clang 64bit - Desktop Qt 5.7.0 clang 64bit - qt.57.clang_64_kit - 1 + Desktop Qt 5.12.0 clang 64bit + Desktop Qt 5.12.0 clang 64bit + qt.qt5.5120.clang_64_kit + 0 0 0 - /Users/dbrock/Google Drive/appleiigs/buckshot/build-buckshot-Desktop_Qt_5_7_0_clang_64bit-Debug + /Users/dbrock/Google Drive/appleiigs/buckshot/build-buckshot-Desktop_Qt_5_12_0_clang_64bit-Debug true @@ -84,13 +92,11 @@ Make Qt4ProjectManager.MakeStep - - -w - -r - + false + false 2 Build @@ -103,13 +109,11 @@ Make Qt4ProjectManager.MakeStep - - -w - -r - + true clean + false 1 Clean @@ -120,13 +124,13 @@ false Debug - + Debug Qt4ProjectManager.Qt4BuildConfiguration 2 true - /Users/dbrock/Google Drive/appleiigs/buckshot/build-buckshot-Desktop_Qt_5_7_0_clang_64bit-Release + /Users/dbrock/Google Drive/appleiigs/buckshot/build-buckshot-Desktop_Qt_5_12_0_clang_64bit-Release true @@ -137,20 +141,18 @@ false false - false + true true Make Qt4ProjectManager.MakeStep - - -w - -r - + false + false 2 Build @@ -163,13 +165,11 @@ Make Qt4ProjectManager.MakeStep - - -w - -r - + true clean + false 1 Clean @@ -180,13 +180,13 @@ false Release - + Release Qt4ProjectManager.Qt4BuildConfiguration 0 true - /Users/dbrock/Google Drive/appleiigs/buckshot/build-buckshot-Desktop_Qt_5_7_0_clang_64bit-Profile + /Users/dbrock/Google Drive/appleiigs/buckshot/build-buckshot-Desktop_Qt_5_12_0_clang_64bit-Profile true @@ -197,20 +197,18 @@ false true - false + true true Make Qt4ProjectManager.MakeStep - - -w - -r - + false + false 2 Build @@ -223,13 +221,11 @@ Make Qt4ProjectManager.MakeStep - - -w - -r - + true clean + false 1 Clean @@ -240,7 +236,7 @@ false Profile - + Profile Qt4ProjectManager.Qt4BuildConfiguration 0 true @@ -254,7 +250,7 @@ ProjectExplorer.BuildSteps.Deploy 1 - Deploy locally + Deploy Configuration ProjectExplorer.DefaultDeployConfiguration @@ -305,18 +301,18 @@ buckshot Qt4ProjectManager.Qt4RunConfiguration:/Users/dbrock/Google Drive/appleiigs/buckshot/buckshot/buckshot.pro - true - buckshot.pro - false - - /Users/dbrock/Google Drive/appleiigs/buckshot/build-buckshot-Desktop_Qt_5_7_0_clang_64bit-Release/buckshot.app/Contents/MacOS + 3768 false true + false + true false false true + + /Users/dbrock/Google Drive/appleiigs/buckshot/build-buckshot-Desktop_Qt_5_12_0_clang_64bit-Debug/buckshot.app/Contents/MacOS 1 @@ -327,10 +323,10 @@ ProjectExplorer.Project.Updater.FileVersion - 18 + 20 Version - 18 + 20 diff --git a/buckshot/mainwindow.cpp b/buckshot/mainwindow.cpp index f25259a..0fae832 100644 --- a/buckshot/mainwindow.cpp +++ b/buckshot/mainwindow.cpp @@ -64,6 +64,28 @@ MainWindow::MainWindow(QWidget *parent) : << "9- Buckels"; ui->comboBox_dithering->addItems(ditheringAlgorithms); + + // POPULATE PALETTE COMBOBOX + QStringList previewPalettes; + previewPalettes << "Kegs32 RGB" + << "CiderPress RGB" + << "Old AppleWin NTSC" + << "New AppleWin NTSC" + << "Wikipedia NTSC" + << "tohgr NTSC DHGR" + << " (N/A) -- Imported" + << "Legacy Canvas" + << "Legacy Win16" + << "Legacy Win32" + << "Legacy VGA BIOS" + << "Legacy VGA PCX" + << "Super Convert RGB" + << "Jace NTSC" + << "Cybernesto-Munafo NTSC" + << "Pseudo Palette" + << "tohgr NTSC HGR"; + ui->comboBox_previewPalette->addItems(previewPalettes); + // HANDLE DISPLAY MODE SELECTION (COMPATIBILITY) updateDisplayModes(); @@ -73,19 +95,27 @@ MainWindow::MainWindow(QWidget *parent) : connect(previewTimer, SIGNAL(timeout()), this, SLOT(previewTimerTimeout())); } -//---- display modes -// 0 "40 x 48 - Full Scale LGR (LGR ONLY)" -// 1 "80 x 48 - Full Scale DLGR (DLGR ONLY)" -// 2 "140 x 192 - Full Scale (HGR & DHGR)" -// 3 "280 x 192 - Double Width Scale (HGR & DHGR)" -// 4 "320 x 200 - Classic Size" -// 5 "560 x 384 - Quadruple Width, Double Height Scale" -// 6 "640 x 400 - Classic Size" -// 7 "640 x 480 - Classic Size"; + +MainWindow::~MainWindow() +{ + delete ui; +} + + void MainWindow::updateDisplayModes() { QList disabledList = QList(); + //---- display modes + // 0 "40 x 48 - Full Scale LGR (LGR ONLY)" + // 1 "80 x 48 - Full Scale DLGR (DLGR ONLY)" + // 2 "140 x 192 - Full Scale (HGR & DHGR)" + // 3 "280 x 192 - Double Width Scale (HGR & DHGR)" + // 4 "320 x 200 - Classic Size" + // 5 "560 x 384 - Quadruple Width, Double Height Scale" + // 6 "640 x 400 - Classic Size" + // 7 "640 x 480 - Classic Size"; + // Enable all first QList enabledList = QList() << 0 << 1 << 2 << 3 << 4 << 5 << 6 << 7; QListIterator e(enabledList); @@ -136,17 +166,10 @@ void MainWindow::updateDisplayModes() { } } - -MainWindow::~MainWindow() -{ - delete ui; -} - - void MainWindow::on_pushButton_sourceFilename_clicked() { QString filename = QFileDialog::getOpenFileName(); - if (filename != NULL) { + if (filename != nullptr) { ui->lineEdit_sourceFilename->setText(filename); QPixmap mypix(filename); ui->label_source->setPixmap(mypix); @@ -199,8 +222,8 @@ void MainWindow::updateInputSize() } QSize sourceSize = ui->label_source->pixmap()->size(); - double sx = (double)inputWidth / sourceSize.width(); - double sy = (double)inputHeight / sourceSize.height(); + double sx = static_cast(inputWidth) / sourceSize.width(); + double sy = static_cast(inputHeight) / sourceSize.height(); QString scaleString = QString("%1 x %2").arg(sx).arg(sy); ui->label_scaleFactor->setText(scaleString); } @@ -214,10 +237,13 @@ void MainWindow::livePreview() // This is the actual preview generation/main logic function + void MainWindow::on_pushButton_preview_clicked() { - if (ui->label_source->pixmap() == NULL) { - ui->plainTextEdit_lastCmd->document()->setPlainText("Please open a source image first!"); + if (ui->label_source->pixmap() == nullptr) { + QString noImage = "Please open a source image first"; + ui->plainTextEdit_lastCmd->setPlainText(noImage); + repaint(); return; } // GET SCALE FACTOR @@ -272,13 +298,20 @@ void MainWindow::on_pushButton_preview_clicked() args << ditherArg; } - args << "V"; // MUST HAVE! V FLAG GENERATES OUR PREVIEW IMAGE + // MUST ALWAYS HAVE A "V" FLAG TO GENERATE OUR PREVIEW IMAGE + if (ui->comboBox_previewPalette->currentIndex() > -1) { + QString ppalArg = QString("V%1").arg(ui->comboBox_previewPalette->currentIndex()); + args << ppalArg; + } + + args << ui->lineEdit_addArgs->text(); // RUN THE CONVERTER SCRIPT process.start(converterPath,args); process.waitForFinished(); // BLOCKS!!! QString commandString = QString("%1 %2").arg(converterPath, args.join(" ")); + qDebug() << commandString; ui->plainTextEdit_lastCmd->document()->setPlainText(commandString); // ALL DONE SO TRY TO LOAD PREVIEW @@ -288,16 +321,20 @@ void MainWindow::on_pushButton_preview_clicked() int scale = 3; realScale = scale; previewPix = previewPix.scaled(80*scale, 48*scale); + qDebug() << "W80"; } if (previewPix.width() == 560) { float scale = 0.5f; realScale = scale; - previewPix = previewPix.scaled((int)(560*scale),(int)(384*scale), Qt::KeepAspectRatio,Qt::SmoothTransformation); + previewPix = previewPix.scaled(qRound(560*scale),qRound(384*scale), Qt::KeepAspectRatio,Qt::SmoothTransformation); + qDebug() << "W560"; } ui->label_preview->setPixmap(previewPix); - ui->groupBox_preview->setTitle(QString("Preview - Scale %1").arg(realScale)); + ui->groupBox_preview->setTitle(QString("Preview - Scale %1").arg(qRound(realScale))); + repaint(); } + // When this timer is running, it checks to see if a // preview update has been requested, and handles it if so. void MainWindow::previewTimerTimeout() @@ -329,14 +366,14 @@ void MainWindow::on_horizontalSlider_colorBleed_valueChanged(int value) updateNeeded = 1; } -void MainWindow::on_comboBox_outputFormat_currentIndexChanged(int index) +void MainWindow::on_comboBox_outputFormat_currentIndexChanged(int /*unused*/) { updateNeeded = 1; updateDisplayModes(); } -void MainWindow::on_comboBox_inputResolution_currentIndexChanged(int index) +void MainWindow::on_comboBox_inputResolution_currentIndexChanged(int /*unused*/) { updateNeeded = 1; } @@ -366,13 +403,13 @@ void MainWindow::on_actionWhat_is_this_triggered() "Once you are satisfied with your conversion settings, click \"Save Image File\" to save in one of the Apple ][ image formats based on the display mode. " "If you want to save that image file directly to a ProDOS volume, that is now supported via the \"Save To ProDOS\" function!\n\n" "Then you can load it up in your favorite emulator, or transfer it to real disks/flash storage to view on glorious vintage hardware.\n\n" - "(c)2016-2017 Dagen Brock *\n\n\n * bmp2dhr is by Bill Buckels and CADIUS is by Brutal Deluxe."); + "(c)2016-2019 Dagen Brock *\n\n\n * bmp2dhr is by Bill Buckels and CADIUS is by Brutal Deluxe."); msgBox.exec(); } void MainWindow::on_pushButton_saveImage_clicked() { - if (ui->label_preview->pixmap() == NULL) { + if (ui->label_preview->pixmap() == nullptr) { ui->plainTextEdit_lastCmd->document()->setPlainText("Please open a source image and run a preview first!"); return; } @@ -404,7 +441,7 @@ void MainWindow::on_pushButton_saveImage_clicked() } // PROMPT FOR SAVE FILENAME AND COPY (HOPEFULLY) TO SAVE FILENAME - QString saveFile = QFileDialog::getSaveFileName(0, "Save file", QDir::currentPath(), filters, &defaultFilter); + QString saveFile = QFileDialog::getSaveFileName(nullptr, "Save file", QDir::currentPath(), filters, &defaultFilter); if (QFile::exists(saveFile)) { QFile::remove(saveFile); } @@ -422,7 +459,7 @@ void MainWindow::on_pushButton_saveToProdos_clicked() { // @Todo: This isn't appropriate when someone changes res/source and has // a previous preview pixmap, it will think we are all OK. - if (ui->label_preview->pixmap() == NULL) { + if (ui->label_preview->pixmap() == nullptr) { ui->plainTextEdit_lastCmd->document()->setPlainText("Please open a source image and run a preview first!"); return; } @@ -442,7 +479,7 @@ void MainWindow::on_pushButton_saveToProdos_clicked() // PROMPT FOR SAVE FILENAME AND COPY (HOPEFULLY) TO SAVE FILENAME - QString prodosImageFile = QFileDialog::getSaveFileName(0, "Choose ProDOS Image to Save to", QDir::currentPath(), filters, &defaultFilter, QFileDialog::DontConfirmOverwrite); + QString prodosImageFile = QFileDialog::getSaveFileName(nullptr, "Choose ProDOS Image to Save to", QDir::currentPath(), filters, &defaultFilter, QFileDialog::DontConfirmOverwrite); // ALSO GENERATE PRODOS SAFE BASENAME QFileInfo fi(prodosImageFile); @@ -493,7 +530,7 @@ void MainWindow::on_pushButton_saveToProdos_clicked() // NOW CHECK AGAIN TO SEE IF OUR IMAGE FILE GOT CREATED if (check_file.exists() && check_file.isFile()) { - qDebug() << "IMAGE FILE CREATED."; + // qDebug() << "IMAGE FILE CREATED."; } else { ui->plainTextEdit_lastCmd->document()->setPlainText(QString("Failed creating image with command: %1").arg(commandString)); return; @@ -512,7 +549,7 @@ void MainWindow::on_pushButton_saveToProdos_clicked() cat_process.start(cadiusPath,cat_args); cat_process.waitForFinished(); // BLOCKS!!! QString cat_output = QString(cat_process.readAllStandardOutput()); - qDebug() << "CATALOG OUTPUT (cat_output)\n " << cat_output; + //qDebug() << "CATALOG OUTPUT (cat_output)\n " << cat_output; // regex scanner index int pos = 0; @@ -532,7 +569,7 @@ void MainWindow::on_pushButton_saveToProdos_clicked() while ((pos = rx.indexIn(cat_output, pos)) != -1) { list << rx.cap(1); - qDebug() << rx.cap(1); + //qDebug() << rx.cap(1); pos += rx.matchedLength(); } @@ -628,7 +665,7 @@ void MainWindow::on_pushButton_saveToProdos_clicked() // GENERATE OUR STUPID _FileInformation.txt in the same directory QString fileinfo_text = QString("%1=Type(%2),AuxType(%3),VersionCreate(70),MinVersion(BE),Access(E3),FolderInfo1(000000000000000000000000000000000000),FolderInfo2(000000000000000000000000000000000000)").arg(prodosFileName, filetype, auxtype); QString fileinfo_file = QString("%1/_FileInformation.txt").arg(tmpDirPath); - qDebug() << "TMP FILE: " << fileinfo_file; + //qDebug() << "TMP FILE: " << fileinfo_file; QFile file( fileinfo_file ); if (file.open(QIODevice::ReadWrite)) { QTextStream stream( &file ); @@ -654,7 +691,7 @@ void MainWindow::on_pushButton_saveToProdos_clicked() // ../tools/Cadius DELETEFILE <[2mg|hdv|po]_image_path> // YES - DELETE QString deleteFile = QString("%1%2").arg(prodosVolumeName,prodosFileName); - qDebug() << "DELETEFILE : " <label_preview->pixmap() == NULL) { + if (ui->label_preview->pixmap() == nullptr) { ui->plainTextEdit_lastCmd->document()->setPlainText("Save cancelled because file exists."); return; } @@ -703,7 +740,12 @@ void MainWindow::on_pushButton_saveToProdos_clicked() return; } -void MainWindow::on_comboBox_dithering_currentIndexChanged(int index) +void MainWindow::on_comboBox_dithering_currentIndexChanged(int /*unused*/) +{ + updateNeeded = 1; +} + +void MainWindow::on_comboBox_previewPalette_currentIndexChanged(int /*unused*/) { updateNeeded = 1; } diff --git a/buckshot/mainwindow.h b/buckshot/mainwindow.h index b38c65b..6815cff 100644 --- a/buckshot/mainwindow.h +++ b/buckshot/mainwindow.h @@ -18,7 +18,7 @@ class MainWindow : public QMainWindow Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0); + explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); private slots: @@ -28,7 +28,7 @@ private slots: void on_horizontalSlider_crossHatch_valueChanged(int value); void on_horizontalSlider_colorBleed_valueChanged(int value); - void on_comboBox_outputFormat_currentIndexChanged(int index); + void on_comboBox_outputFormat_currentIndexChanged(int); void on_comboBox_inputResolution_currentIndexChanged(int index); void on_checkBox_livePreview_stateChanged(int arg1); @@ -40,8 +40,9 @@ private slots: void on_pushButton_saveImage_clicked(); void on_pushButton_saveToProdos_clicked(); - void on_comboBox_dithering_currentIndexChanged(int index); + void on_comboBox_previewPalette_currentIndexChanged(int index); + private: Ui::MainWindow *ui; diff --git a/buckshot/mainwindow.ui b/buckshot/mainwindow.ui index d7a23e2..ce00679 100644 --- a/buckshot/mainwindow.ui +++ b/buckshot/mainwindow.ui @@ -7,7 +7,7 @@ 0 0 671 - 534 + 576 @@ -17,10 +17,10 @@ - 10 + 20 40 311 - 221 + 211 @@ -32,7 +32,7 @@ 10 24 291 - 191 + 181 @@ -98,24 +98,11 @@ - - - - 530 - 260 - 131 - 32 - - - - Preview - - - 305 - 378 + 310 + 385 31 16 @@ -127,8 +114,8 @@ - 305 - 410 + 310 + 415 31 16 @@ -140,8 +127,8 @@ - 360 - 260 + 380 + 265 101 30 @@ -154,8 +141,8 @@ 147 - 408 - 151 + 415 + 161 22 @@ -166,8 +153,8 @@ - 8 - 266 + 10 + 265 134 20 @@ -183,8 +170,8 @@ 147 - 264 - 181 + 265 + 191 26 @@ -193,9 +180,9 @@ 0 - 408 + 415 140 - 20 + 16 @@ -208,14 +195,14 @@ - 105 - 350 + 101 + 355 37 16 - Scale: + Scale Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -225,9 +212,9 @@ 0 - 370 + 385 140 - 30 + 16 @@ -241,7 +228,7 @@ 28 - 296 + 295 114 16 @@ -257,8 +244,8 @@ 147 - 318 - 181 + 325 + 191 26 @@ -267,8 +254,8 @@ 147 - 374 - 151 + 385 + 161 22 @@ -282,27 +269,27 @@ - 150 - 296 - 211 + 155 + 295 + 161 16 - Source Resolution: + 10x10 21 - 320 + 325 121 20 - Scale to Resolution: + Scale to Resolution Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -311,38 +298,22 @@ - 150 - 350 - 211 + 155 + 355 + 171 16 - Scale - - - - - - 520 - 360 - 131 - 20 - - - - Last Command Run: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + 1 360 - 380 - 301 + 385 + 291 79 @@ -351,13 +322,16 @@ 10 + + This box shows the last conversion command run. + - 530 - 290 - 131 + 410 + 480 + 121 32 @@ -368,7 +342,7 @@ - 330 + 340 270 20 201 @@ -382,8 +356,8 @@ 530 - 320 - 131 + 480 + 121 32 @@ -395,13 +369,13 @@ 20 - 440 + 445 121 20 - Dithering: + Dithering Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -411,12 +385,82 @@ 147 - 440 - 181 + 445 + 191 26 + + + + 360 + 355 + 131 + 21 + + + + + + + 390 + 295 + 101 + 20 + + + + Preview Palette: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 500 + 295 + 161 + 26 + + + + + + + 490 + 355 + 141 + 20 + + + + + 12 + + + + <- additional arguments + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 500 + 265 + 161 + 32 + + + + Preview + +