1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-21 23:35:17 +03:00

Remove duplicated code

This commit is contained in:
Romolo Manfredini 2014-01-20 00:56:14 +01:00
parent 034130555e
commit fad6211789
16 changed files with 42 additions and 262 deletions

View file

@ -279,17 +279,7 @@ void burnConfigDialog::listProgrammers()
QStringList arguments;
arguments << "-c?";
avrOutputDialog *ad = new avrOutputDialog(this, ui->avrdude_location->text(), arguments, "List available programmers", AVR_DIALOG_KEEP_OPEN, TRUE);
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
QString Theme=getTheme();
QIcon Icon;
populate_icon(&Icon,Theme,"list.png");
ad->setWindowIcon(Icon);
@ -309,17 +299,7 @@ void burnConfigDialog::on_pushButton_4_clicked()
arguments << "-?";
avrOutputDialog *ad = new avrOutputDialog(this, ui->avrdude_location->text(), arguments, "Show help", AVR_DIALOG_KEEP_OPEN,TRUE);
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
QString Theme=getTheme();
QIcon Icon;
populate_icon(&Icon,Theme,"configure.png");
ad->setWindowIcon(Icon);
@ -339,17 +319,7 @@ void burnConfigDialog::readFuses()
arguments << "-c" << avrProgrammer << "-p" << avrMCU << args << str;
avrOutputDialog *ad = new avrOutputDialog(this, avrLoc, arguments, "Read Fuses",AVR_DIALOG_KEEP_OPEN,TRUE);
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
QString Theme=getTheme();
QIcon Icon;
populate_icon(&Icon,Theme,"fuses.png");
ad->setWindowIcon(Icon);
@ -364,6 +334,7 @@ void burnConfigDialog::restFuses(bool eeProtect)
//avrdude -c usbasp -p m64 -U efuse:w:<0xFF>:m
QMessageBox::StandardButton ret = QMessageBox::No;
QString Theme=getTheme();
ret = QMessageBox::warning(this, tr("Companion"),
tr("<b><u>WARNING!</u></b><br>This will reset the fuses of %1 to the factory settings.<br>Writing fuses can mess up your radio.<br>Do this only if you are sure they are wrong!<br>Are you sure you want to continue?").arg(avrMCU),
@ -386,17 +357,6 @@ void burnConfigDialog::restFuses(bool eeProtect)
QStringList argread;
argread << "-c" << avrProgrammer << "-p" << avrMCU << args <<"-U" << "lfuse:r:"+tempFile+":r" ;
avrOutputDialog *ad = new avrOutputDialog(this, avrLoc, argread, "Reset Fuses",AVR_DIALOG_CLOSE_IF_SUCCESSFUL,FALSE);
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
QIcon Icon;
populate_icon(&Icon,Theme,"fuses.png");
ad->setWindowIcon(Icon);
@ -428,17 +388,6 @@ void burnConfigDialog::restFuses(bool eeProtect)
arguments << "-c" << avrProgrammer << "-p" << avrMCU << args << "-B" << "100" << "-u" << str;
}
avrOutputDialog *ad = new avrOutputDialog(this, avrLoc, arguments, "Reset Fuses",AVR_DIALOG_KEEP_OPEN,TRUE);
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
QIcon Icon;
populate_icon(&Icon,Theme,"fuses.png");
ad->setWindowIcon(Icon);

View file

