From 48af7aefd04b4420d61bce45a7ecf92341e7aebd Mon Sep 17 00:00:00 2001 From: Kjell Kernen Date: Tue, 11 Feb 2014 18:08:54 +0100 Subject: [PATCH 1/2] Made the Splash editor respect the 9x/Taranis LCD widths in a consistent way. Previously everything was displayed as a Taranis bitmap. Pictures larger than 9x width will get scaled to Taranis width (212 pix). --- companion/src/customizesplashdialog.cpp | 15 ++++++++++++--- companion/src/customizesplashdialog.h | 7 +++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/companion/src/customizesplashdialog.cpp b/companion/src/customizesplashdialog.cpp index 3b8240f6c..5e072e851 100644 --- a/companion/src/customizesplashdialog.cpp +++ b/companion/src/customizesplashdialog.cpp @@ -15,6 +15,7 @@ Side::Side(){ saveButton = 0; saveToFileName = new QString(""); source = new Source(UNDEFINED); + format = new LCDFormat(LCDTARANIS); } void Side::copyImage( Side side ) @@ -36,14 +37,17 @@ bool Side::displayImage( QString fileName, Source pictSource ) return false; else image = flash.getSplash(); + *format = flash.getSplashWidth()==WIDTH_TARANIS ? LCDTARANIS : LCD9X; } else { image.load(fileName); + if (pictSource== PICT) + *format = image.width()>WIDTH_9X ? LCDTARANIS : LCD9X; } if (image.isNull()) { return false; } - if (imageLabel->width()==424) { + if (*format==LCDTARANIS) { image=image.convertToFormat(QImage::Format_RGB32); QRgb col; int gray; @@ -58,9 +62,14 @@ bool Side::displayImage( QString fileName, Source pictSource ) } imageLabel->setPixmap(QPixmap::fromImage(image.scaled(imageLabel->width()/2, imageLabel->height()/2))); } - else { + else imageLabel->setPixmap(QPixmap::fromImage(image.scaled(imageLabel->width()/2, imageLabel->height()/2).convertToFormat(QImage::Format_Mono))); - } + + if (*format == LCD9X) + imageLabel->setFixedSize(WIDTH_9X*2, HEIGHT_9X*2); + else + imageLabel->setFixedSize(WIDTH_TARANIS*2, HEIGHT_TARANIS*2); + switch (pictSource){ case FW: fileNameEdit->setText(QObject::tr("FW: %1").arg(fileName)); diff --git a/companion/src/customizesplashdialog.h b/companion/src/customizesplashdialog.h index b4db9a60e..21155dede 100644 --- a/companion/src/customizesplashdialog.h +++ b/companion/src/customizesplashdialog.h @@ -10,7 +10,13 @@ namespace Ui class customizeSplashDialog; } +const int WIDTH_TARANIS = 212; +const int HEIGHT_TARANIS = 64; +const int WIDTH_9X = 128; +const int HEIGHT_9X = 64; + enum Source {FW, PICT, PROFILE, UNDEFINED}; +enum LCDFormat {LCD9X, LCDTARANIS}; class Side { @@ -31,6 +37,7 @@ public: private: Source *source; + LCDFormat *format; }; class customizeSplashDialog : public QDialog From 94720b0c4e9de9f02c21c7f4846353f08b4f3ef2 Mon Sep 17 00:00:00 2001 From: Kjell Kernen Date: Wed, 12 Feb 2014 01:11:30 +0100 Subject: [PATCH 2/2] Fixes width bug for 212 wide images. --- companion/src/apppreferencesdialog.cpp | 28 ++++++-- companion/src/apppreferencesdialog.ui | 96 +++++++++++++------------- 2 files changed, 70 insertions(+), 54 deletions(-) diff --git a/companion/src/apppreferencesdialog.cpp b/companion/src/apppreferencesdialog.cpp index 24a3a15e1..cfcb0b3de 100644 --- a/companion/src/apppreferencesdialog.cpp +++ b/companion/src/apppreferencesdialog.cpp @@ -2,6 +2,7 @@ #include "ui_apppreferencesdialog.h" #include "mainwindow.h" #include "helpers.h" +#include "flashinterface.h" #ifdef JOYSTICKS #include "joystick.h" #include "joystickdialog.h" @@ -339,16 +340,26 @@ void appPreferencesDialog::on_removeProfileButton_clicked() bool appPreferencesDialog::displayImage( QString fileName ) { + QSettings settings; + QImage image(fileName); if (image.isNull()) - { - QMessageBox::critical(this, tr("Error"), tr("Cannot load %1.").arg(fileName)); return false; - } - int width=ui->imageLabel->width(); - ui->imageLabel->setPixmap(QPixmap::fromImage(image.scaled(width, 64))); - if (width==212) { +// This code below just figures out if the width of the latest firmware is 128 or 212. It works , but... + QString filePath1 = settings.value("lastFlashDir", "").toString() + "/" + settings.value("firmware", "").toString() + ".bin"; + QString filePath2 = settings.value("lastFlashDir", "").toString() + "/" + settings.value("firmware", "").toString() + ".hex"; + QFile file(filePath1); + if (!file.exists()) + filePath1 = filePath2; + int width = SPLASH_WIDTH; + FlashInterface flash(filePath1); + if (flash.hasSplash()) + width = flash.getSplashWidth(); // Returns SPLASHX9D_HEIGHT if filePath1 does not exist! +// There must be a cleaner way of finding out the width of the firmware splash! + + ui->imageLabel->setPixmap(QPixmap::fromImage(image.scaled(width, SPLASH_HEIGHT))); + if (width==SPLASHX9D_WIDTH) { image=image.convertToFormat(QImage::Format_RGB32); QRgb col; int gray, height = image.height(); @@ -364,6 +375,11 @@ bool appPreferencesDialog::displayImage( QString fileName ) else { ui->imageLabel->setPixmap(QPixmap::fromImage(image.convertToFormat(QImage::Format_Mono))); } + if (width == SPLASH_WIDTH) + ui->imageLabel->setFixedSize(SPLASH_WIDTH, SPLASH_HEIGHT); + else + ui->imageLabel->setFixedSize(SPLASHX9D_WIDTH, SPLASHX9D_HEIGHT); + return true; } diff --git a/companion/src/apppreferencesdialog.ui b/companion/src/apppreferencesdialog.ui index 33cfe311a..9a7680a42 100644 --- a/companion/src/apppreferencesdialog.ui +++ b/companion/src/apppreferencesdialog.ui @@ -805,47 +805,6 @@ This is used by the templated to determine which channel goes to what number out - - - - Select Image - - - - - - - - 0 - 0 - - - - - 128 - 64 - - - - - 128 - 64 - - - - QFrame::Panel - - - QFrame::Raised - - - - - - true - - - @@ -873,13 +832,6 @@ This is used by the templated to determine which channel goes to what number out - - - - Clear Image - - - @@ -947,6 +899,54 @@ This is used by the templated to determine which channel goes to what number out + + + + + 0 + 0 + + + + + 128 + 64 + + + + + 212 + 64 + + + + QFrame::Panel + + + QFrame::Raised + + + + + + true + + + + + + + Select Image + + + + + + + Clear Image + + +