Sfoglia il codice sorgente

Working on GTK version.

Cixo Develop 5 mesi fa
parent
commit
7f7a6058f6

+ 32 - 0
cppGTK/source/core_window.cpp

@@ -2,17 +2,22 @@
 #include <gtkmm/button.h>
 #include <gtkmm/window.h>
 #include <gtkmm/box.h>
+#include <gtkmm/frame.h>
 #include <gtkmm/orientable.h>
+#include <gtkmm/widget.h>
 #include <iostream>
 
 #include "strings.hpp"
 #include "config.hpp"
 #include "core_window.hpp"
 #include "lights_list.hpp"
+#include "light_adder.hpp"
 
 namespace cx_light {
 
 core_window::core_window() {
+    this->current_visible = NULL;
+
     this->set_title(__(WINDOW_TITLE));
     this->set_default_size(400, 200);
 
@@ -21,6 +26,9 @@ core_window::core_window() {
 
 core_window::~core_window() {
     delete this->center;
+    delete this->current;
+    delete this->lights;
+    delete this->adder;
 }
 
 void core_window::init_default() {
@@ -28,7 +36,17 @@ void core_window::init_default() {
     this->center->set_orientation(Gtk::Orientation::HORIZONTAL);
     this->set_child(*this->center);
 
+    this->current = new Gtk::Box();
+    this->current->set_margin(DEFAULT_MARGIN);
+
+    this->current_frame = new Gtk::Frame();
+    this->current_frame->set_margin(DEFAULT_MARGIN);
+    this->current_frame->set_child(*this->current);
+
     this->create_lights_list();
+    this->center->append(*this->current_frame);
+
+    this->create_light_adder();
 }
 
 void core_window::create_lights_list() {
@@ -36,6 +54,20 @@ void core_window::create_lights_list() {
     this->center->append(*this->lights);
 }
 
+void core_window::create_light_adder() {
+    this->adder = new light_adder();
+    this->set_view(this->adder);
+}
+
+void core_window::set_view(Gtk::Widget *target) {
+    if (this->current_visible != NULL) {
+        this->current->remove(*this->current_visible);
+    }
+
+    this->current_visible = target;
+    this->current->append(*target);
+}
+
 }
 
 

+ 11 - 1
cppGTK/source/core_window.hpp

@@ -4,10 +4,13 @@
 #include <gtkmm/widget.h>
 #include <gtkmm/button.h>
 #include <gtkmm/window.h>
+#include <gtkmm/widget.h>
+#include <gtkmm/frame.h>
 #include <gtkmm/box.h>
 
 #include "strings.hpp"
 #include "lights_list.hpp"
+#include "light_adder.hpp"
 
 namespace cx_light {
 
@@ -16,12 +19,19 @@ class core_window: public Gtk::Window {
         core_window();
         ~core_window() override;
 
+        void set_view(Gtk::Widget *);
+
     private:
+        lights_list *lights;
+        light_adder *adder;
         Gtk::Box *center;
-        lights_list *lights; 
+        Gtk::Frame *current_frame;
+        Gtk::Widget *current_visible;
+        Gtk::Box *current;
 
         void init_default();
         void create_lights_list();
+        void create_light_adder();
 };
 
 }

+ 28 - 0
cppGTK/source/light.cpp

@@ -0,0 +1,28 @@
+#include <string>
+
+#include "light.hpp"
+
+namespace cx_light {
+
+light::light(std::string name, std::string address) {
+    this->name = name;
+    this->address = address;
+}
+
+light::~light() {
+
+}
+
+std::string light::get_name() {
+    return this->name;
+}
+
+std::string light::get_address() {
+    return this->address;
+}
+
+light * light::copy() {
+    return new light(this->get_name(), this->get_address());
+}
+
+}

+ 24 - 0
cppGTK/source/light.hpp

@@ -0,0 +1,24 @@
+#ifndef SOURCE_LIGHT_HPP_DEFINED
+#define SOURCE_LIGHT_HPP_DEFINED
+
+#include <string>
+
+namespace cx_light {
+
+class light {
+    public:
+        light(std::string, std::string);
+        ~light();
+
+        std::string get_name();
+        std::string get_address();
+        light * copy();
+
+    private:
+        std::string name;
+        std::string address;
+};
+
+}
+
+#endif

+ 38 - 0
cppGTK/source/light_adder.cpp

@@ -0,0 +1,38 @@
+#include <gtkmm/grid.h>
+#include <gtkmm/label.h>
+#include <gtkmm/entry.h>
+#include <gtkmm/button.h>
+
+#include "light_adder.hpp"
+
+namespace cx_light {
+
+light_adder::light_adder() {
+    this->title_label = new Gtk::Label("Title");
+    this->title_entry = new Gtk::Entry();
+    this->address_label = new Gtk::Label("Address");
+    this->address_entry = new Gtk::Entry();
+    this->add_button = new Gtk::Button("Add");
+
+    this->attach(*this->title_label, 0, 0);
+    this->attach(*this->title_entry, 1, 0);
+    this->attach(*this->address_label, 0, 1);
+    this->attach(*this->address_entry, 1, 1);
+    this->attach(*this->add_button, 0, 2, 2, 1);
+}
+
+light_adder::~light_adder() {
+    this->remove(*this->title_label);
+    this->remove(*this->title_entry);
+    this->remove(*this->address_label);
+    this->remove(*this->address_entry);
+    this->remove(*this->add_button);
+
+    delete this->title_label;
+    delete this->title_entry;
+    delete this->address_label;
+    delete this->address_entry;
+    delete this->add_button;
+}
+
+}

+ 29 - 0
cppGTK/source/light_adder.hpp

@@ -0,0 +1,29 @@
+#ifndef LIGHT_ADDER_HPP_DEFINED
+#define LIGHT_ADDER_HPP_DEFINED
+
+#include <gtkmm/grid.h>
+#include <gtkmm/label.h>
+#include <gtkmm/entry.h>
+#include <gtkmm/button.h>
+
+namespace cx_light {
+
+class light_adder : public Gtk::Grid {
+    public:
+        light_adder();
+        ~light_adder() override;
+
+    private:
+        Gtk::Label *title_label;
+        Gtk::Entry *title_entry;
+
+        Gtk::Label *address_label;
+        Gtk::Entry *address_entry;
+    
+        Gtk::Button *add_button;
+};
+
+}
+
+#endif
+

+ 29 - 6
cppGTK/source/light_on_list.cpp

@@ -1,18 +1,41 @@
-
-#include <string>
 #include <gtkmm/box.h>
+#include <gtkmm/label.h>
+#include <gtkmm/frame.h>
+#include <gtkmm/button.h>
+#include <gtkmm/orientable.h>
+#include <string>
 
 #include "light_on_list.hpp"
 
 namespace cx_light {
 
-light_on_list::light_on_list(std::string name, bool state) {
-    this->name = name;
-    this->state = state;
+light_on_list::light_on_list(light target) {
+    this->target = target.copy();
+
+    this->center = new Gtk::Box();
+    this->center->set_margin(5);
+    this->center->set_spacing(10);
+    this->center->set_orientation(Gtk::Orientation::HORIZONTAL);
+    
+    this->set_margin_bottom(5);
+    this->set_child(*this->center);
+
+    this->title = new Gtk::Label(this->target->get_name());
+    this->center->append(*this->title);
+   
+    this->show = new Gtk::Button("Show");
+    this->center->append(*this->show);
+
+    this->edit = new Gtk::Button("Edit");
+    this->center->append(*this->edit);
 }
 
 light_on_list::~light_on_list() {
-     
+    delete this->center;
+    delete this->title;
+    delete this->show;
+    delete this->edit;
+    delete this->target; 
 }
 
 int light_on_list::width() {

+ 14 - 6
cppGTK/source/light_on_list.hpp

@@ -2,22 +2,30 @@
 #define LIGHT_ON_LIST_HPP_INCLUDED
 
 #include <gtkmm/box.h>
+#include <gtkmm/label.h>
+#include <gtkmm/frame.h>
+#include <gtkmm/button.h>
+#include <gtkmm/orientable.h>
 #include <string>
 
+#include "light.hpp"
+
 namespace cx_light {
 
-class light_on_list: public Gtk::Box {
+class light_on_list: public Gtk::Frame {
     public:
-        light_on_list(std::string, bool);
+        light_on_list(light);
         ~light_on_list() override;
-       
-        static 
+         
         static int width();
         static int height();
 
     private:
-        bool state;
-        std::string name;
+        light *target;
+        Gtk::Box *center;
+        Gtk::Label *title;
+        Gtk::Button *show;
+        Gtk::Button *edit;
 };
 
 }

+ 26 - 4
cppGTK/source/lights_list.cpp

@@ -7,37 +7,59 @@
 #include "light_on_list.hpp"
 #include "strings.hpp"
 #include "config.hpp"
+#include "light.hpp"
 
 namespace cx_light {
 
 lights_list::lights_list() {
     this->lights = new std::vector<light_on_list *>;
     this->lights->clear();
+   
+    this->content = new Gtk::Box();
+    this->content->set_size_request(light_on_list::width(), -1);
+    this->content->set_orientation(Gtk::Orientation::VERTICAL);
+    this->content->set_margin(DEFAULT_MARGIN);
     
-    this->set_size_request(light_on_list::width(), -1);
-    this->set_orientation(Gtk::Orientation::VERTICAL);
     this->set_margin(DEFAULT_MARGIN);
+    this->set_child(*this->content);
 
     this->add_lights_container();
     this->add_create_light_button();
+
+    #ifdef UI_DEBUG
+    this->add_light(light("Sample", "1.1.1.1"));
+    this->add_light(light("Other", "1.1.1.1"));
+    #endif
 }
 
 lights_list::~lights_list() {
+    for (unsigned int count = 0; count < this->lights->size(); ++count) {
+        delete this->lights->at(count);
+    }
+
     delete this->create_light;
     delete this->lights;
     delete this->lights_container;
+    delete this->content;
 }
 
 void lights_list::add_lights_container() {
     this->lights_container = new Gtk::Box();
     this->lights_container->set_orientation(Gtk::Orientation::VERTICAL);
     this->lights_container->set_size_request(-1, light_on_list::height());
-    this->append(*this->lights_container);
+    this->content->append(*this->lights_container);
 }
 
 void lights_list::add_create_light_button() {
     this->create_light = new Gtk::Button(__(ADD_LIGHT));
-    this->append(*this->create_light);
+    this->content->append(*this->create_light);
+}
+
+void lights_list::add_light(light target) {
+    light_on_list *current = new light_on_list(target);
+    
+    this->lights_container->append(*current);
+    this->lights->push_back(current);
 }
 
 }

+ 6 - 1
cppGTK/source/lights_list.hpp

@@ -3,18 +3,23 @@
 
 #include <vector>
 #include <gtkmm/box.h>
+#include <gtkmm/frame.h>
 #include <gtkmm/button.h>
 
 #include "light_on_list.hpp"
+#include "light.hpp"
 
 namespace cx_light {
 
-class lights_list: public Gtk::Box {
+class lights_list: public Gtk::Frame {
     public:
         lights_list();
         ~lights_list() override;
 
+        void add_light(light);
+
     private:
+        Gtk::Box *content;
         Gtk::Box *lights_container; 
         Gtk::Button *create_light;
         std::vector<light_on_list *> *lights;