-
Notifications
You must be signed in to change notification settings - Fork 13
/
atomic_cell.cpp
75 lines (62 loc) · 2.32 KB
/
atomic_cell.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "atomic_cell.h"
#include <assert.h>
namespace Atomic {
AtomicCell::AtomicCell() :
HighlightCell(),
m_visible(true)
{
}
KDColor AtomicCell::colorForType(AtomType type) const {
switch(type) {
case AtomType::UNKNOWN : {return KDColor::RGB24(0xeeeeee);}
case AtomType::ALKALI_METAL : {return KDColor::RGB24(0xffaa00);}
case AtomType::ALKALI_EARTH_METAL : {return KDColor::RGB24(0xf6f200);}
case AtomType::LANTHANIDE : {return KDColor::RGB24(0xffaa8b);}
case AtomType::ACTINIDE : {return KDColor::RGB24(0xdeaacd);}
case AtomType::TRANSITION_METAL : {return KDColor::RGB24(0xde999c);}
case AtomType::POST_TRANSITION_METAL : {return KDColor::RGB24(0x9cbaac);}
case AtomType::METALLOID : {return KDColor::RGB24(0x52ce8b);}
case AtomType::HALOGEN : {return KDColor::RGB24(0x00debd);}
case AtomType::REACTIVE_NONMETAL : {return KDColor::RGB24(0x00ee00);}
case AtomType::NOBLE_GAS : {return KDColor::RGB24(0x8baaff);}
default: {assert(false); return KDColorBlack;}
}
}
void AtomicCell::drawRect(KDContext * ctx, KDRect rect) const {
if(m_visible) {
KDColor color = colorForType(m_atom.type);
ctx->fillRect(rect, color);
KDPoint textPosition(bounds().topLeft().x() + 2, bounds().topLeft().y() + 2);
ctx->drawString(m_atom.symbol, textPosition, KDFont::SmallFont, KDColorBlack, color);
if(isHighlighted()) {
KDColor highlighColor = KDColor::blend(color, KDColorBlack, 0x7F);
ctx->strokeRect(bounds(), highlighColor);
KDRect rect2(bounds().topLeft().x() + 1, bounds().topLeft().y() + 1, bounds().width() - 2, bounds().height() - 2);
ctx->strokeRect(rect2, highlighColor);
}
} else {
ctx->fillRect(rect, KDColorWhite);
}
}
int AtomicCell::numberOfSubviews() const {
return 0;
}
View * AtomicCell::subviewAtIndex(int index) {
return nullptr;
}
void AtomicCell::layoutSubviews(bool force) {
}
void AtomicCell::setVisible(bool visible) {
if (m_visible != visible) {
m_visible = visible;
markRectAsDirty(bounds());
}
}
void AtomicCell::setAtom(AtomDef atom) {
m_atom = atom;
markRectAsDirty(bounds());
}
void AtomicCell::reloadCell() {
markRectAsDirty(bounds());
}
}