libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GtkCRNDocument.h
Go to the documentation of this file.
1 /* Copyright 2010-2016 CoReNum, INSA-Lyon
2  *
3  * This file is part of libgtkcrnmm.
4  *
5  * libgtkcrnmm is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * libgtkcrnmm is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libgtkcrnmm. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * file: GtkCRNDocument.h
19  * \author Yann LEYDIER
20  */
21 
22 #ifndef GtkCRNDocument_HEADER
23 #define GtkCRNDocument_HEADER
24 
25 #include <gtkmm.h>
26 #include <GtkCRNImage.h>
27 #include <CRNDocument.h>
28 #include <GtkCRNSelectionBox.h>
29 #include <CRNUtils/CRNProgress.h>
30 
31 namespace GtkCRN
32 {
36  class Document:
37 #ifdef CRN_USING_GTKMM3
38  public Gtk::Paned
39 #else
40  public Gtk::HPaned
41 #endif
42  {
43  public:
45  Document(bool show_views = true, bool show_tree = true);
47  virtual ~Document() override;
48 
50  // General document management
52 
53  void set_document(const crn::SDocument &doc);
55  const crn::SDocument& get_document() { return crndoc; }
57  crn::SCDocument get_document() const { return crndoc; }
58 
60  // Views
62 
63  std::vector<crn::String> get_selected_views_ids();
67  void set_selected_view(const crn::String &view_id);
68 
70  void set_show_thumbnails(bool s);
72  void set_show_labels(bool s);
74  void set_show_indexes(bool s);
75 
77  void select_even();
79  void select_odd();
81  void select_all();
83  void deselect_all();
85  void invert_selection();
87  void delete_selection();
88 
89  /* !\brief Opens a dialog to add views */
90  void append_views_dialog();
92  void append_views(const std::vector<crn::Path> &filenames);
94  void refresh_views();
95 
97  void select_first();
99  void select_previous();
101  void select_next();
103  void select_last();
104 
113  void set_default_drop_in(bool b) { droppedin_handle->block(!b); }
115  sigc::signal<void, int, crn::StringUTF8> signal_droppedin() { return view_box.signal_droppedin(); }
116 
118  sigc::signal<void, const crn::String, const std::vector<crn::String> > signal_view_selection_changed() { return selection_changed; }
119 
121  sigc::signal<bool, const std::vector<crn::String> > signal_delete_selection() { return may_delete_selection; }
122 
123 #ifdef CRN_USING_GTKMM3
124 
142  Glib::RefPtr<Gio::SimpleActionGroup>& get_views_actions() { return views_actions;}
143 #else
144 
162  Glib::RefPtr<Gtk::ActionGroup>& get_views_actions() { return views_actions;}
163 #endif
164 
166  // Subblock tree
168 
169  const crn::SBlock& get_selected_block() { return blocksel; }
171  crn::SCBlock get_selected_block() const { return blocksel; }
172 
174  void set_show_subblocks(bool s) { tree_frame.set_visible(s); }
176  bool get_show_subblocks() const { return tree_frame.get_visible(); }
178  void set_show_subblocks_toolbar(bool s) { tree_buttons.set_visible(s); }
180  bool get_show_subblocks_toolbar() const { return tree_buttons.get_visible(); }
181 
182 #ifdef CRN_USING_GTKMM3
183 
191  Glib::RefPtr<Gio::SimpleActionGroup>& get_subblock_actions() { return tree_actions;}
192 #else
193 
201  Glib::RefPtr<Gtk::ActionGroup>& get_subblock_actions() { return tree_actions;}
202 #endif
203 
205  // Displayed image
207 
208  GtkCRN::Image& get_image() { return img; }
210  const GtkCRN::Image& get_image() const { return img; }
211 
213  void reload_image(const crn::String &view_id);
215  void thread_safe_reload_image(const crn::String &view_id);
216 
218  void set_selection_colors(const crn::pixel::RGB8 &col1, const crn::pixel::RGB8 &col2);
220  void set_subblocks_colors(const crn::pixel::RGB8 &col1, const crn::pixel::RGB8 &col2, const crn::pixel::RGB8 &textcol);
222  void set_show_subblock_labels(bool s);
224  bool get_show_subblock_labels() const { return show_subblock_labels; }
225 
227  // Custom panels
229 
230  Gtk::Box& get_left_panel() { return left_box; }
232  Gtk::Box& get_right_panel() { return right_box; }
233 
234  private:
236  // General document management
238  crn::SDocument crndoc;
239  crn::SBlock current_block;
241 #ifdef CRN_USING_HARU
242 
243  void export_pdf();
244 #endif
245 
247  // Views
249 
250 #ifdef CRN_USING_GTKMM3
251  Glib::RefPtr<Gio::SimpleActionGroup> views_actions;
252 #else
253  Glib::RefPtr<Gtk::ActionGroup> views_actions;
254 #endif
255 
257  void create_view_cache(crn::Progress *pw);
258 
260  struct DVI
261  {
262  DVI(Document *d, const crn::String &vi):doc(d),id(vi) {}
263  Document *doc;
264  crn::String id;
265  };
267  static gboolean tsreloadimage(DVI *data);
268 
269  sigc::signal<void, const crn::String, const std::vector<crn::String> > selection_changed;
270  sigc::signal<void, int, crn::StringUTF8>::iterator droppedin_handle;
271  sigc::signal<bool, const std::vector<crn::String> > may_delete_selection;
273  void droppedin(int pos, crn::StringUTF8 data);
275  void moved(std::vector<size_t> to, std::vector<size_t> from);
277  void on_view_selection_changed(Gtk::Widget *last_selected_widget, const std::vector<Gtk::Widget*> selection);
279  bool boxkeyevents(GdkEventKey *ev);
280 
282  class View: public Gtk::VBox
283  {
284  public:
285  View(const crn::String &id, crn::SDocument doc);
286  const crn::String& get_view_id() const { return view_id; }
287  void set_show_thumbnail(bool s) { if (s) thumb.show(); else thumb.hide(); }
288  void set_thumbnail(const crn::Path &fname) { thumb.set(fname.CStr()); }
289  void set_show_label(bool s) { if (s) lab.show(); else lab.hide(); }
290  void set_show_index(bool s) { if (s) index.show(); else index.hide(); }
291  void set_index(size_t i) { index.set_text(crn::StringUTF8(i).CStr()); }
292  private:
293  Gtk::Image thumb;
294  Gtk::Label lab;
295  Gtk::Label index;
296  crn::String view_id;
297  };
298  SelectionBox view_box;
299  Gtk::Frame view_frame;
300  std::vector<std::shared_ptr<View> > views;
301  bool show_thumbnails, show_labels, show_indexes;
303  // Subblock tree
306  Gtk::ScrolledWindow tree_sw;
307  Gtk::VBox tree_box;
308  Gtk::Toolbar tree_buttons;
309 #ifdef CRN_USING_GTKMM3
310  Glib::RefPtr<Gio::SimpleActionGroup> tree_actions;
311 #else
312  Glib::RefPtr<Gtk::ActionGroup> tree_actions;
313 #endif
314 
316  class SubblockColumns : public Gtk::TreeModelColumnRecord
317  {
318  public:
319  SubblockColumns() { add(name); add(block); add(is_tree); add(coords); }
320 
321  Gtk::TreeModelColumn<Glib::ustring> name;
322  Gtk::TreeModelColumn<crn::SBlock> block;
323  Gtk::TreeModelColumn<bool> is_tree;
324  Gtk::TreeModelColumn<Glib::ustring> coords;
325  };
326  SubblockColumns block_columns;
327  Glib::RefPtr<Gtk::TreeStore> block_tree_store;
328  Gtk::TreeView block_tree_view;
329  crn::SBlock blocksel;
332  void clear_tree();
334  void load_tree(const crn::String &view_id);
336  void tree_add_children(Gtk::TreeModel::iterator &it, crn::SBlock b);
338  void subblock_selection_changed();
340  void add_subblock();
342  void rem_subblock();
344  void configure_subblocks();
345 
347  // Displayed image
349  Image img;
352  void on_image_overlay_changed(crn::String overlay_id, crn::String overlay_item_id, Image::MouseMode mm);
354  void show_hide_subblocks_on_image();
355  static const crn::String subblock_list_name;
356  crn::pixel::RGB8 treecol1, treecol2, treetextcol, selcol1, selcol2;
357  bool show_subblock_labels;
358  bool fill_subblocks;
360  // Layout widgets
363 #ifdef CRN_USING_GTKMM3
364  Gtk::Box left_box, right_box;
365  Gtk::Paned vpan;
366  Gtk::Box image_box;
367 #else
368  Gtk::VBox left_box, right_box;
369  Gtk::VPaned vpan;
370  Gtk::HBox image_box;
371 #endif
372  Gtk::Frame tree_frame;
373  };
374 }
375 
376 #endif
377 
378 
void set_show_indexes(bool s)
Shall the views show their index.
Displays a crn::Document.
virtual ~Document() override
Destructor.
const crn::SDocument & get_document()
Gets the displayed document.
std::vector< crn::String > get_selected_views_ids()
Gets the selected views' ids.
void set_show_labels(bool s)
Shall the views show a label.
Glib::RefPtr< Gtk::ActionGroup > & get_subblock_actions()
Gets the action group associated to subblock management.
Base class for a progress display.
Definition: CRNProgress.h:39
void set_subblocks_colors(const crn::pixel::RGB8 &col1, const crn::pixel::RGB8 &col2, const crn::pixel::RGB8 &textcol)
Sets the colors of the subblocks on the image.
void select_first()
If selection size is <= 1, then select the first view, else move last_selected to the first selected ...
GtkCRN::Image & get_image()
Gets the image widget.
void set_default_drop_in(bool b)
Shall we use the default handler for dropped elements? (true by default).
void invert_selection()
Inverts the view selection.
void set_show_subblocks_toolbar(bool s)
Shows or hides subblocks toolbar.
void select_all()
Selects all views.
sigc::signal< void, int, crn::StringUTF8 > signal_droppedin()
Signals when something was dropped from another application. Connect to void on_droppedin(int positio...
void select_even()
Selects even views.
sigc::signal< void, int, crn::StringUTF8 > signal_droppedin()
Signals when something was dropped from another application. Connect to void on_droppedin(int positio...
void delete_selection()
Removes all selected views from the document.
bool get_show_subblocks_toolbar() const
Is subblocks toolbar shown?
void select_odd()
Selects odd views.
A UTF32 character string class.
Definition: CRNString.h:61
bool get_show_subblocks() const
Is subblocks tree shown?
void thread_safe_reload_image(const crn::String &view_id)
Refreshes the thumbnail of a view and the Image if needed (thread safe)
const char * CStr() const noexcept
Conversion to UTF8 cstring.
crn::String get_selected_view_id()
Gets the displayed views's id.
A convenience class for file paths.
Definition: CRNPath.h:39
void refresh_views()
Redraws the view list.
crn::SCBlock get_selected_block() const
Gets the displayed block.
void set_show_subblocks(bool s)
Shows or hides subblocks tree.
Gtk::Box & get_right_panel()
void set_document(const crn::SDocument &doc)
Sets the document to display.
void select_next()
If selection size is 0, the select the first element, if selection size is 1, then select the next vi...
void append_views(const std::vector< crn::Path > &filenames)
Appends new views at the end of the document.
void select_last()
If selection size is <= 1, then select the last view, else move last_selected to the last selected el...
void set_show_subblock_labels(bool s)
Shows or hides subblocks labels on the image.
bool get_show_subblock_labels() const
Are subblocks labels shown on the image?
crn::SCDocument get_document() const
Gets the displayed document.
Glib::RefPtr< Gtk::ActionGroup > & get_views_actions()
Gets the action group associated to views management.
sigc::signal< void, const crn::String, const std::vector< crn::String > > signal_view_selection_changed()
Signal when the selection has changed. Connect to void on_view_selection_changed(const crn::String la...
A widget that holds an image.
Definition: GtkCRNImage.h:43
Gtk::Box & get_left_panel()
Return the VBox on the left of the image.
void reload_image(const crn::String &view_id)
Refreshes the thumbnail of a view and the Image if needed.
void set_show_thumbnails(bool s)
Shall the views show a thumbnail.
const GtkCRN::Image & get_image() const
Gets the image widget.
MouseMode
State of the mouse activity.
Definition: GtkCRNImage.h:116
Document(bool show_views=true, bool show_tree=true)
Constructor.
void deselect_all()
Selects all views.
A character string class.
Definition: CRNStringUTF8.h:49
void set_selected_view(const crn::String &view_id)
Sets the one selected view.
void set_selection_colors(const crn::pixel::RGB8 &col1, const crn::pixel::RGB8 &col2)
Sets the colors of the user selection on the image.
const crn::SBlock & get_selected_block()
Gets the displayed block.
sigc::signal< bool, const std::vector< crn::String > > signal_delete_selection()
Signal when the selection is about to be deleted. Connect to bool on_delete_selection(const std::vect...
void select_previous()
If selection size is 0, the select the first element, if selection size is 1, then select the previou...