Merge pull request #9 from digarok/save-preview

add option to directly save preview - tested lightly, but not going to let this one bake too long.  it's not a big change.
This commit is contained in:
Dagen Brock 2018-12-28 11:01:34 -06:00 committed by GitHub
commit ea97c362dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 85 additions and 32 deletions

View File

@ -9,7 +9,7 @@
#include "qformlayout.h" #include "qformlayout.h"
#include "qdialogbuttonbox.h" #include "qdialogbuttonbox.h"
const QString MainWindow::programName = QString("buckshot"); const QString MainWindow::programName = QString("buckshot");
const QString MainWindow::version = QString("0.03h"); // hotfix const QString MainWindow::version = QString("0.04");
const QString MainWindow::imageName = QString("saved"); const QString MainWindow::imageName = QString("saved");
MainWindow::MainWindow(QWidget *parent) : MainWindow::MainWindow(QWidget *parent) :
@ -102,6 +102,27 @@ MainWindow::~MainWindow()
} }
bool MainWindow::check_canPreview()
{
if (ui->label_source->pixmap() == nullptr) {
ui->plainTextEdit_lastCmd->setPlainText("Please open a source image to run a preview!");
repaint();
return false;
}
return true;
}
bool MainWindow::check_canSave()
{
if (ui->label_preview->pixmap() == nullptr) {
ui->plainTextEdit_lastCmd->setPlainText("Please open a source image and run a preview first!");
repaint();
return false;
}
return true;
}
void MainWindow::updateDisplayModes() { void MainWindow::updateDisplayModes() {
QList<int> disabledList = QList<int>(); QList<int> disabledList = QList<int>();
@ -166,6 +187,7 @@ void MainWindow::updateDisplayModes() {
} }
} }
void MainWindow::on_pushButton_sourceFilename_clicked() void MainWindow::on_pushButton_sourceFilename_clicked()
{ {
QString filename = QFileDialog::getOpenFileName(); QString filename = QFileDialog::getOpenFileName();
@ -181,6 +203,7 @@ void MainWindow::on_pushButton_sourceFilename_clicked()
} }
} }
void MainWindow::updateInputSize() void MainWindow::updateInputSize()
{ {
switch (ui->comboBox_inputResolution->currentIndex()) { switch (ui->comboBox_inputResolution->currentIndex()) {
@ -228,6 +251,7 @@ void MainWindow::updateInputSize()
ui->label_scaleFactor->setText(scaleString); ui->label_scaleFactor->setText(scaleString);
} }
void MainWindow::livePreview() void MainWindow::livePreview()
{ {
if (ui->checkBox_livePreview->isChecked()) { if (ui->checkBox_livePreview->isChecked()) {
@ -237,15 +261,10 @@ void MainWindow::livePreview()
// This is the actual preview generation/main logic function // This is the actual preview generation/main logic function
void MainWindow::on_pushButton_preview_clicked() void MainWindow::on_pushButton_preview_clicked()
{ {
if (ui->label_source->pixmap() == nullptr) { if (!check_canPreview()) return;
QString noImage = "Please open a source image first";
ui->plainTextEdit_lastCmd->setPlainText(noImage);
repaint();
return;
}
// GET SCALE FACTOR // GET SCALE FACTOR
updateInputSize(); updateInputSize();
@ -345,6 +364,7 @@ void MainWindow::previewTimerTimeout()
} }
} }
void MainWindow::on_horizontalSlider_crossHatch_valueChanged(int value) void MainWindow::on_horizontalSlider_crossHatch_valueChanged(int value)
{ {
if (value==0){ if (value==0){
@ -366,6 +386,7 @@ void MainWindow::on_horizontalSlider_colorBleed_valueChanged(int value)
updateNeeded = 1; updateNeeded = 1;
} }
void MainWindow::on_comboBox_outputFormat_currentIndexChanged(int /*unused*/) void MainWindow::on_comboBox_outputFormat_currentIndexChanged(int /*unused*/)
{ {
updateNeeded = 1; updateNeeded = 1;
@ -407,12 +428,11 @@ void MainWindow::on_actionWhat_is_this_triggered()
msgBox.exec(); msgBox.exec();
} }
void MainWindow::on_pushButton_saveImage_clicked() void MainWindow::on_pushButton_saveImage_clicked()
{ {
if (ui->label_preview->pixmap() == nullptr) { if (!check_canSave()) return;
ui->plainTextEdit_lastCmd->document()->setPlainText("Please open a source image and run a preview first!");
return;
}
QString a2filename; QString a2filename;
QString suffix; QString suffix;
QString filters = QString("All Images (*.A2FC *.BIN *.SLO *.DLO);;HGR (*.BIN);;DHGR (*.A2FC);;LR (*.SLO);;DLR (*.DLO);;All files (*.*)"); QString filters = QString("All Images (*.A2FC *.BIN *.SLO *.DLO);;HGR (*.BIN);;DHGR (*.A2FC);;LR (*.SLO);;DLR (*.DLO);;All files (*.*)");
@ -457,12 +477,7 @@ void MainWindow::on_pushButton_saveImage_clicked()
// I consider this small feature a present to the community. // I consider this small feature a present to the community.
void MainWindow::on_pushButton_saveToProdos_clicked() void MainWindow::on_pushButton_saveToProdos_clicked()
{ {
// @Todo: This isn't appropriate when someone changes res/source and has if (!check_canSave()) return;
// a previous preview pixmap, it will think we are all OK.
if (ui->label_preview->pixmap() == nullptr) {
ui->plainTextEdit_lastCmd->document()->setPlainText("Please open a source image and run a preview first!");
return;
}
QString cadiusPath = "/Users/dbrock/appleiigs/tools/Cadius"; QString cadiusPath = "/Users/dbrock/appleiigs/tools/Cadius";
cadiusPath = QString("%1/Cadius").arg(QCoreApplication::applicationDirPath()); cadiusPath = QString("%1/Cadius").arg(QCoreApplication::applicationDirPath());
@ -653,10 +668,6 @@ void MainWindow::on_pushButton_saveToProdos_clicked()
} }
if (ok && !prodosFileName.isEmpty()) { if (ok && !prodosFileName.isEmpty()) {
// COPY IT ... OVER EXISTING NAME? // COPY IT ... OVER EXISTING NAME?
QString saveFile = QString("%1/%2").arg(tmpDirPath,prodosFileName); QString saveFile = QString("%1/%2").arg(tmpDirPath,prodosFileName);
@ -749,3 +760,28 @@ void MainWindow::on_comboBox_previewPalette_currentIndexChanged(int /*unused*/)
{ {
updateNeeded = 1; updateNeeded = 1;
} }
void MainWindow::on_pushButton_savePreview_clicked()
{
if (!check_canSave()) return;
QString a2filename;
QString filters = QString("All Images (*.BMP *.PNG);;Bitmap (*.BMP);;PNG (*.PNG);;All files (*.*)");
QString defaultFilter = "PNG (*.PNG)";
QString suffix = ".PNG";
// PROMPT FOR SAVE FILENAME AND COPY (HOPEFULLY) TO SAVE FILENAME
QString saveFile = QFileDialog::getSaveFileName(nullptr, "Save file", QDir::currentPath(), filters, &defaultFilter);
if (QFile::exists(saveFile)) {
QFile::remove(saveFile);
}
// TRY TO SET CORRECT TYPE FOR SAVE, DEFAULT TO PNG
QFileInfo fi(saveFile);
QString ext = fi.completeSuffix().toUpper();
if (ext == "BMP") {
ui->label_preview->pixmap()->save(saveFile,"BMP", 0);
} else {
ui->label_preview->pixmap()->save(saveFile,"PNG", 0);
}
}

View File

@ -43,12 +43,16 @@ private slots:
void on_comboBox_dithering_currentIndexChanged(int index); void on_comboBox_dithering_currentIndexChanged(int index);
void on_comboBox_previewPalette_currentIndexChanged(int index); void on_comboBox_previewPalette_currentIndexChanged(int index);
void on_pushButton_savePreview_clicked();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
void updateInputSize(); void updateInputSize();
void livePreview(); void livePreview();
void updateDisplayModes(); void updateDisplayModes();
bool check_canSave();
bool check_canPreview();
int inputWidth; int inputWidth;
int inputHeight; int inputHeight;
bool updateNeeded; bool updateNeeded;

View File

@ -312,9 +312,9 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>360</x> <x>360</x>
<y>385</y> <y>370</y>
<width>291</width> <width>291</width>
<height>79</height> <height>71</height>
</rect> </rect>
</property> </property>
<property name="font"> <property name="font">
@ -329,14 +329,14 @@
<widget class="QPushButton" name="pushButton_saveImage"> <widget class="QPushButton" name="pushButton_saveImage">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>410</x> <x>370</x>
<y>480</y> <y>480</y>
<width>121</width> <width>141</width>
<height>32</height> <height>32</height>
</rect> </rect>
</property> </property>
<property name="text"> <property name="text">
<string>Save Image File</string> <string>Save Binary Image</string>
</property> </property>
</widget> </widget>
<widget class="Line" name="line"> <widget class="Line" name="line">
@ -355,14 +355,14 @@
<widget class="QPushButton" name="pushButton_saveToProdos"> <widget class="QPushButton" name="pushButton_saveToProdos">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>530</x> <x>510</x>
<y>480</y> <y>480</y>
<width>121</width> <width>141</width>
<height>32</height> <height>32</height>
</rect> </rect>
</property> </property>
<property name="text"> <property name="text">
<string>Save To ProDOS</string> <string>Save to ProDOS</string>
</property> </property>
</widget> </widget>
<widget class="QLabel" name="label_8"> <widget class="QLabel" name="label_8">
@ -395,7 +395,7 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>360</x> <x>360</x>
<y>355</y> <y>340</y>
<width>131</width> <width>131</width>
<height>21</height> <height>21</height>
</rect> </rect>
@ -431,7 +431,7 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>490</x> <x>490</x>
<y>355</y> <y>340</y>
<width>141</width> <width>141</width>
<height>20</height> <height>20</height>
</rect> </rect>
@ -461,6 +461,19 @@
<string>Preview</string> <string>Preview</string>
</property> </property>
</widget> </widget>
<widget class="QPushButton" name="pushButton_savePreview">
<property name="geometry">
<rect>
<x>370</x>
<y>450</y>
<width>281</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>Save preview as PNG/BMP</string>
</property>
</widget>
</widget> </widget>
<widget class="QMenuBar" name="menuBar"> <widget class="QMenuBar" name="menuBar">
<property name="geometry"> <property name="geometry">