1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
#include "image_cache.h"
#include "linux_utilities/plugin_editor_base.h"
#include "../backend/wb_editor_image.h"
#include <gtkmm/image.h>
#include <gtkmm/button.h>
#include <gtkmm/entry.h>
class ImageEditorFE : public PluginEditorBase
{
ImageEditorBE _be;
Glib::RefPtr<Gtk::Builder> _xml;
Gtk::Image *_image;
virtual bec::BaseEditor *get_be()
{
return &_be;
}
public:
ImageEditorFE(grt::Module *m, bec::GRTManager *grtm, const grt::BaseListRef &args)
: PluginEditorBase(m, grtm, args)
, _be(grtm, workbench_model_ImageFigureRef::cast_from(args[0]))
, _xml(0)
, _image(0)
{
set_border_width(8);
_xml= Gtk::Builder::create_from_file(grtm->get_data_file_path("modules/data/editor_image.glade"));
Gtk::Widget *widget;
_xml->get_widget("editor_image_hbox", widget);
Gtk::Button *button(0);
_xml->get_widget("browse_button", button);
button->signal_clicked().connect(sigc::mem_fun(this, &ImageEditorFE::browse_file));
_xml->get_widget("reset_size_button", button);
button->signal_clicked().connect(sigc::mem_fun(this, &ImageEditorFE::reset_aspect));
Gtk::CheckButton *check;
_xml->get_widget("aspect_check", check);
check->signal_toggled().connect(sigc::mem_fun(this, &ImageEditorFE::aspect_toggled));
Gtk::Entry *entry;
_xml->get_widget("width_entry", entry);
entry->signal_activate().connect(sigc::mem_fun(this, &ImageEditorFE::width_changed));
_xml->get_widget("height_entry", entry);
entry->signal_activate().connect(sigc::mem_fun(this, &ImageEditorFE::height_changed));
_xml->get_widget("image", _image);
widget->reparent(*this);
show_all();
refresh_form_data();
}
void browse_file()
{
std::string filename = open_file_chooser();
if (!filename.empty())
{
_be.set_filename(filename);
do_refresh_form_data();
}
}
void aspect_toggled()
{
Gtk::CheckButton *check;
_xml->get_widget("aspect_check", check);
_be.set_keep_aspect_ratio(check->get_active());
}
void reset_aspect()
{
int w= _image->get_pixbuf()->get_width();
int h= _image->get_pixbuf()->get_height();
_be.set_size(w, h);
}
virtual void do_refresh_form_data()
{
Gtk::Entry *entry;
int w, h;
_be.get_size(w, h);
_xml->get_widget("width_entry", entry);
entry->set_text(strfmt("%i", w));
_xml->get_widget("height_entry", entry);
entry->set_text(strfmt("%i", h));
Gtk::CheckButton *check;
_xml->get_widget("aspect_check", check);
check->set_active(_be.get_keep_aspect_ratio());
Glib::RefPtr<Gdk::Pixbuf> pixbuf(Gdk::Pixbuf::create_from_file(_be.get_attached_image_path()));
if (pixbuf)
_image->set(pixbuf);
else
g_message("ImageEditorFE: can not set image from %s[%s]", _be.get_filename().c_str(), _be.get_attached_image_path().c_str());
}
void width_changed()
{
Gtk::Entry *entry;
_xml->get_widget("width_entry", entry);
int i= base::atoi<int>(entry->get_text().c_str(), 0);
if (i > 0)
_be.set_width(i);
do_refresh_form_data();
}
void height_changed()
{
Gtk::Entry *entry;
_xml->get_widget("height_entry", entry);
int i= base::atoi<int>(entry->get_text().c_str(), 0);
if (i > 0)
_be.set_height(i);
do_refresh_form_data();
}
};
extern "C"
{
GUIPluginBase *createImageEditor(grt::Module *m, bec::GRTManager *grtm, const grt::BaseListRef &args)
{
return Gtk::manage(new ImageEditorFE(m, grtm, args));
}
};
|