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 "controlbarwidget.h"
18 #include "ui_controlbarwidget.h"
20 ControlBarWidget::ControlBarWidget(QWidget *parent) :
22 mp_ui(new Ui::ControlBarWidget),
24 mp_dBusDayNightMode_SettingsWidget(0),
25 m_dayNightMode(SystemDayNight::DAYNIGHTMODE_DAY), // TODO: read from system
26 mp_daynightmodeAdaptor(0)
28 // publish dbus day night mode interface
29 mp_daynightmodeAdaptor = new DaynightmodeAdaptor((QObject*)this);
30 QDBusConnection dbus = QDBusConnection::sessionBus();
31 dbus.registerObject("/ControlBarWidget", this);
32 dbus.registerService("org.agl.mainwindow");
37 ControlBarWidget::~ControlBarWidget()
39 delete mp_daynightmodeAdaptor;
40 if (0 != mp_settingsWidget)
42 delete mp_settingsWidget;
44 if (0 == mp_dBusDayNightMode_SettingsWidget)
46 delete mp_dBusDayNightMode_SettingsWidget;
51 void ControlBarWidget::setDayNightMode(int mode)
56 case SystemDayNight::DAYNIGHTMODE_DAY:
57 m_dayNightMode = SystemDayNight::DAYNIGHTMODE_DAY;
58 mp_ui->widget_Background->setStyleSheet(QString("background-image: url(:/images/backgrounds/bg_green_day.png)"));
60 icon.addFile(QStringLiteral(":/icons/home_day.png"), QSize(), QIcon::Normal, QIcon::Off);
61 mp_ui->pushButton_Home->setIcon(icon);
62 icon.addFile(QStringLiteral(":/icons/settings_day.png"), QSize(), QIcon::Normal, QIcon::Off);
63 mp_ui->pushButton_Settings->setIcon(icon);
65 case SystemDayNight::DAYNIGHTMODE_NIGHT:
66 m_dayNightMode = SystemDayNight::DAYNIGHTMODE_NIGHT;
67 mp_ui->widget_Background->setStyleSheet(QString("background-image: url(:/images/backgrounds/bg_green_night.png)"));
69 icon.addFile(QStringLiteral(":/icons/home_night.png"), QSize(), QIcon::Normal, QIcon::Off);
70 mp_ui->pushButton_Home->setIcon(icon);
71 icon.addFile(QStringLiteral(":/icons/settings_night.png"), QSize(), QIcon::Normal, QIcon::Off);
72 mp_ui->pushButton_Settings->setIcon(icon);
75 m_dayNightMode = SystemDayNight::DAYNIGHTMODE_UNDEFINED;
78 // settings widget if present
79 if (0 != mp_dBusDayNightMode_SettingsWidget)
81 mp_dBusDayNightMode_SettingsWidget->setDayNightMode(m_dayNightMode);
85 void ControlBarWidget::on_pushButton_Settings_clicked()
87 if (0 == mp_settingsWidget)
89 mp_settingsWidget = new SettingsWidget((QWidget*)parent());
92 mp_settingsWidget->move(0, 60);
93 mp_settingsWidget->show();
95 if (0 == mp_dBusDayNightMode_SettingsWidget)
97 // connect to the dBus interface provided by the settings widget
98 mp_dBusDayNightMode_SettingsWidget = new org::agl::daynightmode("org.agl.mainwindow",
100 QDBusConnection::sessionBus(),
102 mp_dBusDayNightMode_SettingsWidget->setDayNightMode(m_dayNightMode);
106 void ControlBarWidget::on_pushButton_Home_clicked()
108 if (0 != mp_settingsWidget)
110 mp_settingsWidget->hide();