81ffdf7bd15b20767b1f0f130f664ff4368f1e74
[staging/HomeScreen.git] / HomeScreen / src / popupwidget.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 "popupwidget.h"
18 #include "ui_popupwidget.h"
19
20 PopupWidget::PopupWidget(QWidget *parent) :
21     QWidget(parent),
22     mp_ui(new Ui::PopupWidget),
23     m_dayNightMode(SystemDayNight::DAYNIGHTMODE_DAY), // TODO: read from system
24     mp_dayNightModeProxy(0),
25     mp_popupAdaptor(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     // publish dbus popup interface
35     mp_popupAdaptor = new PopupAdaptor((QObject*)this);
36     QDBusConnection dbus = QDBusConnection::sessionBus();
37     dbus.registerObject("/Popup", this);
38     dbus.registerService("org.agl.homescreen");
39
40     mp_ui->setupUi(this);
41     this->close();
42 }
43
44 PopupWidget::~PopupWidget()
45 {
46     delete mp_dayNightModeProxy;
47     delete mp_popupAdaptor;
48     delete mp_ui;
49 }
50
51 void PopupWidget::dayNightModeSlot(int mode)
52 {
53     switch (mode)
54     {
55     case SystemDayNight::DAYNIGHTMODE_DAY:
56         m_dayNightMode = SystemDayNight::DAYNIGHTMODE_DAY;
57         mp_ui->widget_Popup->setStyleSheet(QString("QWidget { \
58                                                    border: 1px solid #D3D3D3; \
59                                                    border-radius: 8px; \
60                                                    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)); \
61                                                    color: #333; \
62                                                    padding: 0px; \
63                                                    }  \
64                                                    QWidget:on { \
65                                                    background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #D5D5D5, stop: 1 #EEEEEE); \
66                                                    }"));
67         mp_ui->label_Text->setStyleSheet(QString("background-color: rgba(109, 109, 109, 0); \
68                                                  background-image: url(:/images/transparency.png); \
69                                                  border-image: url(:/images/transparency.png);"));
70         break;
71     case SystemDayNight::DAYNIGHTMODE_NIGHT:
72         m_dayNightMode = SystemDayNight::DAYNIGHTMODE_NIGHT;
73         mp_ui->widget_Popup->setStyleSheet(QString("QWidget { \
74                                                    border: 1px solid #D3D3D3; \
75                                                    border-radius: 8px; \
76                                                    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)); \
77                                                    color: #333; \
78                                                    padding: 0px; \
79                                                    }  \
80                                                    QWidget:on { \
81                                                    background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #D5D5D5, stop: 1 #EEEEEE); \
82                                                    }"));
83         mp_ui->label_Text->setStyleSheet(QString("background-color: rgba(109, 109, 109, 0); \
84                                                  background-image: url(:/images/transparency.png); \
85                                                  border-image: url(:/images/transparency.png);"));
86         break;
87     default:
88         m_dayNightMode = SystemDayNight::DAYNIGHTMODE_UNDEFINED;
89     }
90 }
91
92 void PopupWidget::showPopup(int type, const QString &text)
93 {
94     this->show();
95     this->raise();
96     qDebug("PopupWidget::showPopup: type %d, text %s", type, text.toStdString().c_str());
97     mp_ui->label_Text->setText(text);
98 }
99
100 void PopupWidget::on_pushButton_OK_clicked()
101 {
102     this->close();
103 }