diff --git a/companion/src/CMakeLists.txt b/companion/src/CMakeLists.txt index 0f7ca9cd5..3a8dd26b7 100644 --- a/companion/src/CMakeLists.txt +++ b/companion/src/CMakeLists.txt @@ -156,6 +156,8 @@ SET( companion_SRCS mountlist.cpp avroutputdialog.cpp preferencesdialog.cpp + apppreferencesdialog.cpp + fwpreferencesdialog.cpp burnconfigdialog.cpp comparedialog.cpp contributorsdialog.cpp @@ -177,6 +179,8 @@ SET( companion_SRCS SET( companion_MOC_HDRS avroutputdialog.h preferencesdialog.h + apppreferencesdialog.h + fwpreferencesdialog.h burnconfigdialog.h comparedialog.h printdialog.h @@ -211,6 +215,8 @@ SET( companion_UIS fusesdialog.ui logsdialog.ui preferencesdialog.ui + apppreferencesdialog.ui + fwpreferencesdialog.ui simulatordialog.ui xsimulatordialog.ui burnconfigdialog.ui diff --git a/companion/src/apppreferencesdialog.cpp b/companion/src/apppreferencesdialog.cpp new file mode 100644 index 000000000..4b425a61b --- /dev/null +++ b/companion/src/apppreferencesdialog.cpp @@ -0,0 +1,224 @@ +#include "apppreferencesdialog.h" +#include "ui_apppreferencesdialog.h" +#include "mainwindow.h" +#include "helpers.h" +#ifdef JOYSTICKS +#include "joystick.h" +#include "joystickdialog.h" +#endif +#include +#include + +appPreferencesDialog::appPreferencesDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::appPreferencesDialog) +{ + ui->setupUi(this); + setWindowIcon(CompanionIcon("preferences.png")); + initSettings(); + connect(this, SIGNAL(accepted()), this, SLOT(writeValues())); +#ifndef JOYSTICKS + ui->joystickCB->hide(); + ui->joystickCB->setDisabled(true); + ui->joystickcalButton->hide(); + ui->joystickChkB->hide(); + ui->label_11->hide(); +#endif + resize(0,0); +} + +appPreferencesDialog::~appPreferencesDialog() +{ + delete ui; +} + +void appPreferencesDialog::writeValues() +{ + QSettings settings; + settings.setValue("startup_check_companion", ui->startupCheck_companion9x->isChecked()); + settings.setValue("startup_check_fw", ui->startupCheck_fw->isChecked()); + settings.setValue("wizardEnable", ui->wizardEnable_ChkB->isChecked()); + settings.setValue("show_splash", ui->showSplash->isChecked()); + settings.setValue("simuSW", ui->simuSW->isChecked()); + settings.setValue("history_size", ui->historySize->value()); + settings.setValue("backLight", ui->backLightColor->currentIndex()); + settings.setValue("libraryPath", ui->libraryPath->text()); + settings.setValue("gePath", ui->ge_lineedit->text()); + settings.setValue("embedded_splashes", ui->splashincludeCB->currentIndex()); + settings.setValue("backupEnable", ui->backupEnable->isChecked()); + + if (ui->joystickChkB ->isChecked() && ui->joystickCB->isEnabled()) { + settings.setValue("js_support", ui->joystickChkB ->isChecked()); + settings.setValue("js_ctrl", ui->joystickCB ->currentIndex()); + } + else { + settings.remove("js_support"); + settings.remove("js_ctrl"); + } + + MainWindow * mw = (MainWindow *)this->parent(); + mw->unloadProfile(); +} + +void appPreferencesDialog::on_snapshotPathButton_clicked() +{ + QSettings settings; + QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your snapshot folder"), settings.value("snapshotPath").toString()); + if (!fileName.isEmpty()) { + settings.setValue("snapshotpath", fileName); + settings.setValue("snapshot_to_clipboard", false); + ui->snapshotPath->setText(fileName); + } +} + +void appPreferencesDialog::initSettings() +{ + QSettings settings; + ui->snapshotClipboardCKB->setChecked(settings.value("snapshot_to_clipboard", false).toBool()); + + QString Path=settings.value("snapshotPath", "").toString(); + if (QDir(Path).exists()) { + ui->snapshotPath->setText(Path); + ui->snapshotPath->setReadOnly(true); + } + if (ui->snapshotClipboardCKB->isChecked()) { + ui->snapshotPath->setDisabled(true); + ui->snapshotPathButton->setDisabled(true); + } + ui->startupCheck_companion9x->setChecked(settings.value("startup_check_companion", true).toBool()); + ui->startupCheck_fw->setChecked(settings.value("startup_check_fw", true).toBool()); + ui->wizardEnable_ChkB->setChecked(settings.value("wizardEnable", true).toBool()); + ui->showSplash->setChecked(settings.value("show_splash", true).toBool()); + ui->historySize->setValue(settings.value("history_size", 10).toInt()); + ui->backLightColor->setCurrentIndex(settings.value("backLight", 0).toInt()); + ui->simuSW->setChecked(settings.value("simuSW", false).toBool()); + + Path=settings.value("libraryPath", "").toString(); + if (QDir(Path).exists()) { + ui->libraryPath->setText(Path); + } + Path=settings.value("gePath", "").toString(); + if (QFile(Path).exists()) { + ui->ge_lineedit->setText(Path); + } + Path=settings.value("backupPath", "").toString(); + if (!Path.isEmpty()) { + if (QDir(Path).exists()) { + ui->backupPath->setText(Path); + ui->backupEnable->setEnabled(true); + ui->backupEnable->setChecked(settings.value("backupEnable", true).toBool()); + } else { + ui->backupEnable->setDisabled(true); + } + } else { + ui->backupEnable->setDisabled(true); + } + ui->splashincludeCB->setCurrentIndex(settings.value("embedded_splashes", 0).toInt()); + +#ifdef JOYSTICKS + ui->joystickChkB->setChecked(settings.value("js_support", false).toBool()); + if (ui->joystickChkB->isChecked()) { + QStringList joystickNames; + joystickNames << tr("No joysticks found"); + joystick = new Joystick(0,false,0,0); + ui->joystickcalButton->setDisabled(true); + ui->joystickCB->setDisabled(true); + + if ( joystick ) { + if ( joystick->joystickNames.count() > 0 ) { + joystickNames = joystick->joystickNames; + ui->joystickCB->setEnabled(true); + ui->joystickcalButton->setEnabled(true); + } + joystick->close(); + } + ui->joystickCB->clear(); + ui->joystickCB->insertItems(0, joystickNames); + ui->joystickCB->setCurrentIndex(settings.value("js_ctrl", 0).toInt()); + } + else { + ui->joystickCB->clear(); + ui->joystickCB->setDisabled(true); + ui->joystickcalButton->setDisabled(true); + } +#endif +} + +void appPreferencesDialog::on_libraryPathButton_clicked() +{ + QSettings settings; + QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your library folder"), settings.value("libraryPath").toString()); + if (!fileName.isEmpty()) { + settings.setValue("libraryPath", fileName); + ui->libraryPath->setText(fileName); + } +} + +void appPreferencesDialog::on_snapshotClipboardCKB_clicked() +{ + QSettings settings; + if (ui->snapshotClipboardCKB->isChecked()) { + ui->snapshotPath->setDisabled(true); + ui->snapshotPathButton->setDisabled(true); + settings.setValue("snapshot_to_clipboard", true); + } else { + ui->snapshotPath->setEnabled(true); + ui->snapshotPath->setReadOnly(true); + ui->snapshotPathButton->setEnabled(true); + settings.setValue("snapshot_to_clipboard", false); + } +} + +void appPreferencesDialog::on_backupPathButton_clicked() +{ + QSettings settings; + QString fileName = QFileDialog::getExistingDirectory(this,tr("Select your Models and Settings backup folder"), settings.value("backupPath").toString()); + if (!fileName.isEmpty()) { + settings.setValue("backupPath", fileName); + ui->backupPath->setText(fileName); + } + ui->backupEnable->setEnabled(true); +} + +void appPreferencesDialog::on_ge_pathButton_clicked() +{ + QSettings settings; + QString fileName = QFileDialog::getOpenFileName(this, tr("Select Google Earth executable"),ui->ge_lineedit->text()); + if (!fileName.isEmpty()) { + ui->ge_lineedit->setText(fileName); + } +} + +#ifdef JOYSTICKS +void appPreferencesDialog::on_joystickChkB_clicked() { + if (ui->joystickChkB->isChecked()) { + QStringList joystickNames; + joystickNames << tr("No joysticks found"); + joystick = new Joystick(0,false,0,0); + ui->joystickcalButton->setDisabled(true); + ui->joystickCB->setDisabled(true); + + if ( joystick ) { + if ( joystick->joystickNames.count() > 0 ) { + joystickNames = joystick->joystickNames; + ui->joystickCB->setEnabled(true); + ui->joystickcalButton->setEnabled(true); + } + joystick->close(); + } + ui->joystickCB->clear(); + ui->joystickCB->insertItems(0, joystickNames); + } + else { + ui->joystickCB->clear(); + ui->joystickCB->setDisabled(true); + ui->joystickcalButton->setDisabled(true); + } +} + +void appPreferencesDialog::on_joystickcalButton_clicked() { + joystickDialog * jd=new joystickDialog(this, ui->joystickCB->currentIndex()); + jd->exec(); +} +#endif + diff --git a/companion/src/apppreferencesdialog.h b/companion/src/apppreferencesdialog.h new file mode 100644 index 000000000..d47682512 --- /dev/null +++ b/companion/src/apppreferencesdialog.h @@ -0,0 +1,40 @@ +#ifndef APPPREFERENCESDIALOG_H +#define APPPREFERENCESDIALOG_H + +#include +#include +#include "eeprominterface.h" + +namespace Ui { + class appPreferencesDialog; +} + +class Joystick; + +class appPreferencesDialog : public QDialog +{ + Q_OBJECT + +public: + explicit appPreferencesDialog(QWidget *parent = 0); + ~appPreferencesDialog(); + Joystick *joystick; + +private: + Ui::appPreferencesDialog *ui; + void initSettings(); + +private slots: + void writeValues(); + void on_libraryPathButton_clicked(); + void on_snapshotPathButton_clicked(); + void on_snapshotClipboardCKB_clicked(); + void on_backupPathButton_clicked(); + void on_ge_pathButton_clicked(); +#ifdef JOYSTICKS + void on_joystickChkB_clicked(); + void on_joystickcalButton_clicked(); +#endif +}; + +#endif // APPPREFERENCESDIALOG_H diff --git a/companion/src/apppreferencesdialog.ui b/companion/src/apppreferencesdialog.ui new file mode 100644 index 000000000..bc1f734f3 --- /dev/null +++ b/companion/src/apppreferencesdialog.ui @@ -0,0 +1,505 @@ + + + appPreferencesDialog + + + + 0 + 0 + 685 + 456 + + + + + 0 + 0 + + + + + 685 + 0 + + + + Application Preferences + + + + 2 + + + 6 + + + + + Open Folder + + + + + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + + + + + 0 + 0 + + + + Joystick + + + + + + + Simulator capture folder + + + + + + + Remember simulator switch values + + + + + + + + 0 + 0 + + + + User Splash Screens + + + + + + + + 0 + 0 + + + + Files to keep + + + + + + + Offer to use wizard for new models + + + true + + + + + + + Qt::Horizontal + + + + + + + + 100 + 16777215 + + + + + Blue + + + + + Green + + + + + Red + + + + + Orange + + + + + Yellow + + + + + + + + Automatic check for Companion updates + + + true + + + + + + + Qt::Horizontal + + + + + + + true + + + true + + + + + + + Only capture to clipboard + + + + + + + + 40 + 0 + + + + + 50 + 16777215 + + + + 15 + + + 10 + + + + + + + Qt::Horizontal + + + + + + + Qt::Horizontal + + + + + + + + 250 + 0 + + + + true + + + + + + + Calibrate + + + + + + + Automatic Backup Folder + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + Open Folder + + + false + + + + + + + true + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + Simulator BackLight + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Enable automatic backup before writing firmware + + + + + + + Show splash screen when Companion starts + + + true + + + + + + + Find Executable + + + + + + + Open Folder + + + + + + + Enable + + + + + + + Google Earth Executable + + + + + + + Automatic check for OpenTX firmware updates + + + true + + + + + + + + 0 + 0 + + + + + Include companion splashes + + + + + Only user defined splashes + + + + + + + + + 0 + 0 + + + + Splash Screen Library + + + + + + + true + + + true + + + + + startupCheck_companion9x + backupEnable + line + backupPath + line_2 + startupCheck_fw + wizardEnable_ChkB + ge_label + label_5 + showSplash + line_3 + ge_pathButton + line_4 + backupPathButton + label_3 + backLightColor + snapshotPath + snapshotPathButton + snapshotClipboardCKB + label_11 + joystickCB + joystickcalButton + ge_lineedit + simuSW + buttonBox + line_5 + joystickChkB + label_17 + label_19 + historySize + label_9 + libraryPath + libraryPathButton + line_6 + splashincludeCB + label_10 + + + buttonBox + ge_lineedit + ge_pathButton + historySize + showSplash + startupCheck_fw + startupCheck_companion9x + wizardEnable_ChkB + backupPath + backupPathButton + backupEnable + snapshotPath + snapshotPathButton + snapshotClipboardCKB + simuSW + backLightColor + joystickCB + joystickChkB + joystickcalButton + + + + + + + buttonBox + accepted() + appPreferencesDialog + accept() + + + 376 + 596 + + + 157 + 274 + + + + + buttonBox + rejected() + appPreferencesDialog + reject() + + + 396 + 596 + + + 286 + 274 + + + + + diff --git a/companion/src/companion.qrc b/companion/src/companion.qrc index acb1591a1..cdc68d4e0 100644 --- a/companion/src/companion.qrc +++ b/companion/src/companion.qrc @@ -325,7 +325,8 @@ themes/monochrome/16/print.png themes/monochrome/16/compare.png themes/monochrome/16/saveas.png - themes/monochrome/16/preferences.png + themes/monochrome/16/apppreferences.png + themes/monochrome/16/fwpreferences.png themes/monochrome/16/movedown.png themes/monochrome/16/currentmodel.png themes/monochrome/16/read_flash.png @@ -367,7 +368,8 @@ themes/monochrome/24/print.png themes/monochrome/24/compare.png themes/monochrome/24/saveas.png - themes/monochrome/24/preferences.png + themes/monochrome/24/apppreferences.png + themes/monochrome/24/fwpreferences.png themes/monochrome/24/movedown.png themes/monochrome/24/currentmodel.png themes/monochrome/24/read_flash.png @@ -409,7 +411,8 @@ themes/monochrome/32/print.png themes/monochrome/32/compare.png themes/monochrome/32/saveas.png - themes/monochrome/32/preferences.png + themes/monochrome/32/apppreferences.png + themes/monochrome/32/fwpreferences.png themes/monochrome/32/movedown.png themes/monochrome/32/currentmodel.png themes/monochrome/32/read_flash.png @@ -451,7 +454,8 @@ themes/monochrome/48/print.png themes/monochrome/48/compare.png themes/monochrome/48/saveas.png - themes/monochrome/48/preferences.png + themes/monochrome/48/apppreferences.png + themes/monochrome/48/fwpreferences.png themes/monochrome/48/movedown.png themes/monochrome/48/currentmodel.png themes/monochrome/48/read_flash.png @@ -493,7 +497,8 @@ themes/classic/16/print.png themes/classic/16/compare.png themes/classic/16/saveas.png - themes/classic/16/preferences.png + themes/classic/16/apppreferences.png + themes/classic/16/fwpreferences.png themes/classic/16/movedown.png themes/classic/16/currentmodel.png themes/classic/16/read_flash.png @@ -535,7 +540,8 @@ themes/classic/24/print.png themes/classic/24/compare.png themes/classic/24/saveas.png - themes/classic/24/preferences.png + themes/classic/24/apppreferences.png + themes/classic/24/fwpreferences.png themes/classic/24/movedown.png themes/classic/24/currentmodel.png themes/classic/24/read_flash.png @@ -577,7 +583,8 @@ themes/classic/32/print.png themes/classic/32/compare.png themes/classic/32/saveas.png - themes/classic/32/preferences.png + themes/classic/32/apppreferences.png + themes/classic/32/fwpreferences.png themes/classic/32/movedown.png themes/classic/32/currentmodel.png themes/classic/32/read_flash.png @@ -619,7 +626,8 @@ themes/classic/48/print.png themes/classic/48/compare.png themes/classic/48/saveas.png - themes/classic/48/preferences.png + themes/classic/48/apppreferences.png + themes/classic/48/fwpreferences.png themes/classic/48/movedown.png themes/classic/48/currentmodel.png themes/classic/48/read_flash.png @@ -661,7 +669,8 @@ themes/monoblue/16/print.png themes/monoblue/16/compare.png themes/monoblue/16/saveas.png - themes/monoblue/16/preferences.png + themes/monoblue/16/apppreferences.png + themes/monoblue/16/fwpreferences.png themes/monoblue/16/movedown.png themes/monoblue/16/currentmodel.png themes/monoblue/16/read_flash.png @@ -703,7 +712,8 @@ themes/monoblue/24/print.png themes/monoblue/24/compare.png themes/monoblue/24/saveas.png - themes/monoblue/24/preferences.png + themes/monoblue/24/apppreferences.png + themes/monoblue/24/fwpreferences.png themes/monoblue/24/movedown.png themes/monoblue/24/currentmodel.png themes/monoblue/24/read_flash.png @@ -745,7 +755,8 @@ themes/monoblue/32/print.png themes/monoblue/32/compare.png themes/monoblue/32/saveas.png - themes/monoblue/32/preferences.png + themes/monoblue/32/apppreferences.png + themes/monoblue/32/fwpreferences.png themes/monoblue/32/movedown.png themes/monoblue/32/currentmodel.png themes/monoblue/32/read_flash.png @@ -787,7 +798,8 @@ themes/monoblue/48/print.png themes/monoblue/48/compare.png themes/monoblue/48/saveas.png - themes/monoblue/48/preferences.png + themes/monoblue/48/apppreferences.png + themes/monoblue/48/fwpreferences.png themes/monoblue/48/movedown.png themes/monoblue/48/currentmodel.png themes/monoblue/48/read_flash.png @@ -829,7 +841,8 @@ themes/monowhite/16/print.png themes/monowhite/16/compare.png themes/monowhite/16/saveas.png - themes/monowhite/16/preferences.png + themes/monowhite/16/apppreferences.png + themes/monowhite/16/fwpreferences.png themes/monowhite/16/movedown.png themes/monowhite/16/currentmodel.png themes/monowhite/16/read_flash.png @@ -871,7 +884,8 @@ themes/monowhite/24/print.png themes/monowhite/24/compare.png themes/monowhite/24/saveas.png - themes/monowhite/24/preferences.png + themes/monowhite/24/apppreferences.png + themes/monowhite/24/fwpreferences.png themes/monowhite/24/movedown.png themes/monowhite/24/currentmodel.png themes/monowhite/24/read_flash.png @@ -913,7 +927,8 @@ themes/monowhite/32/print.png themes/monowhite/32/compare.png themes/monowhite/32/saveas.png - themes/monowhite/32/preferences.png + themes/monowhite/32/apppreferences.png + themes/monowhite/32/fwpreferences.png themes/monowhite/32/movedown.png themes/monowhite/32/currentmodel.png themes/monowhite/32/read_flash.png @@ -955,7 +970,8 @@ themes/monowhite/48/print.png themes/monowhite/48/compare.png themes/monowhite/48/saveas.png - themes/monowhite/48/preferences.png + themes/monowhite/48/apppreferences.png + themes/monowhite/48/fwpreferences.png themes/monowhite/48/movedown.png themes/monowhite/48/currentmodel.png themes/monowhite/48/read_flash.png diff --git a/companion/src/customizesplashdialog.cpp b/companion/src/customizesplashdialog.cpp index 30762142f..11954bc9c 100644 --- a/companion/src/customizesplashdialog.cpp +++ b/companion/src/customizesplashdialog.cpp @@ -7,14 +7,39 @@ #include "splashlibrary.h" #include "flashinterface.h" +Side::Side(){ + imageLabel = 0; + fileNameEdit = 0; + saveButton = 0; + source=new Source; + *source = UNDEFINED; +} + +void Side::copyImage( Side side ){ + if ((*source!=UNDEFINED) && (*side.source!=UNDEFINED)) + imageLabel->setPixmap(*side.imageLabel->pixmap()); +} + customizeSplashDialog::customizeSplashDialog(QWidget *parent) : QDialog(parent), ui(new Ui::customizeSplashDialog) { ui->setupUi(this); - ui->libraryButton->setIcon(CompanionIcon("library.png")); - ui->HowToLabel->clear(); - ui->HowToLabel->append("
" + tr("Select an original firmware file") + "
"); + ui->leftLibraryButton->setIcon(CompanionIcon("library.png")); + ui->rightLibraryButton->setIcon(CompanionIcon("library.png")); + + left.imageLabel = ui->leftImageLabel; + right.imageLabel = ui->rightImageLabel; + left.fileNameEdit = ui->leftFileNameEdit; + right.fileNameEdit = ui->rightFileNameEdit; + left.saveButton = ui->leftSaveButton; + right.saveButton = ui->rightSaveButton; + left.libraryButton = ui->leftLibraryButton; + right.libraryButton = ui->rightLibraryButton; + left.invertButton = ui->leftInvertButton; + right.invertButton = ui->rightInvertButton; + + resize(0,0); } customizeSplashDialog::~customizeSplashDialog() @@ -22,92 +47,95 @@ customizeSplashDialog::~customizeSplashDialog() delete ui; } -void customizeSplashDialog::on_FlashLoadButton_clicked() +void customizeSplashDialog::on_copyRightToLeftButton_clicked() { + left.copyImage(right); +} +void customizeSplashDialog::on_copyLeftToRightButton_clicked() { +right.copyImage(left); +} + + +void customizeSplashDialog::on_leftLoadFwButton_clicked() {loadFwButton_clicked(left);} +void customizeSplashDialog::on_rightLoadFwButton_clicked() {loadFwButton_clicked(right);} +void customizeSplashDialog::loadFwButton_clicked(Side side) { QSettings settings; QString fileName = QFileDialog::getOpenFileName(this, tr("Open"), settings.value("lastFlashDir").toString(), FLASH_FILES_FILTER); if (!fileName.isEmpty()) { - ui->ImageLoadButton->setDisabled(true); - ui->libraryButton->setDisabled(true); - ui->SaveFlashButton->setDisabled(true); - ui->SaveImageButton->setDisabled(true); - ui->ImageFileName->clear(); - ui->imageLabel->clear(); - ui->HowToLabel->clear(); - ui->HowToLabel->setStyleSheet("background:rgb(255, 255, 0)"); QFile file(fileName); - if (!file.exists()) { - ui->FWFileName->clear(); - ui->HowToLabel->append("
" + tr("Select an original firmware file") + "
"); + if (fileName.isEmpty() || !file.exists()) return; - } - if (fileName.isEmpty()) { - ui->FWFileName->clear(); - ui->HowToLabel->append("
" + tr("Select an original firmware file") + "
"); - return; - } - - ui->FWFileName->setText(fileName); + FlashInterface flash(fileName); - if (flash.hasSplash()) { - ui->HowToLabel->append("
" + tr("Select an image to customize your splash
or save actual firmware splash") + "
"); - ui->ImageLoadButton->setEnabled(true); - ui->libraryButton->setEnabled(true); - ui->SaveImageButton->setEnabled(true); - ui->imageLabel->setPixmap(QPixmap::fromImage(flash.getSplash())); - ui->imageLabel->setFixedSize(flash.getSplashWidth()*2,flash.getSplashHeight()*2); - } else { + if (!flash.hasSplash()) { QMessageBox::information(this, tr("Error"), tr("Could not find bitmap to replace in file")); return; } + + side.saveButton->setEnabled(true); + side.imageLabel->setPixmap(QPixmap::fromImage(flash.getSplash())); + side.imageLabel->setFixedSize(flash.getSplashWidth()*2,flash.getSplashHeight()*2); + side.fileNameEdit->setText(fileName); settings.setValue("lastFlashDir", QFileInfo(fileName).dir().absolutePath()); + *side.source=FW; + side.saveButton->setEnabled(true); + side.libraryButton->setEnabled(true); + side.invertButton->setEnabled(true); } } -void customizeSplashDialog::on_ImageLoadButton_clicked() { +void customizeSplashDialog::on_leftLoadPictButton_clicked() {loadPictButton_clicked(left);} +void customizeSplashDialog::on_rightLoadPictButton_clicked() {loadPictButton_clicked(right);} +void customizeSplashDialog::loadPictButton_clicked(Side side) +{ QString supportedImageFormats; for (int formatIndex = 0; formatIndex < QImageReader::supportedImageFormats().count(); formatIndex++) { supportedImageFormats += QLatin1String(" *.") + QImageReader::supportedImageFormats()[formatIndex]; } - QSettings settings; QString fileName = QFileDialog::getOpenFileName(this, tr("Open Image to load"), settings.value("lastImagesDir").toString(), tr("Images (%1)").arg(supportedImageFormats)); - if (!fileName.isEmpty()) { - settings.setValue("lastImagesDir", QFileInfo(fileName).dir().absolutePath()); - QImage image(fileName); - if (image.isNull()) { - QMessageBox::critical(this, tr("Error"), tr("Cannot load %1.").arg(fileName)); - return; - } - ui->HowToLabel->clear(); - ui->ImageFileName->setText(fileName); - if (ui->imageLabel->width()==424) { - image=image.convertToFormat(QImage::Format_RGB32); - QRgb col; - int gray; - int width = image.width(); - int height = image.height(); - for (int i = 0; i < width; ++i) - { - for (int j = 0; j < height; ++j) - { - col = image.pixel(i, j); - gray = qGray(col); - image.setPixel(i, j, qRgb(gray, gray, gray)); - } - } - ui->imageLabel->setPixmap(QPixmap::fromImage(image.scaled(ui->imageLabel->width()/2, ui->imageLabel->height()/2))); - } else { - ui->imageLabel->setPixmap(QPixmap::fromImage(image.scaled(ui->imageLabel->width()/2, ui->imageLabel->height()/2).convertToFormat(QImage::Format_Mono))); - } - ui->SaveFlashButton->setEnabled(true); - ui->HowToLabel->append("
" + tr("Save your custimized firmware") + "
"); + if (fileName.isEmpty()){ + return; } + QImage image(fileName); + if (image.isNull()) { + QMessageBox::critical(this, tr("Error"), tr("Cannot load %1.").arg(fileName)); + return; + } + if (side.imageLabel->width()==424) { + image=image.convertToFormat(QImage::Format_RGB32); + QRgb col; + int gray; + int width = image.width(); + int height = image.height(); + for (int i = 0; i < width; ++i) + { + for (int j = 0; j < height; ++j) + { + col = image.pixel(i, j); + gray = qGray(col); + image.setPixel(i, j, qRgb(gray, gray, gray)); + } + } + side.imageLabel->setPixmap(QPixmap::fromImage(image.scaled(side.imageLabel->width()/2, side.imageLabel->height()/2))); + } else { + side.imageLabel->setPixmap(QPixmap::fromImage(image.scaled(side.imageLabel->width()/2, side.imageLabel->height()/2).convertToFormat(QImage::Format_Mono))); + } + + settings.setValue("lastImagesDir", QFileInfo(fileName).dir().absolutePath()); + side.fileNameEdit->setText(fileName); + *side.source=PICT; + side.saveButton->setEnabled(true); + side.libraryButton->setEnabled(true); + side.invertButton->setEnabled(true); } -void customizeSplashDialog::on_libraryButton_clicked() { +void customizeSplashDialog::on_leftLibraryButton_clicked(){libraryButton_clicked(left);} +void customizeSplashDialog::on_rightLibraryButton_clicked(){libraryButton_clicked(right);} +void customizeSplashDialog::libraryButton_clicked( Side side ) +{ QString fileName; splashLibrary *ld = new splashLibrary(this,&fileName); @@ -118,9 +146,7 @@ void customizeSplashDialog::on_libraryButton_clicked() { QMessageBox::critical(this, tr("Error"), tr("Cannot load %1.").arg(fileName)); return; } - ui->HowToLabel->clear(); - ui->ImageFileName->setText(fileName); - if (ui->imageLabel->width()==424) { + if (side.imageLabel->width()==424) { image=image.convertToFormat(QImage::Format_RGB32); QRgb col; int gray; @@ -135,57 +161,52 @@ void customizeSplashDialog::on_libraryButton_clicked() { image.setPixel(i, j, qRgb(gray, gray, gray)); } } - ui->imageLabel->setPixmap(QPixmap::fromImage(image.scaled(ui->imageLabel->width()/2, ui->imageLabel->height()/2))); + side.imageLabel->setPixmap(QPixmap::fromImage(image.scaled(side.imageLabel->width()/2, side.imageLabel->height()/2))); } else { - ui->imageLabel->setPixmap(QPixmap::fromImage(image.scaled(ui->imageLabel->width()/2, ui->imageLabel->height()/2).convertToFormat(QImage::Format_Mono))); + side.imageLabel->setPixmap(QPixmap::fromImage(image.scaled(side.imageLabel->width()/2, side.imageLabel->height()/2).convertToFormat(QImage::Format_Mono))); } - ui->SaveFlashButton->setEnabled(true); - ui->HowToLabel->append("
" + tr("Save your custimized firmware") + "
"); } } -void customizeSplashDialog::on_SaveFlashButton_clicked() +void customizeSplashDialog::on_leftSaveButton_clicked(){saveButton_clicked(left);} +void customizeSplashDialog::on_rightSaveButton_clicked(){saveButton_clicked(right);} +void customizeSplashDialog::saveButton_clicked(Side side) { - QString fileName; QSettings settings; - ui->HowToLabel->clear(); - fileName = QFileDialog::getSaveFileName(this, tr("Write to file"), settings.value("lastFlashDir").toString(), FLASH_FILES_FILTER, 0, QFileDialog::DontConfirmOverwrite); - if (fileName.isEmpty()) { - return; + QString fileName = side.fileNameEdit->text(); + + if (*side.source == FW) + { + FlashInterface flash(fileName); + if (!flash.hasSplash()) { + QMessageBox::critical(this, tr("Error"), tr("Could not store image in firmware file %1").arg(fileName)); + return; + } + QImage image = side.imageLabel->pixmap()->toImage().scaled(flash.getSplashWidth(), flash.getSplashHeight()); + if (flash.setSplash(image) && (flash.saveFlash(fileName) > 0)) + settings.setValue("lastFlashDir", QFileInfo(fileName).dir().absolutePath()); + else + QMessageBox::critical(this, tr("Error"), tr("Could not store image in firmware file %1").arg(fileName)); } - FlashInterface flash(ui->FWFileName->text()); - if (!flash.hasSplash()) { - QMessageBox::critical(this, tr("Error"), tr("Error reading file %1").arg(fileName)); - return; - } - settings.setValue("lastFlashDir", QFileInfo(fileName).dir().absolutePath()); - QImage image = ui->imageLabel->pixmap()->toImage().scaled(flash.getSplashWidth(), flash.getSplashHeight()); - flash.setSplash(image); - if (flash.saveFlash(fileName) > 0) { - ui->HowToLabel->setStyleSheet("background:rgb(0,255.0);"); - ui->HowToLabel->append("
" + tr("Firmware correctly saved.") + "
"); - } else { - ui->HowToLabel->setStyleSheet("background:rgb(255.0.0);"); - ui->HowToLabel->append("
" + tr("Firmware not saved.") + "
"); + else if (*side.source == PICT) + { + if (!fileName.isEmpty()) { + QImage image = side.imageLabel->pixmap()->toImage().scaled(side.imageLabel->width()/2, side.imageLabel->height()/2).convertToFormat(QImage::Format_Indexed8); + if (image.save(fileName)) + settings.setValue("lastImagesDir", QFileInfo(fileName).dir().absolutePath()); + else + QMessageBox::critical(this, tr("Error"), tr("The image file %1 could not be stored").arg(fileName)); + } } } -void customizeSplashDialog::on_InvertColorButton_clicked() +void customizeSplashDialog::on_leftInvertButton_clicked(){invertButton_clicked(left);} +void customizeSplashDialog::on_rightInvertButton_clicked(){invertButton_clicked(right);} +void customizeSplashDialog::invertButton_clicked(Side side) { - QImage image = ui->imageLabel->pixmap()->toImage(); + QImage image = side.imageLabel->pixmap()->toImage(); image.invertPixels(); - ui->imageLabel->setPixmap(QPixmap::fromImage(image)); + side.imageLabel->setPixmap(QPixmap::fromImage(image)); } -void customizeSplashDialog::on_SaveImageButton_clicked() -{ - QString fileName; - QSettings settings; - fileName = QFileDialog::getSaveFileName(this, tr("Write to file"), settings.value("lastImagesDir").toString(), tr("PNG images (*.png);;"), 0, QFileDialog::DontConfirmOverwrite); - if (!fileName.isEmpty()) { - settings.setValue("lastImagesDir", QFileInfo(fileName).dir().absolutePath()); - QImage image = ui->imageLabel->pixmap()->toImage().scaled(ui->imageLabel->width()/2, ui->imageLabel->height()/2).convertToFormat(QImage::Format_Indexed8); - image.save(fileName, "PNG"); - } -} diff --git a/companion/src/customizesplashdialog.h b/companion/src/customizesplashdialog.h index f5a7acd6d..16141e1ae 100644 --- a/companion/src/customizesplashdialog.h +++ b/companion/src/customizesplashdialog.h @@ -10,24 +10,58 @@ namespace Ui class customizeSplashDialog; } +enum Source {FW, PICT, UNDEFINED}; + +class Side +{ +public: + Side(); + void copyImage( Side ); + + QLabel *imageLabel; + QLineEdit *fileNameEdit; + QPushButton *saveButton; + QPushButton *invertButton; + QToolButton *libraryButton; + + Source *source; +}; + class customizeSplashDialog : public QDialog { Q_OBJECT + Side left; + Side right; public: explicit customizeSplashDialog(QWidget *parent = 0); ~customizeSplashDialog(); private slots: - void on_FlashLoadButton_clicked(); - void on_ImageLoadButton_clicked(); - void on_libraryButton_clicked(); - void on_SaveFlashButton_clicked(); - void on_InvertColorButton_clicked(); - void on_SaveImageButton_clicked(); + void on_leftLoadFwButton_clicked(); + void on_leftLoadPictButton_clicked(); + void on_leftLibraryButton_clicked(); + void on_leftSaveButton_clicked(); + void on_leftInvertButton_clicked(); + + void on_rightLoadFwButton_clicked(); + void on_rightLoadPictButton_clicked(); + void on_rightLibraryButton_clicked(); + void on_rightSaveButton_clicked(); + void on_rightInvertButton_clicked(); + + void on_copyRightToLeftButton_clicked(); + void on_copyLeftToRightButton_clicked(); private: + void loadFwButton_clicked( Side ); + void loadPictButton_clicked( Side ); + void libraryButton_clicked( Side ); + void saveButton_clicked( Side ); + void invertButton_clicked( Side ); + Ui::customizeSplashDialog *ui; + enum sideEnum { LEFT, RIGHT }; }; #endif // CUSTOMIZESPLASHDIALOG_H diff --git a/companion/src/customizesplashdialog.ui b/companion/src/customizesplashdialog.ui index 15a803656..4931052d1 100644 --- a/companion/src/customizesplashdialog.ui +++ b/companion/src/customizesplashdialog.ui @@ -2,88 +2,498 @@ customizeSplashDialog + + true + 0 0 - 366 - 303 + 1086 + 285 - + 0 0 - Customize Splash + Transmitter Splash Screen Editor :/icon.png:/icon.png - - - + + + 6 + + + 3 + + + 0 + + + 3 + + + 3 + + + + + 0 + - + - Qt::Horizontal + Qt::Vertical - - - 40 - 20 - - - + - + - - - - 0 - 0 - - - - - 256 - 128 - - - - - 424 - 128 - - - - QFrame::Panel - - - QFrame::Raised - - - - - - :/images/customize.png - - - true + + + Qt::Horizontal - + + + 6 + - + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + true + + + + 424 + 0 + + + + + 426 + 16777215 + + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + + + + + 6 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 424 + 128 + + + + + 424 + 128 + + + + QFrame::Panel + + + QFrame::Plain + - Save Image + + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + + + + + + + false + + + Invert + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + Open Splash Library + + + ... + + + + 24 + 24 + + + + + + + + + + Qt::Horizontal + + + + + + + + + Load FW + + + + + + + Load Pict + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + Save + + + + + + + + + Qt::Horizontal + + + + + + + + + Qt::Vertical + + + + + + + + + ... + + + Qt::LeftArrow + + + + + + + ... + + + Qt::RightArrow + + + + + + + + + Qt::Vertical + + + + + + + + + Qt::Horizontal + + + + + + + 6 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + true + + + + 426 + 0 + + + + + 424 + 16777215 + + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + + + + + 6 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 424 + 128 + + + + + 424 + 128 + + + + QFrame::Panel + + + QFrame::Plain + + + + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + + + + + + + false + + + Invert @@ -101,164 +511,111 @@ - + + + false + + + Open Splash Library + - Invert Color + ... + + + + 24 + 24 + + + + + Qt::Horizontal + + + + + + + + + true + + + Load FW + + + + + + + Load Pict + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + Save + + + + + + + + + Qt::Horizontal + + + - + - Qt::Horizontal - - - - 50 - 20 - - - - - - - - - - - 0 - 0 - - - - - 16777215 - 40 - - - - background:rgb(255, 255, 0); - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - true - - - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> -<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html> - - - true - - - - - - - - - true - - - true - - - - - - - Load Firmware - - - - - - - true - - - true - - - - - - - false - - - Load Image - - - - - - - Open Splash Library - - - ... - - - - 16 - 16 - - - - - - - - Qt::Horizontal - - - - 208 - 20 - - - - - - - - false - - - Save Firmware + Qt::Vertical - - - - Qt::Vertical - - - - 20 - 1 - - - - + + leftFileNameEdit + leftInvertButton + leftLoadFwButton + leftLoadPictButton + leftSaveButton + copyLeftToRightButton + copyRightToLeftButton + rightFileNameEdit + rightInvertButton + rightLoadFwButton + rightLoadPictButton + rightSaveButton + diff --git a/companion/src/fwpreferencesdialog.cpp b/companion/src/fwpreferencesdialog.cpp new file mode 100644 index 000000000..c4c2a820b --- /dev/null +++ b/companion/src/fwpreferencesdialog.cpp @@ -0,0 +1,557 @@ +#include "fwpreferencesdialog.h" +#include "ui_fwpreferencesdialog.h" +#include "mainwindow.h" +#include "eeprominterface.h" +#include "helpers.h" +#include +#include + +fwPreferencesDialog::fwPreferencesDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::fwPreferencesDialog), + updateLock(false) +{ + ui->setupUi(this); + setWindowIcon(CompanionIcon("preferences.png")); + + QCheckBox * OptionCheckBox[]= { + ui->optionCheckBox_1, ui->optionCheckBox_2, ui->optionCheckBox_3, ui->optionCheckBox_4, ui->optionCheckBox_5, ui->optionCheckBox_6, ui->optionCheckBox_7, + ui->optionCheckBox_8, ui->optionCheckBox_9, ui->optionCheckBox_10, ui->optionCheckBox_11, ui->optionCheckBox_12, ui->optionCheckBox_13, ui->optionCheckBox_14, + ui->optionCheckBox_15,ui->optionCheckBox_16, ui->optionCheckBox_17, ui->optionCheckBox_18, ui->optionCheckBox_19, ui->optionCheckBox_20, ui->optionCheckBox_21, + ui->optionCheckBox_22, ui->optionCheckBox_23, ui->optionCheckBox_24, ui->optionCheckBox_25, ui->optionCheckBox_26, ui->optionCheckBox_27, ui->optionCheckBox_28, + ui->optionCheckBox_29, ui->optionCheckBox_30, ui->optionCheckBox_31, ui->optionCheckBox_32, ui->optionCheckBox_33, ui->optionCheckBox_34, ui->optionCheckBox_35, + ui->optionCheckBox_36, ui->optionCheckBox_37, ui->optionCheckBox_38, ui->optionCheckBox_39, ui->optionCheckBox_40, ui->optionCheckBox_41, ui->optionCheckBox_42, + NULL }; + + voice=NULL; + + connect(ui->langCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(firmwareLangChanged())); + connect(ui->voiceCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(firmwareLangChanged())); + + for (int i=0; OptionCheckBox[i]; i++) { + optionsCheckBoxes.push_back(OptionCheckBox[i]); + connect(OptionCheckBox[i], SIGNAL(toggled(bool)), this, SLOT(firmwareOptionChanged(bool))); + } + + initSettings(); + + connect(ui->downloadVerCB, SIGNAL(currentIndexChanged(int)), this, SLOT(baseFirmwareChanged())); + connect(this, SIGNAL(accepted()), this, SLOT(writeValues())); + + resize(0,0); +} + + +fwPreferencesDialog::~fwPreferencesDialog() +{ + delete ui; +} + +void fwPreferencesDialog::baseFirmwareChanged() +{ + QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex()); + voice=NULL; + foreach(FirmwareInfo * firmware, firmwares) { + if (firmware->id == selected_firmware) { + if (firmware->voice) { + ui->voiceLabel->show(); + ui->voiceCombo->show(); + ui->voice_dnld->show(); + ui->sdPathButton->show(); + ui->sdPath->show(); + ui->sdPathLabel->show(); + ui->voiceLabel->setEnabled(true); + ui->voiceCombo->setEnabled(true); + ui->voice_dnld->setEnabled(true); + ui->sdPathButton->setEnabled(true); + ui->sdPath->setEnabled(true); + } else { + ui->voiceLabel->hide(); + ui->voiceCombo->hide(); + ui->voice_dnld->hide(); + ui->sdPathButton->hide(); + ui->sdPath->hide(); + ui->sdPathLabel->hide(); + } + populateFirmwareOptions(firmware); + break; + } + } + firmwareChanged(); +} + +FirmwareVariant fwPreferencesDialog::getFirmwareVariant() +{ + QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex()); + bool voice=false; + foreach(FirmwareInfo * firmware, firmwares) { + if (firmware->id == selected_firmware) { + QString id = firmware->id; + foreach(QCheckBox *cb, optionsCheckBoxes) { + if (cb->isChecked()) { + if (cb->text()=="voice" && cb->isChecked()) + voice=true; + id += QString("-") + cb->text(); + } + } + if (! firmware->eepromInterface->getCapability(MultiLangVoice)) { + if (ui->voiceCombo->count() && (voice || firmware->voice)) + id += QString("-tts") + ui->voiceCombo->currentText(); + } + if (ui->langCombo->count()) + id += QString("-") + ui->langCombo->currentText(); + + return GetFirmwareVariant(id); + } + } + + // Should never occur... + return default_firmware_variant; +} + +void fwPreferencesDialog::firmwareLangChanged() +{ + firmwareChanged(); +} + +void fwPreferencesDialog::firmwareOptionChanged(bool state) +{ + QCheckBox *cb = qobject_cast(sender()); + FirmwareInfo * firmware=NULL; + if (cb && state) { + QVariant selected_firmware = ui->downloadVerCB->itemData(ui->downloadVerCB->currentIndex()); + foreach(firmware, firmwares) { + if (firmware->id == selected_firmware) { + foreach(QList