[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 <QtGui>
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;
}
+4 -6
View File
@@ -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<QCheckBox *> 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
+27 -30
View File
@@ -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);
+3 -1
View File
@@ -1364,7 +1364,9 @@ enum Capability {
PermTimers,
HasSDLogs,
CSFunc,
LCDWidth,
LcdWidth,
LcdHeight,
LcdDepth,
GetThrSwitch,
HasDisplayText,
HasTopLcd,
@@ -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:
+1 -1
View File
@@ -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));
}
}
+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" )) {
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)
+2 -2
View File
@@ -153,8 +153,8 @@ QVector<T> 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);
+1 -1
View File
@@ -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;");