@ -16,17 +16,7 @@ burnDialog::burnDialog(QWidget *parent, int Type, QString * fileName, bool * bac
hexType(Type)
{
ui->setupUi(this);
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
QString Theme=getTheme();
QIcon LibraryIcon;
populate_icon(&LibraryIcon,Theme,"library.png");
ui->libraryButton->setIcon(LibraryIcon);

View file

@ -11,17 +11,7 @@ customizeSplashDialog::customizeSplashDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::customizeSplashDialog) {
ui->setupUi(this);
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
QString Theme=getTheme();
QIcon LibraryIcon;
populate_icon(&LibraryIcon,Theme,"library.png");
ui->libraryButton->setIcon(LibraryIcon);

View file

@ -1485,9 +1485,26 @@ QString getCenterBeep(ModelData * g_model)
return strl.join(", ");
}
void populate_icon(QIcon *Icon, QString usedtheme, QString baseimage) {
void populate_icon(QIcon *Icon, QString usedtheme, QString baseimage)
{
Icon->addFile(":/themes/"+usedtheme+"/16/"+baseimage,QSize(16,16));
Icon->addFile(":/themes/"+usedtheme+"/24/"+baseimage,QSize(24,24));
Icon->addFile(":/themes/"+usedtheme+"/32/"+baseimage,QSize(32,32));
Icon->addFile(":/themes/"+usedtheme+"/48/"+baseimage,QSize(48,48));
}
QString getTheme()
{
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
return Theme;
}

View file

@ -29,6 +29,7 @@ void populateTTraceCB(QComboBox *b, int value);
void populateRotEncCB(QComboBox *b, int value, int renumber);
void populateBacklightCB(QComboBox *b, const uint8_t value);
void populate_icon(QIcon *Icon, QString usedtheme, QString baseimage);
QString getTheme();
class GVarGroup : public QObject {

View file

@ -96,16 +96,8 @@ downloadDialog_forWait(NULL)
this, SLOT(setActiveSubWindow(QWidget*)));
MaxRecentFiles=MAX_RECENT;
Theme=getTheme();
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
int icon_size=settings.value("icon_size", 1).toInt();
switch (icon_size) {
case 0:

View file

@ -68,17 +68,7 @@ MdiChild::MdiChild():
isUntitled(true),
fileChanged(false)
{
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
QString Theme=getTheme();
QIcon SimulateIcon;
populate_icon(&SimulateIcon,Theme,"simulate.png");
@ -522,17 +512,8 @@ QString MdiChild::strippedName(const QString &fullFileName)
void MdiChild::burnTo() // write to Tx
{
QString Theme=getTheme();
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
bool backupEnable=settings.value("backupEnable", true).toBool();
QString backupPath=settings.value("backupPath", "").toString();
if (!backupPath.isEmpty()) {

View file

@ -84,18 +84,7 @@ Curves::Curves(QWidget * parent, ModelData & model):
QGraphicsScene *scene = new QGraphicsScene(ui->curvePreview);
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
ui->curvePreview->setScene(scene);
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
QString Theme=getTheme();
QIcon ClearIcon;
populate_icon(&ClearIcon,Theme,"clear.png");

View file

@ -123,17 +123,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData & model,
connect(fswtchParamArmT[i], SIGNAL(editTextChanged ( const QString)), this, SLOT(customFunctionEdited()));
#ifdef PHONON
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
QString Theme=getTheme();
QIcon PlayIcon;
populate_icon(&PlayIcon,Theme,"play.png");
playBT[i] = new QPushButton(this);
@ -173,17 +163,7 @@ void CustomFunctionsPanel::mediaPlayer_state(Phonon::State newState, Phonon::Sta
{
if (phononLock)
return;
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
QString Theme=getTheme();
QIcon PlayIcon;
populate_icon(&PlayIcon,Theme,"play.png");
@ -216,17 +196,8 @@ void CustomFunctionsPanel::playMusic()
QPushButton *playButton = qobject_cast<QPushButton*>(sender());
int index=playButton->objectName().mid(5,2).toInt();
QString function=playButton->objectName().left(4);
QString Theme=getTheme();
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
QIcon PlayIcon;
populate_icon(&PlayIcon,Theme,"play.png");
QIcon StopIcon;
@ -499,17 +470,7 @@ void CustomFunctionsPanel::fsw_customContextMenuRequested(QPoint pos)
{
QLabel *label = (QLabel *)sender();
selectedFunction = label->property("index").toInt();
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
QString Theme=getTheme();
QIcon ClearIcon;
populate_icon(&ClearIcon,Theme,"clear.png");
QIcon CopyIcon;

View file

@ -382,17 +382,7 @@ void CustomSwitchesPanel::csw_customContextMenuRequested(QPoint pos)
{
QLabel *label = (QLabel *)sender();
selectedSwitch = label->property("index").toInt();
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
QString Theme=getTheme();
QIcon ClearIcon;
populate_icon(&ClearIcon,Theme,"clear.png");
QIcon CopyIcon;

View file

@ -8,17 +8,7 @@ InputsPanel::InputsPanel(QWidget *parent, ModelData & model, GeneralSettings & g
generalSettings(generalSettings),
expoInserted(false)
{
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
QString Theme=getTheme();
QGridLayout * exposLayout = new QGridLayout(this);
@ -358,17 +348,7 @@ void InputsPanel::expoAdd()
void InputsPanel::expolistWidget_customContextMenuRequested(QPoint pos)
{
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
QString Theme=getTheme();
QIcon AddIcon;
populate_icon(&AddIcon,Theme,"add.png");
QIcon EditIcon;

View file

@ -8,17 +8,6 @@ MixesPanel::MixesPanel(QWidget *parent, ModelData & model, GeneralSettings & gen
generalSettings(generalSettings),
mixInserted(false)
{
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
QGridLayout * mixesLayout = new QGridLayout(this);
MixerlistWidget = new MixersList(this, false); // TODO enum
@ -26,6 +15,7 @@ MixesPanel::MixesPanel(QWidget *parent, ModelData & model, GeneralSettings & gen
QPushButton * qbDown = new QPushButton(this);
QPushButton * qbClear = new QPushButton(this);
QString Theme=getTheme();
QIcon qbUpIcon;
populate_icon(&qbUpIcon,Theme,"moveup.png");
qbUp->setText(tr("Move Up"));
@ -423,17 +413,7 @@ void MixesPanel::mixerAdd()
void MixesPanel::mixerlistWidget_customContextMenuRequested(QPoint pos)
{
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
QString Theme=getTheme();
QIcon AddIcon;
populate_icon(&AddIcon,Theme,"add.png");
QIcon EditIcon;

View file

@ -21,18 +21,9 @@ ModelEdit::ModelEdit(RadioData & radioData, int modelId, bool openWizard, bool i
generalSettings(generalSettings)
{
ui->setupUi(this);
QString Theme=getTheme();
QSettings settings("companion", "companion");
restoreGeometry(settings.value("modelEditGeometry").toByteArray());
int theme_set=settings.value("theme", 1).toInt();
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
QIcon SimulateIcon;
populate_icon(&SimulateIcon,Theme,"simulate.png");
ui->pushButton->setIcon(SimulateIcon);

View file

@ -83,17 +83,7 @@ void ModelsListWidget::ShowContextMenu(const QPoint& pos)
const QClipboard *clipboard = QApplication::clipboard();
const QMimeData *mimeData = clipboard->mimeData();
bool hasData = mimeData->hasFormat("application/x-companion9x");
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
QString Theme=getTheme();
QIcon AddIcon;
populate_icon(&AddIcon,Theme,"add.png");
QIcon EditIcon;

View file

@ -17,19 +17,8 @@ preferencesDialog::preferencesDialog(QWidget *parent) :
updateLock(false)
{
ui->setupUi(this);
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
QString Theme=getTheme();
QIcon Icon;
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
populate_icon(&Icon, Theme, "preferences.png");
this->setWindowIcon(Icon);
QIcon LibraryIcon;

View file

@ -9,17 +9,7 @@
splashLibrary::splashLibrary(QWidget *parent, QString * fileName) : QDialog(parent), ui(new Ui::splashLibrary) {
splashFileName = fileName;
ui->setupUi(this);
QSettings settings("companion", "companion");
int theme_set=settings.value("theme", 1).toInt();
QString Theme;
switch(theme_set) {
case 0:
Theme="classic";
break;
default:
Theme="monochrome";
break;
}
QString Theme=getTheme();
QIcon NextIcon;
populate_icon(&NextIcon,Theme,"arrow-right.png");
QIcon PrevIcon;