perfapps/perfmon/ui/hb/app/src/popupdatacontainer.cpp
changeset 51 b048e15729d6
equal deleted inserted replaced
44:5db69f4c3d06 51:b048e15729d6
       
     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 "popupdatacontainer.h"
       
    19 #include "enginewrapper.h"
       
    20 
       
    21 #include <QGraphicsLinearLayout>
       
    22 #include <HbLabel>
       
    23 #include <QPainter>
       
    24 
       
    25 const int leftMargin = 2;
       
    26 
       
    27 PopupDataContainer::PopupDataContainer(const EngineWrapper& engine, QGraphicsItem *parent) :
       
    28     DataContainer(engine, parent)
       
    29 {
       
    30     connect(&engine, SIGNAL(samplesUpdated()), this, SLOT(samplesUpdated()));
       
    31 
       
    32     HbFontSpec spec(HbFontSpec::Secondary);
       
    33     mFont = spec.font();
       
    34     mFont.setPixelSize(12);
       
    35     
       
    36 }
       
    37 
       
    38 void PopupDataContainer::samplesUpdated()
       
    39 {
       
    40     update();
       
    41 }
       
    42 
       
    43 void PopupDataContainer::paint (QPainter *painter,
       
    44     const QStyleOptionGraphicsItem *option,
       
    45     QWidget *widget)
       
    46 {
       
    47     Q_UNUSED(option);
       
    48     Q_UNUSED(widget);
       
    49 
       
    50     // set proper font and prepare font metrics for text height calculation
       
    51     painter->setFont(mFont);
       
    52     QFontMetricsF metrics(mFont);
       
    53 
       
    54     QList<SampleEntry> entries = engine().sampleEntries();
       
    55     qreal verticalPos = metrics.height();
       
    56 
       
    57     for (int i=0; i<entries.length(); i++)
       
    58     {
       
    59         if (engine().settings().dataPopupSources().isEnabled(i) &&
       
    60             entries.at(i).sampleCount() > 0)
       
    61         {
       
    62             const SampleEntry &entry = entries.at(i);
       
    63             const SampleData &sample = entry.sample(0);
       
    64 
       
    65             if (i == ESourceCPU)
       
    66             {
       
    67                 // CPU
       
    68                 double perc = sample.mSize > 0 ?
       
    69                               100. - 100. * sample.mFree / sample.mSize : 0;
       
    70 
       
    71 
       
    72                 QString text = tr("%1 %2%").arg(entry.description()).
       
    73                                arg(perc, 0, 'f', 2);
       
    74                 painter->drawText(QPointF(leftMargin, verticalPos), text);
       
    75             }
       
    76             else if (i == ESourcePwr)
       
    77             {
       
    78                 // Power
       
    79                 QString text = tr("%1 %L2%3").arg(entry.description()).
       
    80                                arg(sample.mSize - sample.mFree).arg(entry.unitShort());
       
    81                 painter->drawText(QPointF(leftMargin, verticalPos), text);
       
    82             }
       
    83             else
       
    84             {
       
    85                 // RAM and Drives
       
    86                 QString text = tr("%1 free %L2%3").arg(entry.description()).
       
    87                                arg(sample.mFree).arg(entry.unitShort());
       
    88                 painter->drawText(QPointF(leftMargin, verticalPos), text);
       
    89             }
       
    90 
       
    91             verticalPos += metrics.height();
       
    92         }
       
    93     }
       
    94 }