lights_list.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <vector>
  2. #include <gtkmm/box.h>
  3. #include <gtkmm/button.h>
  4. #include <gtkmm/orientable.h>
  5. #include "lights_list.hpp"
  6. #include "light_on_list.hpp"
  7. #include "strings.hpp"
  8. #include "config.hpp"
  9. #include "light.hpp"
  10. namespace cx_light {
  11. lights_list::lights_list() {
  12. this->lights = new std::vector<light_on_list *>;
  13. this->lights->clear();
  14. this->content = new Gtk::Box();
  15. this->content->set_size_request(light_on_list::width(), -1);
  16. this->content->set_orientation(Gtk::Orientation::VERTICAL);
  17. this->content->set_margin(DEFAULT_MARGIN);
  18. this->set_margin(DEFAULT_MARGIN);
  19. this->set_child(*this->content);
  20. this->add_lights_container();
  21. this->add_create_light_button();
  22. #ifdef UI_DEBUG
  23. this->add_light(light("Sample", "1.1.1.1"));
  24. this->add_light(light("Other", "1.1.1.1"));
  25. #endif
  26. }
  27. lights_list::~lights_list() {
  28. for (unsigned int count = 0; count < this->lights->size(); ++count) {
  29. delete this->lights->at(count);
  30. }
  31. delete this->create_light;
  32. delete this->lights;
  33. delete this->lights_container;
  34. delete this->content;
  35. }
  36. void lights_list::add_lights_container() {
  37. this->lights_container = new Gtk::Box();
  38. this->lights_container->set_orientation(Gtk::Orientation::VERTICAL);
  39. this->lights_container->set_size_request(-1, light_on_list::height());
  40. this->content->append(*this->lights_container);
  41. }
  42. void lights_list::add_create_light_button() {
  43. this->create_light = new Gtk::Button(__(ADD_LIGHT));
  44. this->content->append(*this->create_light);
  45. }
  46. void lights_list::add_light(light target) {
  47. light_on_list *current = new light_on_list(target);
  48. this->lights_container->append(*current);
  49. this->lights->push_back(current);
  50. }
  51. }