~bookworm-team/bookworm/trunk

« back to all changes in this revision

Viewing changes to src/EBookArea.vala

  • Committer: Logan Garcia
  • Date: 2015-08-12 23:24:34 UTC
  • Revision ID: logangarcia@fastmail.fm-20150812232434-ibfbplwthvo2igmy
add more features from new-branch into development focus

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
namespace BookWorm {
 
2
 
 
3
        public class EBookArea : GtkClutter.Embed {
 
4
 
 
5
                public signal void back_pressed ();
 
6
 
 
7
                EBookWidget ebook_widget;
 
8
 
 
9
                GtkClutter.Actor left_arrow;
 
10
                GtkClutter.Actor right_arrow;
 
11
 
 
12
                int arrow_width;
 
13
                int arrow_height;
 
14
 
 
15
                static const int arrow_distance = 8;
 
16
 
 
17
                public EBookArea () {
 
18
                        expand = true;
 
19
                        (get_stage () as Clutter.Stage).color = Clutter.Color.from_string ("white");
 
20
 
 
21
                        left_arrow = new GtkClutter.Actor ();
 
22
                        var left_arrow_box = create_arrow ("data/arrow_left.svg");
 
23
                        left_arrow_box.button_press_event.connect (() => {
 
24
                                ebook_widget.previous_page ();
 
25
                                return true;
 
26
                        });
 
27
                        left_arrow.contents = left_arrow_box;
 
28
                        get_stage ().add_child (left_arrow);
 
29
 
 
30
                        right_arrow = new GtkClutter.Actor ();
 
31
                        var right_arrow_box = create_arrow ("data/arrow_right.svg");
 
32
                        right_arrow_box.button_press_event.connect (() => {
 
33
                                ebook_widget.next_page ();
 
34
                                return true;
 
35
                        });
 
36
                        right_arrow.contents = right_arrow_box;
 
37
                        get_stage ().add_child (right_arrow);
 
38
                }
 
39
 
 
40
                public void update_toolbar () {
 
41
                        var toolbar = WindowToolbar.instance;
 
42
                        toolbar.reset ();
 
43
 
 
44
                        Gtk.Image bookmarks_img = new Gtk.Image.from_icon_name ("format-justify-fill-symbolic",
 
45
                                                Gtk.IconSize.MENU);
 
46
                        Gtk.ToolButton bookmarks_button = new Gtk.ToolButton (bookmarks_img, null);
 
47
                        bookmarks_button.clicked.connect (() => {
 
48
                                var popover = new Granite.Widgets.PopOver ();
 
49
 
 
50
                                var menu = new HamburgerMenu (null);
 
51
                                menu.show_all ();
 
52
                                (popover.get_child () as Gtk.Container).add (menu);
 
53
                                popover.move_to_widget (bookmarks_button, true);
 
54
                        });
 
55
                        toolbar.pack_start (bookmarks_button);
 
56
 
 
57
                        Gtk.Image home_img = new Gtk.Image.from_icon_name ("user-home-symbolic",
 
58
                                                Gtk.IconSize.MENU);
 
59
                        Gtk.ToolButton home_button = new Gtk.ToolButton (home_img, null);
 
60
                        home_button.clicked.connect (() => {
 
61
                                back_pressed ();
 
62
                        });
 
63
                        toolbar.pack_start (home_button);
 
64
 
 
65
                        Gtk.Image font_smaller_img = new Gtk.Image.from_icon_name ("format-text-smaller-symbolic",
 
66
                                                Gtk.IconSize.MENU);
 
67
                        Gtk.ToolButton font_smaller_button = new Gtk.ToolButton (font_smaller_img, null);
 
68
                        toolbar.pack_end (font_smaller_button);
 
69
 
 
70
                        Gtk.Image font_bigger_img = new Gtk.Image.from_icon_name ("format-text-larger-symbolic",
 
71
                                                Gtk.IconSize.MENU);
 
72
                        Gtk.ToolButton font_bigger_button = new Gtk.ToolButton (font_bigger_img, null);
 
73
                        toolbar.pack_end (font_bigger_button);
 
74
 
 
75
                        var searchbar = new Granite.Widgets.SearchBar (_("Search this book..."));
 
76
 
 
77
                        searchbar.text_changed_pause.connect (() => {
 
78
                                ebook_widget.search (searchbar.text);
 
79
                        });
 
80
 
 
81
                        searchbar.search_icon_release.connect (() => {
 
82
                                ebook_widget.search (searchbar.text);
 
83
                        });
 
84
 
 
85
                        searchbar.activate.connect (() => {
 
86
                                ebook_widget.search (searchbar.text);
 
87
                        });
 
88
 
 
89
                        Gtk.ToolItem searchbar_wrapper = new Gtk.ToolItem ();
 
90
                        searchbar_wrapper.add (searchbar);
 
91
                        toolbar.pack_end (searchbar_wrapper);
 
92
 
 
93
 
 
94
 
 
95
 
 
96
                }
 
97
 
 
98
                public void open_book (string filename) {
 
99
                        var reader = new GtkClutter.Actor ();
 
100
                        var epub_widget = new EPubWidget();
 
101
                        ebook_widget = epub_widget;
 
102
                        reader.contents = epub_widget;
 
103
                        epub_widget.expand = true;
 
104
 
 
105
                        size_allocate.connect ((size) => {
 
106
                                left_arrow.x = arrow_distance;
 
107
                                left_arrow.y = get_allocated_height () / 2 - arrow_height / 2;
 
108
 
 
109
                                right_arrow.x = get_allocated_width () - arrow_distance - arrow_width;
 
110
                                right_arrow.y = get_allocated_height () / 2 - arrow_height / 2;
 
111
 
 
112
                                reader.x = 40;
 
113
                                reader.y = 20;
 
114
                                reader.contents.set_size_request (get_allocated_width () - 80, get_allocated_height () - 40);
 
115
                                queue_draw ();
 
116
                                base.size_allocate (size);
 
117
                        });
 
118
                        get_stage ().add_child (reader);
 
119
                        ebook_widget.open_book (filename);
 
120
                        ebook_widget.show_all ();
 
121
                }
 
122
 
 
123
                public Gtk.EventBox create_arrow (string img_path) {
 
124
 
 
125
                        var result = new Gtk.EventBox ();
 
126
 
 
127
                        var color_white = Gdk.RGBA ();
 
128
                        color_white.parse ("white");
 
129
 
 
130
                        var arrow_img = new Gtk.Image.from_file (img_path);
 
131
                        arrow_img.override_background_color (Gtk.StateFlags.NORMAL, color_white);
 
132
                        result.add (arrow_img);
 
133
 
 
134
                        arrow_width = arrow_img.pixbuf.width;
 
135
                        arrow_height = arrow_img.pixbuf.height;
 
136
 
 
137
                        result.show_all ();
 
138
 
 
139
                        return result;
 
140
 
 
141
                }
 
142
        }
 
143
 
 
144
}