perfmon/ui/hb/datapopup/src/perfmondatapopupdialog.cpp
changeset 48 da3ec8478e66
parent 47 11fa016241a4
child 54 9347c563e054
equal deleted inserted replaced
47:11fa016241a4 48:da3ec8478e66
     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 &parameters) :
       
    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 
       
    41     setDeviceDialogParameters(parameters);
       
    42 }
       
    43 
       
    44 PerfMonDataPopupDialog::~PerfMonDataPopupDialog()
       
    45 {
       
    46 }
       
    47 
       
    48 // Set parameters
       
    49 bool PerfMonDataPopupDialog::setDeviceDialogParameters(const QVariantMap &parameters)
       
    50 {
       
    51     if (parameters.contains("lines"))
       
    52     {
       
    53         QVariant lines = parameters.value("lines");
       
    54         if (!lines.canConvert(QVariant::StringList)) {
       
    55             mLastError = ParameterError;
       
    56             return false;
       
    57         }
       
    58 
       
    59         setLines(lines.toStringList());
       
    60     }
       
    61 
       
    62     if (parameters.contains("location"))
       
    63     {
       
    64         QVariant location = parameters.value("location");
       
    65         if (!location.canConvert<int>()) {
       
    66             mLastError = ParameterError;
       
    67             return false;
       
    68         }
       
    69 
       
    70         if (location.toInt() != LocationTopRight &&
       
    71             location.toInt() != LocationBottomMiddle)
       
    72         {
       
    73             mLastError = ParameterError;
       
    74             return false;
       
    75         }
       
    76 
       
    77         setLocation(static_cast<Location>(location.toInt()));
       
    78     }
       
    79     return true;
       
    80 }
       
    81 
       
    82 // Get error
       
    83 int PerfMonDataPopupDialog::deviceDialogError() const
       
    84 {
       
    85     return mLastError;
       
    86 }
       
    87 
       
    88 // Close device dialog
       
    89 void PerfMonDataPopupDialog::closeDeviceDialog(bool byClient)
       
    90 {
       
    91     Q_UNUSED(byClient);
       
    92     close();
       
    93     // If show event has been received, close is signalled from hide event. If not,
       
    94     // hide event does not come and close is signalled from here.
       
    95     if (!mShowEventReceived) {
       
    96         emit deviceDialogClosed();
       
    97     }
       
    98 }
       
    99 
       
   100 // Return display widget
       
   101 HbPopup *PerfMonDataPopupDialog::deviceDialogWidget() const
       
   102 {
       
   103     return const_cast<PerfMonDataPopupDialog*>(this);
       
   104 }
       
   105 
       
   106 // Widget is about to hide. Closing effect has ended.
       
   107 void PerfMonDataPopupDialog::hideEvent(QHideEvent *event)
       
   108 {
       
   109     if (mainWindow()) {
       
   110         disconnect(mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
       
   111                    this, SLOT(reposition()));
       
   112     }
       
   113     HbPopup::hideEvent(event);
       
   114     emit deviceDialogClosed();
       
   115 }
       
   116 
       
   117 // Widget is about to show
       
   118 void PerfMonDataPopupDialog::showEvent(QShowEvent *event)
       
   119 {
       
   120     if (mainWindow()) {
       
   121         connect(mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)),
       
   122                 this, SLOT(reposition()));
       
   123     }
       
   124     reposition();
       
   125     HbPopup::showEvent(event);
       
   126     mShowEventReceived = true;
       
   127 }
       
   128 
       
   129 
       
   130 void PerfMonDataPopupDialog::mousePressEvent(QGraphicsSceneMouseEvent *event)
       
   131 {
       
   132     Q_UNUSED(event);
       
   133 
       
   134     QVariantMap data;
       
   135     data["mouseEvent"] = "press";
       
   136     emit deviceDialogData(data);
       
   137 }
       
   138 
       
   139 
       
   140 PerfMonDataPopupDialog::Location PerfMonDataPopupDialog::location() const
       
   141 {
       
   142     return mLocation;
       
   143 }
       
   144 
       
   145 void PerfMonDataPopupDialog::setLocation(Location location)
       
   146 {
       
   147     if (location != mLocation) {
       
   148         mLocation = location;
       
   149         reposition();
       
   150     }
       
   151 }
       
   152 
       
   153 QStringList PerfMonDataPopupDialog::lines() const
       
   154 {
       
   155     return mWidget->lines();
       
   156 }
       
   157 
       
   158 void PerfMonDataPopupDialog::setLines(const QStringList &lines)
       
   159 {
       
   160     mWidget->setLines(lines);
       
   161 }
       
   162 
       
   163 void PerfMonDataPopupDialog::reposition()
       
   164 {
       
   165     if (mainWindow()) {
       
   166         QSize screenSize = HbDeviceProfile::profile(mainWindow()).logicalSize();
       
   167         switch (mLocation) {
       
   168             case LocationTopRight:
       
   169                 setPreferredPos(QPointF(screenSize.width(), 0),
       
   170                                 HbPopup::TopRightCorner);
       
   171                 break;
       
   172 
       
   173             case LocationBottomMiddle:
       
   174                 setPreferredPos(QPointF(screenSize.width() / 2, screenSize.height()),
       
   175                                 HbPopup::BottomEdgeCenter);
       
   176                 break;
       
   177         }
       
   178     }
       
   179 }