UASQuickViewTextItem.cc 1.95 KB
Newer Older
1 2 3 4
#include "UASQuickViewTextItem.h"
#include <QVBoxLayout>
UASQuickViewTextItem::UASQuickViewTextItem(QWidget *parent) : UASQuickViewItem(parent)
{
5 6
    // Set a standard vertical layout.
    QVBoxLayout* layout = new QVBoxLayout();
7
    layout->setMargin(0);
8 9 10
    layout->setSizeConstraint(QLayout::SetMinimumSize);

    // Create the title label. Scale the font based on available size.
11 12
    titleLabel = new QLabel(this);
    titleLabel->setAlignment(Qt::AlignHCenter);
13 14 15 16 17 18 19 20
    titleLabel->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Minimum);
    titleLabel->setObjectName(QString::fromUtf8("title"));
    QFont titlefont = titleLabel->font();
    titlefont.setPixelSize(this->height() / 4.0);
    titleLabel->setFont(titlefont);
    layout->addWidget(titleLabel);

    // Create the value label. Scale the font based on available size.
21 22
    valueLabel = new QLabel(this);
    valueLabel->setAlignment(Qt::AlignHCenter);
23 24
    valueLabel->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Minimum);
    valueLabel->setObjectName(QString::fromUtf8("value"));
25 26 27 28
    valueLabel->setText("0.00");
    QFont valuefont = valueLabel->font();
    valuefont.setPixelSize(this->height() / 2.0);
    valueLabel->setFont(valuefont);
29 30 31 32 33
    layout->addWidget(valueLabel);

    // And make sure the items are evenly spaced in the UASQuickView.
    layout->addSpacerItem(new QSpacerItem(20, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));
    this->setLayout(layout);
34 35 36
}
void UASQuickViewTextItem::setValue(double value)
{
37
    valueLabel->setText(QString::number(value,'f',4));
38 39 40 41 42 43
}

void UASQuickViewTextItem::setTitle(QString title)
{
    titleLabel->setText(title);
}
44 45 46 47 48 49 50 51 52 53
void UASQuickViewTextItem::resizeEvent(QResizeEvent *event)
{
    QFont valuefont = valueLabel->font();
    QFont titlefont = titleLabel->font();
    valuefont.setPixelSize(this->height() / 2.0);
    titlefont.setPixelSize(this->height() / 4.0);
    valueLabel->setFont(valuefont);
    titleLabel->setFont(titlefont);
    update();
}