Logo Search packages:      
Sourcecode: inkscape version File versions

void sp_desktop_set_style ( SPDesktop desktop,
SPCSSAttr *  css,
bool  change,
bool  write_current 
)

Apply style on selection on desktop.

Todo:
FIXME: in set_style, compensate pattern and gradient fills, stroke width, rect corners, font size for the object's own transform so that pasting fills does not depend on preserve/optimize.

Todo:
if the style is text-only, apply only to texts?

Definition at line 159 of file desktop-style.cpp.

References SPDesktop::_set_style_signal, SPDesktop::current, Inkscape::Preferences::get(), Inkscape::Selection::itemList(), Inkscape::Preferences::mergeStyle(), SPDesktop::selection, sp_css_attr_unset_uris(), and sp_desktop_apply_css_recursive().

Referenced by Inkscape::UI::ClipboardManagerImpl::_pasteText(), Inkscape::UI::ClipboardManagerImpl::pasteStyle(), sp_desktop_set_color(), sp_fill_style_widget_paint_changed(), sp_stroke_style_any_toggled(), sp_stroke_style_paint_changed(), and sp_stroke_style_scale_line().

{
    if (write_current) {
        Inkscape::Preferences *prefs = Inkscape::Preferences::get();
        // 1. Set internal value
        sp_repr_css_merge(desktop->current, css);

        // 1a. Write to prefs; make a copy and unset any URIs first
        SPCSSAttr *css_write = sp_repr_css_attr_new();
        sp_repr_css_merge(css_write, css);
        sp_css_attr_unset_uris(css_write);
        prefs->mergeStyle("/desktop/style", css_write);

        for (const GSList *i = desktop->selection->itemList(); i != NULL; i = i->next) {
            /* last used styles for 3D box faces are stored separately */
            if (SP_IS_BOX3D_SIDE (i->data)) {
                const char * descr  = box3d_side_axes_string(SP_BOX3D_SIDE(i->data));
                if (descr != NULL) {
                    prefs->mergeStyle(Glib::ustring("/desktop/") + descr + "/style", css_write);
                }
            }
        }
        sp_repr_css_attr_unref(css_write);
    }

    if (!change)
        return;

// 2. Emit signal
    bool intercepted = desktop->_set_style_signal.emit(css);

/** \todo
 * FIXME: in set_style, compensate pattern and gradient fills, stroke width,
 * rect corners, font size for the object's own transform so that pasting
 * fills does not depend on preserve/optimize.
 */

// 3. If nobody has intercepted the signal, apply the style to the selection
    if (!intercepted) {
        for (GSList const *i = desktop->selection->itemList(); i != NULL; i = i->next) {
            /// \todo if the style is text-only, apply only to texts?
            sp_desktop_apply_css_recursive(SP_OBJECT(i->data), css, true);
        }
    }
}


Generated by  Doxygen 1.6.0   Back to index