perfapps/perfmon/ui/hb/app/src/valuedatacontainer.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 "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     // CPUs
       
    55     for (int i = const_cast<EngineWrapper&>( engine() ).CPU0PositionInSamples();
       
    56             i < const_cast<EngineWrapper&>( engine() ).CPU0PositionInSamples() +
       
    57                 const_cast<EngineWrapper&>( engine() ).AmountOfCPUs(); i++)
       
    58     {
       
    59         // check if data available
       
    60         const SampleEntry &entry = entries.at(i);
       
    61 
       
    62         if (entry.sampleCount() == 0)
       
    63             continue;
       
    64 
       
    65         const SampleData &sample = entry.sample(0);
       
    66 
       
    67         double perc = sample.mSize > 0 ?
       
    68                       100. - 100. * sample.mFree / sample.mSize : 0;
       
    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 
       
    76     // RAM and drives
       
    77     for (int i = const_cast<EngineWrapper&>( engine() ).RAMPositionInSamples();
       
    78             i < const_cast<EngineWrapper&>( engine() ).PowerPositionInSamples(); i++)
       
    79     {
       
    80         // check if data available
       
    81         const SampleEntry &entry = entries.at(i);
       
    82 
       
    83         if (entry.sampleCount() == 0)
       
    84             continue;
       
    85 
       
    86         const SampleData &sample = entry.sample(0);
       
    87 
       
    88         if (sample.mSize > 0)
       
    89         {
       
    90             // RAM and Drives
       
    91             QString text = tr("%1 free %L2%3").arg(entry.description()).
       
    92                            arg(sample.mFree).arg(entry.unitShort());
       
    93             painter->drawText(QPointF(leftMargin, c * metrics.height()), text);
       
    94             c++;
       
    95 
       
    96             text = tr("%1 size %L2%3").arg(entry.description()).
       
    97                    arg(sample.mSize).arg(entry.unitShort());
       
    98             painter->drawText(QPointF(leftMargin, c * metrics.height()), text);
       
    99             c++;
       
   100         }
       
   101     }
       
   102     
       
   103     // Power sample
       
   104     // check if data available
       
   105     const SampleEntry &entry = entries.at(const_cast<EngineWrapper&>( engine() ).PowerPositionInSamples());
       
   106 
       
   107     if (entry.sampleCount() > 0)
       
   108     {
       
   109         const SampleData &sample = entry.sample(0);
       
   110 
       
   111         if (sample.mSize > 0)
       
   112         {
       
   113             QString text = tr("%1 %L2%3").arg(entry.description()).
       
   114                     arg(sample.mSize - sample.mFree).arg(entry.unitShort());
       
   115             painter->drawText(QPointF(leftMargin, c * metrics.height()), text);
       
   116             c++;
       
   117         }
       
   118     }
       
   119 }