e2b55a970c829702ef418b80052ec784c38e89b3
[staging/HomeScreen.git] / HomeScreen / src / mainwindow.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 "mainwindow.h"
18 #include "ui_mainwindow.h"
19
20 MainWindow::MainWindow(QWidget *parent) :
21     QMainWindow(parent),
22     mp_ui(new Ui::MainWindow),
23     mp_statusBarWidget(0),
24     mp_controlBarWidget(0),
25     m_dayNightMode(SystemDayNight::DAYNIGHTMODE_DAY), // TODO: read from system
26     mp_dayNightModeProxy(0),
27     mp_popupWidget(0)
28 {
29     // this has to be adopted to the system setup
30     mp_dayNightModeProxy = new org::agl::daynightmode("org.agl.homescreen.simulator", //"org.agl.systeminfoprovider"
31                                                       "/",
32                                                       QDBusConnection::sessionBus(),
33                                                       0);
34     QObject::connect(mp_dayNightModeProxy, SIGNAL(dayNightMode(int)), this, SLOT(dayNightModeSlot(int)));
35
36     // dbus setup
37     QDBusConnection dbus = QDBusConnection::sessionBus();
38
39     dbus.registerObject("/MainWindow", this);
40     dbus.registerService("org.agl.homescreen");
41
42     // no window decoration
43     setWindowFlags(Qt::FramelessWindowHint);
44     mp_ui->setupUi(this);
45
46     mp_statusBarWidget = new StatusBarWidget(this);
47     mp_statusBarWidget->raise();
48     // apply layout
49     mp_statusBarWidget->move(0, 0);
50
51     mp_controlBarWidget = new ControlBarWidget(this);
52     mp_controlBarWidget->raise();
53     // apply layout
54     mp_controlBarWidget->move(0, 1920-60);
55
56     mp_popupWidget = new PopupWidget(this);
57     mp_controlBarWidget->raise();
58     // apply layout
59     mp_popupWidget->move(0, 0);
60
61     setWindowIcon(QIcon(":/icons/home_day.png"));
62 }
63
64 MainWindow::~MainWindow()
65 {
66     delete mp_popupWidget;
67     delete mp_dayNightModeProxy;
68     delete mp_statusBarWidget;
69     delete mp_ui;
70 }
71
72 void MainWindow::dayNightModeSlot(int mode)
73 {
74     switch (mode)
75     {
76     case SystemDayNight::DAYNIGHTMODE_DAY:
77         m_dayNightMode = SystemDayNight::DAYNIGHTMODE_DAY;
78         mp_ui->widget_Background->setStyleSheet(QString("background-image: url(:/images/backgrounds/bg_blue_day.png)"));
79         // home icon
80         mp_ui->widget_Home_Icon->setStyleSheet(QString("border-image: url(:/icons/home_day.png) 0 0 0 0 stretch stretch;"));
81
82         break;
83     case SystemDayNight::DAYNIGHTMODE_NIGHT:
84         m_dayNightMode = SystemDayNight::DAYNIGHTMODE_NIGHT;
85         mp_ui->widget_Background->setStyleSheet(QString("background-image: url(:/images/backgrounds/bg_blue_night.png)"));
86         // home icon
87         mp_ui->widget_Home_Icon->setStyleSheet(QString("border-image: url(:/icons/home_night.png) 0 0 0 0 stretch stretch;"));
88
89         break;
90     default:
91         m_dayNightMode = SystemDayNight::DAYNIGHTMODE_UNDEFINED;
92     }
93 }
94
95 void MainWindow::changeEvent(QEvent* event)
96 {
97     if (QEvent::LanguageChange == event->type())
98     {
99         mp_ui->retranslateUi(this);
100     }
101
102     QMainWindow::changeEvent(event);
103 }
104