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 "mainwindow.h"
18 #include "ui_mainwindow.h"
20 MainWindow::MainWindow(QWidget *parent) :
22 mp_ui(new Ui::MainWindow),
23 mp_statusBarWidget(0),
24 mp_dBusDayNightMode_StatusBarWidget(0),
25 mp_controlBarWidget(0),
26 mp_dBusDayNightMode_ControlBarWidget(0),
27 m_dayNightMode(SystemDayNight::DAYNIGHTMODE_DAY), // TODO: read from system
28 mp_daynightmodeAdaptor(0),
34 QDBusConnection dbus = QDBusConnection::sessionBus();
36 // publish dbus day night mode interface
37 mp_daynightmodeAdaptor = new DaynightmodeAdaptor((QObject*)this);
38 // publish dbus popup interface
39 mp_popupAdaptor = new PopupAdaptor((QObject*)this);
41 dbus.registerObject("/MainWindow", this);
42 dbus.registerService("org.agl.mainwindow");
44 // no window decoration
45 setWindowFlags(Qt::FramelessWindowHint);
48 mp_statusBarWidget = new StatusBarWidget(this);
49 mp_statusBarWidget->raise();
51 mp_statusBarWidget->setGeometry(0, 0, 800, 60);
52 // connect to the dBus interface provided by the status bar widget
53 mp_dBusDayNightMode_StatusBarWidget = new org::agl::daynightmode("org.agl.mainwindow",
55 QDBusConnection::sessionBus(),
58 mp_controlBarWidget = new ControlBarWidget(this);
59 mp_controlBarWidget->raise();
61 mp_controlBarWidget->setGeometry(0, 540, 800, 60);
62 // connect to the dBus interface provided by the control bar widget
63 mp_dBusDayNightMode_ControlBarWidget = new org::agl::daynightmode("org.agl.mainwindow",
65 QDBusConnection::sessionBus(),
69 MainWindow::~MainWindow()
71 delete mp_dBusDayNightMode_ControlBarWidget;
72 delete mp_dBusDayNightMode_StatusBarWidget;
74 if (0 == mp_dBusPopup)
78 if (0 != mp_popupWidget)
80 delete mp_popupWidget;
85 delete mp_popupAdaptor;
86 delete mp_daynightmodeAdaptor;
87 delete mp_statusBarWidget;
91 void MainWindow::setDayNightMode(int mode)
95 case SystemDayNight::DAYNIGHTMODE_DAY:
96 m_dayNightMode = SystemDayNight::DAYNIGHTMODE_DAY;
97 mp_ui->widget_Background->setStyleSheet(QString("background-image: url(:/images/backgrounds/bg_blue_day.png)"));
99 mp_ui->widget_Home_Icon->setStyleSheet(QString("border-image: url(:/icons/home_day.png) 0 0 0 0 stretch stretch;"));
102 case SystemDayNight::DAYNIGHTMODE_NIGHT:
103 m_dayNightMode = SystemDayNight::DAYNIGHTMODE_NIGHT;
104 mp_ui->widget_Background->setStyleSheet(QString("background-image: url(:/images/backgrounds/bg_blue_night.png)"));
106 mp_ui->widget_Home_Icon->setStyleSheet(QString("border-image: url(:/icons/home_night.png) 0 0 0 0 stretch stretch;"));
110 m_dayNightMode = SystemDayNight::DAYNIGHTMODE_UNDEFINED;
113 mp_dBusDayNightMode_StatusBarWidget->setDayNightMode(m_dayNightMode);
114 mp_dBusDayNightMode_ControlBarWidget->setDayNightMode(m_dayNightMode);
117 void MainWindow::showPopup(int type, const QString &text)
119 if (0 == mp_popupWidget)
121 qDebug("0 == mp_popupWidget");
122 mp_popupWidget = new PopupWidget(this);
125 mp_popupWidget->move(0, 0);
126 mp_popupWidget->show();
128 if (0 == mp_dBusPopup)
130 qDebug("0 == mp_dBusPopup");
131 // connect to the dBus interface provided by the popup widget
132 mp_dBusPopup = new org::agl::popup("org.agl.mainwindow",
134 QDBusConnection::sessionBus(),
137 mp_dBusPopup->showPopup(type, text);
140 void MainWindow::changeEvent(QEvent* event)
142 if (QEvent::LanguageChange == event->type())
144 mp_ui->retranslateUi(this);
147 QMainWindow::changeEvent(event);