]> git.llucax.com Git - z.facultad/75.52/treemulator.git/blob - viewer/view_node.cpp
dbcc8185a19202dad989423345ba2a75950d7d57
[z.facultad/75.52/treemulator.git] / viewer / view_node.cpp
1
2 #include "view_node.h"
3
4 ViewNode::ViewNode (Canvas::Group *parent, uint num, uint padre, BTreeNodeHeader &header, std::list<BTreeData *> &keys)
5         : Canvas::Group (*parent)
6 {
7         last_selected = NULL;
8         double header_w = ViewBTree::byte_to_pixels * sizeof (BTreeNodeHeader);
9         this->num = num;
10         this->padre = padre;
11
12         /* Fondo */
13         fondo = new Canvas::Rect (*this, 0, 0, ViewBTree::node_width, ViewBTree::node_height);
14         fondo->property_fill_color() = "gray";
15         fondo->property_outline_color() = "black";
16
17         /* Header */
18         Canvas::Rect *h = new Canvas::Rect (*this, 0, 0, header_w, ViewBTree::node_height);
19         h->property_fill_color() = "blue";
20         h->property_outline_color() = "black";
21
22         /* Numero de nodo */
23         std::string node_num;
24         std::stringstream ss;
25         ss << num;
26         ss >> node_num;
27         new Canvas::Text (*this, header_w/2, ViewBTree::node_height/2, node_num);
28
29         double x = header_w;
30
31         std::list<BTreeData *>::iterator it = keys.begin ();
32         while (it != keys.end ()) {
33                 BTreeData *data = (*it);
34                 double w = ViewBTree::byte_to_pixels * data->Size ();
35
36                 ViewBTreeData *v = ViewBTreeData::Create (data, this, x, 0, w+x, ViewBTree::node_height);
37                 v->signal_clicked ().connect ( sigc::mem_fun (this , &ViewNode::on_item_clicked ));
38                 v->signal_double_clicked ().connect ( sigc::mem_fun (this , &ViewNode::on_item_activated ));
39                 x += w;
40                 it++;
41
42                 datas.push_back (v);
43
44                 if (!dynamic_cast<BTreeLeafData *>(data)) {
45                         /* Si no es un dato de una hoja, tiene hijos */
46                         hijos.push_back (data->GetChild ());
47                 }
48         }
49 }
50
51 void ViewNode::on_item_clicked (BTreeData *data, ViewBTreeData *s)
52 {
53         if (last_selected)
54                 if (s != last_selected)
55                         last_selected->SetSelected (false);
56         last_selected = s;
57         m_signal_selected (data, num, this);
58 }
59
60 void ViewNode::on_item_activated (BTreeData *data, ViewBTreeData *s)
61 {
62         /* Solo activo los que tienen hijos */
63         if (dynamic_cast<BTreeLeafData *> (data) == NULL)
64                 m_signal_activated (data, num, this);
65 }
66
67 ViewNode::type_signal_selected ViewNode::signal_selected ()
68 {
69         return m_signal_selected;
70 }
71
72 ViewNode::type_signal_activated ViewNode::signal_activated ()
73 {
74         return m_signal_activated;
75 }
76
77 void ViewNode::SetSelected (bool b)
78 {
79         if (last_selected) {
80                 last_selected->SetSelected (b);
81         }
82 }
83
84 void ViewNode::HighliteKey (Clave &k)
85 {
86         std::list<ViewBTreeData *>::iterator it;
87
88         it = datas.begin ();
89         while (it != datas.end ()) {
90                 if ((*(*it)) == k) {
91                         if (last_selected)
92                                 last_selected->SetSelected (false);
93                         last_selected = *it;
94                         last_selected->SetSelected (true);
95                 }
96                 it++;
97         }
98 }
99