From 9bbc588e18f7b9647c3d9b03d257a45dda42520a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sun, 27 Jan 2019 01:36:47 +0100 Subject: Improvements to icon loader code --- src/ui/icon-loader.cpp | 118 ++++++++++++++++++------------------------------- src/ui/icon-loader.h | 15 ++++--- 2 files changed, 50 insertions(+), 83 deletions(-) (limited to 'src') diff --git a/src/ui/icon-loader.cpp b/src/ui/icon-loader.cpp index a6011773d..e2aaf5093 100644 --- a/src/ui/icon-loader.cpp +++ b/src/ui/icon-loader.cpp @@ -10,64 +10,63 @@ * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ + #include "icon-loader.h" #include "inkscape.h" -#include "io/resource.h" -#include "preferences.h" -#include "svg/svg-color.h" #include "widgets/toolbox.h" +#include #include #include #include #include -#include -void sp_load_theme() {} +Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, gint size) +{ + Gtk::Image *icon = new Gtk::Image(); + icon->set_from_icon_name(icon_name, Gtk::IconSize(Gtk::ICON_SIZE_BUTTON)); + icon->set_pixel_size(size); + return icon; +} + +Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, Gtk::IconSize icon_size) +{ + Gtk::Image *icon = new Gtk::Image(); + icon->set_from_icon_name(icon_name, icon_size); + return icon; +} + +Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, Gtk::BuiltinIconSize icon_size) +{ + Gtk::Image *icon = new Gtk::Image(); + icon->set_from_icon_name(icon_name, icon_size); + return icon; +} + +GtkWidget *sp_get_icon_image(Glib::ustring icon_name, GtkIconSize icon_size) +{ + return gtk_image_new_from_icon_name(icon_name.c_str(), icon_size); +} + +Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, gchar const *prefs_size) +{ + Gtk::IconSize icon_size = Inkscape::UI::ToolboxFactory::prefToSize_mm(prefs_size); + return sp_get_icon_image(icon_name, icon_size); +} Glib::RefPtr sp_get_icon_pixbuf(Glib::ustring icon_name, gint size) { Glib::RefPtr display = Gdk::Display::get_default(); Glib::RefPtr screen = display->get_default_screen(); Glib::RefPtr icon_theme = Gtk::IconTheme::get_for_screen(screen); - // TODO all calls to "sp_get_icon_pixbuf" need to be removed in thew furture - // Put here temporary for allow use symbolic in a few icons require pixbug instead Gtk::Image - // We coulden't acces to pixbuf of a symbolic ones with the next order - // icon_theme->load_icon(icon_name, size, Gtk::ICON_LOOKUP_FORCE_SIZE); - // Maybe we can do with Gio, but not sure. Also can render a icon to pixbuf but need to be - // a stock-icon not on named ones I think or access directly to the icon.svg file - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Glib::RefPtr _icon_pixbuf; - try { - if (prefs->getBool("/theme/symbolicIcons", false)) { - gchar colornamed[64]; - int colorset = prefs->getInt("/theme/symbolicColor", 0x000000ff); - // Use in case the special widgets have inverse theme background and symbolic - sp_svg_write_color(colornamed, sizeof(colornamed), colorset); - Gdk::RGBA color; - color.set(colornamed); - Gtk::IconInfo iconinfo = - icon_theme->lookup_icon(icon_name + Glib::ustring("-symbolic"), size, Gtk::ICON_LOOKUP_FORCE_SIZE); - if (bool(iconinfo)) { - bool was_symbolic = false; - _icon_pixbuf = iconinfo.load_symbolic(color, color, color, color, was_symbolic); - } - else { - _icon_pixbuf = icon_theme->load_icon(icon_name, size, Gtk::ICON_LOOKUP_FORCE_SIZE); - } - // g_warning("Icon Loader using a future dead function in this icon: %s", icon_name.c_str()); - // limit warns to 1 per run - static bool tmp_warn = true; - if (tmp_warn) { - tmp_warn = false; - g_warning("Icon Loader using a legacy function (sp_get_icon_pixbuf)."); - } - } - else { - _icon_pixbuf = icon_theme->load_icon(icon_name, size, Gtk::ICON_LOOKUP_FORCE_SIZE); - } - } - catch (const Gtk::IconThemeError &e) { - g_warning("Icon Loader error loading icon file: %s", e.what().c_str()); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (prefs->getBool("/theme/symbolicIcons", false)) { + Gtk::IconInfo iconinfo = icon_theme->lookup_icon(icon_name + Glib::ustring("-symbolic"), size, Gtk::ICON_LOOKUP_FORCE_SIZE); + bool was_sumbolic = false; + _icon_pixbuf = iconinfo.load_symbolic(SP_ACTIVE_DESKTOP->getToplevel()->get_style_context(), was_sumbolic); + } else { + Gtk::IconInfo iconinfo = icon_theme->lookup_icon(icon_name, size, Gtk::ICON_LOOKUP_FORCE_SIZE); + _icon_pixbuf = iconinfo.load_icon(); } return _icon_pixbuf; } @@ -103,39 +102,6 @@ Glib::RefPtr sp_get_icon_pixbuf(Glib::ustring icon_name, gchar cons return sp_get_icon_pixbuf(icon_name, icon_size); } - -Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, Gtk::BuiltinIconSize icon_size) -{ - - Gtk::Image *icon = new Gtk::Image(); - icon->set_from_icon_name(icon_name, Gtk::IconSize(icon_size)); - return icon; -} - -Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, Gtk::IconSize icon_size) -{ - - Gtk::Image *icon = new Gtk::Image(); - icon->set_from_icon_name(icon_name, icon_size); - return icon; -} - -Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, gchar const *prefs_size) -{ - - Gtk::IconSize icon_size = Inkscape::UI::ToolboxFactory::prefToSize_mm(prefs_size); - Gtk::Image *icon = new Gtk::Image(); - icon->set_from_icon_name(icon_name, icon_size); - return icon; -} - - -GtkWidget *sp_get_icon_image(Glib::ustring icon_name, GtkIconSize icon_size) -{ - - return gtk_image_new_from_icon_name(icon_name.c_str(), icon_size); -} - /* Local Variables: mode:c++ diff --git a/src/ui/icon-loader.h b/src/ui/icon-loader.h index 3f7f1fcb8..78975e210 100644 --- a/src/ui/icon-loader.h +++ b/src/ui/icon-loader.h @@ -13,16 +13,17 @@ #define SEEN_INK_ICON_LOADER_H #include -#include #include +Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, gint size); +Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, Gtk::BuiltinIconSize icon_size); +Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, Gtk::IconSize icon_size); +Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, gchar const *prefs_sice); +GtkWidget *sp_get_icon_image(Glib::ustring icon_name, GtkIconSize icon_size); Glib::RefPtr sp_get_icon_pixbuf(Glib::ustring icon_name, gint size); -Glib::RefPtr sp_get_icon_pixbuf(Glib::ustring icon_name, Gtk::BuiltinIconSize icon_size); Glib::RefPtr sp_get_icon_pixbuf(Glib::ustring icon_name, Gtk::IconSize icon_size); +Glib::RefPtr sp_get_icon_pixbuf(Glib::ustring icon_name, Gtk::BuiltinIconSize icon_size); Glib::RefPtr sp_get_icon_pixbuf(Glib::ustring icon_name, GtkIconSize icon_size); Glib::RefPtr sp_get_icon_pixbuf(Glib::ustring icon_name, gchar const *prefs_sice); -Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, Gtk::BuiltinIconSize icon_size); -Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, Gtk::IconSize icon_size); -Gtk::Image *sp_get_icon_image(Glib::ustring icon_name, gchar const *prefs_sice); -GtkWidget *sp_get_icon_image(Glib::ustring icon_name, GtkIconSize icon_size); -#endif // SEEN_INK_STOCK_ITEMS_H + +#endif // SEEN_INK_ICON_LOADER_H -- cgit v1.2.3 From eab7157c28648171c0b68e96d41478443c267f9f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Fri, 25 Jan 2019 01:04:08 +0100 Subject: Initial work of LPESelector --- src/live_effects/effect-enum.h | 908 ++++++++++++++++++++++++++++++++++- src/live_effects/effect.cpp | 70 +-- src/ui/dialog/livepatheffect-add.cpp | 222 +++++---- src/ui/dialog/livepatheffect-add.h | 69 +-- src/ui/dialog/lpe-selector.cpp | 69 +++ src/ui/dialog/lpe-selector.h | 38 ++ 6 files changed, 1169 insertions(+), 207 deletions(-) create mode 100644 src/ui/dialog/lpe-selector.cpp create mode 100644 src/ui/dialog/lpe-selector.h (limited to 'src') diff --git a/src/live_effects/effect-enum.h b/src/live_effects/effect-enum.h index b662d3263..595c81a78 100644 --- a/src/live_effects/effect-enum.h +++ b/src/live_effects/effect-enum.h @@ -11,6 +11,10 @@ */ #include "util/enums.h" +#include + + + namespace Inkscape { namespace LivePathEffect { @@ -75,8 +79,908 @@ enum EffectType { INVALID_LPE // This must be last (I made it such that it is not needed anymore I think..., Don't trust on it being last. - johan) }; -extern const Util::EnumData LPETypeData[]; /// defined in effect.cpp -extern const Util::EnumDataConverter LPETypeConverter; /// defined in effect.cpp +template + struct EnumEffectData + { + E id; + const Glib::ustring label; + const Glib::ustring key; + const Glib::ustring icon; + const Glib::ustring description; + const bool on_path; + const bool on_shape; + const bool on_group; + const bool on_use; + const bool on_image; + const bool on_text; + }; + +const Glib::ustring empty_string(""); + +/** + * Simplified management of enumerations of LPE items with UI labels. + * + * @note that get_id_from_key and get_id_from_label return 0 if it cannot find an entry for that key string. + * @note that get_label and get_key return an empty string when the requested id is not in the list. + */ +template class EnumEffectDataConverter +{ +public: + typedef EnumEffectData Data; + + EnumEffectDataConverter(const EnumEffectData* cd, const unsigned int length) + : _length(length), _data(cd) + {} + + E get_id_from_label(const Glib::ustring& label) const + { + for(unsigned int i = 0; i < _length; ++i) { + if(_data[i].label == label) + return _data[i].id; + } + + return (E)0; + } + + E get_id_from_key(const Glib::ustring& key) const + { + for(unsigned int i = 0; i < _length; ++i) { + if(_data[i].key == key) + return _data[i].id; + } + + return (E)0; + } + + bool is_valid_key(const Glib::ustring& key) const + { + for(unsigned int i = 0; i < _length; ++i) { + if(_data[i].key == key) + return true; + } + + return false; + } + + bool is_valid_id(const E id) const + { + for(unsigned int i = 0; i < _length; ++i) { + if(_data[i].id == id) + return true; + } + return false; + } + + const Glib::ustring& get_label(const E id) const + { + for(unsigned int i = 0; i < _length; ++i) { + if(_data[i].id == id) + return _data[i].label; + } + + return empty_string; + } + + const Glib::ustring& get_key(const E id) const + { + for(unsigned int i = 0; i < _length; ++i) { + if(_data[i].id == id) + return _data[i].key; + } + + return empty_string; + } + + const Glib::ustring& get_icon(const E id) const + { + for(unsigned int i = 0; i < _length; ++i) { + if(_data[i].id == id) + return _data[i].icon; + } + + return empty_string; + } + + const Glib::ustring& get_description(const E id) const + { + for(unsigned int i = 0; i < _length; ++i) { + if(_data[i].id == id) + return _data[i].description; + } + + return empty_string; + } + + const bool& get_on_path(const E id) const + { + for(unsigned int i = 0; i < _length; ++i) { + if(_data[i].id == id) + return _data[i].path; + } + + return false; + } + + const bool& get_on_shape(const E id) const + { + for(unsigned int i = 0; i < _length; ++i) { + if(_data[i].id == id) + return _data[i].shape; + } + + return false; + } + + const bool& get_on_group(const E id) const + { + for(unsigned int i = 0; i < _length; ++i) { + if(_data[i].id == id) + return _data[i].group; + } + + return false; + } + + const bool& get_on_text(const E id) const + { + for(unsigned int i = 0; i < _length; ++i) { + if(_data[i].id == id) + return _data[i].shape; + } + + return false; + } + + const bool& get_on_use(const E id) const + { + for(unsigned int i = 0; i < _length; ++i) { + if(_data[i].id == id) + return _data[i].use; + } + + return false; + } + + const EnumEffectData& data(const unsigned int i) const + { + return _data[i]; + } + + const unsigned int _length; +private: + const EnumEffectData* _data; +}; + +const EnumEffectData LPETypeData[] = { + // {constant defined in effect-enum.h, N_("name of your effect"), "name of your effect in SVG"} +/* 0.46 */ + { + BEND_PATH + , N_("Bend") //label + , "bend_path" //key + , "bend-path" //icon + , N_("Curve a item based on skeleton path") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + GEARS + , N_("Gears") //label + , "gears" //key + , "gears" //icon + , N_("Create configurable gears") //description + , true //on_path + , true //on_shape + , false //on_group + , false //on_use + , false //on_image + , false //on_text + }, + { + PATTERN_ALONG_PATH + , N_("Pattern Along Path") //label + , "skeletal" //key + , "skeletal" //icon + , N_("transform a tiem along path with or without repeating") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, // for historic reasons, this effect is called skeletal(strokes) in Inkscape:SVG + { + CURVE_STITCH + , N_("Stitch Sub-Paths") //label + , "curvestitching" //key + , "curvestitching" //icon + , N_("curvestitching") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, +/* 0.47 */ + { + VONKOCH + , N_("VonKoch") //label + , "vonkoch" //key + , "vonkoch" //icon + , N_("vonkoch") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + KNOT + , N_("Knot") //label + , "knot" //key + , "knot" //icon + , N_("knot") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + CONSTRUCT_GRID + , N_("Construct grid") //label + , "construct_grid" //key + , "construct-grid" //icon + , N_("construct_grid") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + SPIRO + , N_("Spiro spline") //label + , "spiro" //key + , "spiro" //icon + , N_("spiro") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + ENVELOPE + , N_("Envelope Deformation") //label + , "envelope" //key + , "envelope" //icon + , N_("Envelope Deformation") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + INTERPOLATE + , N_("Interpolate Sub-Paths") //label + , "interpolate" //key + , "interpolate" //icon + , N_("Interpolate Sub-Paths") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + ROUGH_HATCHES + , N_("Hatches (rough)") //label + , "rough_hatches" //key + , "rough-hatches" //icon + , N_("Hatches (rough)") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + SKETCH + , N_("Sketch") //label + , "sketch" //key + , "sketch" //icon + , N_("Sketch") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + RULER + , N_("Ruler") //label + , "ruler" //key + , "ruler" //icon + , N_("Ruler") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, +/* 0.91 */ + { + POWERSTROKE + , N_("Power stroke") //label + , "powerstroke" //key + , "powerstroke" //icon + , N_("Power stroke") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + CLONE_ORIGINAL + , N_("Clone original") //label + , "clone_original" //key + , "clone-original" //icon + , N_("Clone original") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, +/* 0.92 */ + { + SIMPLIFY + , N_("Simplify") //label + , "simplify" //key + , "simplify" //icon + , N_("Simplify") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + LATTICE2 + , N_("Lattice Deformation 2") //label + , "lattice2" //key + , "lattice2" //icon + , N_("Lattice Deformation 2") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + PERSPECTIVE_ENVELOPE + , N_("Perspective/Envelope") //label + , "perspective-envelope" //key wrong key with "-" retain because historic + , "perspective-envelope" //icon + , N_("Perspective/Envelope") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + INTERPOLATE_POINTS + , N_("Interpolate points") //label + , "interpolate_points" //key + , "interpolate-points" //icon + , N_("Interpolate points") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + TRANSFORM_2PTS + , N_("Transform by 2 points") //label + , "transform_2pts" //key + , "transform-2pts" //icon + , N_("Transform by 2 points") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + SHOW_HANDLES + , N_("Show handles") //label + , "show_handles" //key + , "show-handles" //icon + , N_("Show handles") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + ROUGHEN + , N_("Roughen") //label + , "roughen" //key + , "roughen" //icon + , N_("Roughen") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + BSPLINE + , N_("BSpline") //label + , "bspline" //key + , "bspline" //icon + , N_("BSpline") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + JOIN_TYPE + , N_("Join type") //label + , "join_type" //key + , "join-type" //icon + , N_("Join type") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + TAPER_STROKE + , N_("Taper stroke") //label + , "taper_stroke" //key + , "taper-stroke" //icon + , N_("Taper stroke") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + MIRROR_SYMMETRY + , N_("Mirror symmetry") //label + , "mirror_symmetry" //key + , "mirror-symmetry" //icon + , N_("Mirror symmetry") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + COPY_ROTATE + , N_("Rotate copies") //label + , "copy_rotate" //key + , "copy-rotate" //icon + , N_("Rotate copies") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, +/* Ponyscape -> Inkscape 0.92*/ + { + ATTACH_PATH + , N_("Attach path") //label + , "attach_path" //key + , "attach-path" //icon + , N_("Attach path") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + FILL_BETWEEN_STROKES + , N_("Fill between strokes") //label + , "fill_between_strokes" //key + , "fill-between-strokes" //icon + , N_("Fill between strokes") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + FILL_BETWEEN_MANY + , N_("Fill between many") //label + , "fill_between_many" //key + , "fill-between-many" //icon + , N_("Fill between many") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + ELLIPSE_5PTS + , N_("Ellipse by 5 points") //label + , "ellipse_5pts" //key + , "ellipse-5pts" //icon + , N_("Ellipse by 5 points") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + BOUNDING_BOX + , N_("Bounding Box") //label + , "bounding_box" //key + , "bounding-box" //icon + , N_("Bounding Box") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, +/* 1.0 */ + { + MEASURE_SEGMENTS + , N_("Measure Segments") //label + , "measure_segments" //key + , "measure-segments" //icon + , N_("Measure Segments") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + FILLET_CHAMFER + , N_("Fillet/Chamfer") //label + , "fillet_chamfer" //key + , "fillet-chamfer" //icon + , N_("Fillet/Chamfer") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + BOOL_OP + , N_("Boolean operation") //label + , "bool_op" //key + , "bool-op" //icon + , N_("Boolean operation") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + EMBRODERY_STITCH + , N_("Embroidery stitch") //label + , "embrodery_stitch" //key + , "embrodery-stitch" //icon + , N_("Embroidery stitch") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + POWERCLIP + , N_("Power clip") //label + , "powerclip" //key + , "powerclip" //icon + , N_("Power clip") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + POWERMASK + , N_("Power mask") //label + , "powermask" //key + , "powermask" //icon + , N_("Power mask") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + PTS2ELLIPSE + , N_("Ellipse from points") //label + , "pts2ellipse" //key + , "pts2ellipse" //icon + , N_("Ellipse from points") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + OFFSET + , N_("Offset") //label + , "offset" //key + , "offset" //icon + , N_("Offset") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + DASH_STROKE + , N_("Dash Stroke") //label + , "dash_stroke" //key + , "dash-stroke" //icon + , N_("Dash Stroke") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, +#ifdef LPE_ENABLE_TEST_EFFECTS + { + DOEFFECTSTACK_TEST + , N_("doEffect stack test") //label + , "doeffectstacktest" //key + , "experimental" //icon + , N_("doEffect stack test") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + ANGLE_BISECTOR + , N_("Angle bisector") //label + , "angle_bisector" //key + , "experimental" //icon + , N_("Angle bisector") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + CIRCLE_WITH_RADIUS + , N_("Circle (by center and radius)") //label + , "circle_with_radius" //key + , "experimental" //icon + , N_("Circle (by center and radius)") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + CIRCLE_3PTS + , N_("Circle by 3 points") //label + , "circle_3pts" //key + , "experimental" //icon + , N_("Circle by 3 points") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + DYNASTROKE + , N_("Dynamic stroke") //label + , "dynastroke" //key + , "experimental" //icon + , N_("Dynamic stroke") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + EXTRUDE + , N_("Extrude") //label + , "extrude" //key + , "experimental" //icon + , N_("Extrude") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + LATTICE + , N_("Lattice Deformation") //label + , "lattice" //key + , "experimental" //icon + , N_("Lattice Deformation") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + LINE_SEGMENT + , N_("Line Segment") //label + , "line_segment" //key + , "experimental" //icon + , N_("Line Segment") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + PARALLEL + , N_("Parallel") //label + , "parallel" //key + , "experimental" //icon + , N_("Parallel") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + PATH_LENGTH + , N_("Path length") //label + , "path_length" //key + , "experimental" //icon + , N_("Path length") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + PERP_BISECTOR + , N_("Perpendicular bisector") //label + , "perp_bisector" //key + , "experimental" //icon + , N_("Perpendicular bisector") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + RECURSIVE_SKELETON + , N_("Recursive skeleton") //label + , "recursive_skeleton" //key + , "experimental" //icon + , N_("Recursive skeleton") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + TANGENT_TO_CURVE + , N_("Tangent to curve") //label + , "tangent_to_curve" //key + , "experimental" //icon + , N_("Tangent to curve") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, + { + TEXT_LABEL + , N_("Text label") //label + , "text_label" //key + , "experimental" //icon + , N_("Text label") //description + , true //on_path + , true //on_shape + , true //on_group + , true //on_use + , false //on_image + , false //on_text + }, +#endif + +}; + +extern const EnumEffectData LPETypeData[]; /// defined in effect.cpp +extern const EnumEffectDataConverter LPETypeConverter; /// defined in effect.cpp } //namespace LivePathEffect } //namespace Inkscape diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 92f5a781a..f83d07c6d 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -94,74 +94,10 @@ namespace Inkscape { namespace LivePathEffect { -const Util::EnumData LPETypeData[] = { - // {constant defined in effect-enum.h, N_("name of your effect"), "name of your effect in SVG"} -/* 0.46 */ - {BEND_PATH, N_("Bend"), "bend_path"}, - {GEARS, N_("Gears"), "gears"}, - {PATTERN_ALONG_PATH, N_("Pattern Along Path"), "skeletal"}, // for historic reasons, this effect is called skeletal(strokes) in Inkscape:SVG - {CURVE_STITCH, N_("Stitch Sub-Paths"), "curvestitching"}, -/* 0.47 */ - {VONKOCH, N_("VonKoch"), "vonkoch"}, - {KNOT, N_("Knot"), "knot"}, - {CONSTRUCT_GRID, N_("Construct grid"), "construct_grid"}, - {SPIRO, N_("Spiro spline"), "spiro"}, - {ENVELOPE, N_("Envelope Deformation"), "envelope"}, - {INTERPOLATE, N_("Interpolate Sub-Paths"), "interpolate"}, - {ROUGH_HATCHES, N_("Hatches (rough)"), "rough_hatches"}, - {SKETCH, N_("Sketch"), "sketch"}, - {RULER, N_("Ruler"), "ruler"}, -/* 0.91 */ - {POWERSTROKE, N_("Power stroke"), "powerstroke"}, - {CLONE_ORIGINAL, N_("Clone original"), "clone_original"}, -/* 0.92 */ - {SIMPLIFY, N_("Simplify"), "simplify"}, - {LATTICE2, N_("Lattice Deformation 2"), "lattice2"}, - {PERSPECTIVE_ENVELOPE, N_("Perspective/Envelope"), "perspective-envelope"}, //TODO:Wrong name with "-" - {INTERPOLATE_POINTS, N_("Interpolate points"), "interpolate_points"}, - {TRANSFORM_2PTS, N_("Transform by 2 points"), "transform_2pts"}, - {SHOW_HANDLES, N_("Show handles"), "show_handles"}, - {ROUGHEN, N_("Roughen"), "roughen"}, - {BSPLINE, N_("BSpline"), "bspline"}, - {JOIN_TYPE, N_("Join type"), "join_type"}, - {TAPER_STROKE, N_("Taper stroke"), "taper_stroke"}, - {MIRROR_SYMMETRY, N_("Mirror symmetry"), "mirror_symmetry"}, - {COPY_ROTATE, N_("Rotate copies"), "copy_rotate"}, -/* Ponyscape -> Inkscape 0.92*/ - {ATTACH_PATH, N_("Attach path"), "attach_path"}, - {FILL_BETWEEN_STROKES, N_("Fill between strokes"), "fill_between_strokes"}, - {FILL_BETWEEN_MANY, N_("Fill between many"), "fill_between_many"}, - {ELLIPSE_5PTS, N_("Ellipse by 5 points"), "ellipse_5pts"}, - {BOUNDING_BOX, N_("Bounding Box"), "bounding_box"}, -/* 0.93 */ - {MEASURE_SEGMENTS, N_("Measure Segments"), "measure_segments"}, - {FILLET_CHAMFER, N_("Fillet/Chamfer"), "fillet_chamfer"}, - {BOOL_OP, N_("Boolean operation"), "bool_op"}, - {EMBRODERY_STITCH, N_("Embroidery stitch"), "embrodery_stitch"}, - {POWERCLIP, N_("Power clip"), "powerclip"}, - {POWERMASK, N_("Power mask"), "powermask"}, - {PTS2ELLIPSE, N_("Ellipse from points"), "pts2ellipse"}, - {OFFSET, N_("Offset"), "offset"}, - {DASH_STROKE, N_("Dash Stroke"), "dash_stroke"}, -#ifdef LPE_ENABLE_TEST_EFFECTS - {DOEFFECTSTACK_TEST, N_("doEffect stack test"), "doeffectstacktest"}, - {ANGLE_BISECTOR, N_("Angle bisector"), "angle_bisector"}, - {CIRCLE_WITH_RADIUS, N_("Circle (by center and radius)"), "circle_with_radius"}, - {CIRCLE_3PTS, N_("Circle by 3 points"), "circle_3pts"}, - {DYNASTROKE, N_("Dynamic stroke"), "dynastroke"}, - {EXTRUDE, N_("Extrude"), "extrude"}, - {LATTICE, N_("Lattice Deformation"), "lattice"}, - {LINE_SEGMENT, N_("Line Segment"), "line_segment"}, - {PARALLEL, N_("Parallel"), "parallel"}, - {PATH_LENGTH, N_("Path length"), "path_length"}, - {PERP_BISECTOR, N_("Perpendicular bisector"), "perp_bisector"}, - {RECURSIVE_SKELETON, N_("Recursive skeleton"), "recursive_skeleton"}, - {TANGENT_TO_CURVE, N_("Tangent to curve"), "tangent_to_curve"}, - {TEXT_LABEL, N_("Text label"), "text_label"}, -#endif -}; -const Util::EnumDataConverter LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData)); + + +const EnumEffectDataConverter LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData)); int Effect::acceptsNumClicks(EffectType type) { diff --git a/src/ui/dialog/livepatheffect-add.cpp b/src/ui/dialog/livepatheffect-add.cpp index 1fae9a513..f930199cf 100644 --- a/src/ui/dialog/livepatheffect-add.cpp +++ b/src/ui/dialog/livepatheffect-add.cpp @@ -13,9 +13,10 @@ # include "config.h" // only include where actually required! #endif +#include "live_effects/effect.h" #include "livepatheffect-add.h" #include - +#include "io/resource.h" #include "desktop.h" namespace Inkscape { @@ -23,87 +24,147 @@ namespace UI { namespace Dialog { LivePathEffectAdd::LivePathEffectAdd() : - add_button(_("_Add"), true), - close_button(_("_Cancel"), true), - converter(Inkscape::LivePathEffect::LPETypeConverter), - applied(false) + _add_button(_("_Add"), true), + _close_button(_("_Cancel"), true), + converter(Inkscape::LivePathEffect::LPETypeConverter) { - set_title(_("Add Path Effect")); - - /** - * Scrolled Window - */ - scrolled_window.add(effectlist_treeview); - scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); - scrolled_window.set_shadow_type(Gtk::SHADOW_IN); - scrolled_window.set_size_request(250, 200); - scrolled_window.set_can_focus(); - - /** - * Effect Store and Tree - */ - effectlist_store = Gtk::ListStore::create(_columns); - effectlist_store->set_sort_column (_columns.name, Gtk::SORT_ASCENDING ); - - effectlist_treeview.set_model(effectlist_store); - effectlist_treeview.set_headers_visible(false); - effectlist_treeview.append_column("Name", _columns.name); - //effectlist_treeview.set_activates_default(true); + const std::string req_widgets[] = {"LPESelector", "LPESelectorFlowBox"}; + Glib::ustring gladefile = get_filename(Inkscape::IO::Resource::UIS, "lpe-selector.glade"); + try { + _builder = Gtk::Builder::create_from_file(gladefile); + } catch(const Glib::Error& ex) { + g_warning("Glade file loading failed for filter effect dialog"); + return; + } + Gtk::Object* test; + for(std::string w:req_widgets) { + _builder->get_widget(w,test); + if(!test){ + g_warning("Required widget %s does not exist", w.c_str()); + return; + } + } + _builder->get_widget("LPESelector", _LPESelector); + auto mainVBox = get_content_area(); + mainVBox->pack_start(*_LPESelector, true, true); /** * Initialize Effect list */ - int show = LivePathEffect::ATTACH_PATH; -#ifdef LPE_ENABLE_TEST_EFFECTS - //TODO: Handle when showing the experimental effects without setting flag - show = LivePathEffect::ANGLE_BISECTOR; -#elif WITH_LPETOOL - //TODO: Handle when showing the experimental effects without setting flag - show = LivePathEffect::ANGLE_BISECTOR; -#endif - + _builder->get_widget("LPESelectorFlowBox", _LPESelectorFlowBox); + _builder->get_widget("LPEFilter", _LPEFilter); + _builder->get_widget("LPEInfo", _LPEInfo); + _LPEFilter->signal_search_changed().connect(sigc::mem_fun(*this, &LivePathEffectAdd::on_search)); + const std::string le_widgets[] = {"LPESelectorItem", "LPEName","LPEDescription"}; + Glib::ustring le_gladefile = get_filename(Inkscape::IO::Resource::UIS, "lpe-selector-item.glade"); for(int i = 0; i < static_cast(converter._length); ++i) { - Gtk::TreeModel::Row row = *(effectlist_store->append()); - const Util::EnumData* data = &converter.data(i); - row[_columns.name] = _( converter.get_label(data->id).c_str() ); - row[_columns.data] = data; - if (i == show) { - Glib::RefPtr select = effectlist_treeview.get_selection(); - select->select(row); + + try { + _builder = Gtk::Builder::create_from_file(le_gladefile); + } catch(const Glib::Error& ex) { + g_warning("Glade file loading failed for filter effect dialog"); + return; } - } - - /** - * Buttons - */ - //close_button.set_can_default(); - add_button.set_use_underline(true); - add_button.set_can_default(); - auto mainVBox = get_content_area(); - - mainVBox->pack_start(scrolled_window, true, true); - add_action_widget(close_button, Gtk::RESPONSE_CLOSE); - add_action_widget(add_button, Gtk::RESPONSE_APPLY); + Gtk::Object* test; + for(std::string w:le_widgets) { + _builder->get_widget(w,test); + if(!test){ + g_warning("Required widget %s does not exist", w.c_str()); + return; + } + } + const LivePathEffect::EnumEffectData* data = &converter.data(i); + Gtk::Label * LPEName; + _builder->get_widget("LPEName", LPEName); + Glib::ustring newid = "LPEName_" + Glib::ustring::format(i); + (*LPEName).set_name(newid); + (*LPEName).set_text(converter.get_label(data->id).c_str()); + Gtk::Label * LPEDescription; + _builder->get_widget("LPEDescription", LPEDescription); + newid = "LPEDescription_" + Glib::ustring::format(i); + (*LPEDescription).set_name(newid); + (*LPEDescription).set_text(converter.get_description(data->id)); + Gtk::Image * LPEIcon; + _builder->get_widget("LPEIcon", LPEIcon); + newid = "LPEIcon_" + Glib::ustring::format(i); + (*LPEIcon).set_name(newid); + (*LPEIcon).set_from_icon_name(converter.get_icon(data->id),Gtk::BuiltinIconSize(Gtk::ICON_SIZE_DIALOG)); + Gtk::Box * LPESelectorItem; + _builder->get_widget("LPESelectorItem", LPESelectorItem); + newid = "LPESelectorItem" + Glib::ustring::format(i); + (*LPESelectorItem).set_name(newid); + _LPESelectorFlowBox->insert(*LPESelectorItem, i); + } + _visiblelpe = _LPESelectorFlowBox->get_children().size(); + _LPESelectorFlowBox->signal_child_activated().connect(sigc::mem_fun(*this, &LivePathEffectAdd::on_activate)); + set_title(_("Live Efects Selector")); + show_all_children(); + _LPEInfo->set_visible(false); +} - - /** - * Signal handlers - */ - effectlist_treeview.signal_button_press_event().connect_notify( sigc::mem_fun(*this, &LivePathEffectAdd::onButtonEvent) ); - effectlist_treeview.signal_key_press_event().connect_notify(sigc::mem_fun(*this, &LivePathEffectAdd::onKeyEvent)); - close_button.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectAdd::onClose)); - add_button.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectAdd::onAdd)); - signal_delete_event().connect( sigc::bind_return(sigc::hide(sigc::mem_fun(*this, &LivePathEffectAdd::onClose)), true ) ); +void LivePathEffectAdd::on_activate(Gtk::FlowBoxChild *child){ + for (auto i:_LPESelectorFlowBox->get_children()) { + Gtk::FlowBoxChild * leitem = dynamic_cast(i); + leitem->get_style_context()->remove_class("lpeactive"); + Gtk::Box *box = dynamic_cast(leitem->get_child()); + if (box) { + std::vector contents = box->get_children(); + Gtk::Box *actions = dynamic_cast(contents[3]); + if (actions) { + actions->set_visible(false); + } + } + } + child->get_style_context()->add_class("lpeactive"); + child->show_all_children(); +} - add_button.grab_default(); +bool LivePathEffectAdd::on_filter(Gtk::FlowBoxChild *child) +{ + if (_LPEFilter->get_text().length() < 4) { + _visiblelpe = _LPESelectorFlowBox->get_children().size(); + return true; + } + Gtk::Box *box = dynamic_cast(child->get_child()); + if (box) { + std::vector contents = box->get_children(); + Gtk::Label *lpename = dynamic_cast(contents[1]); + if (lpename) { + size_t s = lpename->get_text().uppercase().find(_LPEFilter->get_text().uppercase(),0); + if(s != -1) { + _visiblelpe++; + return true; + } + } + Gtk::Label *lpedesc = dynamic_cast(contents[2]); + if (lpedesc) { + size_t s = lpedesc->get_text().uppercase().find(_LPEFilter->get_text().uppercase(),0); + if(s != -1) { + _visiblelpe++; + return true; + } + } + } + return false; +} - show_all_children(); +void LivePathEffectAdd::on_search() +{ + _visiblelpe = 0; + _LPESelectorFlowBox->set_filter_func(sigc::mem_fun(*this, &LivePathEffectAdd::on_filter)); + if (_visiblelpe == 0) { + _LPEInfo->set_text(_("Your search do a empty result, please try again")); + _LPEInfo->set_visible(true); + _LPEInfo->get_style_context()->add_class("lpeinfowarn"); + } else { + _LPEInfo->set_visible(false); + _LPEInfo->get_style_context()->remove_class("lpeinfowarn"); + } } void LivePathEffectAdd::onAdd() { - applied = true; onClose(); } @@ -122,35 +183,14 @@ void LivePathEffectAdd::onKeyEvent(GdkEventKey* evt) } } -void LivePathEffectAdd::onButtonEvent(GdkEventButton* evt) -{ - // Double click on tree is same as clicking the add button - if (evt->type == GDK_2BUTTON_PRESS) { - onAdd(); - } -} - -const Util::EnumData* -LivePathEffectAdd::getActiveData() -{ - Gtk::TreeModel::iterator iter = instance().effectlist_treeview.get_selection()->get_selected(); - if ( iter ) { - Gtk::TreeModel::Row row = *iter; - return row[instance()._columns.data]; - } - - return nullptr; -} - - void LivePathEffectAdd::show(SPDesktop *desktop) { LivePathEffectAdd &dial = instance(); - dial.applied=false; dial.set_modal(true); - desktop->setWindowTransient (dial.gobj()); + //dial.set_decorated(false); + dial.set_name("lpedialogselector"); + //desktop->setWindowTransient (dial.gobj()); dial.property_destroy_with_parent() = true; - dial.effectlist_treeview.grab_focus(); dial.run(); } diff --git a/src/ui/dialog/livepatheffect-add.h b/src/ui/dialog/livepatheffect-add.h index 84901385c..88aca58b2 100644 --- a/src/ui/dialog/livepatheffect-add.h +++ b/src/ui/dialog/livepatheffect-add.h @@ -12,10 +12,14 @@ #ifndef INKSCAPE_DIALOG_LIVEPATHEFFECT_ADD_H #define INKSCAPE_DIALOG_LIVEPATHEFFECT_ADD_H +#include +#include +#include +#include +#include +#include +#include #include -#include -#include -#include #include "live_effects/effect-enum.h" class SPDesktop; @@ -37,31 +41,23 @@ public: * Show the dialog */ static void show(SPDesktop *desktop); - - /** - * Returns true is the "Add" button was pressed - */ static bool isApplied() { - return instance().applied; + return false; } - /** - * Return the data associated with the currently selected item - */ - static const Util::EnumData* getActiveData(); - + static const Util::EnumData* getActiveData(){return NULL;}; protected: - /** * Close button was clicked */ void onClose(); - + bool on_filter(Gtk::FlowBoxChild *child); + void on_search(); + void on_activate(Gtk::FlowBoxChild *child); /** * Add button was clicked */ void onAdd(); - /** * Tree was clicked */ @@ -72,37 +68,16 @@ protected: */ void onKeyEvent(GdkEventKey* evt); private: - - Gtk::TreeView effectlist_treeview; - Gtk::ScrolledWindow scrolled_window; - Gtk::Button add_button; - Gtk::Button close_button; - - class ModelColumns : public Gtk::TreeModel::ColumnRecord - { - public: - ModelColumns() - { - add(name); - //add(desc); - add(data); - } - ~ModelColumns() override = default; - - Gtk::TreeModelColumn name; - /** - * TODO - Get detailed descriptions of each Effect to show in the dialog - */ - //Gtk::TreeModelColumn desc; - Gtk::TreeModelColumn*> data; - }; - - ModelColumns _columns; - Glib::RefPtr effectlist_store; - const Util::EnumDataConverter& converter; - - bool applied; - + Gtk::Button _add_button; + Gtk::Button _close_button; + Glib::RefPtr _builder; + Gtk::FlowBox * _LPESelectorFlowBox; + Gtk::SearchEntry *_LPEFilter; + Gtk::Label *_LPEInfo; + Gtk::Box *_LPESelector; + guint _visiblelpe; + class Effect; + const LivePathEffect::EnumEffectDataConverter& converter; static LivePathEffectAdd &instance() { static LivePathEffectAdd instance_; return instance_; diff --git a/src/ui/dialog/lpe-selector.cpp b/src/ui/dialog/lpe-selector.cpp new file mode 100644 index 000000000..5a2f39db4 --- /dev/null +++ b/src/ui/dialog/lpe-selector.cpp @@ -0,0 +1,69 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** + * @file + * Filter Effects dialog. + */ +/* Authors: + * Marc Jeanmougin + * + * Copyright (C) 2017 Authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include +#include +#include +#include +#include +#include "io/sys.h" +#include "io/resource.h" + +namespace Inkscape { +namespace UI { + +LPESelector::LPESelector() : Gtk::Box() +{ + + const std::string req_widgets[] = {"LPESelector", "FilterList", "FilterFERX", "FilterFERY", "FilterFERH", "FilterFERW", "FilterPreview", "FilterPrimitiveDescImage", "FilterPrimitiveList", "FilterPrimitiveDescText", "FilterPrimitiveAdd"}; + Glib::ustring gladefile = get_filename(UIS, "lpe-selector.glade"); + try { + builder = Gtk::Builder::create_from_file(gladefile); + } catch(const Glib::Error& ex) { + g_warning("Glade file loading failed for filter effect dialog"); + return; + } + + Gtk::Object* test; + for(std::string w:req_widgets) { + builder->get_widget(w,test); + if(!test){ + g_warning("Required widget %s does not exist", w.c_str()); + return; + } + } + + builder->get_widget("LPESelector", LPESelector); + _getContents()->add(*LPESelector); + +} +LPESelector::~LPESelector()= default; + + + + + + +} // Never put these namespaces together unless you are using gcc 6+ +} + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/dialog/lpe-selector.h b/src/ui/dialog/lpe-selector.h new file mode 100644 index 000000000..cc6d80f5a --- /dev/null +++ b/src/ui/dialog/lpe-selector.h @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** @file + * @brief Filter Editor dialog + */ +/* Authors: + * Marc Jeanmougin + * + * Copyright (C) 2017 Authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#ifndef INKSCAPE_UI_LPE_SELECTOR_H +#define INKSCAPE_UI_LPE_SELECTOR_H + +#include + +namespace Inkscape { +namespace UI { + +class LPESelector : public Gtk::Box { +public: + + LPESelector(); + ~LPESelector() override; + + static LPESelector &getInstance() + { return *new LPESelector(); } + +// void set_attrs_locked(const bool); +private: + Glib::RefPtr builder; + Glib::RefPtr FilterStore; + Gtk::Box *LPESelector; +}; +} +} +#endif -- cgit v1.2.3 From e0471fb385a7250815528d23f0c2ecbbca675d42 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 26 Jan 2019 06:16:02 +0100 Subject: Adding styling refactoring, moving after to other branch the CSS part --- src/inkscape.cpp | 72 ++++++++++++++++++++------------- src/ui/dialog/filter-editor.cpp | 2 +- src/ui/dialog/inkscape-preferences.cpp | 74 +++++++++++++++++++++++++++++----- src/ui/dialog/livepatheffect-add.cpp | 41 +++++++++---------- src/ui/dialog/livepatheffect-add.h | 3 +- src/ui/dialog/symbols.cpp | 5 ++- src/ui/widget/dash-selector.cpp | 2 +- src/widgets/desktop-widget.cpp | 23 ++++++++++- src/widgets/stroke-marker-selector.cpp | 2 +- src/widgets/toolbox.cpp | 10 ++--- 10 files changed, 160 insertions(+), 74 deletions(-) (limited to 'src') diff --git a/src/inkscape.cpp b/src/inkscape.cpp index 1418f5c3b..baefd6b9f 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -378,7 +378,15 @@ Application::add_gtk_css() Inkscape::Preferences *prefs = Inkscape::Preferences::get(); auto provider = Gtk::CssProvider::create(); Glib::ustring css_str = ""; + gchar colornamed[64]; + gchar colornamed_inverse[64]; + int colorset = prefs->getInt("/theme/symbolicColor", 0x000000ff); + sp_svg_write_color(colornamed, sizeof(colornamed), colorset); + // Use in case the special widgets have inverse theme background and symbolic + int colorset_inverse = colorset ^ 0xffffff00; + sp_svg_write_color(colornamed_inverse, sizeof(colornamed_inverse), colorset_inverse); if (prefs->getBool("/theme/symbolicIcons", false)) { +<<<<<<< HEAD int colorset = prefs->getInt("/theme/symbolicColor", 0x000000ff); gchar colornamed[64]; sp_svg_write_color(colornamed, sizeof(colornamed), colorset); @@ -401,12 +409,47 @@ Application::add_gtk_css() css_str += ";}"; css_str += "#iconregular{ -gtk-icon-style: regular;}"; } +======= + css_str += "*{ -gtk-icon-style: symbolic;}"; + css_str += "image{ color:"; + css_str += colornamed; + css_str += ";}"; +>>>>>>> Adding styling refactoring, moving after to other branch the CSS part } else { css_str += "*{-gtk-icon-style: regular;}"; } - GtkSettings *settings = gtk_settings_get_default(); + css_str += ".iconcolornamed, .iconcolornamed image{ color:"; + css_str += colornamed; + css_str += ";}"; + css_str += ".iconcolornamedinverse, .colornamedinverse image{ color:"; + css_str += colornamed_inverse; + css_str += ";}"; const gchar *gtk_font_name = ""; + const gchar *gtkThemeName; + const gchar *gtkIconThemeName; + gboolean gtkApplicationPreferDarkTheme; + GtkSettings *settings = gtk_settings_get_default(); if (settings) { + g_object_get(settings, "gtk-icon-theme-name", >kIconThemeName, NULL); + g_object_get(settings, "gtk-theme-name", >kThemeName, NULL); + g_object_get(settings, "gtk-application-prefer-dark-theme", >kApplicationPreferDarkTheme, NULL); + g_object_set(settings, "gtk-application-prefer-dark-theme", + prefs->getBool("/theme/darkTheme", gtkApplicationPreferDarkTheme), NULL); + prefs->setString("/theme/defaultIconTheme", Glib::ustring(gtkIconThemeName)); + if (prefs->getString("/theme/gtkTheme") != "") { + g_object_set(settings, "gtk-theme-name", prefs->getString("/theme/gtkTheme").c_str(), NULL); + } + else { + prefs->setString("/theme/gtkTheme", Glib::ustring(gtkThemeName)); + } + + Glib::ustring themeiconname = prefs->getString("/theme/iconTheme"); + if (themeiconname != "") { + g_object_set(settings, "gtk-icon-theme-name", themeiconname.c_str(), NULL); + } + else { + prefs->setString("/theme/iconTheme", Glib::ustring(gtkIconThemeName)); + } g_object_get(settings, "gtk-font-name", >k_font_name, NULL); } if (!strncmp(gtk_font_name, "Cantarell", 9)) { @@ -509,33 +552,6 @@ Application::Application(const char* argv, bool use_gui) : icon_theme->prepend_search_path(get_path_ustring(USER, ICONS)); add_gtk_css(); /* Load the preferences and menus */ - GtkSettings *settings = gtk_settings_get_default(); - if (settings) { - const gchar *gtkThemeName; - const gchar *gtkIconThemeName; - gboolean gtkApplicationPreferDarkTheme; - g_object_get(settings, "gtk-theme-name", >kThemeName, NULL); - g_object_get(settings, "gtk-icon-theme-name", >kIconThemeName, NULL); - g_object_get(settings, "gtk-application-prefer-dark-theme", >kApplicationPreferDarkTheme, NULL); - g_object_set(settings, "gtk-application-prefer-dark-theme", - prefs->getBool("/theme/darkTheme", gtkApplicationPreferDarkTheme), NULL); - prefs->setString("/theme/defaultIconTheme", Glib::ustring(gtkIconThemeName)); - if (prefs->getString("/theme/gtkTheme") != "") { - g_object_set(settings, "gtk-theme-name", prefs->getString("/theme/gtkTheme").c_str(), NULL); - } - else { - prefs->setString("/theme/gtkTheme", Glib::ustring(gtkThemeName)); - } - - Glib::ustring themeiconname = prefs->getString("/theme/iconTheme"); - if (themeiconname != "") { - g_object_set(settings, "gtk-icon-theme-name", themeiconname.c_str(), NULL); - } - else { - prefs->setString("/theme/iconTheme", Glib::ustring(gtkIconThemeName)); - } - } - load_menus(); Inkscape::DeviceManager::getManager().loadConfig(); } diff --git a/src/ui/dialog/filter-editor.cpp b/src/ui/dialog/filter-editor.cpp index 6ad9dca61..ba2c7357a 100644 --- a/src/ui/dialog/filter-editor.cpp +++ b/src/ui/dialog/filter-editor.cpp @@ -69,7 +69,7 @@ FilterEditorDialog::FilterEditorDialog() : UI::Widget::Panel("/dialogs/filtereff { const std::string req_widgets[] = {"FilterEditor", "FilterList", "FilterFERX", "FilterFERY", "FilterFERH", "FilterFERW", "FilterPreview", "FilterPrimitiveDescImage", "FilterPrimitiveList", "FilterPrimitiveDescText", "FilterPrimitiveAdd"}; - Glib::ustring gladefile = get_filename(UIS, "filter-editor.glade"); + Glib::ustring gladefile = get_filename(UIS, "dialog-filter-editor.ui"); try { builder = Gtk::Builder::create_from_file(gladefile); } catch(const Glib::Error& ex) { diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 6634ef170..158aeb617 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -43,6 +43,7 @@ #include "selection.h" #include "shortcuts.h" #include "verbs.h" +#include "inkscape-window.h" #include "display/canvas-grid.h" #include "display/nr-filter-gaussian.h" @@ -59,6 +60,7 @@ #include "svg/svg-color.h" #include "ui/interface.h" #include "ui/widget/style-swatch.h" +#include "widgets/desktop-widget.h" #ifdef HAVE_ASPELL # include @@ -679,30 +681,34 @@ void InkscapePreferences::symbolicDefaultColor(){ void InkscapePreferences::symbolicAddClass() { + using namespace Inkscape::IO::Resource; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setBool("/theme/symbolicIconsDefaultColor", false); auto const screen = Gdk::Screen::get_default(); auto provider = Gtk::CssProvider::create(); Glib::ustring css_str = ""; + + gchar colornamed[64]; + gchar colornamed_inverse[64]; + int colorset = prefs->getInt("/theme/symbolicColor", 0x000000ff); + sp_svg_write_color(colornamed, sizeof(colornamed), colorset); + // Use in case the special widgets have inverse theme background and symbolic + int colorset_inverse = colorset ^ 0xffffff00; + sp_svg_write_color(colornamed_inverse, sizeof(colornamed_inverse), colorset_inverse); if (prefs->getBool("/theme/symbolicIcons", false)) { - int colorset = prefs->getInt("/theme/symbolicColor", 0x000000ff); - gchar colornamed[64]; - sp_svg_write_color(colornamed, sizeof(colornamed), colorset); - // Use in case the special widgets have inverse theme background and symbolic - int colorset_inverse = colorset ^ 0xffffff00; - gchar colornamed_inverse[64]; - sp_svg_write_color(colornamed_inverse, sizeof(colornamed_inverse), colorset_inverse); css_str += "*{ -gtk-icon-style: symbolic;}"; css_str += "image{ color:"; css_str += colornamed; css_str += ";}"; - css_str += "iconinverse{ color:"; - css_str += colornamed_inverse; - css_str += ";}"; - css_str += "iconregular{ -gtk-icon-style: regular;}"; } else { css_str += "*{-gtk-icon-style: regular;}"; } + css_str += ".iconcolornamed, .iconcolornamed image{ color:"; + css_str += colornamed; + css_str += ";}"; + css_str += ".iconcolornamedinverse, .colornamedinverse image{ color:"; + css_str += colornamed_inverse; + css_str += ";}"; // From 3.16, throws an error which we must catch. try { provider->load_from_data(css_str); @@ -717,6 +723,29 @@ void InkscapePreferences::symbolicAddClass() } #endif Gtk::StyleContext::add_provider_for_screen(screen, provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + // we want a tiny file with 3 or 4 lines, so we can load without removing context + // is more understandable than record previously applied + Glib::ustring style = get_filename(UIS, "style.css"); + if (!style.empty()) { + auto provider = Gtk::CssProvider::create(); + + // From 3.16, throws an error which we must catch. + try { + provider->load_from_path (style); + } +#if GTK_CHECK_VERSION(3,16,0) + // Gtk::CssProviderError not defined until 3.16. + catch (const Gtk::CssProviderError& ex) + { + g_critical("CSSProviderError::load_from_path(): failed to load '%s'\n(%s)", + style.c_str(), ex.what().c_str()); + } +#else + catch (...) + {} +#endif + Gtk::StyleContext::add_provider_for_screen (screen, provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + } } void InkscapePreferences::themeChange() { @@ -724,6 +753,29 @@ void InkscapePreferences::themeChange() g_object_set(gtk_settings_get_default(), "gtk-theme-name", prefs->getString("/theme/gtkTheme").c_str(), NULL); g_object_set(gtk_settings_get_default(), "gtk-application-prefer-dark-theme", prefs->getBool("/theme/darkTheme", false), NULL); + gchar *gtkThemeName; + gboolean gtkApplicationPreferDarkTheme; + Gtk::Window *window = SP_ACTIVE_DESKTOP->getToplevel(); + GtkSettings *settings = gtk_settings_get_default(); + if (window && settings) { + g_object_get(settings, "gtk-theme-name", >kThemeName, NULL); + g_object_get(settings, "gtk-application-prefer-dark-theme", >kApplicationPreferDarkTheme, NULL); + bool dark = gtkApplicationPreferDarkTheme || Glib::ustring(gtkThemeName).find(":dark") != -1; + if (!dark) { + Glib::RefPtr stylecontext = window->get_style_context(); + Gdk::RGBA rgba; + bool background_set = stylecontext->lookup_color("theme_bg_color", rgba); + if (background_set && rgba.get_red() + rgba.get_green() + rgba.get_blue() < 1.0) { + dark = true; + } + } + if (dark) + { + window->get_style_context()->add_class("dark"); + } else { + window->get_style_context()->remove_class("dark"); + } + } } void InkscapePreferences::initPageUI() diff --git a/src/ui/dialog/livepatheffect-add.cpp b/src/ui/dialog/livepatheffect-add.cpp index f930199cf..9eea4cccd 100644 --- a/src/ui/dialog/livepatheffect-add.cpp +++ b/src/ui/dialog/livepatheffect-add.cpp @@ -24,12 +24,10 @@ namespace UI { namespace Dialog { LivePathEffectAdd::LivePathEffectAdd() : - _add_button(_("_Add"), true), - _close_button(_("_Cancel"), true), converter(Inkscape::LivePathEffect::LPETypeConverter) { - const std::string req_widgets[] = {"LPESelector", "LPESelectorFlowBox"}; - Glib::ustring gladefile = get_filename(Inkscape::IO::Resource::UIS, "lpe-selector.glade"); + const std::string req_widgets[] = {"LPEDialogSelector", "LPESelector", "LPESelectorFlowBox"}; + Glib::ustring gladefile = get_filename(Inkscape::IO::Resource::UIS, "dialog-livepatheffect-add.ui"); try { _builder = Gtk::Builder::create_from_file(gladefile); } catch(const Glib::Error& ex) { @@ -45,9 +43,7 @@ LivePathEffectAdd::LivePathEffectAdd() : return; } } - _builder->get_widget("LPESelector", _LPESelector); - auto mainVBox = get_content_area(); - mainVBox->pack_start(*_LPESelector, true, true); + _builder->get_widget("LPEDialogSelector", _LPEDialogSelector); /** * Initialize Effect list */ @@ -55,8 +51,8 @@ LivePathEffectAdd::LivePathEffectAdd() : _builder->get_widget("LPEFilter", _LPEFilter); _builder->get_widget("LPEInfo", _LPEInfo); _LPEFilter->signal_search_changed().connect(sigc::mem_fun(*this, &LivePathEffectAdd::on_search)); - const std::string le_widgets[] = {"LPESelectorItem", "LPEName","LPEDescription"}; - Glib::ustring le_gladefile = get_filename(Inkscape::IO::Resource::UIS, "lpe-selector-item.glade"); + const std::string le_widgets[] = {"LPESelectorEffect", "LPEName","LPEDescription"}; + Glib::ustring le_gladefile = get_filename(Inkscape::IO::Resource::UIS, "dialog-livepatheffect-add-effect.ui"); for(int i = 0; i < static_cast(converter._length); ++i) { try { @@ -90,16 +86,16 @@ LivePathEffectAdd::LivePathEffectAdd() : newid = "LPEIcon_" + Glib::ustring::format(i); (*LPEIcon).set_name(newid); (*LPEIcon).set_from_icon_name(converter.get_icon(data->id),Gtk::BuiltinIconSize(Gtk::ICON_SIZE_DIALOG)); - Gtk::Box * LPESelectorItem; - _builder->get_widget("LPESelectorItem", LPESelectorItem); - newid = "LPESelectorItem" + Glib::ustring::format(i); - (*LPESelectorItem).set_name(newid); - _LPESelectorFlowBox->insert(*LPESelectorItem, i); + Gtk::Box * LPESelectorEffect; + _builder->get_widget("LPESelectorEffect", LPESelectorEffect); + newid = "LPESelectorEffect" + Glib::ustring::format(i); + (*LPESelectorEffect).set_name(newid); + _LPESelectorFlowBox->insert(*LPESelectorEffect, i); } _visiblelpe = _LPESelectorFlowBox->get_children().size(); _LPESelectorFlowBox->signal_child_activated().connect(sigc::mem_fun(*this, &LivePathEffectAdd::on_activate)); - set_title(_("Live Efects Selector")); - show_all_children(); + _LPEDialogSelector->set_title(_("Live Efects Selector")); + _LPEDialogSelector->show_all_children(); _LPEInfo->set_visible(false); } @@ -107,6 +103,8 @@ void LivePathEffectAdd::on_activate(Gtk::FlowBoxChild *child){ for (auto i:_LPESelectorFlowBox->get_children()) { Gtk::FlowBoxChild * leitem = dynamic_cast(i); leitem->get_style_context()->remove_class("lpeactive"); + leitem->get_style_context()->remove_class("colorinverse"); + leitem->get_style_context()->remove_class("backgroundinverse"); Gtk::Box *box = dynamic_cast(leitem->get_child()); if (box) { std::vector contents = box->get_children(); @@ -117,6 +115,8 @@ void LivePathEffectAdd::on_activate(Gtk::FlowBoxChild *child){ } } child->get_style_context()->add_class("lpeactive"); + child->get_style_context()->add_class("colorinverse"); + child->get_style_context()->add_class("backgroundinverse"); child->show_all_children(); } @@ -170,7 +170,7 @@ void LivePathEffectAdd::onAdd() void LivePathEffectAdd::onClose() { - hide(); + _LPEDialogSelector->hide(); } void LivePathEffectAdd::onKeyEvent(GdkEventKey* evt) @@ -186,12 +186,7 @@ void LivePathEffectAdd::onKeyEvent(GdkEventKey* evt) void LivePathEffectAdd::show(SPDesktop *desktop) { LivePathEffectAdd &dial = instance(); - dial.set_modal(true); - //dial.set_decorated(false); - dial.set_name("lpedialogselector"); - //desktop->setWindowTransient (dial.gobj()); - dial.property_destroy_with_parent() = true; - dial.run(); + dial._LPEDialogSelector->run(); } } // namespace Dialog diff --git a/src/ui/dialog/livepatheffect-add.h b/src/ui/dialog/livepatheffect-add.h index 88aca58b2..17d46487a 100644 --- a/src/ui/dialog/livepatheffect-add.h +++ b/src/ui/dialog/livepatheffect-add.h @@ -70,8 +70,9 @@ protected: private: Gtk::Button _add_button; Gtk::Button _close_button; + Gtk::Dialog *_LPEDialogSelector; Glib::RefPtr _builder; - Gtk::FlowBox * _LPESelectorFlowBox; + Gtk::FlowBox *_LPESelectorFlowBox; Gtk::SearchEntry *_LPEFilter; Gtk::Label *_LPEInfo; Gtk::Box *_LPESelector; diff --git a/src/ui/dialog/symbols.cpp b/src/ui/dialog/symbols.cpp index fa76fc31a..06a76605b 100644 --- a/src/ui/dialog/symbols.cpp +++ b/src/ui/dialog/symbols.cpp @@ -186,7 +186,6 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : icon_view = new Gtk::IconView(static_cast >(store)); //icon_view->set_text_column( columns->symbol_id ); icon_view->set_tooltip_column( 1 ); - icon_view->set_name( "symbolsView" ); icon_view->set_pixbuf_column( columns->symbol_image ); // Giving the iconview a small minimum size will help users understand // What the dialog does. @@ -214,6 +213,8 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : overlay->set_hexpand(); overlay->set_vexpand(); overlay->add(* scroller); + overlay->get_style_context()->add_class("colorbright"); + overlay->get_style_context()->add_class("backgroundbright"); scroller->set_size_request(100, 250); table->attach(*Gtk::manage(overlay),0,row,2,1); @@ -227,7 +228,7 @@ SymbolsDialog::SymbolsDialog( gchar const* prefsPath ) : iconsize = Gtk::IconSize().register_new(Glib::ustring("ICON_SIZE_DIALOG_EXTRA"), 110, 110); } overlay_icon = sp_get_icon_image("searching", iconsize); - overlay_icon->set_name("iconinverse"); + overlay_icon->get_style_context()->add_class("iconsymbolic"); overlay_icon->set_halign(Gtk::ALIGN_CENTER ); overlay_icon->set_valign(Gtk::ALIGN_START ); overlay_icon->set_margin_top(45); diff --git a/src/ui/widget/dash-selector.cpp b/src/ui/widget/dash-selector.cpp index 81e7881b6..ea5cc57d2 100644 --- a/src/ui/widget/dash-selector.cpp +++ b/src/ui/widget/dash-selector.cpp @@ -61,7 +61,7 @@ DashSelector::DashSelector() dash_combo.pack_start(image_renderer); dash_combo.set_cell_data_func(image_renderer, sigc::mem_fun(*this, &DashSelector::prepareImageRenderer)); dash_combo.set_tooltip_text(_("Dash pattern")); - dash_combo.set_name("dashCombo"); + dash_combo.get_style_context()->add_class("combobright"); dash_combo.show(); dash_combo.signal_changed().connect( sigc::mem_fun(*this, &DashSelector::on_selection) ); diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index b7b9d2ce0..801e6bc41 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -693,7 +693,6 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) } overallTimer = nullptr; } - // Ensure that ruler ranges are updated correctly whenever the canvas table // is resized dtw->_canvas_tbl_size_allocate_connection = dtw->_canvas_tbl->signal_size_allocate().connect(sigc::mem_fun(dtw, &SPDesktopWidget::canvas_tbl_size_allocate)); @@ -890,6 +889,28 @@ sp_desktop_widget_realize (GtkWidget *widget) dtw->desktop->set_display_area (d, 10); dtw->updateNamedview(); + gchar *gtkThemeName; + gboolean gtkApplicationPreferDarkTheme; + GtkSettings *settings = gtk_settings_get_default(); + Gtk::Window *window = SP_ACTIVE_DESKTOP->getToplevel(); + if (settings && window) { + g_object_get(settings, "gtk-theme-name", >kThemeName, NULL); + g_object_get(settings, "gtk-application-prefer-dark-theme", >kApplicationPreferDarkTheme, NULL); + bool dark = gtkApplicationPreferDarkTheme || Glib::ustring(gtkThemeName).find(":dark") != -1; + if (!dark) { + Glib::RefPtr stylecontext = window->get_style_context(); + Gdk::RGBA rgba; + bool background_set = stylecontext->lookup_color("theme_bg_color", rgba); + if (background_set && rgba.get_red() + rgba.get_green() + rgba.get_blue() < 1.0) { + dark = true; + } + } + if (dark) { + window->get_style_context()->add_class("dark"); + } else { + window->get_style_context()->remove_class("dark"); + } + } } /* This is just to provide access to common functionality from sp_desktop_widget_realize() above diff --git a/src/widgets/stroke-marker-selector.cpp b/src/widgets/stroke-marker-selector.cpp index 5bfebb799..095653cb3 100644 --- a/src/widgets/stroke-marker-selector.cpp +++ b/src/widgets/stroke-marker-selector.cpp @@ -52,7 +52,6 @@ MarkerComboBox::MarkerComboBox(gchar const *id, int l) : pack_start(image_renderer, false); set_cell_data_func(image_renderer, sigc::mem_fun(*this, &MarkerComboBox::prepareImageRenderer)); gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(gobj()), MarkerComboBox::separator_cb, nullptr, nullptr); - gtk_widget_set_name(GTK_WIDGET(gobj()), "markerCombo"); empty_image = sp_get_icon_image("no-marker", Gtk::ICON_SIZE_SMALL_TOOLBAR); sandbox = ink_markers_preview_doc (); @@ -62,6 +61,7 @@ MarkerComboBox::MarkerComboBox(gchar const *id, int l) : modified_connection = doc->getDefs()->connectModified( sigc::hide(sigc::hide(sigc::bind(sigc::ptr_fun(&MarkerComboBox::handleDefsModified), this))) ); init_combo(); + this->get_style_context()->add_class("combobright"); show(); } diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 3199e25ef..6e614f582 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -857,7 +857,7 @@ void ToolboxFactory::setOrientation(GtkWidget* toolbox, GtkOrientation orientati void setup_tool_toolbox(GtkWidget *toolbox, SPDesktop *desktop) { setupToolboxCommon( toolbox, desktop, - "tool-toolbar.ui", + "toolbar-tool.ui", "/ui/ToolToolbar", "/toolbox/tools/small"); } @@ -905,12 +905,12 @@ void setup_aux_toolbox(GtkWidget *toolbox, SPDesktop *desktop) Glib::RefPtr mainActions = create_or_fetch_actions( desktop ); // The UI Manager creates widgets based on the definitions in the - // "select-toolbar.ui" file. This is only used with the "prep" + // "toolbar-select.ui" file. This is only used with the "prep" // method of toolbar-creation GtkUIManager* mgr = gtk_ui_manager_new(); GError *err = nullptr; gtk_ui_manager_insert_action_group( mgr, mainActions->gobj(), 0 ); - Glib::ustring filename = get_filename(UIS, "select-toolbar.ui"); + Glib::ustring filename = get_filename(UIS, "toolbar-select.ui"); guint ret = gtk_ui_manager_add_ui_from_file(mgr, filename.c_str(), &err); if(err) { g_warning("Failed to load aux toolbar %s: %s", filename.c_str(), err->message); @@ -1061,7 +1061,7 @@ void update_aux_toolbox(SPDesktop * /*desktop*/, ToolBase *eventcontext, GtkWidg void setup_commands_toolbox(GtkWidget *toolbox, SPDesktop *desktop) { setupToolboxCommon( toolbox, desktop, - "commands-toolbar.ui", + "toolbar-commands.ui", "/ui/CommandsToolbar", "/toolbox/small" ); } @@ -1375,7 +1375,7 @@ void setup_snap_toolbox(GtkWidget *toolbox, SPDesktop *desktop) } setupToolboxCommon( toolbox, desktop, - "snap-toolbar.ui", + "toolbar-snap.ui", "/ui/SnapToolbar", "/toolbox/secondary" ); } -- cgit v1.2.3 From 5f64983988239d9cbd34b5389944919948aadfd3 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 26 Jan 2019 06:52:13 +0100 Subject: Improvements to CSS to easy tweak widgets --- src/live_effects/effect-enum.h | 908 +---------------------------------- src/live_effects/effect.cpp | 70 ++- src/ui/dialog/filter-editor.cpp | 2 +- src/ui/dialog/livepatheffect-add.cpp | 225 ++++----- src/ui/dialog/livepatheffect-add.h | 70 ++- src/widgets/toolbox.cpp | 10 +- 6 files changed, 217 insertions(+), 1068 deletions(-) (limited to 'src') diff --git a/src/live_effects/effect-enum.h b/src/live_effects/effect-enum.h index 595c81a78..b662d3263 100644 --- a/src/live_effects/effect-enum.h +++ b/src/live_effects/effect-enum.h @@ -11,10 +11,6 @@ */ #include "util/enums.h" -#include - - - namespace Inkscape { namespace LivePathEffect { @@ -79,908 +75,8 @@ enum EffectType { INVALID_LPE // This must be last (I made it such that it is not needed anymore I think..., Don't trust on it being last. - johan) }; -template - struct EnumEffectData - { - E id; - const Glib::ustring label; - const Glib::ustring key; - const Glib::ustring icon; - const Glib::ustring description; - const bool on_path; - const bool on_shape; - const bool on_group; - const bool on_use; - const bool on_image; - const bool on_text; - }; - -const Glib::ustring empty_string(""); - -/** - * Simplified management of enumerations of LPE items with UI labels. - * - * @note that get_id_from_key and get_id_from_label return 0 if it cannot find an entry for that key string. - * @note that get_label and get_key return an empty string when the requested id is not in the list. - */ -template class EnumEffectDataConverter -{ -public: - typedef EnumEffectData Data; - - EnumEffectDataConverter(const EnumEffectData* cd, const unsigned int length) - : _length(length), _data(cd) - {} - - E get_id_from_label(const Glib::ustring& label) const - { - for(unsigned int i = 0; i < _length; ++i) { - if(_data[i].label == label) - return _data[i].id; - } - - return (E)0; - } - - E get_id_from_key(const Glib::ustring& key) const - { - for(unsigned int i = 0; i < _length; ++i) { - if(_data[i].key == key) - return _data[i].id; - } - - return (E)0; - } - - bool is_valid_key(const Glib::ustring& key) const - { - for(unsigned int i = 0; i < _length; ++i) { - if(_data[i].key == key) - return true; - } - - return false; - } - - bool is_valid_id(const E id) const - { - for(unsigned int i = 0; i < _length; ++i) { - if(_data[i].id == id) - return true; - } - return false; - } - - const Glib::ustring& get_label(const E id) const - { - for(unsigned int i = 0; i < _length; ++i) { - if(_data[i].id == id) - return _data[i].label; - } - - return empty_string; - } - - const Glib::ustring& get_key(const E id) const - { - for(unsigned int i = 0; i < _length; ++i) { - if(_data[i].id == id) - return _data[i].key; - } - - return empty_string; - } - - const Glib::ustring& get_icon(const E id) const - { - for(unsigned int i = 0; i < _length; ++i) { - if(_data[i].id == id) - return _data[i].icon; - } - - return empty_string; - } - - const Glib::ustring& get_description(const E id) const - { - for(unsigned int i = 0; i < _length; ++i) { - if(_data[i].id == id) - return _data[i].description; - } - - return empty_string; - } - - const bool& get_on_path(const E id) const - { - for(unsigned int i = 0; i < _length; ++i) { - if(_data[i].id == id) - return _data[i].path; - } - - return false; - } - - const bool& get_on_shape(const E id) const - { - for(unsigned int i = 0; i < _length; ++i) { - if(_data[i].id == id) - return _data[i].shape; - } - - return false; - } - - const bool& get_on_group(const E id) const - { - for(unsigned int i = 0; i < _length; ++i) { - if(_data[i].id == id) - return _data[i].group; - } - - return false; - } - - const bool& get_on_text(const E id) const - { - for(unsigned int i = 0; i < _length; ++i) { - if(_data[i].id == id) - return _data[i].shape; - } - - return false; - } - - const bool& get_on_use(const E id) const - { - for(unsigned int i = 0; i < _length; ++i) { - if(_data[i].id == id) - return _data[i].use; - } - - return false; - } - - const EnumEffectData& data(const unsigned int i) const - { - return _data[i]; - } - - const unsigned int _length; -private: - const EnumEffectData* _data; -}; - -const EnumEffectData LPETypeData[] = { - // {constant defined in effect-enum.h, N_("name of your effect"), "name of your effect in SVG"} -/* 0.46 */ - { - BEND_PATH - , N_("Bend") //label - , "bend_path" //key - , "bend-path" //icon - , N_("Curve a item based on skeleton path") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - GEARS - , N_("Gears") //label - , "gears" //key - , "gears" //icon - , N_("Create configurable gears") //description - , true //on_path - , true //on_shape - , false //on_group - , false //on_use - , false //on_image - , false //on_text - }, - { - PATTERN_ALONG_PATH - , N_("Pattern Along Path") //label - , "skeletal" //key - , "skeletal" //icon - , N_("transform a tiem along path with or without repeating") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, // for historic reasons, this effect is called skeletal(strokes) in Inkscape:SVG - { - CURVE_STITCH - , N_("Stitch Sub-Paths") //label - , "curvestitching" //key - , "curvestitching" //icon - , N_("curvestitching") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, -/* 0.47 */ - { - VONKOCH - , N_("VonKoch") //label - , "vonkoch" //key - , "vonkoch" //icon - , N_("vonkoch") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - KNOT - , N_("Knot") //label - , "knot" //key - , "knot" //icon - , N_("knot") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - CONSTRUCT_GRID - , N_("Construct grid") //label - , "construct_grid" //key - , "construct-grid" //icon - , N_("construct_grid") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - SPIRO - , N_("Spiro spline") //label - , "spiro" //key - , "spiro" //icon - , N_("spiro") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - ENVELOPE - , N_("Envelope Deformation") //label - , "envelope" //key - , "envelope" //icon - , N_("Envelope Deformation") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - INTERPOLATE - , N_("Interpolate Sub-Paths") //label - , "interpolate" //key - , "interpolate" //icon - , N_("Interpolate Sub-Paths") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - ROUGH_HATCHES - , N_("Hatches (rough)") //label - , "rough_hatches" //key - , "rough-hatches" //icon - , N_("Hatches (rough)") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - SKETCH - , N_("Sketch") //label - , "sketch" //key - , "sketch" //icon - , N_("Sketch") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - RULER - , N_("Ruler") //label - , "ruler" //key - , "ruler" //icon - , N_("Ruler") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, -/* 0.91 */ - { - POWERSTROKE - , N_("Power stroke") //label - , "powerstroke" //key - , "powerstroke" //icon - , N_("Power stroke") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - CLONE_ORIGINAL - , N_("Clone original") //label - , "clone_original" //key - , "clone-original" //icon - , N_("Clone original") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, -/* 0.92 */ - { - SIMPLIFY - , N_("Simplify") //label - , "simplify" //key - , "simplify" //icon - , N_("Simplify") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - LATTICE2 - , N_("Lattice Deformation 2") //label - , "lattice2" //key - , "lattice2" //icon - , N_("Lattice Deformation 2") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - PERSPECTIVE_ENVELOPE - , N_("Perspective/Envelope") //label - , "perspective-envelope" //key wrong key with "-" retain because historic - , "perspective-envelope" //icon - , N_("Perspective/Envelope") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - INTERPOLATE_POINTS - , N_("Interpolate points") //label - , "interpolate_points" //key - , "interpolate-points" //icon - , N_("Interpolate points") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - TRANSFORM_2PTS - , N_("Transform by 2 points") //label - , "transform_2pts" //key - , "transform-2pts" //icon - , N_("Transform by 2 points") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - SHOW_HANDLES - , N_("Show handles") //label - , "show_handles" //key - , "show-handles" //icon - , N_("Show handles") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - ROUGHEN - , N_("Roughen") //label - , "roughen" //key - , "roughen" //icon - , N_("Roughen") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - BSPLINE - , N_("BSpline") //label - , "bspline" //key - , "bspline" //icon - , N_("BSpline") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - JOIN_TYPE - , N_("Join type") //label - , "join_type" //key - , "join-type" //icon - , N_("Join type") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - TAPER_STROKE - , N_("Taper stroke") //label - , "taper_stroke" //key - , "taper-stroke" //icon - , N_("Taper stroke") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - MIRROR_SYMMETRY - , N_("Mirror symmetry") //label - , "mirror_symmetry" //key - , "mirror-symmetry" //icon - , N_("Mirror symmetry") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - COPY_ROTATE - , N_("Rotate copies") //label - , "copy_rotate" //key - , "copy-rotate" //icon - , N_("Rotate copies") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, -/* Ponyscape -> Inkscape 0.92*/ - { - ATTACH_PATH - , N_("Attach path") //label - , "attach_path" //key - , "attach-path" //icon - , N_("Attach path") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - FILL_BETWEEN_STROKES - , N_("Fill between strokes") //label - , "fill_between_strokes" //key - , "fill-between-strokes" //icon - , N_("Fill between strokes") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - FILL_BETWEEN_MANY - , N_("Fill between many") //label - , "fill_between_many" //key - , "fill-between-many" //icon - , N_("Fill between many") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - ELLIPSE_5PTS - , N_("Ellipse by 5 points") //label - , "ellipse_5pts" //key - , "ellipse-5pts" //icon - , N_("Ellipse by 5 points") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - BOUNDING_BOX - , N_("Bounding Box") //label - , "bounding_box" //key - , "bounding-box" //icon - , N_("Bounding Box") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, -/* 1.0 */ - { - MEASURE_SEGMENTS - , N_("Measure Segments") //label - , "measure_segments" //key - , "measure-segments" //icon - , N_("Measure Segments") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - FILLET_CHAMFER - , N_("Fillet/Chamfer") //label - , "fillet_chamfer" //key - , "fillet-chamfer" //icon - , N_("Fillet/Chamfer") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - BOOL_OP - , N_("Boolean operation") //label - , "bool_op" //key - , "bool-op" //icon - , N_("Boolean operation") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - EMBRODERY_STITCH - , N_("Embroidery stitch") //label - , "embrodery_stitch" //key - , "embrodery-stitch" //icon - , N_("Embroidery stitch") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - POWERCLIP - , N_("Power clip") //label - , "powerclip" //key - , "powerclip" //icon - , N_("Power clip") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - POWERMASK - , N_("Power mask") //label - , "powermask" //key - , "powermask" //icon - , N_("Power mask") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - PTS2ELLIPSE - , N_("Ellipse from points") //label - , "pts2ellipse" //key - , "pts2ellipse" //icon - , N_("Ellipse from points") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - OFFSET - , N_("Offset") //label - , "offset" //key - , "offset" //icon - , N_("Offset") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - DASH_STROKE - , N_("Dash Stroke") //label - , "dash_stroke" //key - , "dash-stroke" //icon - , N_("Dash Stroke") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, -#ifdef LPE_ENABLE_TEST_EFFECTS - { - DOEFFECTSTACK_TEST - , N_("doEffect stack test") //label - , "doeffectstacktest" //key - , "experimental" //icon - , N_("doEffect stack test") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - ANGLE_BISECTOR - , N_("Angle bisector") //label - , "angle_bisector" //key - , "experimental" //icon - , N_("Angle bisector") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - CIRCLE_WITH_RADIUS - , N_("Circle (by center and radius)") //label - , "circle_with_radius" //key - , "experimental" //icon - , N_("Circle (by center and radius)") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - CIRCLE_3PTS - , N_("Circle by 3 points") //label - , "circle_3pts" //key - , "experimental" //icon - , N_("Circle by 3 points") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - DYNASTROKE - , N_("Dynamic stroke") //label - , "dynastroke" //key - , "experimental" //icon - , N_("Dynamic stroke") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - EXTRUDE - , N_("Extrude") //label - , "extrude" //key - , "experimental" //icon - , N_("Extrude") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - LATTICE - , N_("Lattice Deformation") //label - , "lattice" //key - , "experimental" //icon - , N_("Lattice Deformation") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - LINE_SEGMENT - , N_("Line Segment") //label - , "line_segment" //key - , "experimental" //icon - , N_("Line Segment") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - PARALLEL - , N_("Parallel") //label - , "parallel" //key - , "experimental" //icon - , N_("Parallel") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - PATH_LENGTH - , N_("Path length") //label - , "path_length" //key - , "experimental" //icon - , N_("Path length") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - PERP_BISECTOR - , N_("Perpendicular bisector") //label - , "perp_bisector" //key - , "experimental" //icon - , N_("Perpendicular bisector") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - RECURSIVE_SKELETON - , N_("Recursive skeleton") //label - , "recursive_skeleton" //key - , "experimental" //icon - , N_("Recursive skeleton") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - TANGENT_TO_CURVE - , N_("Tangent to curve") //label - , "tangent_to_curve" //key - , "experimental" //icon - , N_("Tangent to curve") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, - { - TEXT_LABEL - , N_("Text label") //label - , "text_label" //key - , "experimental" //icon - , N_("Text label") //description - , true //on_path - , true //on_shape - , true //on_group - , true //on_use - , false //on_image - , false //on_text - }, -#endif - -}; - -extern const EnumEffectData LPETypeData[]; /// defined in effect.cpp -extern const EnumEffectDataConverter LPETypeConverter; /// defined in effect.cpp +extern const Util::EnumData LPETypeData[]; /// defined in effect.cpp +extern const Util::EnumDataConverter LPETypeConverter; /// defined in effect.cpp } //namespace LivePathEffect } //namespace Inkscape diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index f83d07c6d..92f5a781a 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -94,10 +94,74 @@ namespace Inkscape { namespace LivePathEffect { +const Util::EnumData LPETypeData[] = { + // {constant defined in effect-enum.h, N_("name of your effect"), "name of your effect in SVG"} +/* 0.46 */ + {BEND_PATH, N_("Bend"), "bend_path"}, + {GEARS, N_("Gears"), "gears"}, + {PATTERN_ALONG_PATH, N_("Pattern Along Path"), "skeletal"}, // for historic reasons, this effect is called skeletal(strokes) in Inkscape:SVG + {CURVE_STITCH, N_("Stitch Sub-Paths"), "curvestitching"}, +/* 0.47 */ + {VONKOCH, N_("VonKoch"), "vonkoch"}, + {KNOT, N_("Knot"), "knot"}, + {CONSTRUCT_GRID, N_("Construct grid"), "construct_grid"}, + {SPIRO, N_("Spiro spline"), "spiro"}, + {ENVELOPE, N_("Envelope Deformation"), "envelope"}, + {INTERPOLATE, N_("Interpolate Sub-Paths"), "interpolate"}, + {ROUGH_HATCHES, N_("Hatches (rough)"), "rough_hatches"}, + {SKETCH, N_("Sketch"), "sketch"}, + {RULER, N_("Ruler"), "ruler"}, +/* 0.91 */ + {POWERSTROKE, N_("Power stroke"), "powerstroke"}, + {CLONE_ORIGINAL, N_("Clone original"), "clone_original"}, +/* 0.92 */ + {SIMPLIFY, N_("Simplify"), "simplify"}, + {LATTICE2, N_("Lattice Deformation 2"), "lattice2"}, + {PERSPECTIVE_ENVELOPE, N_("Perspective/Envelope"), "perspective-envelope"}, //TODO:Wrong name with "-" + {INTERPOLATE_POINTS, N_("Interpolate points"), "interpolate_points"}, + {TRANSFORM_2PTS, N_("Transform by 2 points"), "transform_2pts"}, + {SHOW_HANDLES, N_("Show handles"), "show_handles"}, + {ROUGHEN, N_("Roughen"), "roughen"}, + {BSPLINE, N_("BSpline"), "bspline"}, + {JOIN_TYPE, N_("Join type"), "join_type"}, + {TAPER_STROKE, N_("Taper stroke"), "taper_stroke"}, + {MIRROR_SYMMETRY, N_("Mirror symmetry"), "mirror_symmetry"}, + {COPY_ROTATE, N_("Rotate copies"), "copy_rotate"}, +/* Ponyscape -> Inkscape 0.92*/ + {ATTACH_PATH, N_("Attach path"), "attach_path"}, + {FILL_BETWEEN_STROKES, N_("Fill between strokes"), "fill_between_strokes"}, + {FILL_BETWEEN_MANY, N_("Fill between many"), "fill_between_many"}, + {ELLIPSE_5PTS, N_("Ellipse by 5 points"), "ellipse_5pts"}, + {BOUNDING_BOX, N_("Bounding Box"), "bounding_box"}, +/* 0.93 */ + {MEASURE_SEGMENTS, N_("Measure Segments"), "measure_segments"}, + {FILLET_CHAMFER, N_("Fillet/Chamfer"), "fillet_chamfer"}, + {BOOL_OP, N_("Boolean operation"), "bool_op"}, + {EMBRODERY_STITCH, N_("Embroidery stitch"), "embrodery_stitch"}, + {POWERCLIP, N_("Power clip"), "powerclip"}, + {POWERMASK, N_("Power mask"), "powermask"}, + {PTS2ELLIPSE, N_("Ellipse from points"), "pts2ellipse"}, + {OFFSET, N_("Offset"), "offset"}, + {DASH_STROKE, N_("Dash Stroke"), "dash_stroke"}, +#ifdef LPE_ENABLE_TEST_EFFECTS + {DOEFFECTSTACK_TEST, N_("doEffect stack test"), "doeffectstacktest"}, + {ANGLE_BISECTOR, N_("Angle bisector"), "angle_bisector"}, + {CIRCLE_WITH_RADIUS, N_("Circle (by center and radius)"), "circle_with_radius"}, + {CIRCLE_3PTS, N_("Circle by 3 points"), "circle_3pts"}, + {DYNASTROKE, N_("Dynamic stroke"), "dynastroke"}, + {EXTRUDE, N_("Extrude"), "extrude"}, + {LATTICE, N_("Lattice Deformation"), "lattice"}, + {LINE_SEGMENT, N_("Line Segment"), "line_segment"}, + {PARALLEL, N_("Parallel"), "parallel"}, + {PATH_LENGTH, N_("Path length"), "path_length"}, + {PERP_BISECTOR, N_("Perpendicular bisector"), "perp_bisector"}, + {RECURSIVE_SKELETON, N_("Recursive skeleton"), "recursive_skeleton"}, + {TANGENT_TO_CURVE, N_("Tangent to curve"), "tangent_to_curve"}, + {TEXT_LABEL, N_("Text label"), "text_label"}, +#endif - - -const EnumEffectDataConverter LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData)); +}; +const Util::EnumDataConverter LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData)); int Effect::acceptsNumClicks(EffectType type) { diff --git a/src/ui/dialog/filter-editor.cpp b/src/ui/dialog/filter-editor.cpp index ba2c7357a..6ad9dca61 100644 --- a/src/ui/dialog/filter-editor.cpp +++ b/src/ui/dialog/filter-editor.cpp @@ -69,7 +69,7 @@ FilterEditorDialog::FilterEditorDialog() : UI::Widget::Panel("/dialogs/filtereff { const std::string req_widgets[] = {"FilterEditor", "FilterList", "FilterFERX", "FilterFERY", "FilterFERH", "FilterFERW", "FilterPreview", "FilterPrimitiveDescImage", "FilterPrimitiveList", "FilterPrimitiveDescText", "FilterPrimitiveAdd"}; - Glib::ustring gladefile = get_filename(UIS, "dialog-filter-editor.ui"); + Glib::ustring gladefile = get_filename(UIS, "filter-editor.glade"); try { builder = Gtk::Builder::create_from_file(gladefile); } catch(const Glib::Error& ex) { diff --git a/src/ui/dialog/livepatheffect-add.cpp b/src/ui/dialog/livepatheffect-add.cpp index 9eea4cccd..1fae9a513 100644 --- a/src/ui/dialog/livepatheffect-add.cpp +++ b/src/ui/dialog/livepatheffect-add.cpp @@ -13,10 +13,9 @@ # include "config.h" // only include where actually required! #endif -#include "live_effects/effect.h" #include "livepatheffect-add.h" #include -#include "io/resource.h" + #include "desktop.h" namespace Inkscape { @@ -24,153 +23,93 @@ namespace UI { namespace Dialog { LivePathEffectAdd::LivePathEffectAdd() : - converter(Inkscape::LivePathEffect::LPETypeConverter) + add_button(_("_Add"), true), + close_button(_("_Cancel"), true), + converter(Inkscape::LivePathEffect::LPETypeConverter), + applied(false) { - const std::string req_widgets[] = {"LPEDialogSelector", "LPESelector", "LPESelectorFlowBox"}; - Glib::ustring gladefile = get_filename(Inkscape::IO::Resource::UIS, "dialog-livepatheffect-add.ui"); - try { - _builder = Gtk::Builder::create_from_file(gladefile); - } catch(const Glib::Error& ex) { - g_warning("Glade file loading failed for filter effect dialog"); - return; - } + set_title(_("Add Path Effect")); + + /** + * Scrolled Window + */ + scrolled_window.add(effectlist_treeview); + scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); + scrolled_window.set_shadow_type(Gtk::SHADOW_IN); + scrolled_window.set_size_request(250, 200); + scrolled_window.set_can_focus(); + + /** + * Effect Store and Tree + */ + effectlist_store = Gtk::ListStore::create(_columns); + effectlist_store->set_sort_column (_columns.name, Gtk::SORT_ASCENDING ); + + effectlist_treeview.set_model(effectlist_store); + effectlist_treeview.set_headers_visible(false); + effectlist_treeview.append_column("Name", _columns.name); + //effectlist_treeview.set_activates_default(true); - Gtk::Object* test; - for(std::string w:req_widgets) { - _builder->get_widget(w,test); - if(!test){ - g_warning("Required widget %s does not exist", w.c_str()); - return; - } - } - _builder->get_widget("LPEDialogSelector", _LPEDialogSelector); /** * Initialize Effect list */ - _builder->get_widget("LPESelectorFlowBox", _LPESelectorFlowBox); - _builder->get_widget("LPEFilter", _LPEFilter); - _builder->get_widget("LPEInfo", _LPEInfo); - _LPEFilter->signal_search_changed().connect(sigc::mem_fun(*this, &LivePathEffectAdd::on_search)); - const std::string le_widgets[] = {"LPESelectorEffect", "LPEName","LPEDescription"}; - Glib::ustring le_gladefile = get_filename(Inkscape::IO::Resource::UIS, "dialog-livepatheffect-add-effect.ui"); - for(int i = 0; i < static_cast(converter._length); ++i) { - - try { - _builder = Gtk::Builder::create_from_file(le_gladefile); - } catch(const Glib::Error& ex) { - g_warning("Glade file loading failed for filter effect dialog"); - return; - } + int show = LivePathEffect::ATTACH_PATH; +#ifdef LPE_ENABLE_TEST_EFFECTS + //TODO: Handle when showing the experimental effects without setting flag + show = LivePathEffect::ANGLE_BISECTOR; +#elif WITH_LPETOOL + //TODO: Handle when showing the experimental effects without setting flag + show = LivePathEffect::ANGLE_BISECTOR; +#endif - Gtk::Object* test; - for(std::string w:le_widgets) { - _builder->get_widget(w,test); - if(!test){ - g_warning("Required widget %s does not exist", w.c_str()); - return; - } + for(int i = 0; i < static_cast(converter._length); ++i) { + Gtk::TreeModel::Row row = *(effectlist_store->append()); + const Util::EnumData* data = &converter.data(i); + row[_columns.name] = _( converter.get_label(data->id).c_str() ); + row[_columns.data] = data; + if (i == show) { + Glib::RefPtr select = effectlist_treeview.get_selection(); + select->select(row); } - const LivePathEffect::EnumEffectData* data = &converter.data(i); - Gtk::Label * LPEName; - _builder->get_widget("LPEName", LPEName); - Glib::ustring newid = "LPEName_" + Glib::ustring::format(i); - (*LPEName).set_name(newid); - (*LPEName).set_text(converter.get_label(data->id).c_str()); - Gtk::Label * LPEDescription; - _builder->get_widget("LPEDescription", LPEDescription); - newid = "LPEDescription_" + Glib::ustring::format(i); - (*LPEDescription).set_name(newid); - (*LPEDescription).set_text(converter.get_description(data->id)); - Gtk::Image * LPEIcon; - _builder->get_widget("LPEIcon", LPEIcon); - newid = "LPEIcon_" + Glib::ustring::format(i); - (*LPEIcon).set_name(newid); - (*LPEIcon).set_from_icon_name(converter.get_icon(data->id),Gtk::BuiltinIconSize(Gtk::ICON_SIZE_DIALOG)); - Gtk::Box * LPESelectorEffect; - _builder->get_widget("LPESelectorEffect", LPESelectorEffect); - newid = "LPESelectorEffect" + Glib::ustring::format(i); - (*LPESelectorEffect).set_name(newid); - _LPESelectorFlowBox->insert(*LPESelectorEffect, i); } - _visiblelpe = _LPESelectorFlowBox->get_children().size(); - _LPESelectorFlowBox->signal_child_activated().connect(sigc::mem_fun(*this, &LivePathEffectAdd::on_activate)); - _LPEDialogSelector->set_title(_("Live Efects Selector")); - _LPEDialogSelector->show_all_children(); - _LPEInfo->set_visible(false); -} -void LivePathEffectAdd::on_activate(Gtk::FlowBoxChild *child){ - for (auto i:_LPESelectorFlowBox->get_children()) { - Gtk::FlowBoxChild * leitem = dynamic_cast(i); - leitem->get_style_context()->remove_class("lpeactive"); - leitem->get_style_context()->remove_class("colorinverse"); - leitem->get_style_context()->remove_class("backgroundinverse"); - Gtk::Box *box = dynamic_cast(leitem->get_child()); - if (box) { - std::vector contents = box->get_children(); - Gtk::Box *actions = dynamic_cast(contents[3]); - if (actions) { - actions->set_visible(false); - } - } - } - child->get_style_context()->add_class("lpeactive"); - child->get_style_context()->add_class("colorinverse"); - child->get_style_context()->add_class("backgroundinverse"); - child->show_all_children(); -} + /** + * Buttons + */ + //close_button.set_can_default(); + add_button.set_use_underline(true); + add_button.set_can_default(); -bool LivePathEffectAdd::on_filter(Gtk::FlowBoxChild *child) -{ - if (_LPEFilter->get_text().length() < 4) { - _visiblelpe = _LPESelectorFlowBox->get_children().size(); - return true; - } - Gtk::Box *box = dynamic_cast(child->get_child()); - if (box) { - std::vector contents = box->get_children(); - Gtk::Label *lpename = dynamic_cast(contents[1]); - if (lpename) { - size_t s = lpename->get_text().uppercase().find(_LPEFilter->get_text().uppercase(),0); - if(s != -1) { - _visiblelpe++; - return true; - } - } - Gtk::Label *lpedesc = dynamic_cast(contents[2]); - if (lpedesc) { - size_t s = lpedesc->get_text().uppercase().find(_LPEFilter->get_text().uppercase(),0); - if(s != -1) { - _visiblelpe++; - return true; - } - } - } - return false; -} + auto mainVBox = get_content_area(); -void LivePathEffectAdd::on_search() -{ - _visiblelpe = 0; - _LPESelectorFlowBox->set_filter_func(sigc::mem_fun(*this, &LivePathEffectAdd::on_filter)); - if (_visiblelpe == 0) { - _LPEInfo->set_text(_("Your search do a empty result, please try again")); - _LPEInfo->set_visible(true); - _LPEInfo->get_style_context()->add_class("lpeinfowarn"); - } else { - _LPEInfo->set_visible(false); - _LPEInfo->get_style_context()->remove_class("lpeinfowarn"); - } + mainVBox->pack_start(scrolled_window, true, true); + add_action_widget(close_button, Gtk::RESPONSE_CLOSE); + add_action_widget(add_button, Gtk::RESPONSE_APPLY); + + + /** + * Signal handlers + */ + effectlist_treeview.signal_button_press_event().connect_notify( sigc::mem_fun(*this, &LivePathEffectAdd::onButtonEvent) ); + effectlist_treeview.signal_key_press_event().connect_notify(sigc::mem_fun(*this, &LivePathEffectAdd::onKeyEvent)); + close_button.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectAdd::onClose)); + add_button.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectAdd::onAdd)); + signal_delete_event().connect( sigc::bind_return(sigc::hide(sigc::mem_fun(*this, &LivePathEffectAdd::onClose)), true ) ); + + add_button.grab_default(); + + show_all_children(); } void LivePathEffectAdd::onAdd() { + applied = true; onClose(); } void LivePathEffectAdd::onClose() { - _LPEDialogSelector->hide(); + hide(); } void LivePathEffectAdd::onKeyEvent(GdkEventKey* evt) @@ -183,10 +122,36 @@ void LivePathEffectAdd::onKeyEvent(GdkEventKey* evt) } } +void LivePathEffectAdd::onButtonEvent(GdkEventButton* evt) +{ + // Double click on tree is same as clicking the add button + if (evt->type == GDK_2BUTTON_PRESS) { + onAdd(); + } +} + +const Util::EnumData* +LivePathEffectAdd::getActiveData() +{ + Gtk::TreeModel::iterator iter = instance().effectlist_treeview.get_selection()->get_selected(); + if ( iter ) { + Gtk::TreeModel::Row row = *iter; + return row[instance()._columns.data]; + } + + return nullptr; +} + + void LivePathEffectAdd::show(SPDesktop *desktop) { LivePathEffectAdd &dial = instance(); - dial._LPEDialogSelector->run(); + dial.applied=false; + dial.set_modal(true); + desktop->setWindowTransient (dial.gobj()); + dial.property_destroy_with_parent() = true; + dial.effectlist_treeview.grab_focus(); + dial.run(); } } // namespace Dialog diff --git a/src/ui/dialog/livepatheffect-add.h b/src/ui/dialog/livepatheffect-add.h index 17d46487a..84901385c 100644 --- a/src/ui/dialog/livepatheffect-add.h +++ b/src/ui/dialog/livepatheffect-add.h @@ -12,14 +12,10 @@ #ifndef INKSCAPE_DIALOG_LIVEPATHEFFECT_ADD_H #define INKSCAPE_DIALOG_LIVEPATHEFFECT_ADD_H -#include -#include -#include -#include -#include -#include -#include #include +#include +#include +#include #include "live_effects/effect-enum.h" class SPDesktop; @@ -41,23 +37,31 @@ public: * Show the dialog */ static void show(SPDesktop *desktop); + + /** + * Returns true is the "Add" button was pressed + */ static bool isApplied() { - return false; + return instance().applied; } - static const Util::EnumData* getActiveData(){return NULL;}; + /** + * Return the data associated with the currently selected item + */ + static const Util::EnumData* getActiveData(); + protected: + /** * Close button was clicked */ void onClose(); - bool on_filter(Gtk::FlowBoxChild *child); - void on_search(); - void on_activate(Gtk::FlowBoxChild *child); + /** * Add button was clicked */ void onAdd(); + /** * Tree was clicked */ @@ -68,17 +72,37 @@ protected: */ void onKeyEvent(GdkEventKey* evt); private: - Gtk::Button _add_button; - Gtk::Button _close_button; - Gtk::Dialog *_LPEDialogSelector; - Glib::RefPtr _builder; - Gtk::FlowBox *_LPESelectorFlowBox; - Gtk::SearchEntry *_LPEFilter; - Gtk::Label *_LPEInfo; - Gtk::Box *_LPESelector; - guint _visiblelpe; - class Effect; - const LivePathEffect::EnumEffectDataConverter& converter; + + Gtk::TreeView effectlist_treeview; + Gtk::ScrolledWindow scrolled_window; + Gtk::Button add_button; + Gtk::Button close_button; + + class ModelColumns : public Gtk::TreeModel::ColumnRecord + { + public: + ModelColumns() + { + add(name); + //add(desc); + add(data); + } + ~ModelColumns() override = default; + + Gtk::TreeModelColumn name; + /** + * TODO - Get detailed descriptions of each Effect to show in the dialog + */ + //Gtk::TreeModelColumn desc; + Gtk::TreeModelColumn*> data; + }; + + ModelColumns _columns; + Glib::RefPtr effectlist_store; + const Util::EnumDataConverter& converter; + + bool applied; + static LivePathEffectAdd &instance() { static LivePathEffectAdd instance_; return instance_; diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 6e614f582..3199e25ef 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -857,7 +857,7 @@ void ToolboxFactory::setOrientation(GtkWidget* toolbox, GtkOrientation orientati void setup_tool_toolbox(GtkWidget *toolbox, SPDesktop *desktop) { setupToolboxCommon( toolbox, desktop, - "toolbar-tool.ui", + "tool-toolbar.ui", "/ui/ToolToolbar", "/toolbox/tools/small"); } @@ -905,12 +905,12 @@ void setup_aux_toolbox(GtkWidget *toolbox, SPDesktop *desktop) Glib::RefPtr mainActions = create_or_fetch_actions( desktop ); // The UI Manager creates widgets based on the definitions in the - // "toolbar-select.ui" file. This is only used with the "prep" + // "select-toolbar.ui" file. This is only used with the "prep" // method of toolbar-creation GtkUIManager* mgr = gtk_ui_manager_new(); GError *err = nullptr; gtk_ui_manager_insert_action_group( mgr, mainActions->gobj(), 0 ); - Glib::ustring filename = get_filename(UIS, "toolbar-select.ui"); + Glib::ustring filename = get_filename(UIS, "select-toolbar.ui"); guint ret = gtk_ui_manager_add_ui_from_file(mgr, filename.c_str(), &err); if(err) { g_warning("Failed to load aux toolbar %s: %s", filename.c_str(), err->message); @@ -1061,7 +1061,7 @@ void update_aux_toolbox(SPDesktop * /*desktop*/, ToolBase *eventcontext, GtkWidg void setup_commands_toolbox(GtkWidget *toolbox, SPDesktop *desktop) { setupToolboxCommon( toolbox, desktop, - "toolbar-commands.ui", + "commands-toolbar.ui", "/ui/CommandsToolbar", "/toolbox/small" ); } @@ -1375,7 +1375,7 @@ void setup_snap_toolbox(GtkWidget *toolbox, SPDesktop *desktop) } setupToolboxCommon( toolbox, desktop, - "toolbar-snap.ui", + "snap-toolbar.ui", "/ui/SnapToolbar", "/toolbox/secondary" ); } -- cgit v1.2.3 From 087826ec04e8fe69f570ef0a25a6963339de523f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 26 Jan 2019 06:57:02 +0100 Subject: Remove files from prev branch splited --- src/ui/dialog/lpe-selector.cpp | 69 ------------------------------------------ src/ui/dialog/lpe-selector.h | 38 ----------------------- 2 files changed, 107 deletions(-) delete mode 100644 src/ui/dialog/lpe-selector.cpp delete mode 100644 src/ui/dialog/lpe-selector.h (limited to 'src') diff --git a/src/ui/dialog/lpe-selector.cpp b/src/ui/dialog/lpe-selector.cpp deleted file mode 100644 index 5a2f39db4..000000000 --- a/src/ui/dialog/lpe-selector.cpp +++ /dev/null @@ -1,69 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** - * @file - * Filter Effects dialog. - */ -/* Authors: - * Marc Jeanmougin - * - * Copyright (C) 2017 Authors - * - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#include -#include -#include -#include -#include -#include "io/sys.h" -#include "io/resource.h" - -namespace Inkscape { -namespace UI { - -LPESelector::LPESelector() : Gtk::Box() -{ - - const std::string req_widgets[] = {"LPESelector", "FilterList", "FilterFERX", "FilterFERY", "FilterFERH", "FilterFERW", "FilterPreview", "FilterPrimitiveDescImage", "FilterPrimitiveList", "FilterPrimitiveDescText", "FilterPrimitiveAdd"}; - Glib::ustring gladefile = get_filename(UIS, "lpe-selector.glade"); - try { - builder = Gtk::Builder::create_from_file(gladefile); - } catch(const Glib::Error& ex) { - g_warning("Glade file loading failed for filter effect dialog"); - return; - } - - Gtk::Object* test; - for(std::string w:req_widgets) { - builder->get_widget(w,test); - if(!test){ - g_warning("Required widget %s does not exist", w.c_str()); - return; - } - } - - builder->get_widget("LPESelector", LPESelector); - _getContents()->add(*LPESelector); - -} -LPESelector::~LPESelector()= default; - - - - - - -} // Never put these namespaces together unless you are using gcc 6+ -} - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/dialog/lpe-selector.h b/src/ui/dialog/lpe-selector.h deleted file mode 100644 index cc6d80f5a..000000000 --- a/src/ui/dialog/lpe-selector.h +++ /dev/null @@ -1,38 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/** @file - * @brief Filter Editor dialog - */ -/* Authors: - * Marc Jeanmougin - * - * Copyright (C) 2017 Authors - * - * Released under GNU GPL v2+, read the file 'COPYING' for more information. - */ - -#ifndef INKSCAPE_UI_LPE_SELECTOR_H -#define INKSCAPE_UI_LPE_SELECTOR_H - -#include - -namespace Inkscape { -namespace UI { - -class LPESelector : public Gtk::Box { -public: - - LPESelector(); - ~LPESelector() override; - - static LPESelector &getInstance() - { return *new LPESelector(); } - -// void set_attrs_locked(const bool); -private: - Glib::RefPtr builder; - Glib::RefPtr FilterStore; - Gtk::Box *LPESelector; -}; -} -} -#endif -- cgit v1.2.3 From 790d6941180549dd79b6e96f4c0880f829c15ed5 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 26 Jan 2019 18:03:03 +0100 Subject: Fix compiling errors --- src/inkscape.cpp | 8 +++--- src/ui/dialog/inkscape-preferences.cpp | 46 ++++++++++++++++------------------ src/widgets/desktop-widget.cpp | 6 ++--- 3 files changed, 28 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/inkscape.cpp b/src/inkscape.cpp index baefd6b9f..d6a0b8aff 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -434,20 +434,18 @@ Application::add_gtk_css() g_object_get(settings, "gtk-theme-name", >kThemeName, NULL); g_object_get(settings, "gtk-application-prefer-dark-theme", >kApplicationPreferDarkTheme, NULL); g_object_set(settings, "gtk-application-prefer-dark-theme", - prefs->getBool("/theme/darkTheme", gtkApplicationPreferDarkTheme), NULL); + prefs->getBool("/theme/darkTheme", gtkApplicationPreferDarkTheme), NULL); prefs->setString("/theme/defaultIconTheme", Glib::ustring(gtkIconThemeName)); if (prefs->getString("/theme/gtkTheme") != "") { g_object_set(settings, "gtk-theme-name", prefs->getString("/theme/gtkTheme").c_str(), NULL); - } - else { + } else { prefs->setString("/theme/gtkTheme", Glib::ustring(gtkThemeName)); } Glib::ustring themeiconname = prefs->getString("/theme/iconTheme"); if (themeiconname != "") { g_object_set(settings, "gtk-icon-theme-name", themeiconname.c_str(), NULL); - } - else { + } else { prefs->setString("/theme/iconTheme", Glib::ustring(gtkIconThemeName)); } g_object_get(settings, "gtk-font-name", >k_font_name, NULL); diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 158aeb617..d10a2ac4a 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -34,6 +34,7 @@ #include "cms-system.h" #include "document.h" #include "enums.h" +#include "inkscape-window.h" #include "inkscape.h" #include "message-stack.h" #include "path-prefix.h" @@ -43,7 +44,6 @@ #include "selection.h" #include "shortcuts.h" #include "verbs.h" -#include "inkscape-window.h" #include "display/canvas-grid.h" #include "display/nr-filter-gaussian.h" @@ -687,7 +687,7 @@ void InkscapePreferences::symbolicAddClass() auto const screen = Gdk::Screen::get_default(); auto provider = Gtk::CssProvider::create(); Glib::ustring css_str = ""; - + gchar colornamed[64]; gchar colornamed_inverse[64]; int colorset = prefs->getInt("/theme/symbolicColor", 0x000000ff); @@ -727,24 +727,23 @@ void InkscapePreferences::symbolicAddClass() // is more understandable than record previously applied Glib::ustring style = get_filename(UIS, "style.css"); if (!style.empty()) { - auto provider = Gtk::CssProvider::create(); - - // From 3.16, throws an error which we must catch. - try { - provider->load_from_path (style); - } -#if GTK_CHECK_VERSION(3,16,0) - // Gtk::CssProviderError not defined until 3.16. - catch (const Gtk::CssProviderError& ex) - { - g_critical("CSSProviderError::load_from_path(): failed to load '%s'\n(%s)", - style.c_str(), ex.what().c_str()); - } + auto provider = Gtk::CssProvider::create(); + + // From 3.16, throws an error which we must catch. + try { + provider->load_from_path(style); + } +#if GTK_CHECK_VERSION(3, 16, 0) + // Gtk::CssProviderError not defined until 3.16. + catch (const Gtk::CssProviderError &ex) { + g_critical("CSSProviderError::load_from_path(): failed to load '%s'\n(%s)", style.c_str(), + ex.what().c_str()); + } #else - catch (...) - {} + catch (...) { + } #endif - Gtk::StyleContext::add_provider_for_screen (screen, provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + Gtk::StyleContext::add_provider_for_screen(screen, provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); } } void InkscapePreferences::themeChange() @@ -756,21 +755,20 @@ void InkscapePreferences::themeChange() gchar *gtkThemeName; gboolean gtkApplicationPreferDarkTheme; Gtk::Window *window = SP_ACTIVE_DESKTOP->getToplevel(); - GtkSettings *settings = gtk_settings_get_default(); + GtkSettings *settings = gtk_settings_get_default(); if (window && settings) { g_object_get(settings, "gtk-theme-name", >kThemeName, NULL); g_object_get(settings, "gtk-application-prefer-dark-theme", >kApplicationPreferDarkTheme, NULL); bool dark = gtkApplicationPreferDarkTheme || Glib::ustring(gtkThemeName).find(":dark") != -1; if (!dark) { - Glib::RefPtr stylecontext = window->get_style_context(); - Gdk::RGBA rgba; - bool background_set = stylecontext->lookup_color("theme_bg_color", rgba); + Glib::RefPtr stylecontext = window->get_style_context(); + Gdk::RGBA rgba; + bool background_set = stylecontext->lookup_color("theme_bg_color", rgba); if (background_set && rgba.get_red() + rgba.get_green() + rgba.get_blue() < 1.0) { dark = true; } } - if (dark) - { + if (dark) { window->get_style_context()->add_class("dark"); } else { window->get_style_context()->remove_class("dark"); diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index 801e6bc41..88c70c75a 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -898,9 +898,9 @@ sp_desktop_widget_realize (GtkWidget *widget) g_object_get(settings, "gtk-application-prefer-dark-theme", >kApplicationPreferDarkTheme, NULL); bool dark = gtkApplicationPreferDarkTheme || Glib::ustring(gtkThemeName).find(":dark") != -1; if (!dark) { - Glib::RefPtr stylecontext = window->get_style_context(); - Gdk::RGBA rgba; - bool background_set = stylecontext->lookup_color("theme_bg_color", rgba); + Glib::RefPtr stylecontext = window->get_style_context(); + Gdk::RGBA rgba; + bool background_set = stylecontext->lookup_color("theme_bg_color", rgba); if (background_set && rgba.get_red() + rgba.get_green() + rgba.get_blue() < 1.0) { dark = true; } -- cgit v1.2.3 From a266e9f871e38a28d1a3f7d5c8732590e5e4fecd Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 26 Jan 2019 18:42:42 +0100 Subject: Add desktop function to know we are on dark theme --- src/desktop.cpp | 6 ++++++ src/desktop.h | 1 + 2 files changed, 7 insertions(+) (limited to 'src') diff --git a/src/desktop.cpp b/src/desktop.cpp index 4e3a28243..20c4914a4 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -1293,6 +1293,12 @@ SPDesktop::is_iconified() return 0!=(window_state & GDK_WINDOW_STATE_ICONIFIED); } +bool +SPDesktop::is_darktheme() +{ + return getToplevel()->get_style_context()->has_class("dark"); +} + void SPDesktop::iconify() { diff --git a/src/desktop.h b/src/desktop.h index 539e55935..d4babf61f 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -417,6 +417,7 @@ public: void toggleToolbar(gchar const *toolbar_name); bool is_iconified(); + bool is_darktheme(); bool is_maximized(); bool is_fullscreen(); bool is_focusMode(); -- cgit v1.2.3 From 8383fcabb598df319ed8a1a13964633fe16ba6c8 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sat, 26 Jan 2019 20:24:01 +0100 Subject: Remove not rebased parts --- src/inkscape.cpp | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src') diff --git a/src/inkscape.cpp b/src/inkscape.cpp index d6a0b8aff..fd185649a 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -386,7 +386,6 @@ Application::add_gtk_css() int colorset_inverse = colorset ^ 0xffffff00; sp_svg_write_color(colornamed_inverse, sizeof(colornamed_inverse), colorset_inverse); if (prefs->getBool("/theme/symbolicIcons", false)) { -<<<<<<< HEAD int colorset = prefs->getInt("/theme/symbolicColor", 0x000000ff); gchar colornamed[64]; sp_svg_write_color(colornamed, sizeof(colornamed), colorset); @@ -409,12 +408,6 @@ Application::add_gtk_css() css_str += ";}"; css_str += "#iconregular{ -gtk-icon-style: regular;}"; } -======= - css_str += "*{ -gtk-icon-style: symbolic;}"; - css_str += "image{ color:"; - css_str += colornamed; - css_str += ";}"; ->>>>>>> Adding styling refactoring, moving after to other branch the CSS part } else { css_str += "*{-gtk-icon-style: regular;}"; } -- cgit v1.2.3 From d5788f6816d40360c54a29c8b735d6b6c5dd2db2 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Sun, 27 Jan 2019 02:08:22 +0100 Subject: Finich CSS refactor --- src/inkscape.cpp | 5 +++-- src/ui/dialog/inkscape-preferences.cpp | 7 +++++-- src/widgets/desktop-widget.cpp | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/inkscape.cpp b/src/inkscape.cpp index fd185649a..5c6f29c3f 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -395,12 +395,13 @@ Application::add_gtk_css() sp_svg_write_color(colornamed_inverse, sizeof(colornamed_inverse), colorset_inverse); if (prefs->getBool("/theme/symbolicIconsDefaultColor", true)) { css_str += "*{ -gtk-icon-style: symbolic;}"; - css_str += "image{ color: @theme_fg_color}"; + css_str += ".dark,.bright,.dark image,.bright image{ color: @theme_fg_color}"; css_str += "iconinverse{ color: @theme_bg_color;}"; css_str += "iconregular{ -gtk-icon-style: regular;}"; } else { css_str += "*{ -gtk-icon-style: symbolic;}"; - css_str += "image{ color:"; + css_str += ".dark *,.bright *{ color: @theme_fg_color;}"; + css_str += ".dark,.bright,.dark image,.bright image{ color:"; css_str += colornamed; css_str += ";}"; css_str += "#iconinverse{ color:"; diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index d10a2ac4a..191182528 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -656,7 +656,7 @@ void InkscapePreferences::symbolicDefaultColor(){ Glib::ustring css_str = ""; if (prefs->getBool("/theme/symbolicIcons", false)) { css_str += "*{ -gtk-icon-style: symbolic;}"; - css_str += "image{ color: @theme_fg_color}"; + css_str += ".dark,.bright,.dark image,.bright image{ color: @theme_fg_color;}"; css_str += "iconinverse{ color: @theme_bg_color;}"; css_str += "iconregular{ -gtk-icon-style: regular;}"; } else { @@ -697,7 +697,8 @@ void InkscapePreferences::symbolicAddClass() sp_svg_write_color(colornamed_inverse, sizeof(colornamed_inverse), colorset_inverse); if (prefs->getBool("/theme/symbolicIcons", false)) { css_str += "*{ -gtk-icon-style: symbolic;}"; - css_str += "image{ color:"; + css_str += ".dark *,.bright *{ color: @theme_fg_color;}"; + css_str += ".dark,.bright,.dark image,.bright image{ color:"; css_str += colornamed; css_str += ";}"; } else { @@ -770,7 +771,9 @@ void InkscapePreferences::themeChange() } if (dark) { window->get_style_context()->add_class("dark"); + window->get_style_context()->remove_class("bright"); } else { + window->get_style_context()->add_class("bright"); window->get_style_context()->remove_class("dark"); } } diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index 88c70c75a..9db8b2af4 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -907,7 +907,9 @@ sp_desktop_widget_realize (GtkWidget *widget) } if (dark) { window->get_style_context()->add_class("dark"); + window->get_style_context()->remove_class("bright"); } else { + window->get_style_context()->add_class("bright"); window->get_style_context()->remove_class("dark"); } } -- cgit v1.2.3