2 * Copyright (C) 2016 Mentor Graphics Development (Deutschland) GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "settingswidget.h"
18 #include "ui_settingswidget.h"
20 #include <include/daynightmode.hpp>
22 SettingsWidget::SettingsWidget(QWidget *parent) :
24 mp_ui(new Ui::SettingsWidget),
27 // no window decoration
28 setWindowFlags(Qt::FramelessWindowHint);
30 // multi-language support
31 mp_translator = new QTranslator();
32 mp_translator->load("homescreen_en_US.qm", ":/translations"); // TODO: read from system
33 QApplication::instance()->installTranslator(mp_translator);
37 mp_ui->comboBox_language->addItem(QString("English"), QVariant("homescreen_en_US.qm")); // TODO: make this configurable
38 mp_ui->comboBox_language->addItem(QString("Deutsch"), QVariant("homescreen_de_DE.qm"));
39 mp_ui->comboBox_language->addItem(QString("日本語"), QVariant("homescreen_ja_JP.qm"));
41 mp_ui->comboBox_colorScheme->addItem(QString("Default"), QVariant("default")); // TODO: make this configurable
42 mp_ui->comboBox_colorScheme->addItem(QString("Demo 1"), QVariant("demo1"));
43 mp_ui->comboBox_colorScheme->addItem(QString("Demo 2"), QVariant("demo2"));
46 mp_ui->comboBox_language->setCurrentIndex(settings.value("systemsettings/language", 0).toInt());
47 mp_ui->comboBox_colorScheme->setCurrentIndex(settings.value("systemsettings/colorschemeindex", 0).toInt());
50 SettingsWidget::~SettingsWidget()
56 void SettingsWidget::updateColorScheme()
59 QSettings settings_cs(QApplication::applicationDirPath() +
61 settings.value("systemsettings/colorscheme", "default").toString() +
63 QString::number(settings.value("systemsettings/proximityobjectdetected", false).toBool()) +
65 QString::number(settings.value("systemsettings/daynightmode", SystemDayNight::DAYNIGHTMODE_DAY).toInt()) +
67 QSettings::IniFormat);
69 mp_ui->widget_background->setStyleSheet(settings_cs.value("SettingsWidget/widget_background_css").toString());
70 mp_ui->comboBox_language->setStyleSheet(settings_cs.value("SettingsWidget/comboBox_language_css").toString());
71 mp_ui->comboBox_colorScheme->setStyleSheet(settings_cs.value("SettingsWidget/comboBox_colorScheme_css").toString());
72 mp_ui->widget_settingsIcon->setStyleSheet(settings_cs.value("SettingsWidget/widget_settingsIcon_css").toString());
75 void SettingsWidget::changeEvent(QEvent* event)
77 if (QEvent::LanguageChange == event->type())
79 mp_ui->retranslateUi(this);
82 QWidget::changeEvent(event);
85 void SettingsWidget::on_comboBox_language_currentIndexChanged(const QString &)
87 if (0 != mp_translator)
88 mp_translator->load(mp_ui->comboBox_language->currentData().toString(), ":/translations");
91 settings.setValue("systemsettings/language", mp_ui->comboBox_language->currentIndex());
94 void SettingsWidget::on_comboBox_colorScheme_currentIndexChanged(const QString &)
97 settings.setValue("systemsettings/colorscheme", mp_ui->comboBox_colorScheme->currentData().toString());
98 settings.setValue("systemsettings/colorschemeindex", mp_ui->comboBox_colorScheme->currentIndex());
99 // make sure that everything is written to the settings file before continuing
102 emit colorSchemeChanged();