[Companion] Some refactoring around the splash image handling (#4067)

This commit is contained in:
Bertrand Songis
2016-11-23 08:46:22 +01:00
committed by GitHub
parent 9983ff9851
commit 343d6daf86
9 changed files with 87 additions and 76 deletions
+17 -20
View File
@@ -11,7 +11,7 @@
#include <QDesktopServices> #include <QDesktopServices>
#include <QtGui> #include <QtGui>
AppPreferencesDialog::AppPreferencesDialog(QWidget *parent) : AppPreferencesDialog::AppPreferencesDialog(QWidget * parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::AppPreferencesDialog) ui(new Ui::AppPreferencesDialog)
{ {
@@ -23,7 +23,7 @@ AppPreferencesDialog::AppPreferencesDialog(QWidget *parent) :
connect(ui->downloadVerCB, SIGNAL(currentIndexChanged(int)), this, SLOT(baseFirmwareChanged())); connect(ui->downloadVerCB, SIGNAL(currentIndexChanged(int)), this, SLOT(baseFirmwareChanged()));
connect(this, SIGNAL(accepted()), this, SLOT(writeValues())); connect(this, SIGNAL(accepted()), this, SLOT(writeValues()));
#ifndef JOYSTICKS #if !defined(JOYSTICKS)
ui->joystickCB->hide(); ui->joystickCB->hide();
ui->joystickCB->setDisabled(true); ui->joystickCB->setDisabled(true);
ui->joystickcalButton->hide(); ui->joystickcalButton->hide();
@@ -91,7 +91,7 @@ void AppPreferencesDialog::writeValues()
void AppPreferencesDialog::on_snapshotPathButton_clicked() 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()) { if (!fileName.isEmpty()) {
g.snapshotDir(fileName); g.snapshotDir(fileName);
g.snapToClpbrd(false); g.snapToClpbrd(false);
@@ -137,15 +137,17 @@ void AppPreferencesDialog::initSettings()
ui->backupPath->setText(g.backupDir()); ui->backupPath->setText(g.backupDir());
ui->backupEnable->setEnabled(true); ui->backupEnable->setEnabled(true);
ui->backupEnable->setChecked(g.enableBackup()); ui->backupEnable->setChecked(g.enableBackup());
} else { }
else {
ui->backupEnable->setDisabled(true); ui->backupEnable->setDisabled(true);
} }
} else { }
else {
ui->backupEnable->setDisabled(true); ui->backupEnable->setDisabled(true);
} }
ui->splashincludeCB->setCurrentIndex(g.embedSplashes()); ui->splashincludeCB->setCurrentIndex(g.embedSplashes());
#ifdef JOYSTICKS #if defined(JOYSTICKS)
ui->joystickChkB->setChecked(g.jsSupport()); ui->joystickChkB->setChecked(g.jsSupport());
if (ui->joystickChkB->isChecked()) { if (ui->joystickChkB->isChecked()) {
QStringList joystickNames; QStringList joystickNames;
@@ -172,7 +174,7 @@ void AppPreferencesDialog::initSettings()
ui->joystickcalButton->setDisabled(true); ui->joystickcalButton->setDisabled(true);
} }
#endif #endif
// Profile Tab Inits // Profile Tab Inits
ui->channelorderCB->setCurrentIndex(g.profile[g.id()].channelOrder()); ui->channelorderCB->setCurrentIndex(g.profile[g.id()].channelOrder());
ui->stickmodeCB->setCurrentIndex(g.profile[g.id()].defaultMode()); ui->stickmodeCB->setCurrentIndex(g.profile[g.id()].defaultMode());
ui->renameFirmware->setChecked(g.profile[g.id()].renameFwFiles()); ui->renameFirmware->setChecked(g.profile[g.id()].renameFwFiles());
@@ -185,7 +187,8 @@ void AppPreferencesDialog::initSettings()
} else { } else {
ui->pbackupEnable->setDisabled(true); ui->pbackupEnable->setDisabled(true);
} }
} else { }
else {
ui->pbackupEnable->setDisabled(true); ui->pbackupEnable->setDisabled(true);
} }
@@ -270,7 +273,7 @@ void AppPreferencesDialog::on_ge_pathButton_clicked()
} }
} }
#ifdef JOYSTICKS #if defined(JOYSTICKS)
void AppPreferencesDialog::on_joystickChkB_clicked() { void AppPreferencesDialog::on_joystickChkB_clicked() {
if (ui->joystickChkB->isChecked()) { if (ui->joystickChkB->isChecked()) {
QStringList joystickNames; QStringList joystickNames;
@@ -325,23 +328,17 @@ void AppPreferencesDialog::on_removeProfileButton_clicked()
} }
} }
bool AppPreferencesDialog::displayImage(const QString & fileName)
bool AppPreferencesDialog::displayImage( QString fileName )
{ {
// Start by clearing the pixmap // Start by clearing the label
ui->imageLabel->setPixmap(QPixmap()); ui->imageLabel->clear();
QImage image(fileName); QImage image(fileName);
if (image.isNull()) if (image.isNull())
return false; 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->setPixmap(makePixMap(image));
ui->imageLabel->setFixedSize(width, SPLASH_HEIGHT); ui->imageLabel->setFixedSize(GetCurrentFirmware()->getCapability(LcdWidth), GetCurrentFirmware()->getCapability(LcdHeight));
return true; return true;
} }
+4 -6
View File
@@ -16,9 +16,9 @@ class AppPreferencesDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit AppPreferencesDialog(QWidget *parent = 0); explicit AppPreferencesDialog(QWidget * parent = 0);
~AppPreferencesDialog(); ~AppPreferencesDialog();
Joystick *joystick; Joystick * joystick;
private: private:
QList<QCheckBox *> optionsCheckBoxes; QList<QCheckBox *> optionsCheckBoxes;
@@ -33,9 +33,7 @@ class AppPreferencesDialog : public QDialog
Ui::AppPreferencesDialog *ui; Ui::AppPreferencesDialog *ui;
void initSettings(); void initSettings();
bool displayImage( QString fileName ); bool displayImage(const QString & fileName);
void loadProfileString(QString profile, QString label);
void loadFromProfile();
protected slots: protected slots:
void shrink(); void shrink();
@@ -55,7 +53,7 @@ class AppPreferencesDialog : public QDialog
void on_SplashSelect_clicked(); void on_SplashSelect_clicked();
void on_clearImageButton_clicked(); void on_clearImageButton_clicked();
#ifdef JOYSTICKS #if defined(JOYSTICKS)
void on_joystickChkB_clicked(); void on_joystickChkB_clicked();
void on_joystickcalButton_clicked(); void on_joystickcalButton_clicked();
#endif #endif
+27 -30
View File
@@ -29,11 +29,11 @@ void Side::markSourceButton()
void Side::copyImage( Side side ) void Side::copyImage( Side side )
{ {
if ((*source!=UNDEFINED) && (*side.source!=UNDEFINED)) if ((*source!=UNDEFINED) && (*side.source!=UNDEFINED))
imageLabel->setPixmap(*side.imageLabel->pixmap()); imageLabel->setPixmap(*side.imageLabel->pixmap());
} }
bool Side::displayImage( QString fileName, Source pictSource ) bool Side::displayImage(QString fileName, Source pictSource)
{ {
QImage image; QImage image;
@@ -41,7 +41,7 @@ bool Side::displayImage( QString fileName, Source pictSource )
return false; return false;
// Determine which picture format to use // Determine which picture format to use
if (pictSource == FW ){ if (pictSource == FW) {
FirmwareInterface firmware(fileName); FirmwareInterface firmware(fileName);
if (!firmware.hasSplash()) if (!firmware.hasSplash())
return false; return false;
@@ -56,37 +56,34 @@ bool Side::displayImage( QString fileName, Source pictSource )
else if (pictSource == PROFILE) else if (pictSource == PROFILE)
*format = (g.profile[g.id()].fwType().contains("x9")) ? LCDTARANIS : LCD9X; *format = (g.profile[g.id()].fwType().contains("x9")) ? LCDTARANIS : LCD9X;
} }
if (image.isNull()) { if (image.isNull()) {
return false; 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){ // Load image
case FW: QPixmap pixmap = makePixMap(image);
fileNameEdit->setText(QObject::tr("FW: %1").arg(fileName)); imageLabel->setPixmap(pixmap);
*saveToFileName = fileName; imageLabel->setFixedSize(pixmap.width()*2, pixmap.height()*2);
*source=FW;
break; switch (pictSource) {
case PICT: case FW:
fileNameEdit->setText(QObject::tr("Pict: %1").arg(fileName)); fileNameEdit->setText(QObject::tr("FW: %1").arg(fileName));
*saveToFileName = fileName; *saveToFileName = fileName;
*source=PICT; *source = FW;
break; break;
case PROFILE: case PICT:
fileNameEdit->setText(QObject::tr("Profile image")); fileNameEdit->setText(QObject::tr("Pict: %1").arg(fileName));
*saveToFileName = fileName; *saveToFileName = fileName;
*source=PROFILE; *source = PICT;
break; break;
default: case PROFILE:
break; fileNameEdit->setText(QObject::tr("Profile image"));
*saveToFileName = fileName;
*source = PROFILE;
break;
default:
break;
} }
saveButton->setEnabled(true); saveButton->setEnabled(true);
libraryButton->setEnabled(true); libraryButton->setEnabled(true);
+3 -1
View File
@@ -1364,7 +1364,9 @@ enum Capability {
PermTimers, PermTimers,
HasSDLogs, HasSDLogs,
CSFunc, CSFunc,
LCDWidth, LcdWidth,
LcdHeight,
LcdDepth,
GetThrSwitch, GetThrSwitch,
HasDisplayText, HasDisplayText,
HasTopLcd, HasTopLcd,
@@ -767,8 +767,25 @@ int OpenTxFirmware::getCapability(Capability capability)
return 18; return 18;
case HasSDLogs: case HasSDLogs:
return ((IS_2560(board) || IS_ARM(board)) ? true : false); return ((IS_2560(board) || IS_ARM(board)) ? true : false);
case LCDWidth: case LcdWidth:
return (IS_TARANIS(board) ? 212 : 128) ; 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: case GetThrSwitch:
return (IS_TARANIS(board) ? SWITCH_SF1 : SWITCH_THR) ; return (IS_TARANIS(board) ? SWITCH_SF1 : SWITCH_THR) ;
case HasDisplayText: case HasDisplayText:
+1 -1
View File
@@ -115,7 +115,7 @@ void FlashFirmwareDialog::updateUI()
} }
if (!image.isNull()) { if (!image.isNull()) {
ui->splash->setPixmap(makePixMap(image, g.profile[g.id()].fwType())); ui->splash->setPixmap(makePixMap(image));
} }
} }
+13 -13
View File
@@ -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" )) { Firmware * firmware = GetCurrentFirmware();
image = image.convertToFormat(QImage::Format_RGB32); QImage result = image.scaled(firmware->getCapability(LcdWidth), firmware->getCapability(LcdHeight));
QRgb col; if (firmware->getCapability(LcdDepth) == 4) {
int gray; result = result.convertToFormat(QImage::Format_RGB32);
for (int i = 0; i < image.width(); ++i) { for (int i = 0; i < image.width(); ++i) {
for (int j = 0; j < image.height(); ++j) { for (int j = 0; j < image.height(); ++j) {
col = image.pixel(i, j); QRgb col = result.pixel(i, j);
gray = qGray(col); int gray = qGray(col);
image.setPixel(i, j, qRgb(gray, gray, gray)); 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) int version2index(const QString & version)
+2 -2
View File
@@ -153,8 +153,8 @@ QVector<T> findWidgets(QObject * object, const QString & name)
return result; return result;
} }
// Format a pixmap to fit on the radio using a specific firmware // Format a pixmap to fit on the current firmware
QPixmap makePixMap( QImage image, QString firmwareType ); QPixmap makePixMap(const QImage & image);
int version2index(const QString & version); int version2index(const QString & version);
QString index2version(int index); QString index2version(int index);
+1 -1
View File
@@ -42,7 +42,7 @@ void SplashLibraryDialog::setupPage(int page)
if ((i + 20 * page) < imageList.size()) { if ((i + 20 * page) < imageList.size()) {
QImage image(imageList.at(i + 20 * page)); QImage image(imageList.at(i + 20 * page));
if (!image.isNull()) { if (!image.isNull()) {
sl[i]->setPixmap(makePixMap(image, g.profile[g.id()].fwType())); sl[i]->setPixmap(makePixMap(image));
sl[i]->setEnabled(true); sl[i]->setEnabled(true);
sl[i]->setId((i + 20 * page)); sl[i]->setId((i + 20 * page));
sl[i]->setStyleSheet("border:1px solid; border-color:#999999;"); sl[i]->setStyleSheet("border:1px solid; border-color:#999999;");