X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fui%2Fdialog%2Flivepatheffect-editor.cpp;h=f6b9975282cd6cd638747fc24783cddc783a3937;hb=0c01694a499e247c324a0618c2caad7fa7db449d;hp=c92d015f53f1e67e41b7e66c3a942405ca00557c;hpb=0563fd55cbad59e8a878e6d4cbbdd8e47f74488d;p=inkscape.git diff --git a/src/ui/dialog/livepatheffect-editor.cpp b/src/ui/dialog/livepatheffect-editor.cpp index c92d015f5..f6b997528 100644 --- a/src/ui/dialog/livepatheffect-editor.cpp +++ b/src/ui/dialog/livepatheffect-editor.cpp @@ -17,6 +17,7 @@ #include #include "livepatheffect-editor.h" +#include "ui/widget/imagetoggler.h" #include "verbs.h" #include "selection.h" #include "sp-shape.h" @@ -32,9 +33,8 @@ #include "inkscape.h" #include "desktop-handles.h" #include "desktop.h" -#include "document-private.h" +#include "document.h" #include "xml/node.h" -#include "xml/document.h" #include #include @@ -56,12 +56,18 @@ static void lpeeditor_selection_changed (Inkscape::Selection * selection, gpoint lpeeditor->onSelectionChanged(selection); } +static void lpeeditor_selection_modified (Inkscape::Selection * selection, guint /*flags*/, gpointer data) +{ + LivePathEffectEditor *lpeeditor = static_cast(data); + lpeeditor->onSelectionChanged(selection); +} + /*####################### * LivePathEffectEditor */ -LivePathEffectEditor::LivePathEffectEditor() +LivePathEffectEditor::LivePathEffectEditor() : UI::Widget::Panel("", "dialogs.livepatheffect", SP_VERB_DIALOG_LIVE_PATH_EFFECT), combo_effecttype(Inkscape::LivePathEffect::LPETypeConverter), effectwidget(NULL), @@ -103,34 +109,41 @@ LivePathEffectEditor::LivePathEffectEditor() // button_hbox.pack_start(button_up, true, true); // button_hbox.pack_start(button_down, true, true); // button_hbox.pack_end(button_remove, true, true); - toolbar.set_toolbar_style(Gtk::TOOLBAR_ICONS); + toolbar.set_toolbar_style(Gtk::TOOLBAR_ICONS); // Add toolbar items to toolbar - toolbar.append(button_up); - toolbar.append(button_down); - toolbar.append(button_remove); + toolbar.append(button_up); + toolbar.append(button_down); + toolbar.append(button_remove); + + + // Add toolbar + //add_toolbar(toolbar); + toolbar.show_all(); //Show the toolbar and all its child widgets. - - // Add toolbar - //add_toolbar(toolbar); - toolbar.show_all(); //Show the toolbar and all its child widgets. - //Create the Tree model: effectlist_store = Gtk::ListStore::create(columns); effectlist_view.set_model(effectlist_store); effectlist_view.set_rules_hint(); - effectlist_view.set_headers_clickable(true); - effectlist_view.set_headers_visible(true); + effectlist_view.set_headers_visible(false); // Handle tree selections effectlist_selection = effectlist_view.get_selection(); effectlist_selection->signal_changed().connect( sigc::mem_fun(*this, &LivePathEffectEditor::on_effect_selection_changed) ); - effectlist_view.set_headers_visible(false); - //Add the TreeView's view columns: - effectlist_view.append_column("Effect", columns.col_name); + //Add the visibility icon column: + Inkscape::UI::Widget::ImageToggler *eyeRenderer = manage( new Inkscape::UI::Widget::ImageToggler("visible", "hidden") ); + int visibleColNum = effectlist_view.append_column("is_visible", *eyeRenderer) - 1; + eyeRenderer->signal_toggled().connect( sigc::mem_fun(*this, &LivePathEffectEditor::on_visibility_toggled) ); + eyeRenderer->property_activatable() = true; + Gtk::TreeViewColumn* col = effectlist_view.get_column(visibleColNum); + if ( col ) { + col->add_attribute( eyeRenderer->property_active(), columns.col_visible ); + } + //Add the effect name column: + effectlist_view.append_column("Effect", columns.col_name); contents->pack_start(effectapplication_frame, false, false); contents->pack_start(effectlist_frame, true, true); @@ -148,7 +161,7 @@ LivePathEffectEditor::LivePathEffectEditor() //button_remove.hide(); } -LivePathEffectEditor::~LivePathEffectEditor() +LivePathEffectEditor::~LivePathEffectEditor() { if (effectwidget) { effectcontrol_vbox.remove(*effectwidget); @@ -158,6 +171,7 @@ LivePathEffectEditor::~LivePathEffectEditor() if (current_desktop) { selection_changed_connection.disconnect(); + selection_modified_connection.disconnect(); } } @@ -220,10 +234,10 @@ LivePathEffectEditor::onSelectionChanged(Inkscape::Selection *sel) if ( SP_IS_LPE_ITEM(item) ) { SPLPEItem *lpeitem = SP_LPE_ITEM(item); - effect_list_update(lpeitem); + effect_list_reload(lpeitem); current_lpeitem = lpeitem; - + set_sensitize_all(true); if ( sp_lpe_item_has_path_effect(lpeitem) ) { Inkscape::LivePathEffect::Effect *lpe = sp_lpe_item_get_current_lpe(lpeitem); @@ -236,10 +250,8 @@ LivePathEffectEditor::onSelectionChanged(Inkscape::Selection *sel) showText(_("No effect applied")); button_remove.set_sensitive(false); } - } - else - { - showText(_("Item is not compound by paths")); + } else { + showText(_("Item is not a path or shape")); set_sensitize_all(false); } } else { @@ -252,11 +264,14 @@ LivePathEffectEditor::onSelectionChanged(Inkscape::Selection *sel) } } +/* + * First clears the effectlist_store, then appends all effects from the effectlist. + */ void -LivePathEffectEditor::effect_list_update(SPLPEItem *lpeitem) +LivePathEffectEditor::effect_list_reload(SPLPEItem *lpeitem) { effectlist_store->clear(); - + PathEffectList effectlist = sp_lpe_item_get_effect_list(lpeitem); PathEffectList::iterator it; for( it = effectlist.begin() ; it!=effectlist.end(); it++ ) @@ -264,11 +279,12 @@ LivePathEffectEditor::effect_list_update(SPLPEItem *lpeitem) Gtk::TreeModel::Row row = *(effectlist_store->append()); row[columns.col_name] = (*it)->lpeobject->lpe->getName(); row[columns.lperef] = *it; + row[columns.col_visible] = (*it)->lpeobject->lpe->isVisible(); } } -void +void LivePathEffectEditor::setDesktop(SPDesktop *desktop) { Panel::setDesktop(desktop); @@ -279,6 +295,7 @@ LivePathEffectEditor::setDesktop(SPDesktop *desktop) if (current_desktop) { selection_changed_connection.disconnect(); + selection_modified_connection.disconnect(); } current_desktop = desktop; @@ -286,6 +303,8 @@ LivePathEffectEditor::setDesktop(SPDesktop *desktop) Inkscape::Selection *selection = sp_desktop_selection(desktop); selection_changed_connection = selection->connectChanged( sigc::bind (sigc::ptr_fun(&lpeeditor_selection_changed), this ) ); + selection_modified_connection = selection->connectModified( + sigc::bind (sigc::ptr_fun(&lpeeditor_selection_modified), this ) ); onSelectionChanged(selection); } else { @@ -320,21 +339,10 @@ LivePathEffectEditor::onApply() item = sel->singleItem(); // get new item } - // Path effect definition - Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); - Inkscape::XML::Node *repr = xml_doc->createElement("inkscape:path-effect"); - repr->setAttribute("effect", data->key.c_str() ); - - SP_OBJECT_REPR(SP_DOCUMENT_DEFS(doc))->addChild(repr, NULL); // adds to and assigns the 'id' attribute - const gchar * repr_id = repr->attribute("id"); - Inkscape::GC::release(repr); + LivePathEffect::Effect::createAndApply(data->key.c_str(), doc, item); - gchar *href = g_strdup_printf("#%s", repr_id); - sp_lpe_item_add_path_effect(SP_LPE_ITEM(item), href, true); - g_free(href); - - sp_document_done(doc, SP_VERB_DIALOG_LIVE_PATH_EFFECT, - _("Create and apply path effect")); + sp_document_done(doc, SP_VERB_DIALOG_LIVE_PATH_EFFECT, + _("Create and apply path effect")); onSelectionChanged(sel); } @@ -349,46 +357,43 @@ LivePathEffectEditor::onRemove() SPItem *item = sel->singleItem(); if ( item && SP_IS_LPE_ITEM(item) ) { sp_lpe_item_remove_current_path_effect(SP_LPE_ITEM(item), false); - - sp_document_done ( sp_desktop_document (current_desktop), SP_VERB_DIALOG_LIVE_PATH_EFFECT, + + sp_document_done ( sp_desktop_document (current_desktop), SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Remove path effect") ); - effect_list_update(SP_LPE_ITEM(item)); + effect_list_reload(SP_LPE_ITEM(item)); } } } void LivePathEffectEditor::onUp() { - Inkscape::Selection *sel = _getSelection(); + Inkscape::Selection *sel = _getSelection(); if ( sel && !sel->isEmpty() ) { SPItem *item = sel->singleItem(); if ( item && SP_IS_LPE_ITEM(item) ) { - - sp_lpe_item_up_current_path_effect(SP_LPE_ITEM(item)); - - sp_document_done ( sp_desktop_document (current_desktop), SP_VERB_DIALOG_LIVE_PATH_EFFECT, - _("Remove path effect") ); + sp_lpe_item_up_current_path_effect(SP_LPE_ITEM(item)); - effect_list_update(SP_LPE_ITEM(item)); + sp_document_done ( sp_desktop_document (current_desktop), SP_VERB_DIALOG_LIVE_PATH_EFFECT, + _("Move path effect up") ); + + effect_list_reload(SP_LPE_ITEM(item)); } } - } void LivePathEffectEditor::onDown() { - Inkscape::Selection *sel = _getSelection(); + Inkscape::Selection *sel = _getSelection(); if ( sel && !sel->isEmpty() ) { SPItem *item = sel->singleItem(); if ( item && SP_IS_LPE_ITEM(item) ) { - - sp_lpe_item_down_current_path_effect(SP_LPE_ITEM(item)); - - sp_document_done ( sp_desktop_document (current_desktop), SP_VERB_DIALOG_LIVE_PATH_EFFECT, - _("Remove path effect") ); + sp_lpe_item_down_current_path_effect(SP_LPE_ITEM(item)); + + sp_document_done ( sp_desktop_document (current_desktop), SP_VERB_DIALOG_LIVE_PATH_EFFECT, + _("Move path effect down") ); - effect_list_update(SP_LPE_ITEM(item)); + effect_list_reload(SP_LPE_ITEM(item)); } } } @@ -408,6 +413,23 @@ void LivePathEffectEditor::on_effect_selection_changed() } } +void LivePathEffectEditor::on_visibility_toggled( Glib::ustring const& str ) +{ + Gtk::TreeModel::Children::iterator iter = effectlist_view.get_model()->get_iter(str); + Gtk::TreeModel::Row row = *iter; + + LivePathEffect::LPEObjectReference * lpeobjref = row[columns.lperef]; + + if ( lpeobjref ) { + bool newValue = !row[columns.col_visible]; + row[columns.col_visible] = newValue; + /* FIXME: this explicit writing to SVG is wrong. The lpe_item should have a method to disable/enable an effect within its stack. + * So one can call: lpe_item->setActive(lpeobjref->lpeobject); */ + lpeobjref->lpeobject->lpe->getRepr()->setAttribute("is_visible", newValue ? "true" : "false"); + sp_document_done( sp_desktop_document(current_desktop), SP_VERB_DIALOG_LIVE_PATH_EFFECT, + _("Change path effect's visibility") ); + } +} } // namespace Dialog } // namespace UI