Add hacks at pretty C++ stuff.
authorCarl Hetherington <cth@carlh.net>
Tue, 7 Feb 2012 12:12:54 +0000 (12:12 +0000)
committerCarl Hetherington <cth@carlh.net>
Tue, 7 Feb 2012 12:12:54 +0000 (12:12 +0000)
hacks/pretty-c++/Makefile [new file with mode: 0644]
hacks/pretty-c++/src/film.h [new file with mode: 0644]
hacks/pretty-c++/src/film_view.cc [new file with mode: 0644]
hacks/pretty-c++/src/film_view.h [new file with mode: 0644]
hacks/pretty-c++/src/main.cc [new file with mode: 0644]
hacks/pretty-c++/src/main_window.cc [new file with mode: 0644]
hacks/pretty-c++/src/main_window.h [new file with mode: 0644]
hacks/pretty-c++/src/ratio.cc [new file with mode: 0644]
hacks/pretty-c++/src/ratio.h [new file with mode: 0644]

diff --git a/hacks/pretty-c++/Makefile b/hacks/pretty-c++/Makefile
new file mode 100644 (file)
index 0000000..3eeef02
--- /dev/null
@@ -0,0 +1,4 @@
+SRC :=         src/main_window.cc src/main.cc
+
+dvdomatic:     $(SRC)
+               g++ -g -Wall -o $@ $(SRC) `pkg-config --cflags --libs gtkmm-2.4`
diff --git a/hacks/pretty-c++/src/film.h b/hacks/pretty-c++/src/film.h
new file mode 100644 (file)
index 0000000..4361c47
--- /dev/null
@@ -0,0 +1,22 @@
+#include "ratio.h"
+
+class Film
+{
+public:
+
+private:
+       std::string _name;
+       std::string _content;
+       Ratio       _ratio;
+       bool        _dvd;
+       int         _dvd_title;
+       bool        _deinterlace;
+       int         _left_crop;
+       int         _right_crop;
+       int         _top_crop;
+       int         _bottom_crop;
+
+       int         _width;
+       int         _height;
+       float       _length;
+};
diff --git a/hacks/pretty-c++/src/film_view.cc b/hacks/pretty-c++/src/film_view.cc
new file mode 100644 (file)
index 0000000..988f25f
--- /dev/null
@@ -0,0 +1,145 @@
+FilmView::FilmView ()
+       : _film (0)
+       , _content_file_radio (_content_group)
+       , _content_file_chooser ("Content", Gtk::FILE_CHOOSER_ACTION_OPEN)
+       , _content_file_button (_content_file_chooser)
+       , _content_folder_radio (_content_group)
+       , _content_folder_chooser ("Content", Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER)
+       , _content_folder_button (_content_folder_chooser)
+       , _dvd ("DVD")
+       , _deinterlace ("Deinterlace")
+{
+       _table = manage (new Gtk::Table);
+       table->set_row_spacings (4);
+       table->set_col_spacings (12);
+       main_vbox->pack_start (*table, false, false);
+
+       int n = 0;
+
+       table->attach (*left_aligned_label ("Content"), 0, 1, n, n + 1);
+       _content_file_chooser.add_button ("Select", Gtk::RESPONSE_OK);
+       _content_folder_chooser.add_button ("Select", Gtk::RESPONSE_OK);
+       Gtk::HBox* b = Gtk::manage (new Gtk::HBox);
+       b->set_spacing (12);
+       _content_file_radio.set_label ("File");
+       b->pack_start (_content_file_radio, false, false);
+       b->pack_start (_content_file_button, true, true);
+       _content_folder_radio.set_label ("Folder");
+       b->pack_start (_content_folder_radio, false, false);
+       b->pack_start (_content_folder_button, true, true);
+       table->attach (*b, 1, 2, n, n + 1);
+       ++n;
+
+       table->attach (*left_aligned_label ("Name"), 0, 1, n, n + 1);
+       table->attach (_name, 1, 2, n, n + 1);
+       ++n;
+
+       table->attach (*left_aligned_label ("Ratio"), 0, 1, n, n + 1);
+       _ratio.append_text ("1.33:1 (4:3)");
+       _ratio.append_text ("1.78:1 (16:9)");
+       _ratio.append_text ("1.85:1 (Flat)");
+       _ratio.append_text ("2.39:1 (Scope)");
+       table->attach (_ratio, 1, 2, n, n + 1);
+       _ratio.set_active_text ("1.85:1 (Flat)");
+       ++n;
+
+       table->attach (_dvd, 0, 2, n, n + 1);
+       ++n;
+
+       table->attach (*left_aligned_label ("DVD title"), 0, 1, n, n + 1);
+       _dvd_title.set_range (1, 64);
+       _dvd_title.set_increments (1, 4);
+       _dvd_title.set_value (1);
+       table->attach (_dvd_title, 1, 2, n, n + 1);
+       ++n;
+
+       table->attach (_deinterlace, 0, 2, n, n + 1);
+       ++n;
+
+       table->attach (*left_aligned_label ("Left Crop"), 0, 1, n, n + 1);
+       _left_crop.set_range (0, 1024);
+       _left_crop.set_increments (1, 64);
+       _left_crop.set_value (0);
+       table->attach (_left_crop, 1, 2, n, n + 1);
+       ++n;
+
+       table->attach (*left_aligned_label ("Right Crop"), 0, 1, n, n + 1);
+       _right_crop.set_range (0, 1024);
+       _right_crop.set_increments (1, 64);
+       _right_crop.set_value (0);
+       table->attach (_right_crop, 1, 2, n, n + 1);
+       ++n;
+
+       table->attach (*left_aligned_label ("Top Crop"), 0, 1, n, n + 1);
+       _top_crop.set_range (0, 1024);
+       _top_crop.set_increments (1, 64);
+       _top_crop.set_value (0);
+       table->attach (_top_crop, 1, 2, n, n + 1);
+       ++n;
+
+       table->attach (*left_aligned_label ("Bottom Crop"), 0, 1, n, n + 1);
+       _bottom_crop.set_range (0, 1024);
+       _bottom_crop.set_increments (1, 64);
+       _bottom_crop.set_value (0);
+       table->attach (_bottom_crop, 1, 2, n, n + 1);
+       ++n;
+
+       table->attach (*left_aligned_label ("Size"), 0, 1, n, n + 1);
+       table->attach (_size, 1, 2, n, n + 1);
+       ++n;
+
+       table->attach (*left_aligned_label ("Length"), 0, 1, n, n + 1);
+       table->attach (_length, 1, 2, n, n + 1);
+       ++n;
+       
+       /* We only need to connect to one of the radios in the group */
+       _content_file_radio.signal_toggled().connect (sigc::mem_fun (*this, &FilmView::content_radio_toggled));
+       _content_file_button.signal_file_set().connect (sigc::mem_fun (*this, &FilmView::content_changed));
+       _content_folder_button.signal_file_set().connect (sigc::mem_fun (*this, &FilmView::content_changed));
+       _dvd.signal_toggled().connect (sigc::mem_fun (*this, &FilmView::update_dvd_title_sensitivity));
+
+       update_content_radio_sensitivity ();
+       update_dvd_title_sensitivity ();
+       show_all ();
+}
+
+Gtk::Label *
+FilmView::left_aligned_label (string const & t) const
+{
+       Gtk::Label* l = Gtk::manage (new Gtk::Label (t));
+       l->set_alignment (0, 0.5);
+       return l;
+}
+
+void
+FilmView::content_radio_toggled ()
+{
+       update_content_radio_sensitivity ();
+       content_changed ();
+}
+
+void
+FilmView::update_content_radio_sensitivity ()
+{
+       _content_file_button.set_sensitive (_content_file_radio.get_active ());
+       _content_folder_button.set_sensitive (_content_folder_radio.get_active ());
+}
+
+void
+FilmView::update_dvd_title_sensitivity ()
+{
+       _dvd_title.set_sensitive (_dvd.get_active ());
+}
+
+void
+FilmView::content_changed ()
+{
+       cout << "Content changed.\n";
+}
+
+void
+FilmView::set_film (Film* f)
+{
+       _film = f;
+       update ();
+}
diff --git a/hacks/pretty-c++/src/film_view.h b/hacks/pretty-c++/src/film_view.h
new file mode 100644 (file)
index 0000000..9391684
--- /dev/null
@@ -0,0 +1,37 @@
+class FilmView
+{
+public:
+       FilmView ();
+
+       void set_film (Film* f);
+
+       Gtk::Widget* widget ();
+       
+private:
+       Gtk::Label* left_aligned_label (std::string const &) const;
+       void content_changed ();
+       void content_radio_toggled ();
+       void update_content_radio_sensitivity ();
+       void update_dvd_title_sensitivity ();
+
+       Film* _film;
+
+       Gtk::RadioButtonGroup _content_group;
+       Gtk::RadioButton _content_file_radio;
+       Gtk::FileChooserDialog _content_file_chooser;
+       Gtk::FileChooserButton _content_file_button;
+       Gtk::RadioButton _content_folder_radio;
+       Gtk::FileChooserDialog _content_folder_chooser;
+       Gtk::FileChooserButton _content_folder_button;
+       Gtk::Entry _name;
+       Gtk::ComboBoxText _ratio;
+       Gtk::CheckButton _dvd;
+       Gtk::CheckButton _deinterlace;
+       Gtk::SpinButton _dvd_title;
+       Gtk::SpinButton _left_crop;
+       Gtk::SpinButton _right_crop;
+       Gtk::SpinButton _top_crop;
+       Gtk::SpinButton _bottom_crop;
+       Gtk::Label _size;
+       Gtk::Label _length;
+};
diff --git a/hacks/pretty-c++/src/main.cc b/hacks/pretty-c++/src/main.cc
new file mode 100644 (file)
index 0000000..f9d39c1
--- /dev/null
@@ -0,0 +1,11 @@
+#include "main_window.h"
+
+int main (int argc, char* argv[])
+{
+       Gtk::Main kit (argc, argv);
+       
+       MainWindow window;
+       Gtk::Main::run (window);
+
+       return 0;
+}
diff --git a/hacks/pretty-c++/src/main_window.cc b/hacks/pretty-c++/src/main_window.cc
new file mode 100644 (file)
index 0000000..e6974bc
--- /dev/null
@@ -0,0 +1,16 @@
+#include "main_window.h"
+#include <iostream>
+
+using namespace std;
+
+MainWindow::MainWindow ()
+{
+       set_title ("DVD-o-matic");
+       maximize ();
+
+       Gtk::VBox* main_vbox = manage (new Gtk::VBox);
+       main_vbox->set_border_width (12);
+       add (*main_vbox);
+       
+       main_vbox->add (*_film_view.widget ());
+}
diff --git a/hacks/pretty-c++/src/main_window.h b/hacks/pretty-c++/src/main_window.h
new file mode 100644 (file)
index 0000000..63a2248
--- /dev/null
@@ -0,0 +1,11 @@
+#include <gtkmm.h>
+#include <string>
+
+class MainWindow : public Gtk::Window
+{
+public:
+       MainWindow ();
+
+private:
+       FilmView _film_view;
+};
diff --git a/hacks/pretty-c++/src/ratio.cc b/hacks/pretty-c++/src/ratio.cc
new file mode 100644 (file)
index 0000000..b1df7fa
--- /dev/null
@@ -0,0 +1,35 @@
+#include <sstream>
+#include "ratio.h"
+
+using namespace std;
+
+Ratio::Ratio ()
+       : _ratio (1.85)
+{
+
+}
+
+Ratio::Ratio (float r)
+       : _ratio (r)
+{
+
+}
+
+string
+Ratio::name () const
+{
+       switch (_ratio) {
+       case 1.85:
+               return "Flat (1.85:1)";
+               break;
+       case 2.39:
+               return "Scope (2.39:1)";
+               break;
+       }
+
+       stringstream s;
+       s << _ratio;
+       return s.str ();
+}
+
+       
diff --git a/hacks/pretty-c++/src/ratio.h b/hacks/pretty-c++/src/ratio.h
new file mode 100644 (file)
index 0000000..a08999f
--- /dev/null
@@ -0,0 +1,17 @@
+#include <string>
+
+class Ratio
+{
+public:
+       Ratio ();
+       Ratio (float);
+       
+       float ratio () const {
+               return _ratio;
+       }
+
+       std::string name () const;
+
+private:
+       float _ratio;
+};