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"
21 SettingsWidget::SettingsWidget(QWidget *parent) :
23 mp_ui(new Ui::SettingsWidget),
24 m_dayNightMode(SystemDayNight::DAYNIGHTMODE_DAY), // TODO: read from system
25 mp_dayNightModeProxy(0),
28 // this has to be adopted to the system setup
29 mp_dayNightModeProxy = new org::agl::daynightmode("org.agl.homescreen.simulator", //"org.agl.systeminfoprovider"
31 QDBusConnection::sessionBus(),
33 QObject::connect(mp_dayNightModeProxy, SIGNAL(dayNightMode(int)), this, SLOT(dayNightModeSlot(int)));
35 // multi-language support
36 mp_translator = new QTranslator();
37 mp_translator->load("homescreen_en_US.qm", ":/translations"); // TODO: read from system
38 QApplication::instance()->installTranslator(mp_translator);
42 mp_ui->comboBoxLanguage->addItem(QString("English"), QVariant("homescreen_en_US.qm")); // TODO: make this configurable?
43 mp_ui->comboBoxLanguage->addItem(QString("Deutsch"), QVariant("homescreen_de_DE.qm"));
44 mp_ui->comboBoxLanguage->addItem(QString("日本語"), QVariant("homescreen_ja_JP.qm"));
47 mp_ui->comboBoxLanguage->setCurrentIndex(settings.value("systemsettings/language", 0).toInt());
50 SettingsWidget::~SettingsWidget()
53 delete mp_dayNightModeProxy;
56 settings.setValue("systemsettings/language", mp_ui->comboBoxLanguage->currentIndex());
60 void SettingsWidget::dayNightModeSlot(int mode)
64 case SystemDayNight::DAYNIGHTMODE_DAY:
65 m_dayNightMode = SystemDayNight::DAYNIGHTMODE_DAY;
66 mp_ui->widget_Background->setStyleSheet(QString("background-image: url(:/images/backgrounds/bg_blue_day.png);"));
67 mp_ui->comboBoxLanguage->setStyleSheet(QString("QComboBox { \
68 border: 1px solid #D3D3D3; \
70 background: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(242, 242, 249, 255), stop:1 rgba(255, 255, 255, 255)); \
75 background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #D5D5D5, stop: 1 #EEEEEE); \
77 QComboBox::drop-down { \
81 QComboBox::down-arrow:on { \
84 mp_ui->widget_Settings_Icon->setStyleSheet(QString("border-image: url(:/icons/settings_day.png) 0 0 0 0 stretch stretch;"));
86 case SystemDayNight::DAYNIGHTMODE_NIGHT:
87 m_dayNightMode = SystemDayNight::DAYNIGHTMODE_NIGHT;
88 mp_ui->widget_Background->setStyleSheet(QString("background-image: url(:/images/backgrounds/bg_blue_night.png);"));
89 mp_ui->comboBoxLanguage->setStyleSheet(QString("QComboBox { \
90 border: 1px solid #D3D3D3; \
92 background: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(147, 147, 151, 255), stop:1 rgba(255, 255, 255, 255)); \
97 background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #D5D5D5, stop: 1 #EEEEEE); \
99 QComboBox::drop-down { \
101 border-radius: 0px; \
103 QComboBox::down-arrow:on { \
106 mp_ui->widget_Settings_Icon->setStyleSheet(QString("border-image: url(:/icons/settings_night.png) 0 0 0 0 stretch stretch;"));
109 m_dayNightMode = SystemDayNight::DAYNIGHTMODE_UNDEFINED;
113 void SettingsWidget::changeEvent(QEvent* event)
115 if (QEvent::LanguageChange == event->type())
117 mp_ui->retranslateUi(this);
120 QWidget::changeEvent(event);
123 void SettingsWidget::on_comboBoxLanguage_currentIndexChanged(const QString &)
125 if (0 != mp_translator)
126 mp_translator->load(mp_ui->comboBoxLanguage->currentData().toString(), ":/translations");