-
Notifications
You must be signed in to change notification settings - Fork 13
/
atom_info.cpp
54 lines (45 loc) · 1.54 KB
/
atom_info.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
#include "atom_info.h"
#include <poincare/integer.h>
#include <poincare/number.h>
namespace Atomic {
atomInfo::atomInfo() :
View(),
m_atomName(KDFont::SmallFont)
{
}
void atomInfo::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(rect, KDColorWhite);
char protons[4];
char nucleons[4];
char mass[12];
Poincare::Integer(m_atom.num).serialize(protons, 4);
Poincare::Integer(m_atom.neutrons + m_atom.num).serialize(nucleons, 4);
Poincare::Number::FloatNumber(m_atom.mass).serialize(mass, 12, Poincare::Preferences::PrintFloatMode::Decimal, 12);
KDPoint coordonates(bounds().topLeft());
ctx->drawString(nucleons, coordonates, KDFont::SmallFont);
coordonates = KDPoint(coordonates.x(), coordonates.y() + 14);
ctx->drawString(protons, coordonates, KDFont::SmallFont);
coordonates = KDPoint(bounds().left() + 23, bounds().top() + 6);
ctx->drawString(m_atom.symbol, coordonates);
coordonates = KDPoint(bounds().left() + 60, bounds().top() + 13);
ctx->drawString(mass, coordonates, KDFont::SmallFont);
}
int atomInfo::numberOfSubviews() const {
return 1;
}
View * atomInfo::subviewAtIndex(int index) {
assert(index == 0);
return &m_atomName;
}
void atomInfo::layoutSubviews(bool force) {
m_atomName.setFrame(KDRect(KDPoint(60, 0), KDSize(bounds().width() - 60, KDFont::SmallFont->glyphSize().height())), force);
}
void atomInfo::setAtom(AtomDef atom) {
m_atom = atom;
m_atomName.setMessage(atom.name);
markRectAsDirty(bounds());
}
KDSize atomInfo::minimalSizeForOptimalDisplay() const {
return KDSize(150, 40);
}
}