mirror of
https://github.com/opentx/opentx.git
synced 2025-07-26 17:55:19 +03:00
App Preferences dialog tabs fully functional, except for adding profiles.
Splash Editor fully functional. Improved handling of image formats remain. Merged branch 'origin/next'
This commit is contained in:
commit
d5e22111e1
28 changed files with 786 additions and 408 deletions
|
@ -7,19 +7,128 @@
|
|||
#include "splashlibrary.h"
|
||||
#include "flashinterface.h"
|
||||
|
||||
//*** Side Class ***
|
||||
|
||||
Side::Side(){
|
||||
imageLabel = 0;
|
||||
fileNameEdit = 0;
|
||||
saveButton = 0;
|
||||
source=new Source;
|
||||
*source = UNDEFINED;
|
||||
saveToFileName = new QString("");
|
||||
source = new Source(UNDEFINED);
|
||||
}
|
||||
|
||||
void Side::copyImage( Side side ){
|
||||
if ((*source!=UNDEFINED) && (*side.source!=UNDEFINED))
|
||||
void Side::copyImage( Side side )
|
||||
{
|
||||
if ((*source!=UNDEFINED) && (*side.source!=UNDEFINED))
|
||||
imageLabel->setPixmap(*side.imageLabel->pixmap());
|
||||
}
|
||||
|
||||
bool Side::displayImage( QString fileName, Source pictSource )
|
||||
{
|
||||
QImage image;
|
||||
|
||||
if (fileName.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
if (pictSource == FW ){
|
||||
FlashInterface flash(fileName);
|
||||
if (!flash.hasSplash())
|
||||
return false;
|
||||
else
|
||||
image = flash.getSplash();
|
||||
}
|
||||
else {
|
||||
image.load(fileName);
|
||||
}
|
||||
if (image.isNull()) {
|
||||
return false;
|
||||
}
|
||||
if (imageLabel->width()==424) {
|
||||
image=image.convertToFormat(QImage::Format_RGB32);
|
||||
QRgb col;
|
||||
int gray;
|
||||
int width = image.width();
|
||||
int height = image.height();
|
||||
for (int i = 0; i < width; ++i) {
|
||||
for (int j = 0; j < height; ++j) {
|
||||
col = image.pixel(i, j);
|
||||
gray = qGray(col);
|
||||
image.setPixel(i, j, qRgb(gray, gray, gray));
|
||||
}
|
||||
}
|
||||
imageLabel->setPixmap(QPixmap::fromImage(image.scaled(imageLabel->width()/2, imageLabel->height()/2)));
|
||||
}
|
||||
else {
|
||||
imageLabel->setPixmap(QPixmap::fromImage(image.scaled(imageLabel->width()/2, imageLabel->height()/2).convertToFormat(QImage::Format_Mono)));
|
||||
}
|
||||
switch (pictSource){
|
||||
case FW:
|
||||
fileNameEdit->setText(QObject::tr("FW: %1").arg(fileName));
|
||||
*saveToFileName = fileName;
|
||||
*source=FW;
|
||||
break;
|
||||
case PICT:
|
||||
fileNameEdit->setText(QObject::tr("Pict: %1").arg(fileName));
|
||||
*saveToFileName = fileName;
|
||||
*source=PICT;
|
||||
break;
|
||||
case PROFILE:
|
||||
fileNameEdit->setText(QObject::tr("Profile image"));
|
||||
*saveToFileName = fileName;
|
||||
*source=PROFILE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
saveButton->setEnabled(true);
|
||||
libraryButton->setEnabled(true);
|
||||
invertButton->setEnabled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Side::refreshImage()
|
||||
{
|
||||
return displayImage( *saveToFileName, *source );
|
||||
}
|
||||
|
||||
bool Side::saveImage()
|
||||
{
|
||||
QSettings settings;
|
||||
|
||||
if (*source == FW )
|
||||
{
|
||||
FlashInterface flash(*saveToFileName);
|
||||
if (!flash.hasSplash()) {
|
||||
return false;
|
||||
}
|
||||
QImage image = imageLabel->pixmap()->toImage().scaled(flash.getSplashWidth(), flash.getSplashHeight());
|
||||
if (flash.setSplash(image) && (flash.saveFlash(*saveToFileName) > 0)) {
|
||||
settings.setValue("lastFlashDir", QFileInfo(*saveToFileName).dir().absolutePath());
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (*source == PICT) {
|
||||
QImage image = imageLabel->pixmap()->toImage().scaled(imageLabel->width()/2, imageLabel->height()/2).convertToFormat(QImage::Format_Indexed8);
|
||||
if (image.save(*saveToFileName)) {
|
||||
settings.setValue("lastImagesDir", QFileInfo(*saveToFileName).dir().absolutePath());
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (*source == PROFILE) {
|
||||
QImage image = imageLabel->pixmap()->toImage().scaled(imageLabel->width()/2, imageLabel->height()/2).convertToFormat(QImage::Format_Indexed8);
|
||||
if (!image.save(*saveToFileName)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//*** customizeSplashDialog Class ***
|
||||
|
||||
customizeSplashDialog::customizeSplashDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::customizeSplashDialog)
|
||||
|
@ -39,6 +148,7 @@ customizeSplashDialog::customizeSplashDialog(QWidget *parent) :
|
|||
left.invertButton = ui->leftInvertButton;
|
||||
right.invertButton = ui->rightInvertButton;
|
||||
|
||||
loadProfile(left);
|
||||
resize(0,0);
|
||||
}
|
||||
|
||||
|
@ -62,25 +172,10 @@ void customizeSplashDialog::loadFirmware(Side side)
|
|||
QSettings settings;
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), settings.value("lastFlashDir").toString(), FLASH_FILES_FILTER);
|
||||
if (!fileName.isEmpty()) {
|
||||
QFile file(fileName);
|
||||
if (fileName.isEmpty() || !file.exists())
|
||||
return;
|
||||
|
||||
FlashInterface flash(fileName);
|
||||
if (!flash.hasSplash()) {
|
||||
QMessageBox::information(this, tr("Error"), tr("Could not find bitmap to replace in file"));
|
||||
return;
|
||||
}
|
||||
|
||||
side.saveButton->setEnabled(true);
|
||||
side.imageLabel->setPixmap(QPixmap::fromImage(flash.getSplash()));
|
||||
side.imageLabel->setFixedSize(flash.getSplashWidth()*2,flash.getSplashHeight()*2);
|
||||
side.fileNameEdit->setText(fileName);
|
||||
if (!side.displayImage( fileName, FW ))
|
||||
QMessageBox::critical(this, tr("Error"), tr("Cannot load embedded FW image from %1.").arg(fileName));
|
||||
else
|
||||
settings.setValue("lastFlashDir", QFileInfo(fileName).dir().absolutePath());
|
||||
*side.source=FW;
|
||||
side.saveButton->setEnabled(true);
|
||||
side.libraryButton->setEnabled(true);
|
||||
side.invertButton->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,46 +191,25 @@ void customizeSplashDialog::loadPicture(Side side)
|
|||
QString fileName = QFileDialog::getOpenFileName(this,
|
||||
tr("Open Image to load"), settings.value("lastImagesDir").toString(), tr("Images (%1)").arg(supportedImageFormats));
|
||||
|
||||
if (fileName.isEmpty()){
|
||||
return;
|
||||
if (!fileName.isEmpty()) {
|
||||
if (!side.displayImage( fileName, PICT ))
|
||||
QMessageBox::critical(this, tr("Error"), tr("Cannot load the image file %1.").arg(fileName));
|
||||
else
|
||||
settings.setValue("lastImagesDir", QFileInfo(fileName).dir().absolutePath());
|
||||
}
|
||||
QImage image(fileName);
|
||||
if (image.isNull()) {
|
||||
QMessageBox::critical(this, tr("Error"), tr("Cannot load %1.").arg(fileName));
|
||||
return;
|
||||
}
|
||||
if (side.imageLabel->width()==424) {
|
||||
image=image.convertToFormat(QImage::Format_RGB32);
|
||||
QRgb col;
|
||||
int gray;
|
||||
int width = image.width();
|
||||
int height = image.height();
|
||||
for (int i = 0; i < width; ++i)
|
||||
{
|
||||
for (int j = 0; j < height; ++j)
|
||||
{
|
||||
col = image.pixel(i, j);
|
||||
gray = qGray(col);
|
||||
image.setPixel(i, j, qRgb(gray, gray, gray));
|
||||
}
|
||||
}
|
||||
side.imageLabel->setPixmap(QPixmap::fromImage(image.scaled(side.imageLabel->width()/2, side.imageLabel->height()/2)));
|
||||
} else {
|
||||
side.imageLabel->setPixmap(QPixmap::fromImage(image.scaled(side.imageLabel->width()/2, side.imageLabel->height()/2).convertToFormat(QImage::Format_Mono)));
|
||||
}
|
||||
|
||||
settings.setValue("lastImagesDir", QFileInfo(fileName).dir().absolutePath());
|
||||
side.fileNameEdit->setText(fileName);
|
||||
*side.source=PICT;
|
||||
side.saveButton->setEnabled(true);
|
||||
side.libraryButton->setEnabled(true);
|
||||
side.invertButton->setEnabled(true);
|
||||
}
|
||||
|
||||
void customizeSplashDialog::on_leftLoadProfileButton_clicked() {loadProfile(left);}
|
||||
void customizeSplashDialog::on_rightLoadProfileButton_clicked() {loadProfile(right);}
|
||||
void customizeSplashDialog::loadProfile(Side side)
|
||||
{
|
||||
QSettings settings;
|
||||
QString fileName=settings.value("SplashFileName","").toString();
|
||||
|
||||
if (!fileName.isEmpty()) {
|
||||
if (!side.displayImage( fileName, PROFILE ))
|
||||
QMessageBox::critical(this, tr("Error"), tr("Cannot load the profile image %1.").arg(fileName));
|
||||
}
|
||||
}
|
||||
|
||||
void customizeSplashDialog::on_leftLibraryButton_clicked(){libraryButton_clicked(left);}
|
||||
|
@ -143,67 +217,26 @@ void customizeSplashDialog::on_rightLibraryButton_clicked(){libraryButton_clicke
|
|||
void customizeSplashDialog::libraryButton_clicked( Side side )
|
||||
{
|
||||
QString fileName;
|
||||
|
||||
splashLibrary *ld = new splashLibrary(this,&fileName);
|
||||
ld->exec();
|
||||
if (!fileName.isEmpty()) {
|
||||
QImage image(fileName);
|
||||
if (image.isNull()) {
|
||||
QMessageBox::critical(this, tr("Error"), tr("Cannot load %1.").arg(fileName));
|
||||
return;
|
||||
}
|
||||
if (side.imageLabel->width()==424) {
|
||||
image=image.convertToFormat(QImage::Format_RGB32);
|
||||
QRgb col;
|
||||
int gray;
|
||||
int width = image.width();
|
||||
int height = image.height();
|
||||
for (int i = 0; i < width; ++i)
|
||||
{
|
||||
for (int j = 0; j < height; ++j)
|
||||
{
|
||||
col = image.pixel(i, j);
|
||||
gray = qGray(col);
|
||||
image.setPixel(i, j, qRgb(gray, gray, gray));
|
||||
}
|
||||
}
|
||||
side.imageLabel->setPixmap(QPixmap::fromImage(image.scaled(side.imageLabel->width()/2, side.imageLabel->height()/2)));
|
||||
} else {
|
||||
side.imageLabel->setPixmap(QPixmap::fromImage(image.scaled(side.imageLabel->width()/2, side.imageLabel->height()/2).convertToFormat(QImage::Format_Mono)));
|
||||
}
|
||||
if (!side.displayImage( fileName, UNDEFINED ))
|
||||
QMessageBox::critical(this, tr("Error"), tr("Cannot load the library image %1.").arg(fileName));
|
||||
}
|
||||
}
|
||||
|
||||
void customizeSplashDialog::on_leftSaveButton_clicked(){saveButton_clicked(left);}
|
||||
void customizeSplashDialog::on_rightSaveButton_clicked(){saveButton_clicked(right);}
|
||||
void customizeSplashDialog::saveButton_clicked(Side side)
|
||||
void customizeSplashDialog::saveButton_clicked( Side side )
|
||||
{
|
||||
QSettings settings;
|
||||
QString fileName = side.fileNameEdit->text();
|
||||
|
||||
if (*side.source == FW)
|
||||
{
|
||||
FlashInterface flash(fileName);
|
||||
if (!flash.hasSplash()) {
|
||||
QMessageBox::critical(this, tr("Error"), tr("Could not store image in firmware file %1").arg(fileName));
|
||||
return;
|
||||
}
|
||||
QImage image = side.imageLabel->pixmap()->toImage().scaled(flash.getSplashWidth(), flash.getSplashHeight());
|
||||
if (flash.setSplash(image) && (flash.saveFlash(fileName) > 0))
|
||||
settings.setValue("lastFlashDir", QFileInfo(fileName).dir().absolutePath());
|
||||
else
|
||||
QMessageBox::critical(this, tr("Error"), tr("Could not store image in firmware file %1").arg(fileName));
|
||||
}
|
||||
else if (*side.source == PICT)
|
||||
{
|
||||
if (!fileName.isEmpty()) {
|
||||
QImage image = side.imageLabel->pixmap()->toImage().scaled(side.imageLabel->width()/2, side.imageLabel->height()/2).convertToFormat(QImage::Format_Indexed8);
|
||||
if (image.save(fileName))
|
||||
settings.setValue("lastImagesDir", QFileInfo(fileName).dir().absolutePath());
|
||||
else
|
||||
QMessageBox::critical(this, tr("Error"), tr("The image file %1 could not be stored").arg(fileName));
|
||||
if (side.saveImage()){
|
||||
QMessageBox::information(this, tr("File Saved"), tr("The image was saved to the file %1").arg(*side.saveToFileName));
|
||||
if ( !side.refreshImage()){
|
||||
QMessageBox::critical(this, tr("Image Refresh Error"), tr("Failed to refresh image from file %1").arg(*side.saveToFileName));
|
||||
}
|
||||
}
|
||||
else
|
||||
QMessageBox::critical(this, tr("File Save Error"), tr("Failed to write image to %1").arg(*side.saveToFileName));
|
||||
}
|
||||
|
||||
void customizeSplashDialog::on_leftInvertButton_clicked(){invertButton_clicked(left);}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue