26 #ifndef CRN_USING_GTKMM3
27 using namespace GtkCRN;
29 const crn::String AltoImage::pageList(U
"nimrod::4pages");
30 const crn::String AltoImage::spaceList(U
"nimrod::3spaces");
31 const crn::String AltoImage::blockList(U
"nimrod::2blocks");
32 const crn::String AltoImage::lineList(U
"nimrod::1lines");
33 const crn::String AltoImage::wordList(U
"nimrod::0words");
36 actions(Gtk::ActionGroup::create(
"alto image")),
40 can_edit_blocks(
true),
41 can_edit_spaces(
true),
44 actions->add(Gtk::ToggleAction::create(
"alto-pages", Gtk::StockID(
"gtk-crn-two-pages"),
_(
"Show/hide _pages"),
_(
"Show/hide pages")), sigc::mem_fun(
this, &AltoImage::show_hide_pages));
45 actions->add(Gtk::ToggleAction::create(
"alto-spaces", Gtk::StockID(
"gtk-crn-block"),
_(
"Show/hide _spaces"),
_(
"Show/hide spaces")), sigc::mem_fun(
this, &AltoImage::show_hide_spaces));
46 actions->add(Gtk::ToggleAction::create(
"alto-textblocks", Gtk::StockID(
"gtk-crn-paragraph"),
_(
"Show/hide _text blocks"),
_(
"Show/hide text blocks")), sigc::mem_fun(
this, &AltoImage::show_hide_blocks));
47 actions->add(Gtk::ToggleAction::create(
"alto-textlines", Gtk::Stock::JUSTIFY_LEFT,
_(
"Show/hide text _lines"),
_(
"Show/hide text lines")), sigc::mem_fun(
this, &AltoImage::show_hide_lines));
48 actions->add(Gtk::ToggleAction::create(
"alto-words", Gtk::Stock::ITALIC,
_(
"Show/hide _words"),
_(
"Show/hide words")), sigc::mem_fun(
this, &AltoImage::show_hide_words));
49 actions->add(Gtk::ToggleAction::create(
"alto-edit", Gtk::Stock::EDIT,
_(
"_Edit alto"),
_(
"Edit alto")), sigc::mem_fun(
this, &AltoImage::toggle_edit));
50 Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(actions->get_action(
"alto-edit"))->set_active(
false);
73 rmb_connect.disconnect();
74 overlay_connect.disconnect();
129 rmb_connect = img->
signal_rmb_clicked().connect(sigc::mem_fun(
this, &AltoImage::on_rmb_clicked));
130 overlay_connect = img->
signal_overlay_changed().connect(sigc::mem_fun(
this, &AltoImage::on_overlay_changed));
140 if (display_image && img)
153 if (clear_image && img)
155 img->
set_pixbuf(Glib::RefPtr<Gdk::Pixbuf>(
nullptr));
161 void AltoImage::show_hide_pages()
163 showpages = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(actions->get_action(
"alto-pages"))->get_active();
168 void AltoImage::show_hide_spaces()
170 showspaces = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(actions->get_action(
"alto-spaces"))->get_active();
175 void AltoImage::show_hide_blocks()
177 showtextblocks = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(actions->get_action(
"alto-textblocks"))->get_active();
182 void AltoImage::show_hide_lines()
184 showtextlines = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(actions->get_action(
"alto-textlines"))->get_active();
189 void AltoImage::show_hide_words()
191 showwords = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(actions->get_action(
"alto-words"))->get_active();
196 void AltoImage::toggle_edit()
198 edit_mode = Glib::RefPtr<Gtk::ToggleAction>::cast_dynamic(actions->get_action(
"alto-edit"))->get_active();
209 void AltoImage::on_rmb_clicked(guint mouse_button, guint32 time, std::vector<std::pair<crn::String, crn::String> > overlay_items_under_mouse,
int x,
int y)
213 popup.reset(
new Gtk::Menu);
215 for (
size_t tmp = 0; tmp < overlay_items_under_mouse.size(); ++tmp)
222 Gtk::MenuItem *mit = Gtk::manage(
new Gtk::MenuItem(
_(
"Add word")));
223 mit->signal_activate().connect(sigc::mem_fun(
this, &AltoImage::add_word));
229 else if ((overlay_items_under_mouse[tmp].first == wordList) && can_edit_words)
231 Gtk::MenuItem *mit = Gtk::manage(
new Gtk::MenuItem(
_(
"Delete word")));
232 mit->signal_activate().connect(sigc::bind(sigc::mem_fun(
this, &AltoImage::delete_word), overlay_items_under_mouse[tmp].second));
240 popup->popup(mouse_button, time);
251 if (overlay_id == spaceList)
259 view->ResizeSpace(path, rect.rect,
false);
265 const std::vector<crn::xml::Id> blocks(space.GetTextBlocks());
270 const std::vector<crn::xml::Id> lines(tb.GetTextLines());
275 const std::vector<crn::xml::Id> words(tl.GetWords());
279 img->
add_overlay_item(wordList, w.GetPath().ToString(), w.GetBBox(), w.GetContent());
280 word_resized.emit(w.GetPath());
295 else if (overlay_id == blockList)
304 view->ResizeTextBlock(path, rect.rect,
false);
311 const std::vector<crn::xml::Id> lines(tb.GetTextLines());
316 const std::vector<crn::xml::Id> words(tl.GetWords());
320 img->
add_overlay_item(wordList, w.GetPath().ToString(), w.GetBBox(), w.GetContent());
321 word_resized.emit(w.GetPath());
335 else if (overlay_id == lineList)
345 view->ResizeTextLine(path, rect.rect,
false);
353 const std::vector<crn::xml::Id> words(tl.GetWords());
357 img->
add_overlay_item(wordList, w.GetPath().ToString(), w.GetBBox(), w.GetContent());
358 word_resized.emit(w.GetPath());
371 else if (overlay_id == wordList)
382 view->ResizeWord(path, rect.rect);
384 img->
add_overlay_item(wordList, path.ToString(), w.GetBBox(), w.GetContent());
391 word_resized.emit(path);
398 void AltoImage::set_overlays()
409 const std::vector<crn::xml::Id> pages(view->GetPages());
413 img->
add_overlay_item(pageList, apage.GetPath().ToString(), apage.GetBBox());
414 const std::vector<crn::xml::Id> spaces(apage.GetSpaces());
418 img->
add_overlay_item(spaceList, aspace.GetPath().ToString(), aspace.GetBBox());
419 const std::vector<crn::xml::Id> blocks(aspace.GetTextBlocks());
423 img->
add_overlay_item(blockList, ablock.GetPath().ToString(), ablock.GetBBox());
424 const std::vector<crn::xml::Id> lines(ablock.GetTextLines());
428 img->
add_overlay_item(lineList, aline.GetPath().ToString(), aline.GetBBox());
429 const std::vector<crn::xml::Id> words(aline.GetWords());
433 img->
add_overlay_item(wordList, aword.GetPath().ToString(), aword.GetBBox(), aword.GetContent());
453 word_deleted.emit(path);
459 void AltoImage::add_word()
465 const std::vector<crn::xml::Id> pages(view->GetPages());
469 if (!(apage.GetBBox() & bbox).IsValid())
471 const std::vector<crn::xml::Id> spaces(apage.GetSpaces());
475 if (!(aspace.GetBBox() & bbox).IsValid())
477 const std::vector<crn::xml::Id> blocks(aspace.GetTextBlocks());
481 if (!(ablock.GetBBox() & bbox).IsValid())
483 const std::vector<crn::xml::Id> lines(ablock.GetTextLines());
487 if (!(aline.GetBBox() & bbox).IsValid())
491 const bool horiz = aline.
GetBBox().
GetWidth() > aline.GetBBox().GetHeight();
492 const std::vector<crn::xml::Id> words(aline.GetWords());
500 if (aword.GetBBox().GetLeft() > bbox.GetLeft())
502 nextword = aword.GetId();
508 if (aword.GetBBox().GetTop() > bbox.GetTop())
510 nextword = aword.GetId();
516 crn::Rect linebox(aline.GetBBox() | bbox);
517 if (linebox != aline.GetBBox())
522 view->ResizeTextLine(aline.GetPath(), linebox,
false);
531 img->
add_overlay_item(wordList, newword.GetPath().ToString(), newword.GetBBox(), newword.GetContent());
532 path = newword.GetPath();
537 img->
add_overlay_item(wordList, newword.GetPath().ToString(), newword.GetBBox(), newword.GetContent());
538 path = newword.GetPath();
540 word_added.emit(path);
Glib::RefPtr< Gdk::Pixbuf > PixbufFromCRNImage(const crn::ImageBase &img)
Creates a Gdk::Pixbuf from a crn::Image.
void set_overlay_visible(const crn::String &id, bool visible)
Shows or hides an overlay.
OverlayConfig & get_overlay_config(const crn::String &id)
Gets the configuration of an overlay.
sigc::signal< void, guint, guint32, std::vector< std::pair< crn::String, crn::String > >, int, int > signal_rmb_clicked()
Returns a signal that can be used to generate pop-up menus. Binds to void on_rmb_clicked(guint mouse_...
const crn::Rect & get_selection_as_rect() const
Gets the mouse selection as a rectangle.
void set_view(const crn::xml::AltoWrapper::View &v, bool display_image)
Sets the alto view.
bool IsEmpty() const noexcept
Checks if the string is empty.
AltoImage(Image *image=nullptr)
bool IsNotEmpty() const noexcept
Checks if the string is not empty.
void set_image(Image *image)
Sets the Image widget to wrap around.
void RemoveWord(const Id &wid)
Removes a line element.
A UTF32 character string class.
void set_selection_type(Overlay typ)
Sets the mouse selection type.
void clear_overlay(const crn::String &id)
Clears an overlay.
void add_overlay_item(const crn::String &overlay_id, const crn::String &item_id, const crn::Rect &r, const crn::StringUTF8 &label="")
Adds a rectangle to an overlay.
A widget that holds an image.
static const crn::String & selection_overlay()
Returns the name of the mouse selection overlay.
int GetWidth() const
Returns the width of the rectangle.
void force_redraw()
Force the image to redraw.
MouseMode
State of the mouse activity.
void set_pixbuf(Glib::RefPtr< Gdk::Pixbuf > pb)
Sets the new image to display.
void clear_selection()
Clears the mouse selection.
A character string class.
sigc::signal< void, crn::String, crn::String, MouseMode > signal_overlay_changed()
Returns the signal associated to changes in selections. Binds to void on_overlay_changed(crn::String ...
OverlayItem & get_overlay_item(const crn::String &overlay_id, const crn::String &item_id)
Gets an overlay item.
Gdk::Color ColorFromCRNPixel(const crn::pixel::RGB8 &p)
Creates a Gdk::Color from a crn::Pixel.
void unset_view(bool clear_image)
Unsets the alto view.
void remove_overlay_item(const crn::String &overlay_id, const crn::String &item_id)
Removes an overlay item.
const Rect & GetBBox() const
Gets the coordinates of the text line.
An item was not found in a container.