~ubuntu-branches/debian/sid/qspeakers/sid

« back to all changes in this revision

Viewing changes to sealedbox.cpp

  • Committer: Package Import Robot
  • Author(s): Benoît Rouits
  • Date: 2016-10-25 21:23:27 UTC
  • Revision ID: package-import@ubuntu.com-20161025212327-oyyitrn6c9ac6706
Tags: upstream-1.0
Import upstream version 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <QLocale>
 
2
#include <QDebug>
 
3
 
 
4
#include "sealedbox.h"
 
5
 
 
6
SealedBox::SealedBox(double vol)
 
7
{
 
8
    volume = vol;
 
9
}
 
10
 
 
11
void SealedBox::setVolume(double vol)
 
12
{
 
13
    volume = vol;
 
14
}
 
15
 
 
16
double SealedBox::getVolume() const
 
17
{
 
18
    return volume;
 
19
}
 
20
 
 
21
QDomElement SealedBox::toDomElement(QDomDocument& doc) const
 
22
{
 
23
    QDomElement e = Box::toDomElement(doc);
 
24
    e.setAttribute("type", "sealed");
 
25
 
 
26
    QLocale c(QLocale::C);
 
27
    e.setAttribute("volume", c.toString(volume));
 
28
 
 
29
    return e;
 
30
}
 
31
 
 
32
void SealedBox::fromDomElement(const QDomElement &e)
 
33
{
 
34
    Box::fromDomElement(e);
 
35
    if (e.attribute("type") != "sealed") {
 
36
        qWarning() << __func__ << "wrong box type! (not sealed, giving up)";
 
37
        return;
 
38
    }
 
39
 
 
40
    QLocale c(QLocale::C);
 
41
    volume = c.toDouble(e.attribute("volume"));
 
42
}
 
43
 
 
44
void SealedBox::render(QPainter *painter, const QRectF &area)
 
45
{    
 
46
    if (!painter)
 
47
        return;
 
48
 
 
49
    painter->drawRoundRect(area.toRect(), 5, 5);
 
50
 
 
51
    QString text = QObject::tr("Vol. %1 L").arg(getVolume());
 
52
    QRectF where(area.left(), area.top(), area.width(), area.height());
 
53
    QTextOption option(Qt::AlignVCenter|Qt::AlignLeft);
 
54
    painter->drawText(where, text, option);
 
55
}