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