diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/live_effects/effect-enum.h | 907 | ||||
| -rw-r--r-- | src/live_effects/effect.cpp | 4 | ||||
| -rw-r--r-- | src/ui/dialog/inkscape-preferences.cpp | 40 | ||||
| -rw-r--r-- | src/ui/dialog/livepatheffect-add.cpp | 99 | ||||
| -rw-r--r-- | src/ui/dialog/livepatheffect-add.h | 59 | ||||
| -rw-r--r-- | src/ui/dialog/lpe-selector.cpp | 71 | ||||
| -rw-r--r-- | src/ui/dialog/lpe-selector.h | 36 | ||||
| -rw-r--r-- | src/widgets/toolbox.cpp | 15 |
8 files changed, 1127 insertions, 104 deletions
diff --git a/src/live_effects/effect-enum.h b/src/live_effects/effect-enum.h index b662d3263..97c3cda9a 100644 --- a/src/live_effects/effect-enum.h +++ b/src/live_effects/effect-enum.h @@ -11,6 +11,9 @@ */ #include "util/enums.h" +#include <glibmm/i18n.h> + + namespace Inkscape { namespace LivePathEffect { @@ -75,8 +78,912 @@ 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) }; +<<<<<<< HEAD extern const Util::EnumData<EffectType> LPETypeData[]; /// defined in effect.cpp extern const Util::EnumDataConverter<EffectType> LPETypeConverter; /// defined in effect.cpp +======= +template <typename E> +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 <typename E> +class EnumEffectDataConverter { + public: + typedef EnumEffectData<E> Data; + + EnumEffectDataConverter(const EnumEffectData<E> *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<E> &data(const unsigned int i) const { return _data[i]; } + + const unsigned int _length; + + private: + const EnumEffectData<E> *_data; +}; + +const EnumEffectData<EffectType> 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<EffectType> LPETypeData[]; /// defined in effect.cpp +extern const EnumEffectDataConverter<EffectType> LPETypeConverter; /// defined in effect.cpp +>>>>>>> fixing coding style and translation and merge from master } //namespace LivePathEffect } //namespace Inkscape diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 92f5a781a..dfad38e3a 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -160,8 +160,8 @@ const Util::EnumData<EffectType> LPETypeData[] = { {TEXT_LABEL, N_("Text label"), "text_label"}, #endif -}; -const Util::EnumDataConverter<EffectType> LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData)); + +const EnumEffectDataConverter<EffectType> LPETypeConverter(LPETypeData, sizeof(LPETypeData) / sizeof(*LPETypeData)); int Effect::acceptsNumClicks(EffectType type) { diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 86529fbbb..1f094abbf 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -44,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" @@ -728,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() @@ -757,15 +755,15 @@ 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<Gtk::StyleContext> stylecontext = window->get_style_context(); - Gdk::RGBA rgba; - bool background_set = stylecontext->lookup_color("theme_bg_color", rgba); + Glib::RefPtr<Gtk::StyleContext> 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; } diff --git a/src/ui/dialog/livepatheffect-add.cpp b/src/ui/dialog/livepatheffect-add.cpp index 630008606..b11ee66b7 100644 --- a/src/ui/dialog/livepatheffect-add.cpp +++ b/src/ui/dialog/livepatheffect-add.cpp @@ -13,31 +13,32 @@ # include "config.h" // only include where actually required! #endif +#include "desktop.h" +#include "io/resource.h" +#include "live_effects/effect.h" #include "livepatheffect-add.h" #include <glibmm/i18n.h> -#include "desktop.h" - namespace Inkscape { namespace UI { namespace Dialog { -LivePathEffectAdd::LivePathEffectAdd() : - converter(Inkscape::LivePathEffect::LPETypeConverter) +LivePathEffectAdd::LivePathEffectAdd() + : converter(Inkscape::LivePathEffect::LPETypeConverter) { - const std::string req_widgets[] = {"LPEDialogSelector", "LPESelector", "LPESelectorFlowBox"}; + 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) { + } 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){ + 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; } @@ -50,43 +51,42 @@ 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[] = {"LPESelectorEffect", "LPEName","LPEDescription"}; + 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<int>(converter._length); ++i) { - + for (int i = 0; i < static_cast<int>(converter._length); ++i) { + try { _builder = Gtk::Builder::create_from_file(le_gladefile); - } catch(const Glib::Error& ex) { + } catch (const Glib::Error &ex) { g_warning("Glade file loading failed for filter effect dialog"); return; } - for(int i = 0; i < static_cast<int>(converter._length); ++i) { - Gtk::TreeModel::Row row = *(effectlist_store->append()); - const Util::EnumData<LivePathEffect::EffectType>* data = &converter.data(i); - row[_columns.name] = _( converter.get_label(data->id).c_str() ); - row[_columns.data] = data; - if (i == show) { - Glib::RefPtr<Gtk::TreeSelection> select = effectlist_treeview.get_selection(); - select->select(row); + 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<LivePathEffect::EffectType>* data = &converter.data(i); - Gtk::Label * LPEName; + const LivePathEffect::EnumEffectData<LivePathEffect::EffectType> *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; + 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; + 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; + (*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); @@ -99,15 +99,16 @@ LivePathEffectAdd::LivePathEffectAdd() : _LPEInfo->set_visible(false); } -void LivePathEffectAdd::on_activate(Gtk::FlowBoxChild *child){ - for (auto i:_LPESelectorFlowBox->get_children()) { - Gtk::FlowBoxChild * leitem = dynamic_cast<Gtk::FlowBoxChild *>(i); +void LivePathEffectAdd::on_activate(Gtk::FlowBoxChild *child) +{ + for (auto i : _LPESelectorFlowBox->get_children()) { + Gtk::FlowBoxChild *leitem = dynamic_cast<Gtk::FlowBoxChild *>(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<Gtk::Box *>(leitem->get_child()); if (box) { - std::vector<Gtk::Widget*> contents = box->get_children(); + std::vector<Gtk::Widget *> contents = box->get_children(); Gtk::Box *actions = dynamic_cast<Gtk::Box *>(contents[3]); if (actions) { actions->set_visible(false); @@ -120,7 +121,34 @@ void LivePathEffectAdd::on_activate(Gtk::FlowBoxChild *child){ child->show_all_children(); } - auto mainVBox = get_content_area(); +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<Gtk::Box *>(child->get_child()); + if (box) { + std::vector<Gtk::Widget *> contents = box->get_children(); + Gtk::Label *lpename = dynamic_cast<Gtk::Label *>(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<Gtk::Label *>(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; +} mainVBox->pack_start(scrolled_window, true, true); add_action_widget(close_button, Gtk::RESPONSE_CLOSE); @@ -147,10 +175,7 @@ void LivePathEffectAdd::onAdd() onClose(); } -void LivePathEffectAdd::onClose() -{ - _LPEDialogSelector->hide(); -} +void LivePathEffectAdd::onClose() { _LPEDialogSelector->hide(); } void LivePathEffectAdd::onKeyEvent(GdkEventKey* evt) { diff --git a/src/ui/dialog/livepatheffect-add.h b/src/ui/dialog/livepatheffect-add.h index 671751ed2..003c9c127 100644 --- a/src/ui/dialog/livepatheffect-add.h +++ b/src/ui/dialog/livepatheffect-add.h @@ -12,11 +12,15 @@ #ifndef INKSCAPE_DIALOG_LIVEPATHEFFECT_ADD_H #define INKSCAPE_DIALOG_LIVEPATHEFFECT_ADD_H -#include <gtkmm/dialog.h> -#include <gtkmm/liststore.h> -#include <gtkmm/treeview.h> -#include <gtkmm/scrolledwindow.h> #include "live_effects/effect-enum.h" +#include <gtkmm/box.h> +#include <gtkmm/builder.h> +#include <gtkmm/dialog.h> +#include <gtkmm/flowbox.h> +#include <gtkmm/flowboxchild.h> +#include <gtkmm/label.h> +#include <gtkmm/searchentry.h> +#include <gtkmm/stylecontext.h> class SPDesktop; @@ -37,21 +41,11 @@ public: * Show the dialog */ static void show(SPDesktop *desktop); + static bool isApplied() { return false; } - /** - * Returns true is the "Add" button was pressed - */ - static bool isApplied() { - return instance().applied; - } - - /** - * Return the data associated with the currently selected item - */ - static const Util::EnumData<LivePathEffect::EffectType>* getActiveData(); - -protected: + static const Util::EnumData<LivePathEffect::EffectType> *getActiveData() { return NULL; }; + protected: /** * Close button was clicked */ @@ -72,21 +66,22 @@ protected: */ void onKeyEvent(GdkEventKey* evt); private: - Gtk::Button _add_button; - Gtk::Button _close_button; - Gtk::Dialog *_LPEDialogSelector; - Glib::RefPtr<Gtk::Builder> _builder; - Gtk::FlowBox *_LPESelectorFlowBox; - Gtk::SearchEntry *_LPEFilter; - Gtk::Label *_LPEInfo; - Gtk::Box *_LPESelector; - guint _visiblelpe; - class Effect; - const LivePathEffect::EnumEffectDataConverter<LivePathEffect::EffectType>& converter; - static LivePathEffectAdd &instance() { - static LivePathEffectAdd instance_; - return instance_; - } + Gtk::Button _add_button; + Gtk::Button _close_button; + Gtk::Dialog *_LPEDialogSelector; + Glib::RefPtr<Gtk::Builder> _builder; + Gtk::FlowBox *_LPESelectorFlowBox; + Gtk::SearchEntry *_LPEFilter; + Gtk::Label *_LPEInfo; + Gtk::Box *_LPESelector; + guint _visiblelpe; + class Effect; + const LivePathEffect::EnumEffectDataConverter<LivePathEffect::EffectType> &converter; + static LivePathEffectAdd &instance() + { + static LivePathEffectAdd instance_; + return instance_; + } LivePathEffectAdd(LivePathEffectAdd const &) = delete; // no copy LivePathEffectAdd &operator=(LivePathEffectAdd const &) = delete; // no assign }; diff --git a/src/ui/dialog/lpe-selector.cpp b/src/ui/dialog/lpe-selector.cpp new file mode 100644 index 000000000..9c4cfb4b1 --- /dev/null +++ b/src/ui/dialog/lpe-selector.cpp @@ -0,0 +1,71 @@ +// 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 "io/resource.h" +#include "io/sys.h" +#include <glibmm/convert.h> +#include <glibmm/error.h> +#include <glibmm/i18n.h> +#include <glibmm/main.h> +#include <glibmm/stringutils.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; + + + +} // namespace UI +} // namespace Inkscape + +/* + 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..53ec21df2 --- /dev/null +++ b/src/ui/dialog/lpe-selector.h @@ -0,0 +1,36 @@ +// 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 <gtkmm/gtkmm.h> + +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<Gtk::Builder> builder; + Glib::RefPtr<Glib::Object> FilterStore; + Gtk::Box *LPESelector; +}; +} // namespace UI +} // namespace Inkscape +#endif diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 12b5c58d3..bf2736fe6 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -694,10 +694,7 @@ void ToolboxFactory::setOrientation(GtkWidget* toolbox, GtkOrientation orientati void setup_tool_toolbox(GtkWidget *toolbox, SPDesktop *desktop) { - setupToolboxCommon( toolbox, desktop, - "toolbar-tool.ui", - "/ui/ToolToolbar", - "/toolbox/tools/small"); + setupToolboxCommon(toolbox, desktop, "toolbar-tool.ui", "/ui/ToolToolbar", "/toolbox/tools/small"); } void update_tool_toolbox( SPDesktop *desktop, ToolBase *eventcontext, GtkWidget * /*toolbox*/ ) @@ -931,10 +928,7 @@ void update_aux_toolbox(SPDesktop * /*desktop*/, ToolBase *eventcontext, GtkWidg void setup_commands_toolbox(GtkWidget *toolbox, SPDesktop *desktop) { - setupToolboxCommon( toolbox, desktop, - "toolbar-commands.ui", - "/ui/CommandsToolbar", - "/toolbox/small" ); + setupToolboxCommon(toolbox, desktop, "toolbar-commands.ui", "/ui/CommandsToolbar", "/toolbox/small"); } void update_commands_toolbox(SPDesktop * /*desktop*/, ToolBase * /*eventcontext*/, GtkWidget * /*toolbox*/) @@ -1245,10 +1239,7 @@ void setup_snap_toolbox(GtkWidget *toolbox, SPDesktop *desktop) g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_snap_callback), toolbox ); } - setupToolboxCommon( toolbox, desktop, - "toolbar-snap.ui", - "/ui/SnapToolbar", - "/toolbox/secondary" ); + setupToolboxCommon(toolbox, desktop, "toolbar-snap.ui", "/ui/SnapToolbar", "/toolbox/secondary"); } Glib::ustring ToolboxFactory::getToolboxName(GtkWidget* toolbox) |
