51
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <QtDebug>
|
|
19 |
#include <QIcon>
|
|
20 |
#include <QVariant>
|
|
21 |
#include <QList>
|
|
22 |
#include <HbMainWindow>
|
|
23 |
|
|
24 |
#include "perfmondatapopupdialog_p.h"
|
|
25 |
#include "perfmondatapopuppluginerrors_p.h"
|
|
26 |
#include "perfmondatapopupwidget_p.h"
|
|
27 |
|
|
28 |
// Constructor
|
|
29 |
PerfMonDataPopupDialog::PerfMonDataPopupDialog(const QVariantMap ¶meters) :
|
|
30 |
mLastError(NoError),
|
|
31 |
mShowEventReceived(false),
|
|
32 |
mLocation(LocationTopRight),
|
|
33 |
mWidget(new PerfMonDataPopupWidget(this))
|
|
34 |
{
|
|
35 |
setTimeout(0);
|
|
36 |
setModal(false);
|
|
37 |
setDismissPolicy(HbPopup::NoDismiss);
|
|
38 |
setBackgroundItem(0);
|
|
39 |
setContentWidget(mWidget);
|
|
40 |
setBackgroundFaded(false);
|
|
41 |
|
|
42 |
setDeviceDialogParameters(parameters);
|
|
43 |
}
|
|
44 |
|
|
45 |
PerfMonDataPopupDialog::~PerfMonDataPopupDialog()
|
|
46 |
{
|
|
47 |
}
|
|
48 |
|
|
49 |
// Set parameters
|
|
50 |
bool PerfMonDataPopupDialog::setDeviceDialogParameters(const QVariantMap ¶meters)
|
|
51 |
{
|
|
52 |
if (parameters.contains("lines"))
|
|
53 |
{
|
|
54 |
QVariant lines = parameters.value("lines");
|
|
55 |
if (!lines.canConvert(QVariant::StringList)) {
|
|
56 |
mLastError = ParameterError;
|
|
57 |
return false;
|
|
58 |
}
|
|
59 |
|
|
60 |
setLines(lines.toStringList());
|
|
61 |
}
|
|
62 |
|
|
63 |
if (parameters.contains("location"))
|
|
64 |
{
|
|
65 |
QVariant location = parameters.value("location");
|
|
66 |
if (!location.canConvert<int>()) {
|
|
67 |
mLastError = ParameterError;
|
|
68 |
return false;
|
|
69 |
}
|
|
70 |
|
|
71 |
if (location.toInt() != LocationTopRight &&
|
|
72 |
location.toInt() != LocationBottomMiddle)
|
|
73 |
{
|
|
74 |
mLastError = ParameterError;
|
|
75 |
return false;
|
|
76 |
}
|
|
77 |
|
|
78 |
setLocation(static_cast<Location>(location.toInt()));
|
|
79 |
}
|
|
80 |
update();
|
|
81 |
return true;
|
|
82 |
}
|
|
83 |
|
|
84 |
// Get error
|
|
85 |
int PerfMonDataPopupDialog::deviceDialogError() const
|
|
86 |
{
|
|
87 |
return mLastError;
|
|
88 |
}
|
|
89 |
|
|
90 |
// Close device dialog
|
|
91 |
void PerfMonDataPopupDialog::closeDeviceDialog(bool byClient)
|
|
92 |
{
|
|
93 |
Q_UNUSED(byClient);
|
|
94 |
close();
|
|
95 |
// If show event has been received, close is signalled from hide event. If not,
|
|
96 |
// hide event does not come and close is signalled from here.
|
|
97 |
if (!mShowEventReceived) {
|
|
98 |
emit deviceDialogClosed();
|
|
99 |
}
|
|
100 |
}
|
|
101 |
|
|
102 |
// Return display widget
|
|
103 |
HbPopup *PerfMonDataPopupDialog::deviceDialogWidget() const
|
|
104 |
{
|
|
105 |
return const_cast<PerfMonDataPopupDialog*>(this);
|
|
106 |
}
|
|
107 |
|
|
108 |
// Widget is about to hide. Closing effect has ended.
|
|
109 |
void PerfMonDataPopupDialog::hideEvent(QHideEvent *event)
|
|
110 |
{
|
|
111 |
if (mainWindow()) {
|
|
112 |
disconnect(mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
|
|
113 |
this, SLOT(reposition()));
|
|
114 |
}
|
|
115 |
HbPopup::hideEvent(event);
|
|
116 |
emit deviceDialogClosed();
|
|
117 |
}
|
|
118 |
|
|
119 |
// Widget is about to show
|
|
120 |
void PerfMonDataPopupDialog::showEvent(QShowEvent *event)
|
|
121 |
{
|
|
122 |
if (mainWindow()) {
|
|
123 |
connect(mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
|
|
124 |
this, SLOT(reposition()));
|
|
125 |
}
|
|
126 |
reposition();
|
|
127 |
HbPopup::showEvent(event);
|
|
128 |
mShowEventReceived = true;
|
|
129 |
}
|
|
130 |
|
|
131 |
|
|
132 |
void PerfMonDataPopupDialog::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
133 |
{
|
|
134 |
Q_UNUSED(event);
|
|
135 |
|
|
136 |
QVariantMap data;
|
|
137 |
data["mouseEvent"] = "press";
|
|
138 |
emit deviceDialogData(data);
|
|
139 |
}
|
|
140 |
|
|
141 |
|
|
142 |
PerfMonDataPopupDialog::Location PerfMonDataPopupDialog::location() const
|
|
143 |
{
|
|
144 |
return mLocation;
|
|
145 |
}
|
|
146 |
|
|
147 |
void PerfMonDataPopupDialog::setLocation(Location location)
|
|
148 |
{
|
|
149 |
if (location != mLocation) {
|
|
150 |
mLocation = location;
|
|
151 |
reposition();
|
|
152 |
}
|
|
153 |
}
|
|
154 |
|
|
155 |
QStringList PerfMonDataPopupDialog::lines() const
|
|
156 |
{
|
|
157 |
return mWidget->lines();
|
|
158 |
}
|
|
159 |
|
|
160 |
void PerfMonDataPopupDialog::setLines(const QStringList &lines)
|
|
161 |
{
|
|
162 |
mWidget->setLines(lines);
|
|
163 |
}
|
|
164 |
|
|
165 |
void PerfMonDataPopupDialog::reposition()
|
|
166 |
{
|
|
167 |
if (mainWindow()) {
|
|
168 |
QSize screenSize = HbDeviceProfile::profile(mainWindow()).logicalSize();
|
|
169 |
switch (mLocation) {
|
|
170 |
case LocationTopRight:
|
|
171 |
setPreferredPos(QPointF(screenSize.width(), 0),
|
|
172 |
HbPopup::TopRightCorner);
|
|
173 |
break;
|
|
174 |
|
|
175 |
case LocationBottomMiddle:
|
|
176 |
setPreferredPos(QPointF(screenSize.width() / 2, screenSize.height()),
|
|
177 |
HbPopup::BottomEdgeCenter);
|
|
178 |
break;
|
|
179 |
}
|
|
180 |
}
|
|
181 |
}
|