e01fe265f4047a1222b2f66e6ca6618697d79ca0
[staging/HomeScreen.git] / HomeScreen / src / controlbarwidget.cpp
1 /*
2  * Copyright (C) 2016 Mentor Graphics Development (Deutschland) GmbH
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include "controlbarwidget.h"
18 #include "ui_controlbarwidget.h"
19
20 ControlBarWidget::ControlBarWidget(QWidget *parent) :
21     QWidget(parent),
22     mp_ui(new Ui::ControlBarWidget),
23     mp_settingsWidget(0),
24     m_dayNightMode(SystemDayNight::DAYNIGHTMODE_DAY), // TODO: read from system
25     mp_dayNightModeProxy(0)
26 {
27     // this has to be adopted to the system setup
28     mp_dayNightModeProxy = new org::agl::daynightmode("org.agl.homescreen.simulator", //"org.agl.systeminfoprovider"
29                                                       "/",
30                                                       QDBusConnection::sessionBus(),
31                                                       0);
32     QObject::connect(mp_dayNightModeProxy, SIGNAL(dayNightMode(int)), this, SLOT(dayNightModeSlot(int)));
33
34     mp_ui->setupUi(this);
35 }
36
37 ControlBarWidget::~ControlBarWidget()
38 {
39     delete mp_dayNightModeProxy;
40     if (0 != mp_settingsWidget)
41     {
42         delete mp_settingsWidget;
43     }
44     delete mp_ui;
45 }
46
47 void ControlBarWidget::dayNightModeSlot(int mode)
48 {
49     QIcon icon;
50     switch (mode)
51     {
52     case SystemDayNight::DAYNIGHTMODE_DAY:
53         m_dayNightMode = SystemDayNight::DAYNIGHTMODE_DAY;
54         mp_ui->widget_Background->setStyleSheet(QString("background-image: url(:/images/backgrounds/bg_green_day.png)"));
55
56         icon.addFile(QStringLiteral(":/icons/home_day.png"), QSize(), QIcon::Normal, QIcon::Off);
57         mp_ui->pushButton_Home->setIcon(icon);
58         icon.addFile(QStringLiteral(":/icons/settings_day.png"), QSize(), QIcon::Normal, QIcon::Off);
59         mp_ui->pushButton_Settings->setIcon(icon);
60         break;
61     case SystemDayNight::DAYNIGHTMODE_NIGHT:
62         m_dayNightMode = SystemDayNight::DAYNIGHTMODE_NIGHT;
63         mp_ui->widget_Background->setStyleSheet(QString("background-image: url(:/images/backgrounds/bg_green_night.png)"));
64
65         icon.addFile(QStringLiteral(":/icons/home_night.png"), QSize(), QIcon::Normal, QIcon::Off);
66         mp_ui->pushButton_Home->setIcon(icon);
67         icon.addFile(QStringLiteral(":/icons/settings_night.png"), QSize(), QIcon::Normal, QIcon::Off);
68         mp_ui->pushButton_Settings->setIcon(icon);
69         break;
70     default:
71         m_dayNightMode = SystemDayNight::DAYNIGHTMODE_UNDEFINED;
72     }
73 }
74
75 void ControlBarWidget::on_pushButton_Settings_clicked()
76 {
77     if (0 == mp_settingsWidget)
78     {
79         mp_settingsWidget = new SettingsWidget((QWidget*)parent());
80     }
81
82     mp_settingsWidget->move(0, 60);
83     mp_settingsWidget->show();
84 }
85
86 void ControlBarWidget::on_pushButton_Home_clicked()
87 {
88     if (0 != mp_settingsWidget)
89     {
90         mp_settingsWidget->hide();
91     }
92 }