Debian Codegraph @

hiro/qt/widget/table-view-cell.cpp

raw
1 #if defined(Hiro_TableView)
2
3 namespace hiro {
4
5 auto pTableViewCell::construct() -> void {
6 }
7
8 auto pTableViewCell::destruct() -> void {
9 }
10
11 auto pTableViewCell::setAlignment(Alignment alignment) -> void {
12 _setState();
13 }
14
15 auto pTableViewCell::setBackgroundColor(Color color) -> void {
16 _setState();
17 }
18
19 auto pTableViewCell::setCheckable(bool checkable) -> void {
20 _setState();
21 }
22
23 auto pTableViewCell::setChecked(bool checked) -> void {
24 _setState();
25 }
26
27 auto pTableViewCell::setFont(const string& font) -> void {
28 _setState();
29 }
30
31 auto pTableViewCell::setForegroundColor(Color color) -> void {
32 _setState();
33 }
34
35 auto pTableViewCell::setIcon(const image& icon) -> void {
36 _setState();
37 }
38
39 auto pTableViewCell::setText(const string& text) -> void {
40 _setState();
41 }
42
43 auto pTableViewCell::_parent() -> maybe<pTableViewItem&> {
44 if(auto parent = self().parentTableViewItem()) {
45 if(auto delegate = parent->self()) return *delegate;
46 }
47 return nothing;
48 }
49
50 auto pTableViewCell::_setState() -> void {
51 if(auto parent = _parent()) {
52 if(auto grandparent = parent->_parent()) {
53 auto lock = grandparent->acquire();
54 parent->qtItem->setBackground(self().offset(), CreateBrush(self().backgroundColor(true)));
55 if(state().checkable) {
56 parent->qtItem->setCheckState(self().offset(), state().checked ? Qt::Checked : Qt::Unchecked);
57 } else {
58 //extremely unintuitive; but this is the only way to remove an existing checkbox from a cell
59 parent->qtItem->setData(self().offset(), Qt::CheckStateRole, QVariant());
60 }
61 parent->qtItem->setFont(self().offset(), pFont::create(self().font(true)));
62 parent->qtItem->setForeground(self().offset(), CreateBrush(self().foregroundColor(true)));
63 parent->qtItem->setIcon(self().offset(), CreateIcon(state().icon));
64 parent->qtItem->setText(self().offset(), QString::fromUtf8(state().text));
65 parent->qtItem->setTextAlignment(self().offset(), (Qt::Alignment)CalculateAlignment(self().alignment(true)));
66 }
67 }
68 }
69
70 }
71
72 #endif