[Companion] Some refactoring around the splash image handling (#4067)
This commit is contained in:
@@ -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();
|
||||||
@@ -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;
|
||||||
@@ -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
|
ui->imageLabel->setPixmap(makePixMap(image));
|
||||||
int width = SPLASH_WIDTH;
|
ui->imageLabel->setFixedSize(GetCurrentFirmware()->getCapability(LcdWidth), GetCurrentFirmware()->getCapability(LcdHeight));
|
||||||
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);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -56,18 +56,15 @@ 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
|
// Load image
|
||||||
if (*format==LCDTARANIS) {
|
QPixmap pixmap = makePixMap(image);
|
||||||
imageLabel->setPixmap( makePixMap( image, "x9" ));
|
imageLabel->setPixmap(pixmap);
|
||||||
imageLabel->setFixedSize(WIDTH_TARANIS*2, HEIGHT_TARANIS*2);
|
imageLabel->setFixedSize(pixmap.width()*2, pixmap.height()*2);
|
||||||
}
|
|
||||||
else {
|
|
||||||
imageLabel->setPixmap( makePixMap( image, "9x" ));
|
|
||||||
imageLabel->setFixedSize(WIDTH_9X*2, HEIGHT_9X*2);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (pictSource) {
|
switch (pictSource) {
|
||||||
case FW:
|
case FW:
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
@@ -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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-11
@@ -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 {
|
else {
|
||||||
image = image.scaled(SPLASH_WIDTH, SPLASH_HEIGHT).convertToFormat(QImage::Format_Mono);
|
result = result.convertToFormat(QImage::Format_Mono);
|
||||||
}
|
}
|
||||||
return(QPixmap::fromImage(image));
|
|
||||||
|
return QPixmap::fromImage(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
int version2index(const QString & version)
|
int version2index(const QString & version)
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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;");
|
||||||
|
|||||||
Reference in New Issue
Block a user