perfmon/ui/hb/datapopup/src/perfmondatapopupwidget.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 <QPainter>
       
    19 
       
    20 #include "perfmondatapopupwidget_p.h"
       
    21 
       
    22 const qreal popupMargin = 5.;
       
    23 
       
    24 PerfMonDataPopupWidget::PerfMonDataPopupWidget(QGraphicsItem *parent) :
       
    25     HbWidget(parent)
       
    26 {
       
    27     HbFontSpec fontSpec(HbFontSpec::Secondary);
       
    28     mFont = fontSpec.font();
       
    29     mFont.setPixelSize(12);
       
    30 }
       
    31 
       
    32 QStringList PerfMonDataPopupWidget::lines() const
       
    33 {
       
    34     return mLines;
       
    35 }
       
    36 
       
    37 void PerfMonDataPopupWidget::setLines(const QStringList &lines)
       
    38 {
       
    39     mLines = lines;
       
    40     updateGeometry();
       
    41 }
       
    42 
       
    43 QSizeF PerfMonDataPopupWidget::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
       
    44 {
       
    45     if (which == Qt::PreferredSize)
       
    46     {
       
    47         QFontMetricsF metrics(mFont);
       
    48 
       
    49         qreal width = 0;
       
    50         foreach (const QString &line, mLines) {
       
    51             width = qMax(width, metrics.width(line));
       
    52         }
       
    53         qreal height = metrics.height() * mLines.length();
       
    54 
       
    55         return QSizeF(width + 2 * popupMargin, height + 2 * popupMargin);
       
    56     }
       
    57 
       
    58     return HbWidget::sizeHint(which, constraint);
       
    59 }
       
    60 
       
    61 void PerfMonDataPopupWidget::paint(QPainter *painter,
       
    62     const QStyleOptionGraphicsItem *option, QWidget *widget)
       
    63 {
       
    64     Q_UNUSED(widget);
       
    65     Q_UNUSED(option);
       
    66 
       
    67     QFontMetricsF metrics(mFont);
       
    68     qreal lineHeight = metrics.height();
       
    69     qreal verticalPos = lineHeight + popupMargin;
       
    70 
       
    71     // draw background
       
    72     painter->setBrush(Qt::white);
       
    73     painter->drawRect(option->rect);
       
    74 
       
    75     painter->setFont(mFont);
       
    76 
       
    77     foreach (const QString &line, mLines) {
       
    78         painter->drawText(QPointF(popupMargin, verticalPos), line);
       
    79         verticalPos += lineHeight;
       
    80     }
       
    81 
       
    82 }