feat(cpn): save model images with models and settings (#7234)
This commit is contained in:
@@ -83,46 +83,23 @@ SetupPanel::SetupPanel(QWidget * parent, ModelData & model, GeneralSettings & ge
|
||||
else {
|
||||
ui->imagePreview->setFixedSize(QSize(64, 32));
|
||||
}
|
||||
|
||||
QStringList items;
|
||||
items.append("");
|
||||
QString path = g.profile[g.id()].sdPath();
|
||||
path.append("/IMAGES/");
|
||||
QDir qd(path);
|
||||
if (qd.exists()) {
|
||||
QStringList filters = firmware->getCapabilityStr(ModelImageFilters).split("|");
|
||||
foreach ( QString file, qd.entryList(filters, QDir::Files) ) {
|
||||
QFileInfo fi(file);
|
||||
QString temp;
|
||||
if (firmware->getCapability(ModelImageKeepExtn))
|
||||
temp = fi.fileName();
|
||||
else
|
||||
temp = fi.completeBaseName();
|
||||
if (!items.contains(temp) && temp.length() <= firmware->getCapability(ModelImageNameLen))
|
||||
items.append(temp);
|
||||
}
|
||||
}
|
||||
if (!items.contains(model.bitmap)) {
|
||||
loadImageList(items, Helpers::getImagesCacheDir());
|
||||
loadImageList(items, g.currentProfile().sdPath() % "/IMAGES/");
|
||||
|
||||
if (!items.contains(model.bitmap))
|
||||
items.append(model.bitmap);
|
||||
}
|
||||
|
||||
items.sort(Qt::CaseInsensitive);
|
||||
|
||||
foreach (QString file, items) {
|
||||
ui->image->addItem(file);
|
||||
|
||||
if (file == model.bitmap) {
|
||||
ui->image->setCurrentIndex(ui->image->count() - 1);
|
||||
if (!file.isEmpty()) {
|
||||
QString fileName = path;
|
||||
fileName.append(model.bitmap);
|
||||
if (!firmware->getCapability(ModelImageKeepExtn)) {
|
||||
QString extn = firmware->getCapabilityStr(ModelImageFilters);
|
||||
if (extn.size() > 0)
|
||||
extn.remove(0, 1); // remove *
|
||||
fileName.append(extn);
|
||||
}
|
||||
QImage image(fileName);
|
||||
if (!image.isNull()) {
|
||||
ui->imagePreview->setPixmap(QPixmap::fromImage(image.scaled(ui->imagePreview->size())));
|
||||
}
|
||||
}
|
||||
loadImagePreview();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -392,25 +369,7 @@ void SetupPanel::on_image_currentIndexChanged(int index)
|
||||
if (!lock) {
|
||||
memset(model->bitmap, 0, CPN_MAX_BITMAP_LEN);
|
||||
strncpy(model->bitmap, ui->image->currentText().toLatin1(), CPN_MAX_BITMAP_LEN);
|
||||
if (model->bitmap[0] != '\0') {
|
||||
QString path = g.profile[g.id()].sdPath();
|
||||
path.append("/IMAGES/");
|
||||
path.append(model->bitmap);
|
||||
if (!firmware->getCapability(ModelImageKeepExtn)) {
|
||||
QString extn = firmware->getCapabilityStr(ModelImageFilters);
|
||||
if (extn.size() > 0)
|
||||
extn.remove(0, 1); // remove *
|
||||
path.append(extn);
|
||||
}
|
||||
QImage image(path);
|
||||
if (!image.isNull())
|
||||
ui->imagePreview->setPixmap(QPixmap::fromImage(image.scaled(ui->imagePreview->size())));
|
||||
else
|
||||
ui->imagePreview->clear();
|
||||
}
|
||||
else {
|
||||
ui->imagePreview->clear();
|
||||
}
|
||||
loadImagePreview();
|
||||
emit modified();
|
||||
}
|
||||
}
|
||||
@@ -829,3 +788,37 @@ void SetupPanel::onFunctionSwitchesUpdateItemModels()
|
||||
updateStartupSwitches();
|
||||
sharedItemModels->update(AbstractItemModel::IMUE_FunctionSwitches);
|
||||
}
|
||||
|
||||
void SetupPanel::loadImageList(QStringList &list, const QString & path)
|
||||
{
|
||||
QDir d(path);
|
||||
const int maxnamelen = firmware->getCapability(ModelImageNameLen);
|
||||
const bool keepextn = firmware->getCapability(ModelImageKeepExtn);
|
||||
|
||||
if (d.exists()) {
|
||||
QStringList filters = firmware->getCapabilityStr(ModelImageFilters).split("|");
|
||||
|
||||
foreach ( QString file, d.entryList(filters, QDir::Files) ) {
|
||||
QFileInfo fi(file);
|
||||
QString temp = keepextn ? fi.fileName() : fi.completeBaseName();
|
||||
|
||||
if (!list.contains(temp) && temp.length() <= maxnamelen)
|
||||
list.append(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetupPanel::loadImagePreview()
|
||||
{
|
||||
if (!model->isBitmapEmpty()) {
|
||||
QImage image;
|
||||
QString filename(model->getImageFilename());
|
||||
QString path(Helpers::getImagePath(filename));
|
||||
|
||||
if (!path.isEmpty() && image.load(path))
|
||||
ui->imagePreview->setPixmap(QPixmap::fromImage(image.scaled(ui->imagePreview->size())));
|
||||
else
|
||||
ui->imagePreview->clear();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,4 +115,6 @@ class SetupPanel : public ModelPanel
|
||||
void connectItemModelEvents(const FilteredItemModel * itemModel);
|
||||
CompoundItemModelFactory * panelItemModels;
|
||||
FilteredItemModelFactory * panelFilteredModels;
|
||||
void loadImageList(QStringList &list, const QString & dir);
|
||||
void loadImagePreview();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user