-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathprojectproperties.cpp
More file actions
75 lines (56 loc) · 1.79 KB
/
Copy pathprojectproperties.cpp
File metadata and controls
75 lines (56 loc) · 1.79 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <QDomElement>
#include <QDomDocument>
#include <QPainter>
#include "projectproperties.h"
QDomElement ProjectProperties::toDomElement(QDomDocument &doc) const
{
QDomElement props = doc.createElement("properties");
QDomElement t = doc.createElement("title");
QDomText tval = doc.createTextNode(this->title);
t.appendChild(tval);
QDomElement n = doc.createElement("note");
QDomText nval = doc.createTextNode(this->note);
n.appendChild(nval);
props.appendChild(t);
props.appendChild(n);
return props;
}
void ProjectProperties::fromDomElement(const QDomElement &el)
{
QDomNodeList titles = el.elementsByTagName("title");
if (!titles.isEmpty()) {
QDomElement t = titles.at(0).toElement();
title = t.text();
}
QDomNodeList notes = el.elementsByTagName("note");
if (!notes.isEmpty()) {
QDomElement n = notes.at(0).toElement();
note = n.text();
}
}
void ProjectProperties::clear() {
title = "";
note = "";
}
qreal ProjectProperties::renderNote(QPainter *painter, const QRectF& area)
{
painter->drawRoundedRect(area.toRect(), 5, 5);
QFont orig = painter->font();
qreal textHeight = painter->fontMetrics().height();
QTextOption option(Qt::AlignLeft);
QRectF elementArea(area);
QFont font;
font.setPointSize(11);
font.setBold(false);
painter->setFont(font);
const int margins = 13; /* pixels */
qreal tab = area.left() + margins;
elementArea.moveTop(elementArea.y() + textHeight / 2.);
QRectF where = elementArea;
where.setX(elementArea.x() + tab / 2.);
/* note */
painter->drawText(where, this->note, option);
elementArea.moveTop(elementArea.y() + textHeight);
painter->setFont(orig);
return elementArea.y() + 3 * textHeight; /* next y */
}