diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2016-07-24 16:49:11 +0000 |
|---|---|---|
| committer | jabiertxof <info@marker.es> | 2016-07-24 16:49:11 +0000 |
| commit | a5d6c9a27683820be3d84eea73c2d6f161ce0e8e (patch) | |
| tree | b9ba6c20747c4d6d7b4479d229b9daf8eea5c5bd /src | |
| parent | This for you CR ยท Measure line, show the distance on rect lines CAD like wit... (diff) | |
| download | inkscape-a5d6c9a27683820be3d84eea73c2d6f161ce0e8e.tar.gz inkscape-a5d6c9a27683820be3d84eea73c2d6f161ce0e8e.zip | |
Add Text tag and update widgets code
(bzr r15017.1.2)
Diffstat (limited to 'src')
26 files changed, 586 insertions, 199 deletions
diff --git a/src/knotholder.cpp b/src/knotholder.cpp index a2d1cf017..86ae8f0b8 100644 --- a/src/knotholder.cpp +++ b/src/knotholder.cpp @@ -17,6 +17,7 @@ #include "document.h" #include "document-undo.h" +#include "selection.h" #include "sp-shape.h" #include "knot.h" #include "knotholder.h" @@ -202,7 +203,7 @@ KnotHolder::knot_moved_handler(SPKnot *knot, Geom::Point const &p, guint state) } void -KnotHolder::knot_ungrabbed_handler(SPKnot */*knot*/, guint) +KnotHolder::knot_ungrabbed_handler(SPKnot */*knot*/, guint /*state*/) { this->dragging = false; @@ -226,8 +227,12 @@ KnotHolder::knot_ungrabbed_handler(SPKnot */*knot*/, guint) // write the ones that were changed? Inkscape::LivePathEffect::Effect *lpe = lpeItem->getCurrentLPE(); if (lpe) { + lpe->upd_params = true; LivePathEffectObject *lpeobj = lpe->getLPEObj(); lpeobj->updateRepr(); + //Force redraw for update widgets + Inkscape::Selection *selection = desktop->getSelection(); + selection ->emitModified(); } } diff --git a/src/knotholder.h b/src/knotholder.h index f1bacebe5..f055a163a 100644 --- a/src/knotholder.h +++ b/src/knotholder.h @@ -51,7 +51,7 @@ public: void knot_moved_handler(SPKnot *knot, Geom::Point const &p, unsigned int state); void knot_clicked_handler(SPKnot *knot, unsigned int state); - void knot_ungrabbed_handler(SPKnot *knot, unsigned int); + void knot_ungrabbed_handler(SPKnot *knot, unsigned int state); void add(KnotHolderEntity *e); diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index ed66dd2d9..c3d740862 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -69,7 +69,7 @@ set(live_effects_SRC parameter/powerstrokepointarray.cpp parameter/random.cpp parameter/text.cpp - parameter/texttopath.cpp + parameter/font.cpp parameter/togglebutton.cpp parameter/transformedpoint.cpp parameter/unit.cpp @@ -151,7 +151,7 @@ set(live_effects_SRC parameter/powerstrokepointarray.h parameter/random.h parameter/text.h - parameter/texttopath.h + parameter/font.h parameter/togglebutton.h parameter/transformedpoint.h parameter/unit.h diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index d01312ca7..a62e8b62b 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -370,6 +370,7 @@ Effect::Effect(LivePathEffectObject *lpeobject) concatenate_before_pwd2(false), sp_lpe_item(NULL), current_zoom(1), + upd_params(true), sp_curve(NULL), provides_own_flash_paths(true), // is automatically set to false if providesOwnFlashPaths() is not overridden is_ready(false) // is automatically set to false if providesOwnFlashPaths() is not overridden @@ -697,7 +698,7 @@ Effect::newWidget() ++it; } - + upd_params = false; return dynamic_cast<Gtk::Widget *>(vbox); } diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 898e089b7..e0a7cbe6b 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -122,6 +122,7 @@ public: void editNextParamOncanvas(SPItem * item, SPDesktop * desktop); bool apply_to_clippath_and_mask; + bool upd_params; protected: Effect(LivePathEffectObject *lpeobject); diff --git a/src/live_effects/lpe-measure-line.cpp b/src/live_effects/lpe-measure-line.cpp index d6fe02afd..7b823b072 100644 --- a/src/live_effects/lpe-measure-line.cpp +++ b/src/live_effects/lpe-measure-line.cpp @@ -7,6 +7,11 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ #include "live_effects/lpe-measure-line.h" +#include "inkscape.h" +#include "uri.h" +#include "uri-references.h" +#include "desktop.h" +#include "document.h" // TODO due to internal breakage in glibmm headers, this must be last: #include <glibmm/i18n.h> @@ -17,16 +22,98 @@ namespace LivePathEffect { LPEMeasureLine::LPEMeasureLine(LivePathEffectObject *lpeobject) : Effect(lpeobject), - text(_("text:"), _("text"), "text", &wr, this, "This is a labelXXX") + fontselector(_("Font Selector:"), _("Font Selector"), "fontselector", &wr, this, " ") { - registerParameter(&text); + registerParameter(&fontselector); + rtext = NULL; + fontlister = Inkscape::FontLister::get_instance(); } LPEMeasureLine::~LPEMeasureLine() {} +void +LPEMeasureLine::doBeforeEffect (SPLPEItem const* lpeitem) +{ + if (SP_ACTIVE_DESKTOP) { + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::URI SVGElem_uri(((Glib::ustring)"#" + (Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); + Inkscape::URIReference* SVGElemRef = new Inkscape::URIReference(desktop->doc()); + SVGElemRef->attach(SVGElem_uri); + SPObject *elemref = NULL; + Inkscape::XML::Node *rtspan = NULL; + if (elemref = SVGElemRef->getObject()) { + rtext = elemref->getRepr(); + sp_repr_set_svg_double(rtext, "x", 0); + sp_repr_set_svg_double(rtext, "y", 0); + } else { + rtext = xml_doc->createElement("svg:text"); + rtext->setAttribute("xml:space", "preserve"); + rtext->setAttribute("id", ((Glib::ustring)SP_OBJECT(lpeitem)->getId() + (Glib::ustring)"_mlsize").c_str()); + /* Set style */ + sp_repr_set_svg_double(rtext, "x", 0); + sp_repr_set_svg_double(rtext, "y", 0); + /* Create <tspan> */ + rtspan = xml_doc->createElement("svg:tspan"); + rtspan->setAttribute("sodipodi:role", "line"); + } + SPCSSAttr *css = sp_repr_css_attr_new(); + Glib::ustring fontspec = fontselector.param_readFontSpec(fontselector.param_getSVGValue()); + double fontsize = fontselector.param_readFontSize(fontselector.param_getSVGValue()); + fontlister->fill_css( css, fontspec ); + std::stringstream font_size; + font_size.imbue(std::locale::classic()); + font_size << fontsize << "pt"; + sp_repr_css_set_property (css, "font-size", font_size.str().c_str()); + sp_repr_css_set_property (css, "font-style", "normal"); + sp_repr_css_set_property (css, "font-weight", "normal"); + sp_repr_css_set_property (css, "line-height", "125%"); + sp_repr_css_set_property (css, "letter-spacing", "0"); + sp_repr_css_set_property (css, "word-spacing", "0"); + sp_repr_css_set_property (css, "text-align", "center"); + sp_repr_css_set_property (css, "text-anchor", "middle"); + sp_repr_css_set_property (css, "fill", "#000000"); + sp_repr_css_set_property (css, "fill-opacity", "1"); + sp_repr_css_set_property (css, "stroke", "none"); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + if (!rtspan) { + rtspan = rtext->firstChild(); + } + rtspan->setAttribute("style", css_str.c_str()); + sp_repr_css_attr_unref (css); + if (!elemref) { + rtext->addChild(rtspan, NULL); + Inkscape::GC::release(rtspan); + } + /* Create TEXT */ + std::stringstream lenghtstr; + lenghtstr.imbue(std::locale::classic()); + lenghtstr << lenght; + Inkscape::XML::Node *rstring = NULL; + if (!elemref) { + rstring = xml_doc->createTextNode(lenghtstr.str().c_str()); + rtspan->addChild(rstring, NULL); + Inkscape::GC::release(rstring); + } else { + rstring = rtspan->firstChild(); + rstring->setContent(lenghtstr.str().c_str()); + } + SPObject * text_obj = NULL; + if (!elemref) { + text_obj = SP_OBJECT(desktop->currentLayer()->appendChildRepr(rtext)); + Inkscape::GC::release(rtext); + } else { + text_obj = desktop->currentLayer()->get_child_by_repr(rtext); + } + text_obj->updateRepr(); + } +} + Geom::PathVector LPEMeasureLine::doEffect_path(Geom::PathVector const &path_in) { + lenght = Geom::distance(path_in.initialPoint(), path_in.finalPoint()); return path_in; } diff --git a/src/live_effects/lpe-measure-line.h b/src/live_effects/lpe-measure-line.h index 5ba1ff8c6..7e576ffe6 100644 --- a/src/live_effects/lpe-measure-line.h +++ b/src/live_effects/lpe-measure-line.h @@ -9,8 +9,11 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "live_effects/parameter/texttopath.h" +#include "live_effects/parameter/font.h" #include "live_effects/effect.h" +#include <libnrtype/font-lister.h> +#include "xml/node.h" + namespace Inkscape { namespace LivePathEffect { @@ -19,13 +22,13 @@ class LPEMeasureLine : public Effect { public: LPEMeasureLine(LivePathEffectObject *lpeobject); virtual ~LPEMeasureLine(); - + virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); - private: - - TextToPathParam text; - + double lenght; + FontParam fontselector; + Inkscape::FontLister *fontlister; + Inkscape::XML::Node *rtext; LPEMeasureLine(const LPEMeasureLine &); LPEMeasureLine &operator=(const LPEMeasureLine &); diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index 3c4ce0708..d32cf42fc 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -90,7 +90,6 @@ LPETransform2Pts::doOnApply(SPLPEItem const* lpeitem) { using namespace Geom; original_bbox(lpeitem); - point_a = Point(boundingbox_X.min(), boundingbox_Y.middle()); point_b = Point(boundingbox_X.max(), boundingbox_Y.middle()); SPLPEItem * splpeitem = const_cast<SPLPEItem *>(lpeitem); diff --git a/src/live_effects/parameter/font.cpp b/src/live_effects/parameter/font.cpp new file mode 100644 index 000000000..174b66152 --- /dev/null +++ b/src/live_effects/parameter/font.cpp @@ -0,0 +1,126 @@ +/* + * Authors: + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + + +#include "ui/widget/registered-widget.h" +#include "live_effects/parameter/font.h" +#include "live_effects/effect.h" +#include "ui/widget/font-selector.h" +#include "svg/svg.h" +#include "svg/stringstream.h" +#include "verbs.h" + +#include <glibmm/i18n.h> + +namespace Inkscape { + +namespace LivePathEffect { + +FontParam::FontParam( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect, const Glib::ustring default_value ) + : Parameter(label, tip, key, wr, effect), + value(default_value), + defvalue(default_value) +{ +} + +void +FontParam::param_set_default() +{ + param_setValue(defvalue); +} + + +Glib::ustring +FontParam::param_readFontSpec(const gchar * strvalue) +{ + Glib::ustring result; + gchar ** strarray = g_strsplit(strvalue, " @ ", 2); + double fontsize; + if (strarray[1]) { + unsigned int success = sp_svg_number_read_d(strarray[1], &fontsize); + if (success == 1) { + result = (Glib::ustring)strarray[0]; + g_strfreev (strarray); + return result; + } + } + g_strfreev (strarray); + return result; +} + +double +FontParam::param_readFontSize(const gchar * strvalue) +{ + gchar ** strarray = g_strsplit(strvalue, " @ ", 2); + double fontsize = 0; + if (strarray[1]) { + unsigned int success = sp_svg_number_read_d(strarray[1], &fontsize); + if (success == 1) { + g_strfreev (strarray); + return fontsize; + } + } + g_strfreev (strarray); + return fontsize; +} + +bool +FontParam::param_readSVGValue(const gchar * strvalue) +{ + double fontsize = param_readFontSize(strvalue); + Glib::ustring fontspec = param_readFontSpec(strvalue); + Inkscape::SVGOStringStream os; + os << fontspec << " @ " << fontsize; + param_setValue((Glib::ustring)os.str()); + return true; +} + +gchar * +FontParam::param_getSVGValue() const +{ + return g_strdup(value.c_str()); +} + +Gtk::Widget * +FontParam::param_newWidget() +{ + Inkscape::UI::Widget::RegisteredFontSelector * fontselectorwdg = Gtk::manage( + new Inkscape::UI::Widget::RegisteredFontSelector( param_label, + param_tooltip, + param_key, + *param_wr, + param_effect->getRepr(), + param_effect->getSPDoc() ) ); + double fontsize = param_readFontSize(param_getSVGValue()); + Glib::ustring fontspec = param_readFontSpec(param_getSVGValue()); + fontselectorwdg->setValue( fontspec, fontsize ); + fontselectorwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change font selector parameter")); + + return dynamic_cast<Gtk::Widget *> (fontselectorwdg); +} + +void +FontParam::param_setValue(const Glib::ustring newvalue) +{ + value = newvalue; +} + +} /* namespace LivePathEffect */ + +} /* 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 : diff --git a/src/live_effects/parameter/texttopath.h b/src/live_effects/parameter/font.h index 9a0ee38e2..e7bcc59d2 100644 --- a/src/live_effects/parameter/texttopath.h +++ b/src/live_effects/parameter/font.h @@ -1,5 +1,5 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_TEXT_TO_PATH_H -#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_TEXT_TO_PATH_H +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_FONT_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_FONT_H /* * Inkscape::LivePathEffectParameters @@ -7,52 +7,42 @@ * Authors: * Released under GNU GPL, read the file 'COPYING' for more information */ - #include <glib.h> - -#include "display/canvas-bpath.h" +#include <gtkmm.h> #include "live_effects/parameter/parameter.h" -struct SPCanvasText; - namespace Inkscape { namespace LivePathEffect { -class TextToPathParam : public Parameter { +class FontParam : public Parameter { public: - TextToPathParam( const Glib::ustring& label, + FontParam( const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect, const Glib::ustring default_value = ""); - virtual ~TextToPathParam() {} + virtual ~FontParam() {} virtual Gtk::Widget * param_newWidget(); - virtual bool param_readSVGValue(const gchar * strvalue); + double param_readFontSize(const gchar * strvalue); + Glib::ustring param_readFontSpec(const gchar * strvalue); virtual gchar * param_getSVGValue() const; void param_setValue(const Glib::ustring newvalue); + virtual void param_set_default(); - void setPos(Geom::Point pos); - void setPosAndAnchor(const Geom::Piecewise<Geom::D2<Geom::SBasis> > &pwd2, - const double t, const double length, bool use_curvature = false); - void setAnchor(double x_value, double y_value); const Glib::ustring get_value() const { return defvalue; }; private: - TextToPathParam(const TextToPathParam&); - TextToPathParam& operator=(const TextToPathParam&); - double anchor_x; - double anchor_y; - + FontParam(const FontParam&); + FontParam& operator=(const FontParam&); Glib::ustring value; Glib::ustring defvalue; - SPCanvasText *canvas_text; }; /* @@ -61,10 +51,10 @@ private: * parameter must be initialized differently than usual (only with a pointer to the parent effect; * no label, no tooltip, etc.). */ -class TextToPathParamInternal : public TextToPathParam { +class FontParamInternal : public FontParam { public: - TextToPathParamInternal(Effect* effect) : - TextToPathParam("", "", "", NULL, effect) {} + FontParamInternal(Effect* effect) : + FontParam("", "", "", NULL, effect) {} virtual Gtk::Widget * param_newWidget() { return NULL; } }; diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index ca3471b29..b4f2c7758 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -134,7 +134,7 @@ PointParam::param_newWidget() Gtk::HBox * hbox = Gtk::manage( new Gtk::HBox() ); static_cast<Gtk::HBox*>(hbox)->pack_start(*pointwdg, true, true); static_cast<Gtk::HBox*>(hbox)->show_all_children(); - + param_effect->upd_params = false; return dynamic_cast<Gtk::Widget *> (hbox); } diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h index 4329e0bcd..06773c80e 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -11,7 +11,6 @@ #include <glib.h> #include <2geom/point.h> - #include "live_effects/parameter/parameter.h" #include "knot-holder-entity.h" diff --git a/src/live_effects/parameter/texttopath.cpp b/src/live_effects/parameter/texttopath.cpp deleted file mode 100644 index 8625e4d71..000000000 --- a/src/live_effects/parameter/texttopath.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com> - * - * Authors: - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "ui/widget/registered-widget.h" -#include <glibmm/i18n.h> - -#include "live_effects/parameter/texttopath.h" -#include "live_effects/effect.h" -#include "svg/svg.h" -#include "svg/stringstream.h" -#include "widgets/icon.h" -#include "inkscape.h" -#include "verbs.h" -#include "display/canvas-text.h" - -#include <2geom/sbasis-geometric.h> - -namespace Inkscape { - -namespace LivePathEffect { - -TextToPathParam::TextToPathParam( const Glib::ustring& label, const Glib::ustring& tip, - const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, const Glib::ustring default_value ) - : Parameter(label, tip, key, wr, effect), - value(default_value), - defvalue(default_value) -{ - SPDesktop *desktop = SP_ACTIVE_DESKTOP; // FIXME: we shouldn't use this! - canvas_text = (SPCanvasText *) sp_canvastext_new(desktop->getTempGroup(), desktop, Geom::Point(0,0), ""); - sp_canvastext_set_text (canvas_text, default_value.c_str()); - sp_canvastext_set_coords (canvas_text, 0, 0); -} - -void -TextToPathParam::param_set_default() -{ - param_setValue(defvalue); -} - -void -TextToPathParam::setPos(Geom::Point pos) -{ - sp_canvastext_set_coords (canvas_text, pos); -} - -void -TextToPathParam::setPosAndAnchor(const Geom::Piecewise<Geom::D2<Geom::SBasis> > &pwd2, - const double t, const double length, bool /*use_curvature*/) -{ - using namespace Geom; - - Piecewise<D2<SBasis> > pwd2_reparam = arc_length_parametrization(pwd2, 2 , 0.1); - double t_reparam = pwd2_reparam.cuts.back() * t; - Point pos = pwd2_reparam.valueAt(t_reparam); - Point dir = unit_vector(derivative(pwd2_reparam).valueAt(t_reparam)); - Point n = -rot90(dir); - double angle = Geom::angle_between(dir, Point(1,0)); - - sp_canvastext_set_coords(canvas_text, pos + n * length); - sp_canvastext_set_anchor_manually(canvas_text, std::sin(angle), -std::cos(angle)); -} - -void -TextToPathParam::setAnchor(double x_value, double y_value) -{ - anchor_x = x_value; - anchor_y = y_value; - sp_canvastext_set_anchor_manually (canvas_text, anchor_x, anchor_y); -} - -bool -TextToPathParam::param_readSVGValue(const gchar * strvalue) -{ - param_setValue(strvalue); - return true; -} - -gchar * -TextToPathParam::param_getSVGValue() const -{ - return g_strdup(value.c_str()); -} - -Gtk::Widget * -TextToPathParam::param_newWidget() -{ - Inkscape::UI::Widget::RegisteredText *rsu = Gtk::manage(new Inkscape::UI::Widget::RegisteredText( - param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc())); - - rsu->setText(value.c_str()); - rsu->setProgrammatically = false; - - rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change text parameter")); - - return dynamic_cast<Gtk::Widget *> (rsu); -} - -void -TextToPathParam::param_setValue(const Glib::ustring newvalue) -{ - value = newvalue; - - sp_canvastext_set_text (canvas_text, newvalue.c_str()); -} - -} /* namespace LivePathEffect */ - -} /* 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 : diff --git a/src/live_effects/parameter/togglebutton.cpp b/src/live_effects/parameter/togglebutton.cpp index 47a8b5615..5977a5114 100644 --- a/src/live_effects/parameter/togglebutton.cpp +++ b/src/live_effects/parameter/togglebutton.cpp @@ -12,6 +12,7 @@ #include "live_effects/effect.h" #include "svg/svg.h" #include "svg/stringstream.h" +#include "selection.h" #include "widgets/icon.h" #include "inkscape.h" #include "verbs.h" @@ -106,6 +107,7 @@ ToggleButtonParam::param_newWidget() }else{ gtk_box_pack_start (GTK_BOX(boxButton), labelButton, false, false, 1); } + param_effect->upd_params = false; checkwdg->add(*Gtk::manage(Glib::wrap(boxButton))); checkwdg->setActive(value); checkwdg->setProgrammatically = false; @@ -157,6 +159,12 @@ ToggleButtonParam::param_setValue(bool newvalue) void ToggleButtonParam::toggled() { + //Force redraw for update widgets + param_effect->upd_params = true; + if (SP_ACTIVE_DESKTOP) { + Inkscape::Selection *selection = SP_ACTIVE_DESKTOP->getSelection(); + selection ->emitModified(); + } _signal_toggled.emit(); } diff --git a/src/selection.cpp b/src/selection.cpp index 6fc426be7..91d6d2634 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -282,6 +282,11 @@ void Selection::clear() { _emitChanged(); } +void Selection::emitModified() +{ + _emitChanged(); +} + std::vector<SPObject*> const &Selection::list() { if(!_objs_vector.empty()) return _objs_vector; diff --git a/src/selection.h b/src/selection.h index 952dde51d..bf6acb015 100644 --- a/src/selection.h +++ b/src/selection.h @@ -192,6 +192,11 @@ public: void clear(); /** + * Emmit modified signal + */ + void emitModified(); + + /** * Returns true if no items are selected. */ bool isEmpty() const { return _objs.empty(); } diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 587974b90..62f341962 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -128,6 +128,7 @@ set(ui_SRC widget/entity-entry.cpp widget/entry.cpp widget/filter-effect-chooser.cpp + widget/font-selector.cpp widget/font-variants.cpp widget/frame.cpp widget/gimpcolorwheel.c @@ -312,6 +313,7 @@ set(ui_SRC widget/entity-entry.h widget/entry.h widget/filter-effect-chooser.h + widget/font-selector.h widget/font-variants.h widget/frame.h widget/gimpspinscale.h diff --git a/src/ui/dialog/livepatheffect-editor.cpp b/src/ui/dialog/livepatheffect-editor.cpp index 422ec10ae..7205beaa8 100644 --- a/src/ui/dialog/livepatheffect-editor.cpp +++ b/src/ui/dialog/livepatheffect-editor.cpp @@ -61,7 +61,7 @@ void lpeeditor_selection_changed (Inkscape::Selection * selection, gpointer data { LivePathEffectEditor *lpeeditor = static_cast<LivePathEffectEditor *>(data); lpeeditor->lpe_list_locked = false; - lpeeditor->onSelectionChanged(selection); + lpeeditor->onSelectionChanged(selection, true); } static void lpeeditor_selection_modified (Inkscape::Selection * selection, guint /*flags*/, gpointer data) @@ -98,7 +98,8 @@ LivePathEffectEditor::LivePathEffectEditor() button_up(), button_down(), current_desktop(NULL), - current_lpeitem(NULL) + current_lpeitem(NULL), + current_lperef(NULL) { Gtk::Box *contents = _getContents(); contents->set_spacing(4); @@ -206,6 +207,10 @@ LivePathEffectEditor::~LivePathEffectEditor() void LivePathEffectEditor::showParams(LivePathEffect::Effect& effect) { + if ( ! effect.upd_params ) { + return; + } + if (effectwidget) { effectcontrol_vbox.remove(*effectwidget); delete effectwidget; @@ -265,9 +270,8 @@ LivePathEffectEditor::set_sensitize_all(bool sensitive) button_down.set_sensitive(sensitive); } - void -LivePathEffectEditor::onSelectionChanged(Inkscape::Selection *sel) +LivePathEffectEditor::onSelectionChanged(Inkscape::Selection *sel, bool upd_params) { if (lpe_list_locked) { // this was triggered by selecting a row in the list, so skip reloading @@ -291,6 +295,9 @@ LivePathEffectEditor::onSelectionChanged(Inkscape::Selection *sel) if ( lpeitem->hasPathEffect() ) { Inkscape::LivePathEffect::Effect *lpe = lpeitem->getCurrentLPE(); if (lpe) { + if (upd_params) { + lpe->upd_params = true; + } showParams(*lpe); lpe_list_locked = true; selectInList(lpe); @@ -494,6 +501,12 @@ LivePathEffectEditor::onRemove() SPItem *item = sel->singleItem(); SPLPEItem *lpeitem = dynamic_cast<SPLPEItem *>(item); if ( lpeitem ) { + if (current_lperef && current_lperef->lpeobject) { + LivePathEffect::Effect * effect = current_lperef->lpeobject->get_lpe(); + if (effect) { + effect->upd_params = true; + } + } lpeitem->removeCurrentPathEffect(false); DocumentUndo::done( current_desktop->getDocument(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, @@ -548,11 +561,17 @@ void LivePathEffectEditor::on_effect_selection_changed() Gtk::TreeModel::iterator it = sel->get_selected(); LivePathEffect::LPEObjectReference * lperef = (*it)[columns.lperef]; - if (lperef && current_lpeitem) { + if (lperef && current_lpeitem && current_lperef != lperef) { + //The last condition ignore Gtk::TreeModel may occasionally be changed emitted when nothing has happened if (lperef->lpeobject->get_lpe()) { lpe_list_locked = true; // prevent reload of the list which would lose selection current_lpeitem->setCurrentPathEffect(lperef); - showParams(*lperef->lpeobject->get_lpe()); + current_lperef = lperef; + LivePathEffect::Effect * effect = lperef->lpeobject->get_lpe(); + if (effect) { + effect->upd_params = true; + showParams(*effect); + } } } } diff --git a/src/ui/dialog/livepatheffect-editor.h b/src/ui/dialog/livepatheffect-editor.h index 4aac25eaa..b7ec1eeec 100644 --- a/src/ui/dialog/livepatheffect-editor.h +++ b/src/ui/dialog/livepatheffect-editor.h @@ -45,7 +45,8 @@ public: static LivePathEffectEditor &getInstance() { return *new LivePathEffectEditor(); } - void onSelectionChanged(Inkscape::Selection *sel); + void onSelectionChanged(Inkscape::Selection *sel, bool upd_params = false); + void onSelectionModified(Inkscape::Selection *sel); virtual void on_effect_selection_changed(); void setDesktop(SPDesktop *desktop); @@ -126,6 +127,8 @@ private: SPLPEItem * current_lpeitem; + LivePathEffect::LPEObjectReference * current_lperef; + friend void lpeeditor_selection_changed (Inkscape::Selection * selection, gpointer data); LivePathEffectEditor(LivePathEffectEditor const &d); diff --git a/src/ui/widget/Makefile_insert b/src/ui/widget/Makefile_insert index eb98e6872..bb833e5ec 100644 --- a/src/ui/widget/Makefile_insert +++ b/src/ui/widget/Makefile_insert @@ -33,6 +33,8 @@ ink_common_sources += \ ui/widget/entry.h \ ui/widget/filter-effect-chooser.h \ ui/widget/filter-effect-chooser.cpp \ + ui/widget/font-selector.h \ + ui/widget/font-selector.cpp \ ui/widget/font-variants.h \ ui/widget/font-variants.cpp \ ui/widget/gimpspinscale.c \ diff --git a/src/ui/widget/font-selector.cpp b/src/ui/widget/font-selector.cpp new file mode 100644 index 000000000..77bf83fe1 --- /dev/null +++ b/src/ui/widget/font-selector.cpp @@ -0,0 +1,115 @@ +/* + * + * Released under GNU GPL. Read the file 'COPYING' for more information. + */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include "font-selector.h" +#include "widgets/icon.h" +#include <glibmm/i18n.h> + +namespace Inkscape { +namespace UI { +namespace Widget { + +FontSelector::FontSelector(Glib::ustring const &label, Glib::ustring const &tooltip, + Glib::ustring const &suffix, + Glib::ustring const &icon, + bool mnemonic) + :_widget(new Gtk::HBox()), expanded(true) +{ + Gtk::VBox * vbox_expander = Gtk::manage( new Gtk::VBox() ); + GtkWidget *fontsel = sp_font_selector_new(); + gtk_widget_set_size_request (fontsel, 290, 150); + fsel = SP_FONT_SELECTOR(fontsel); + Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( "on", Inkscape::ICON_SIZE_BUTTON) ); + Gtk::Button * pButton = Gtk::manage(new Gtk::Button()); + pButton->set_relief(Gtk::RELIEF_NONE); + pIcon->show(); + pButton->add(*pIcon); + pButton->show(); + pButton->signal_clicked().connect(sigc::mem_fun(*this, &FontSelector::onFontSelectorSave)); + pButton->set_tooltip_text(_("Save the changes to font selector")); + vbox_expander->pack_start(*Gtk::manage(Glib::wrap(fontsel)), true, true); + vbox_expander->pack_start(*pButton, true, true); + expander = Gtk::manage(new Gtk::Expander(Glib::ustring(_("Font Selector:")))); + expander->add(*vbox_expander); + expander->set_expanded(expanded); + expander->set_spacing(5); + expander->set_use_markup(true); + onExpanderChanged(); + _widget->set_tooltip_text(tooltip); + expander->property_expanded().signal_changed().connect(sigc::mem_fun(*this, &FontSelector::onExpanderChanged) ); + pack_start(*expander, true, true); + pack_start(*Gtk::manage(_widget), true, true); +} + +void +FontSelector::onExpanderChanged() +{ + expanded = expander->get_expanded(); + if(expanded) { + expander->set_label (Glib::ustring(_("Font Selector:"))); + } else { + expander->set_label (Glib::ustring(_("Font Selector: <b>hided</b>"))); + } +} + +Glib::ustring FontSelector::getFontSpec() const +{ + return _fontspec; +} + +void FontSelector::setFontSpec(Glib::ustring fontspec) +{ + _fontspec = fontspec; +} + +double FontSelector::getFontSize() const +{ + return _fontsize; +} + +void FontSelector::setFontSize(double fontsize) +{ + _fontsize = fontsize; +} + +void FontSelector::setValue (Glib::ustring fontspec, double fontsize) +{ + if (_fontsize != fontsize || _fontspec != fontspec) { + setFontSize(fontsize); + setFontSpec(fontspec); + sp_font_selector_set_fontspec(fsel, fontspec, fontsize); + } +} + +void +FontSelector::onFontSelectorSave() +{ + if (_fontspec != sp_font_selector_get_fontspec(fsel) || _fontsize != sp_font_selector_get_size(fsel)) { + setFontSpec(sp_font_selector_get_fontspec(fsel)); + setFontSize(sp_font_selector_get_size(fsel)); + signal_fontselupd.emit(); + onExpanderChanged(); + } +} + + +} // namespace Widget +} // 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/widget/font-selector.h b/src/ui/widget/font-selector.h new file mode 100644 index 000000000..cfea54bde --- /dev/null +++ b/src/ui/widget/font-selector.h @@ -0,0 +1,81 @@ +/* + * + * Copyright (C) 2007 Author + * + * Released under GNU GPL. Read the file 'COPYING' for more information. + */ + +#ifndef INKSCAPE_UI_WIDGET_FONT_SELECTOR_H +#define INKSCAPE_UI_WIDGET_FONT_SELECTOR_H + +#include <gtkmm.h> +#include "widgets/font-selector.h" + +struct SPFontSelector; +namespace Inkscape { +namespace UI { +namespace Widget { + +/** + * A labelled text box, with spin buttons and optional + * icon or suffix, for entering arbitrary number values. It adds an extra + * number called "startseed", that is not UI edittable, but should be put in SVG. + * This does NOT generate a random number, but provides merely the saving of + * the startseed value. + */ +class FontSelector : public Gtk::HBox +{ +public: + + /** + * Construct a FontSelector Widget. + * + * @param label Label. + * @param suffix Suffix, placed after the widget (defaults to ""). + * @param icon Icon filename, placed before the label (defaults to ""). + * @param mnemonic Mnemonic toggle; if true, an underscore (_) in the label + * indicates the next character should be used for the + * mnemonic accelerator key (defaults to false). + */ + FontSelector( Glib::ustring const &label, + Glib::ustring const &tooltip, + Glib::ustring const &suffix = "", + Glib::ustring const &icon = "", + bool mnemonic = true); + + Glib::ustring getFontSpec() const; + void onExpanderChanged(); + void setFontSpec(Glib::ustring fontspec); + double getFontSize() const; + void setFontSize(double fontsize); + void setValue (Glib::ustring fontspec, double fontsize); + sigc::signal <void> signal_fontselupd; + +protected: + Gtk::Widget *_widget; + bool expanded; + Gtk::Expander * expander; + SPFontSelector *fsel; + Glib::ustring _fontspec; + double _fontsize; + +private: + void onFontSelectorSave(); +}; + +} // namespace Widget +} // namespace UI +} // namespace Inkscape + +#endif // INKSCAPE_UI_WIDGET_RANDOM_H + +/* + 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/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp index 298377af3..7abab25c9 100644 --- a/src/ui/widget/registered-widget.cpp +++ b/src/ui/widget/registered-widget.cpp @@ -25,6 +25,7 @@ #include "ui/widget/scalar-unit.h" #include "ui/widget/point.h" #include "ui/widget/random.h" +#include "ui/widget/font-selector.h" #include "widgets/spinbutton-events.h" #include "xml/repr.h" @@ -805,6 +806,49 @@ RegisteredRandom::on_value_changed() _wr->setUpdating (false); } +/*######################################### + * Registered FONT-SELECTOR + */ + +RegisteredFontSelector::~RegisteredFontSelector() +{ + _value_changed_connection.disconnect(); +} + +RegisteredFontSelector::RegisteredFontSelector ( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, + SPDocument* doc_in ) + : RegisteredWidget<FontSelector> (label, tip) +{ + init_parent(key, wr, repr_in, doc_in); + _value_changed_connection = signal_fontselupd.connect (sigc::mem_fun (*this, &RegisteredFontSelector::on_value_changed)); +} + +void +RegisteredFontSelector::setValue (Glib::ustring fontspec, double fontsize) +{ + if (fontsize != 0) { //have value in the effect + FontSelector::setValue (fontspec, fontsize); + } +} + +void +RegisteredFontSelector::on_value_changed() +{ + + if (_wr->isUpdating()) + return; + + _wr->setUpdating (true); + + Inkscape::SVGOStringStream os; + os << getFontSpec() << " @ " << getFontSize(); + + write_to_xml(os.str().c_str()); + + _wr->setUpdating (false); +} + } // namespace Dialog } // namespace UI } // namespace Inkscape diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h index 9d2489712..17c04de9f 100644 --- a/src/ui/widget/registered-widget.h +++ b/src/ui/widget/registered-widget.h @@ -22,6 +22,7 @@ #include "ui/widget/text.h" #include "ui/widget/random.h" #include "ui/widget/unit-menu.h" +#include "ui/widget/font-selector.h" #include "ui/widget/color-picker.h" #include "inkscape.h" @@ -419,6 +420,23 @@ protected: void on_value_changed(); }; +class RegisteredFontSelector : public RegisteredWidget<FontSelector> { +public: + virtual ~RegisteredFontSelector(); + RegisteredFontSelector ( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Registry& wr, + Inkscape::XML::Node* repr_in = NULL, + SPDocument *doc_in = NULL); + + void setValue (Glib::ustring fontspec, double fontsize); + +protected: + sigc::connection _value_changed_connection; + void on_value_changed(); +}; + } // namespace Widget } // namespace UI } // namespace Inkscape diff --git a/src/widgets/font-selector.cpp b/src/widgets/font-selector.cpp index aefcb2e81..eeb80ab28 100644 --- a/src/widgets/font-selector.cpp +++ b/src/widgets/font-selector.cpp @@ -19,9 +19,6 @@ # include "config.h" #endif -#include <libnrtype/font-lister.h> -#include <libnrtype/font-instance.h> - #include <2geom/transforms.h> #include <gtk/gtk.h> @@ -34,29 +31,7 @@ /* SPFontSelector */ -struct SPFontSelector -{ -#if GTK_CHECK_VERSION(3,0,0) - GtkBox hbox; -#else - GtkHBox hbox; -#endif - unsigned int block_emit : 1; - - GtkWidget *family; - GtkWidget *style; - GtkWidget *size; - - GtkWidget *family_treeview; - GtkWidget *style_treeview; - - NRNameList families; - NRStyleList styles; - gfloat fontsize; - bool fontsize_dirty; - Glib::ustring *fontspec; -}; struct SPFontSelectorClass @@ -274,6 +249,7 @@ static void sp_font_selector_dispose(GObject *object) if (fsel->fontspec) { delete fsel->fontspec; + fsel->fontspec = 0; } if (fsel->families.length > 0) { diff --git a/src/widgets/font-selector.h b/src/widgets/font-selector.h index ff5472d2d..2d55a87ab 100644 --- a/src/widgets/font-selector.h +++ b/src/widgets/font-selector.h @@ -15,10 +15,33 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - +#include <libnrtype/font-lister.h> +#include <libnrtype/font-instance.h> #include <glib.h> -struct SPFontSelector; +struct SPFontSelector +{ +#if GTK_CHECK_VERSION(3,0,0) + GtkBox hbox; +#else + GtkHBox hbox; +#endif + + unsigned int block_emit : 1; + + GtkWidget *family; + GtkWidget *style; + GtkWidget *size; + + GtkWidget *family_treeview; + GtkWidget *style_treeview; + + NRNameList families; + NRStyleList styles; + gfloat fontsize; + bool fontsize_dirty; + Glib::ustring *fontspec; +}; #define SP_TYPE_FONT_SELECTOR (sp_font_selector_get_type ()) #define SP_FONT_SELECTOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), SP_TYPE_FONT_SELECTOR, SPFontSelector)) |
