Fix companion model edit image names (#848)
* Fix companion model edit bitmap image names * Add radio conversion of file extension
This commit is contained in:
@@ -53,7 +53,10 @@ enum Capability {
|
|||||||
VoicesAsNumbers,
|
VoicesAsNumbers,
|
||||||
VoicesMaxLength,
|
VoicesMaxLength,
|
||||||
MultiLangVoice,
|
MultiLangVoice,
|
||||||
ModelImage,
|
HasModelImage,
|
||||||
|
ModelImageNameLen,
|
||||||
|
ModelImageFilters,
|
||||||
|
ModelImageKeepExtn,
|
||||||
CustomFunctions,
|
CustomFunctions,
|
||||||
SafetyChannelCustomFunction,
|
SafetyChannelCustomFunction,
|
||||||
LogicalSwitches,
|
LogicalSwitches,
|
||||||
@@ -348,6 +351,8 @@ class Firmware
|
|||||||
|
|
||||||
virtual int getCapability(Capability) = 0;
|
virtual int getCapability(Capability) = 0;
|
||||||
|
|
||||||
|
virtual QString getCapabilityStr(Capability) = 0;
|
||||||
|
|
||||||
virtual QString getAnalogInputName(unsigned int index) = 0;
|
virtual QString getAnalogInputName(unsigned int index) = 0;
|
||||||
|
|
||||||
virtual QTime getMaxTimerStart() = 0;
|
virtual QTime getMaxTimerStart() = 0;
|
||||||
|
|||||||
@@ -334,3 +334,8 @@ int Er9xInterface::getCapability(Capability capability)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Er9xInterface::getCapabilityStr(Capability capability)
|
||||||
|
{
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ class Er9xInterface : public EEPROMInterface
|
|||||||
|
|
||||||
virtual int getCapability(Capability capability);
|
virtual int getCapability(Capability capability);
|
||||||
|
|
||||||
|
virtual QString getCapabilityStr(Capability);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
RleFile * efile;
|
RleFile * efile;
|
||||||
|
|||||||
@@ -387,3 +387,8 @@ int Ersky9xInterface::getCapability(Capability capability)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Ersky9xInterface::getCapabilityStr(Capability capability)
|
||||||
|
{
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ class Ersky9xInterface : public EEPROMInterface
|
|||||||
|
|
||||||
virtual int getCapability(Capability capability);
|
virtual int getCapability(Capability capability);
|
||||||
|
|
||||||
|
virtual QString getCapabilityStr(Capability);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
RleFile * efile;
|
RleFile * efile;
|
||||||
|
|||||||
@@ -407,6 +407,21 @@ void ModelData::convert(RadioDataConversionState & cstate)
|
|||||||
thrTraceSrc = RawSource(SOURCE_TYPE_STICK, (int)thrTraceSrc + 3).convert(cstate).index - 3;
|
thrTraceSrc = RawSource(SOURCE_TYPE_STICK, (int)thrTraceSrc + 3).convert(cstate).index - 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Firmware *fw = getCurrentFirmware();
|
||||||
|
|
||||||
|
if (fw->getCapability(HasModelImage) && bitmap[0] != '\0') {
|
||||||
|
QString filename = bitmap;
|
||||||
|
QFileInfo file(filename);
|
||||||
|
if (fw->getCapability(ModelImageKeepExtn) && file.suffix() == "")
|
||||||
|
filename.append(".bmp"); // bmp is assumed default for radios that do not store file extension
|
||||||
|
else if (!fw->getCapability(ModelImageKeepExtn) && file.suffix() != "") {
|
||||||
|
int posn = filename.indexOf("." % file.suffix(), + 1);
|
||||||
|
filename.remove(posn, filename.size() - posn + 1);
|
||||||
|
}
|
||||||
|
memset(bitmap, 0, CPN_MAX_BITMAP_LEN);
|
||||||
|
strncpy(bitmap, filename.toLatin1().data(), fw->getCapability(ModelImageNameLen));
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < CPN_MAX_MODULES; i++) {
|
for (int i = 0; i < CPN_MAX_MODULES; i++) {
|
||||||
moduleData[i].convert(cstate.withComponentIndex(i));
|
moduleData[i].convert(cstate.withComponentIndex(i));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ enum TrainerMode {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define INPUT_NAME_LEN 4
|
#define INPUT_NAME_LEN 4
|
||||||
|
#define CPN_MAX_BITMAP_LEN 14
|
||||||
|
|
||||||
class ModelData {
|
class ModelData {
|
||||||
Q_DECLARE_TR_FUNCTIONS(ModelData)
|
Q_DECLARE_TR_FUNCTIONS(ModelData)
|
||||||
@@ -145,7 +146,7 @@ class ModelData {
|
|||||||
unsigned int rssiSource;
|
unsigned int rssiSource;
|
||||||
RSSIAlarmData rssiAlarms;
|
RSSIAlarmData rssiAlarms;
|
||||||
|
|
||||||
char bitmap[10+1];
|
char bitmap[CPN_MAX_BITMAP_LEN + 1];
|
||||||
|
|
||||||
unsigned int trainerMode; // TrainerMode
|
unsigned int trainerMode; // TrainerMode
|
||||||
|
|
||||||
|
|||||||
@@ -447,8 +447,12 @@ int OpenTxFirmware::getCapability(::Capability capability)
|
|||||||
return 60;
|
return 60;
|
||||||
case Imperial:
|
case Imperial:
|
||||||
return 0;
|
return 0;
|
||||||
case ModelImage:
|
case HasModelImage:
|
||||||
return (board == BOARD_TARANIS_X9D || IS_TARANIS_PLUS(board) || board == BOARD_TARANIS_X9DP_2019 || IS_FAMILY_HORUS_OR_T16(board));
|
return (board == BOARD_TARANIS_X9D || IS_TARANIS_PLUS(board) || board == BOARD_TARANIS_X9DP_2019 || IS_FAMILY_HORUS_OR_T16(board));
|
||||||
|
case ModelImageNameLen:
|
||||||
|
return (IS_FAMILY_HORUS_OR_T16(board) ? 14 : 10); // including extension if saved and <= CPN_MAX_BITMAP_LEN
|
||||||
|
case ModelImageKeepExtn:
|
||||||
|
return (IS_FAMILY_HORUS_OR_T16(board) ? true : false);
|
||||||
case HasBeeper:
|
case HasBeeper:
|
||||||
return false;
|
return false;
|
||||||
case HasPxxCountry:
|
case HasPxxCountry:
|
||||||
@@ -748,6 +752,16 @@ int OpenTxFirmware::getCapability(::Capability capability)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString OpenTxFirmware::getCapabilityStr(::Capability capability)
|
||||||
|
{
|
||||||
|
switch (capability) {
|
||||||
|
case ModelImageFilters:
|
||||||
|
return IS_FAMILY_HORUS_OR_T16(board) ? "*.bmp|*.jpg|*.png" : "*.bmp";
|
||||||
|
default:
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString OpenTxFirmware::getAnalogInputName(unsigned int index)
|
QString OpenTxFirmware::getAnalogInputName(unsigned int index)
|
||||||
{
|
{
|
||||||
return Boards::getAnalogInputName(board, index);
|
return Boards::getAnalogInputName(board, index);
|
||||||
|
|||||||
@@ -118,6 +118,8 @@ class OpenTxFirmware: public Firmware
|
|||||||
|
|
||||||
virtual int getCapability(Capability);
|
virtual int getCapability(Capability);
|
||||||
|
|
||||||
|
virtual QString getCapabilityStr(Capability);
|
||||||
|
|
||||||
virtual QString getAnalogInputName(unsigned int index);
|
virtual QString getAnalogInputName(unsigned int index);
|
||||||
|
|
||||||
virtual QTime getMaxTimerStart();
|
virtual QTime getMaxTimerStart();
|
||||||
|
|||||||
@@ -1036,62 +1036,51 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
|
|||||||
ui->name->setValidator(new QRegExpValidator(rx, this));
|
ui->name->setValidator(new QRegExpValidator(rx, this));
|
||||||
ui->name->setMaxLength(firmware->getCapability(ModelName));
|
ui->name->setMaxLength(firmware->getCapability(ModelName));
|
||||||
|
|
||||||
if (firmware->getCapability(ModelImage)) {
|
if (firmware->getCapability(HasModelImage)) {
|
||||||
|
if (Boards::getCapability(board, Board::HasColorLcd)) {
|
||||||
|
ui->imagePreview->setFixedSize(QSize(192, 114));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ui->imagePreview->setFixedSize(QSize(64, 32));
|
||||||
|
}
|
||||||
QStringList items;
|
QStringList items;
|
||||||
items.append("");
|
items.append("");
|
||||||
QString path = g.profile[g.id()].sdPath();
|
QString path = g.profile[g.id()].sdPath();
|
||||||
path.append("/IMAGES/");
|
path.append("/IMAGES/");
|
||||||
QDir qd(path);
|
QDir qd(path);
|
||||||
if (qd.exists()) {
|
if (qd.exists()) {
|
||||||
QStringList filters;
|
QStringList filters = firmware->getCapabilityStr(ModelImageFilters).split("|");
|
||||||
if(IS_FAMILY_HORUS_OR_T16(board)) {
|
foreach ( QString file, qd.entryList(filters, QDir::Files) ) {
|
||||||
filters << "*.bmp" << "*.jpg" << "*.png";
|
QFileInfo fi(file);
|
||||||
foreach ( QString file, qd.entryList(filters, QDir::Files) ) {
|
QString temp;
|
||||||
QFileInfo fi(file);
|
if (firmware->getCapability(ModelImageKeepExtn))
|
||||||
QString temp = fi.fileName();
|
temp = fi.fileName();
|
||||||
if (!items.contains(temp) && temp.length() <= 6 + 4) {
|
else
|
||||||
items.append(temp);
|
temp = fi.completeBaseName();
|
||||||
}
|
if (!items.contains(temp) && temp.length() <= firmware->getCapability(ModelImageNameLen))
|
||||||
}
|
items.append(temp);
|
||||||
}
|
|
||||||
else {
|
|
||||||
filters << "*.bmp";
|
|
||||||
foreach (QString file, qd.entryList(filters, QDir::Files)) {
|
|
||||||
QFileInfo fi(file);
|
|
||||||
QString temp = fi.completeBaseName();
|
|
||||||
if (!items.contains(temp) && temp.length() <= 10 + 4) {
|
|
||||||
items.append(temp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!items.contains(model.bitmap)) {
|
if (!items.contains(model.bitmap)) {
|
||||||
items.append(model.bitmap);
|
items.append(model.bitmap);
|
||||||
}
|
}
|
||||||
items.sort();
|
items.sort(Qt::CaseInsensitive);
|
||||||
foreach (QString file, items) {
|
foreach (QString file, items) {
|
||||||
ui->image->addItem(file);
|
ui->image->addItem(file);
|
||||||
if (file == model.bitmap) {
|
if (file == model.bitmap) {
|
||||||
ui->image->setCurrentIndex(ui->image->count() - 1);
|
ui->image->setCurrentIndex(ui->image->count() - 1);
|
||||||
QString fileName = path;
|
if (!file.isEmpty()) {
|
||||||
fileName.append(model.bitmap);
|
QString fileName = path;
|
||||||
if (!IS_FAMILY_HORUS_OR_T16(board))
|
|
||||||
fileName.append(".bmp");
|
|
||||||
QImage image(fileName);
|
|
||||||
if (image.isNull() && !IS_FAMILY_HORUS_OR_T16(board)) {
|
|
||||||
fileName = path;
|
|
||||||
fileName.append(model.bitmap);
|
fileName.append(model.bitmap);
|
||||||
fileName.append(".BMP");
|
if (!firmware->getCapability(ModelImageKeepExtn)) {
|
||||||
image.load(fileName);
|
QString extn = firmware->getCapabilityStr(ModelImageFilters);
|
||||||
}
|
if (extn.size() > 0)
|
||||||
if (!image.isNull()) {
|
extn.remove(0, 1); // remove *
|
||||||
if (IS_FAMILY_HORUS_OR_T16(board)) {
|
fileName.append(extn);
|
||||||
ui->imagePreview->setFixedSize(QSize(192, 114));
|
|
||||||
ui->imagePreview->setPixmap(QPixmap::fromImage(image.scaled(192, 114)));
|
|
||||||
}
|
}
|
||||||
else {
|
QImage image(fileName);
|
||||||
ui->imagePreview->setFixedSize(QSize(64, 32));
|
if (!image.isNull()) {
|
||||||
ui->imagePreview->setPixmap(QPixmap::fromImage(image.scaled(64, 32)));
|
ui->imagePreview->setPixmap(QPixmap::fromImage(image.scaled(ui->imagePreview->size())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1334,36 +1323,23 @@ void SetupPanel::on_name_editingFinished()
|
|||||||
void SetupPanel::on_image_currentIndexChanged(int index)
|
void SetupPanel::on_image_currentIndexChanged(int index)
|
||||||
{
|
{
|
||||||
if (!lock) {
|
if (!lock) {
|
||||||
Board::Type board = firmware->getBoard();
|
memset(model->bitmap, 0, CPN_MAX_BITMAP_LEN);
|
||||||
strncpy(model->bitmap, ui->image->currentText().toLatin1(), 10);
|
strncpy(model->bitmap, ui->image->currentText().toLatin1(), CPN_MAX_BITMAP_LEN);
|
||||||
QString path = g.profile[g.id()].sdPath();
|
if (model->bitmap[0] != '\0') {
|
||||||
path.append("/IMAGES/");
|
QString path = g.profile[g.id()].sdPath();
|
||||||
QDir qd(path);
|
path.append("/IMAGES/");
|
||||||
if (qd.exists()) {
|
path.append(model->bitmap);
|
||||||
QString fileName=path;
|
if (!firmware->getCapability(ModelImageKeepExtn)) {
|
||||||
fileName.append(model->bitmap);
|
QString extn = firmware->getCapabilityStr(ModelImageFilters);
|
||||||
if (!IS_FAMILY_HORUS_OR_T16(board))
|
if (extn.size() > 0)
|
||||||
fileName.append(".bmp");
|
extn.remove(0, 1); // remove *
|
||||||
QImage image(fileName);
|
path.append(extn);
|
||||||
if (image.isNull() && !IS_FAMILY_HORUS_OR_T16(board)) {
|
|
||||||
fileName=path;
|
|
||||||
fileName.append(model->bitmap);
|
|
||||||
fileName.append(".BMP");
|
|
||||||
image.load(fileName);
|
|
||||||
}
|
}
|
||||||
if (!image.isNull()) {
|
QImage image(path);
|
||||||
if (IS_FAMILY_HORUS_OR_T16(board)) {
|
if (!image.isNull())
|
||||||
ui->imagePreview->setFixedSize(QSize(192, 114));
|
ui->imagePreview->setPixmap(QPixmap::fromImage(image.scaled(ui->imagePreview->size())));
|
||||||
ui->imagePreview->setPixmap(QPixmap::fromImage(image.scaled(192, 114)));
|
else
|
||||||
}
|
|
||||||
else {
|
|
||||||
ui->imagePreview->setFixedSize(QSize(64, 32));
|
|
||||||
ui->imagePreview->setPixmap(QPixmap::fromImage(image.scaled(64, 32)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ui->imagePreview->clear();
|
ui->imagePreview->clear();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ui->imagePreview->clear();
|
ui->imagePreview->clear();
|
||||||
|
|||||||
@@ -313,7 +313,7 @@ QString MultiModelPrinter::printSetup()
|
|||||||
if (!IS_FAMILY_HORUS_OR_T16(firmware->getBoard())) {
|
if (!IS_FAMILY_HORUS_OR_T16(firmware->getBoard())) {
|
||||||
ROWLABELCOMPARECELL(tr("EEprom Size"), 0, modelPrinter->printEEpromSize(), 0);
|
ROWLABELCOMPARECELL(tr("EEprom Size"), 0, modelPrinter->printEEpromSize(), 0);
|
||||||
}
|
}
|
||||||
if (firmware->getCapability(ModelImage)) {
|
if (firmware->getCapability(HasModelImage)) {
|
||||||
ROWLABELCOMPARECELL(tr("Model Image"), 0, model->bitmap, 0);
|
ROWLABELCOMPARECELL(tr("Model Image"), 0, model->bitmap, 0);
|
||||||
}
|
}
|
||||||
ROWLABELCOMPARECELL(tr("Throttle"), 0, modelPrinter->printThrottle(), 0);
|
ROWLABELCOMPARECELL(tr("Throttle"), 0, modelPrinter->printThrottle(), 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user