From 343d6daf8638bd0e8e0ae8180bf35617561cfb17 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Wed, 23 Nov 2016 08:46:22 +0100 Subject: [PATCH] [Companion] Some refactoring around the splash image handling (#4067) --- companion/src/apppreferencesdialog.cpp | 37 ++++++------ companion/src/apppreferencesdialog.h | 10 ++-- companion/src/customizesplashdialog.cpp | 57 +++++++++---------- companion/src/eeprominterface.h | 4 +- .../src/firmwares/opentx/opentxinterface.cpp | 21 ++++++- companion/src/flashfirmwaredialog.cpp | 2 +- companion/src/helpers.cpp | 26 ++++----- companion/src/helpers.h | 4 +- companion/src/splashlibrarydialog.cpp | 2 +- 9 files changed, 87 insertions(+), 76 deletions(-) diff --git a/companion/src/apppreferencesdialog.cpp b/companion/src/apppreferencesdialog.cpp index 7daf6bfd0..94594910e 100644 --- a/companion/src/apppreferencesdialog.cpp +++ b/companion/src/apppreferencesdialog.cpp @@ -11,7 +11,7 @@ #include #include -AppPreferencesDialog::AppPreferencesDialog(QWidget *parent) : +AppPreferencesDialog::AppPreferencesDialog(QWidget * parent) : QDialog(parent), ui(new Ui::AppPreferencesDialog) { @@ -23,7 +23,7 @@ AppPreferencesDialog::AppPreferencesDialog(QWidget *parent) : connect(ui->downloadVerCB, SIGNAL(currentIndexChanged(int)), this, SLOT(baseFirmwareChanged())); connect(this, SIGNAL(accepted()), this, SLOT(writeValues())); -#ifndef JOYSTICKS +#if !defined(JOYSTICKS) ui->joystickCB->hide(); ui->joystickCB->setDisabled(true); ui->joystickcalButton->hide(); @@ -91,7 +91,7 @@ void AppPreferencesDialog::writeValues() void AppPreferencesDialog::on_snapshotPathButton_clicked() { - QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your snapshot folder"), g.snapshotDir()); + QString fileName = QFileDialog::getExistingDirectory(this, tr("Select your snapshot folder"), g.snapshotDir()); if (!fileName.isEmpty()) { g.snapshotDir(fileName); g.snapToClpbrd(false); @@ -137,15 +137,17 @@ void AppPreferencesDialog::initSettings() ui->backupPath->setText(g.backupDir()); ui->backupEnable->setEnabled(true); ui->backupEnable->setChecked(g.enableBackup()); - } else { + } + else { ui->backupEnable->setDisabled(true); } - } else { + } + else { ui->backupEnable->setDisabled(true); } ui->splashincludeCB->setCurrentIndex(g.embedSplashes()); -#ifdef JOYSTICKS +#if defined(JOYSTICKS) ui->joystickChkB->setChecked(g.jsSupport()); if (ui->joystickChkB->isChecked()) { QStringList joystickNames; @@ -172,7 +174,7 @@ void AppPreferencesDialog::initSettings() ui->joystickcalButton->setDisabled(true); } #endif -// Profile Tab Inits + // Profile Tab Inits ui->channelorderCB->setCurrentIndex(g.profile[g.id()].channelOrder()); ui->stickmodeCB->setCurrentIndex(g.profile[g.id()].defaultMode()); ui->renameFirmware->setChecked(g.profile[g.id()].renameFwFiles()); @@ -185,7 +187,8 @@ void AppPreferencesDialog::initSettings() } else { ui->pbackupEnable->setDisabled(true); } - } else { + } + else { ui->pbackupEnable->setDisabled(true); } @@ -270,7 +273,7 @@ void AppPreferencesDialog::on_ge_pathButton_clicked() } } -#ifdef JOYSTICKS +#if defined(JOYSTICKS) void AppPreferencesDialog::on_joystickChkB_clicked() { if (ui->joystickChkB->isChecked()) { QStringList joystickNames; @@ -325,23 +328,17 @@ void AppPreferencesDialog::on_removeProfileButton_clicked() } } - -bool AppPreferencesDialog::displayImage( QString fileName ) +bool AppPreferencesDialog::displayImage(const QString & fileName) { - // Start by clearing the pixmap - ui->imageLabel->setPixmap(QPixmap()); + // Start by clearing the label + ui->imageLabel->clear(); QImage image(fileName); if (image.isNull()) return false; - - // Use the firmware name to determine splash width - int width = SPLASH_WIDTH; - if (g.profile[g.id()].fwType().contains("x9")) - width = SPLASHX9D_WIDTH; - ui->imageLabel->setPixmap( makePixMap( image, g.profile[g.id()].fwType())); - ui->imageLabel->setFixedSize(width, SPLASH_HEIGHT); + ui->imageLabel->setPixmap(makePixMap(image)); + ui->imageLabel->setFixedSize(GetCurrentFirmware()->getCapability(LcdWidth), GetCurrentFirmware()->getCapability(LcdHeight)); return true; } diff --git a/companion/src/apppreferencesdialog.h b/companion/src/apppreferencesdialog.h index bace7c642..991959d4e 100644 --- a/companion/src/apppreferencesdialog.h +++ b/companion/src/apppreferencesdialog.h @@ -16,9 +16,9 @@ class AppPreferencesDialog : public QDialog Q_OBJECT public: - explicit AppPreferencesDialog(QWidget *parent = 0); + explicit AppPreferencesDialog(QWidget * parent = 0); ~AppPreferencesDialog(); - Joystick *joystick; + Joystick * joystick; private: QList optionsCheckBoxes; @@ -33,9 +33,7 @@ class AppPreferencesDialog : public QDialog Ui::AppPreferencesDialog *ui; void initSettings(); - bool displayImage( QString fileName ); - void loadProfileString(QString profile, QString label); - void loadFromProfile(); + bool displayImage(const QString & fileName); protected slots: void shrink(); @@ -55,7 +53,7 @@ class AppPreferencesDialog : public QDialog void on_SplashSelect_clicked(); void on_clearImageButton_clicked(); -#ifdef JOYSTICKS +#if defined(JOYSTICKS) void on_joystickChkB_clicked(); void on_joystickcalButton_clicked(); #endif diff --git a/companion/src/customizesplashdialog.cpp b/companion/src/customizesplashdialog.cpp index 1a83e8b54..53fff5146 100644 --- a/companion/src/customizesplashdialog.cpp +++ b/companion/src/customizesplashdialog.cpp @@ -29,11 +29,11 @@ void Side::markSourceButton() void Side::copyImage( Side side ) { - if ((*source!=UNDEFINED) && (*side.source!=UNDEFINED)) + if ((*source!=UNDEFINED) && (*side.source!=UNDEFINED)) imageLabel->setPixmap(*side.imageLabel->pixmap()); } -bool Side::displayImage( QString fileName, Source pictSource ) +bool Side::displayImage(QString fileName, Source pictSource) { QImage image; @@ -41,7 +41,7 @@ bool Side::displayImage( QString fileName, Source pictSource ) return false; // Determine which picture format to use - if (pictSource == FW ){ + if (pictSource == FW) { FirmwareInterface firmware(fileName); if (!firmware.hasSplash()) return false; @@ -56,37 +56,34 @@ bool Side::displayImage( QString fileName, Source pictSource ) else if (pictSource == PROFILE) *format = (g.profile[g.id()].fwType().contains("x9")) ? LCDTARANIS : LCD9X; } + if (image.isNull()) { return false; } - // Load image - if (*format==LCDTARANIS) { - imageLabel->setPixmap( makePixMap( image, "x9" )); - imageLabel->setFixedSize(WIDTH_TARANIS*2, HEIGHT_TARANIS*2); - } - else { - imageLabel->setPixmap( makePixMap( image, "9x" )); - imageLabel->setFixedSize(WIDTH_9X*2, HEIGHT_9X*2); - } - 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; + // Load image + QPixmap pixmap = makePixMap(image); + imageLabel->setPixmap(pixmap); + imageLabel->setFixedSize(pixmap.width()*2, pixmap.height()*2); + + 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); diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index ca2fe11f7..d3e4dc299 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -1364,7 +1364,9 @@ enum Capability { PermTimers, HasSDLogs, CSFunc, - LCDWidth, + LcdWidth, + LcdHeight, + LcdDepth, GetThrSwitch, HasDisplayText, HasTopLcd, diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index 9cad80d49..f756522af 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -767,8 +767,25 @@ int OpenTxFirmware::getCapability(Capability capability) return 18; case HasSDLogs: return ((IS_2560(board) || IS_ARM(board)) ? true : false); - case LCDWidth: - return (IS_TARANIS(board) ? 212 : 128) ; + case LcdWidth: + if (IS_HORUS(board)) + return 480; + else if (IS_TARANIS(board)) + return 212; + else + return 128; + case LcdHeight: + if (IS_HORUS(board)) + return 272; + else + return 64; + case LcdDepth: + if (IS_HORUS(board)) + return 16; + else if (IS_TARANIS(board)) + return 4; + else + return 1; case GetThrSwitch: return (IS_TARANIS(board) ? SWITCH_SF1 : SWITCH_THR) ; case HasDisplayText: diff --git a/companion/src/flashfirmwaredialog.cpp b/companion/src/flashfirmwaredialog.cpp index a196ea211..d75660efd 100644 --- a/companion/src/flashfirmwaredialog.cpp +++ b/companion/src/flashfirmwaredialog.cpp @@ -115,7 +115,7 @@ void FlashFirmwareDialog::updateUI() } if (!image.isNull()) { - ui->splash->setPixmap(makePixMap(image, g.profile[g.id()].fwType())); + ui->splash->setPixmap(makePixMap(image)); } } diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index 42381a194..08f978b45 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -832,25 +832,25 @@ void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx) } } -QPixmap makePixMap( QImage image, QString firmwareType ) +QPixmap makePixMap(const QImage & image) { - if (firmwareType.contains( "x9" )) { - image = image.convertToFormat(QImage::Format_RGB32); - QRgb col; - int gray; + Firmware * firmware = GetCurrentFirmware(); + QImage result = image.scaled(firmware->getCapability(LcdWidth), firmware->getCapability(LcdHeight)); + if (firmware->getCapability(LcdDepth) == 4) { + result = result.convertToFormat(QImage::Format_RGB32); for (int i = 0; i < image.width(); ++i) { for (int j = 0; j < image.height(); ++j) { - col = image.pixel(i, j); - gray = qGray(col); - image.setPixel(i, j, qRgb(gray, gray, gray)); + QRgb col = result.pixel(i, j); + int gray = qGray(col); + result.setPixel(i, j, qRgb(gray, gray, gray)); } } - image = image.scaled(SPLASHX9D_WIDTH, SPLASHX9D_HEIGHT); - } - else { - image = image.scaled(SPLASH_WIDTH, SPLASH_HEIGHT).convertToFormat(QImage::Format_Mono); } - return(QPixmap::fromImage(image)); + else { + result = result.convertToFormat(QImage::Format_Mono); + } + + return QPixmap::fromImage(result); } int version2index(const QString & version) diff --git a/companion/src/helpers.h b/companion/src/helpers.h index b5b6ebf74..60607a047 100644 --- a/companion/src/helpers.h +++ b/companion/src/helpers.h @@ -153,8 +153,8 @@ QVector findWidgets(QObject * object, const QString & name) return result; } -// Format a pixmap to fit on the radio using a specific firmware -QPixmap makePixMap( QImage image, QString firmwareType ); +// Format a pixmap to fit on the current firmware +QPixmap makePixMap(const QImage & image); int version2index(const QString & version); QString index2version(int index); diff --git a/companion/src/splashlibrarydialog.cpp b/companion/src/splashlibrarydialog.cpp index f9aafaa25..cd574323e 100644 --- a/companion/src/splashlibrarydialog.cpp +++ b/companion/src/splashlibrarydialog.cpp @@ -42,7 +42,7 @@ void SplashLibraryDialog::setupPage(int page) if ((i + 20 * page) < imageList.size()) { QImage image(imageList.at(i + 20 * page)); if (!image.isNull()) { - sl[i]->setPixmap(makePixMap(image, g.profile[g.id()].fwType())); + sl[i]->setPixmap(makePixMap(image)); sl[i]->setEnabled(true); sl[i]->setId((i + 20 * page)); sl[i]->setStyleSheet("border:1px solid; border-color:#999999;");