/[qspeakers]/sealedbox.cpp
ViewVC logotype

Contents of /sealedbox.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 97 - (show annotations)
Thu May 7 22:54:16 2015 UTC (2 years, 1 month ago) by ben
File size: 1173 byte(s)
improve printing, current tab only
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 }

  ViewVC Help
Powered by ViewVC 1.1.26