13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
|
18 #include <HbMainWindow> |
18 #include <HbView> |
19 #include <HbView> |
19 #include <HbEvent> |
20 #include <HbEvent> |
20 #include <QFontMetrics> |
21 #include <QFontMetrics> |
21 |
22 |
22 #include "datapopup.h" |
23 #include "datapopup.h" |
23 #include "enginewrapper.h" |
24 #include "enginewrapper.h" |
24 #include "popupdatacontainer.h" |
25 #include "popupdatacontainer.h" |
25 |
26 |
26 DataPopup::DataPopup(EngineWrapper &engine) : |
27 DataPopup::DataPopup(EngineWrapper &engine, HbMainWindow &mainWindow) : |
27 mEngine(engine), |
28 mEngine(engine), |
|
29 mMainWindow(mainWindow), |
28 mPopupCreated(false), |
30 mPopupCreated(false), |
29 mPopupVisible(false) |
31 mPopupVisible(false) |
30 { |
32 { |
31 connect(&mEngine, SIGNAL(samplesUpdated()), this, SLOT(updateSamples())); |
33 connect(&mEngine, SIGNAL(samplesUpdated()), this, SLOT(updateSamples())); |
32 connect(&mEngine, SIGNAL(settingsUpdated()), this, SLOT(updateSettings())); |
34 connect(&mEngine, SIGNAL(settingsUpdated()), this, SLOT(updateSettings())); |
33 connect(this, SIGNAL(dataReceived(QVariantMap)), this, SLOT(triggerAction(QVariantMap))); |
35 connect(this, SIGNAL(dataReceived(QVariantMap)), this, SLOT(triggerAction(QVariantMap))); |
|
36 connect(&mainWindow, SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(orientationChanged(Qt::Orientation))); |
|
37 connect(&mainWindow, SIGNAL(obscured()), this, SLOT(inBackground())); |
|
38 connect(&mainWindow, SIGNAL(revealed()), this, SLOT(inForeground())); |
34 } |
39 } |
35 |
40 |
36 void DataPopup::show() |
41 void DataPopup::show() |
37 { |
42 { |
38 mPopupVisible = true; |
43 mPopupVisible = true; |
64 updateData(); |
69 updateData(); |
65 } |
70 } |
66 |
71 |
67 void DataPopup::updateSettings() |
72 void DataPopup::updateSettings() |
68 { |
73 { |
69 // mEngine.settings().dataPopupVisibility can only be changed from |
74 updateVisibility(!mMainWindow.isObscured()); |
70 // main window, so we may assume the window is in foreground |
|
71 updateVisibility(true); |
|
72 updateData(); |
75 updateData(); |
73 } |
76 } |
74 |
77 |
75 void DataPopup::updateVisibility(bool foreground) |
78 void DataPopup::updateVisibility(bool foreground) |
76 { |
79 { |
77 if (mEngine.settings().dataPopupVisibility() == EDataPopupVisbilityAlwaysOn || |
80 if (mEngine.settings().dataPopupVisibility() == EDataPopupVisbilityAlwaysOn || |
78 (mEngine.settings().dataPopupVisibility() == EDataPopupVisbilityBackgroundOnly && !foreground)) { |
81 (mEngine.settings().dataPopupVisibility() == EDataPopupVisbilityBackgroundOnly && !foreground)) { |
79 |
|
80 show(); |
82 show(); |
81 } else { |
83 } else { |
82 hide(); |
84 hide(); |
83 } |
85 } |
84 } |
86 } |
85 |
87 |
86 void DataPopup::triggerAction(QVariantMap data) |
88 void DataPopup::triggerAction(QVariantMap data) |
87 { |
89 { |
88 if (data.contains("mouseEvent") && data["mouseEvent"].toString() == "press") { |
90 if (data.contains("mouseEvent") && data["mouseEvent"].toString() == "press") { |
89 emit clicked(); |
|
90 |
|
91 // data popup was clicked, move it to other position |
91 // data popup was clicked, move it to other position |
|
92 hide(); |
|
93 |
92 mEngine.settings().setDataPopupLocation( |
94 mEngine.settings().setDataPopupLocation( |
93 EDataPopupLocationBottomMiddle - mEngine.settings().dataPopupLocation()); |
95 EDataPopupLocationBottomMiddle - mEngine.settings().dataPopupLocation()); |
94 mEngine.updateSettings(); |
96 mEngine.updateSettings(); |
|
97 |
|
98 show(); |
95 } |
99 } |
96 } |
100 } |
97 |
101 |
98 QVariantMap DataPopup::collectParams() const |
102 QVariantMap DataPopup::collectParams() const |
99 { |
103 { |
173 show(); |
177 show(); |
174 } else { |
178 } else { |
175 HbDeviceDialog::update(collectParams()); |
179 HbDeviceDialog::update(collectParams()); |
176 } |
180 } |
177 } |
181 } |
|
182 |
|
183 void DataPopup::orientationChanged(Qt::Orientation /*newOrientation*/) |
|
184 { |
|
185 // force the reposition of the window |
|
186 if( mEngine.settings().dataPopupVisibility() == EDataPopupVisbilityAlwaysOn || |
|
187 (mEngine.settings().dataPopupVisibility() == EDataPopupVisbilityBackgroundOnly && mMainWindow.isObscured()) ) { |
|
188 hide(); |
|
189 show(); |
|
190 } |
|
191 } |
|
192 |
|
193 void DataPopup::inForeground() |
|
194 { |
|
195 updateVisibility(true); |
|
196 } |
|
197 |
|
198 void DataPopup::inBackground() |
|
199 { |
|
200 updateVisibility(false); |
|
201 } |