perfmon/ui/hb/app/src/valuedatacontainer.cpp
branchRCL_3
changeset 19 b3cee849fa46
equal deleted inserted replaced
18:48060abbbeaf 19:b3cee849fa46
       
     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 "valuedatacontainer.h"
       
    19 #include "enginewrapper.h"
       
    20 
       
    21 #include <QGraphicsLinearLayout>
       
    22 #include <QPalette>
       
    23 #include <QPainter>
       
    24 #include <HbColorScheme>
       
    25 
       
    26 const int leftMargin = 2;
       
    27 
       
    28 ValueDataContainer::ValueDataContainer(const EngineWrapper& engine, QGraphicsItem *parent) :
       
    29     DataContainer(engine, parent)
       
    30 {
       
    31     HbFontSpec spec(HbFontSpec::Secondary);
       
    32     mFont = spec.font();
       
    33 }
       
    34 
       
    35 void ValueDataContainer::paint (QPainter *painter,
       
    36     const QStyleOptionGraphicsItem *option,
       
    37     QWidget *widget)
       
    38 {
       
    39     Q_UNUSED(option);
       
    40     Q_UNUSED(widget);
       
    41 
       
    42     // set proper font and prepare font metrics for text height calculation
       
    43     painter->setFont(mFont);
       
    44 
       
    45     QColor col = HbColorScheme::color("qtc_textedit_normal");
       
    46     if(col.isValid())
       
    47         painter->setPen(col);
       
    48     
       
    49     QFontMetricsF metrics(mFont);
       
    50 
       
    51     QList<SampleEntry> entries = engine().sampleEntries();
       
    52     int c = 1;
       
    53 
       
    54     for (int i=0; i<entries.length(); i++)
       
    55     {
       
    56         const SampleEntry &entry = entries.at(i);
       
    57 
       
    58         if (entry.sampleCount() == 0)
       
    59             continue;
       
    60 
       
    61         const SampleData &sample = entry.sample(0);
       
    62 
       
    63         if (i == 0)
       
    64         {
       
    65             // CPU
       
    66             double perc = sample.mSize > 0 ?
       
    67                           100. - 100. * sample.mFree / sample.mSize : 0;
       
    68 
       
    69 
       
    70             QString text = tr("%1 %2%").arg(entry.description()).
       
    71                            arg(perc, 0, 'f', 0);
       
    72             painter->drawText(QPointF(leftMargin, c * metrics.height()), text);
       
    73             c++;
       
    74         }
       
    75         else if (sample.mSize > 0)
       
    76         {
       
    77             // RAM and Drives
       
    78             QString text = tr("%1 free %L2%3").arg(entry.description()).
       
    79                            arg(sample.mFree).arg(entry.unitShort());
       
    80             painter->drawText(QPointF(leftMargin, c * metrics.height()), text);
       
    81             c++;
       
    82 
       
    83             text = tr("%1 size %L2%3").arg(entry.description()).
       
    84                    arg(sample.mSize).arg(entry.unitShort());
       
    85             painter->drawText(QPointF(leftMargin, c * metrics.height()), text);
       
    86             c++;
       
    87         }
       
    88     }
       
    89 }