dbb33756bd786e9432e18ec7be93f8c416e1b492Jon A. Cruz * Live Path Effect editing dialog - implementation.
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm * Johan Engelen <j.b.c.engelen@utwente.nl>
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk * Steren Giannini <steren.giannini@gmail.com>
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk * Bastien Bouclet <bgkweb@gmail.com>
9dc68827cbd515262ecb8d5ae8547d9e82c72e00Jon A. Cruz * Abhishek Sharma
e9b6af083e34e2397a8ddbe9781920733d09d151Ted Gould * Copyright (C) 2007 Authors
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm * Released under GNU GPL. Read the file 'COPYING' for more information.
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm/*####################
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm * Callback functions
738092bcf0d040b2431137e191dfd7cf3ce3afadJohan Engelenvoid lpeeditor_selection_changed (Inkscape::Selection * selection, gpointer data)
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm LivePathEffectEditor *lpeeditor = static_cast<LivePathEffectEditor *>(data);
a95be1234ba4df33d6d074589edaa56f0d546069buliabyakstatic void lpeeditor_selection_modified (Inkscape::Selection * selection, guint /*flags*/, gpointer data)
a95be1234ba4df33d6d074589edaa56f0d546069buliabyak LivePathEffectEditor *lpeeditor = static_cast<LivePathEffectEditor *>(data);
12d084654ee6f91cc12b6218508ee5d3e37de2baLiam P. Whitestatic void lpe_style_button(Gtk::Button& btn, char const* iconName)
12d084654ee6f91cc12b6218508ee5d3e37de2baLiam P. White GtkWidget *child = sp_icon_new(Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName);
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm * LivePathEffectEditor
0d00bc9f32167e81375a4be524572b27e2894ee4John Smith * TRANSLATORS: this dialog is accessible via menu Path - Path Effect Editor...
e9b6af083e34e2397a8ddbe9781920733d09d151Ted Gould : UI::Widget::Panel("", "/dialogs/livepatheffect", SP_VERB_DIALOG_LIVE_PATH_EFFECT),
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen //Add the TreeView, inside a ScrolledWindow, with the button underneath:
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen effectlist_vbox.pack_start(scrolled_window, Gtk::PACK_EXPAND_WIDGET);
0d00bc9f32167e81375a4be524572b27e2894ee4John Smith effectlist_vbox.pack_end(toolbar_hbox, Gtk::PACK_SHRINK);
0d00bc9f32167e81375a4be524572b27e2894ee4John Smith button_add.set_tooltip_text(_("Add path effect"));
12d084654ee6f91cc12b6218508ee5d3e37de2baLiam P. White lpe_style_button(button_add, INKSCAPE_ICON("list-add"));
0d00bc9f32167e81375a4be524572b27e2894ee4John Smith button_remove.set_tooltip_text(_("Delete current path effect"));
12d084654ee6f91cc12b6218508ee5d3e37de2baLiam P. White lpe_style_button(button_remove, INKSCAPE_ICON("list-remove"));
0d00bc9f32167e81375a4be524572b27e2894ee4John Smith button_up.set_tooltip_text(_("Raise the current path effect"));
12d084654ee6f91cc12b6218508ee5d3e37de2baLiam P. White lpe_style_button(button_up, INKSCAPE_ICON("go-up"));
0d00bc9f32167e81375a4be524572b27e2894ee4John Smith button_down.set_tooltip_text(_("Lower the current path effect"));
12d084654ee6f91cc12b6218508ee5d3e37de2baLiam P. White lpe_style_button(button_down, INKSCAPE_ICON("go-down"));
0d00bc9f32167e81375a4be524572b27e2894ee4John Smith // Add toolbar items to toolbar
8e7d13ca30e4b9671afc47f03dc11affd5507077Alex Valavanis // TODO: This has been removed from Gtkmm 3.0. Check that
8e7d13ca30e4b9671afc47f03dc11affd5507077Alex Valavanis // everything still looks OK!
0d00bc9f32167e81375a4be524572b27e2894ee4John Smith toolbar_hbox.set_child_secondary( button_add , true);
0d00bc9f32167e81375a4be524572b27e2894ee4John Smith toolbar_hbox.set_child_secondary( button_remove , true);
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen //Create the Tree model:
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen effectlist_store = Gtk::ListStore::create(columns);
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen // Handle tree selections
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen effectlist_selection = effectlist_view.get_selection();
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen effectlist_selection->signal_changed().connect( sigc::mem_fun(*this, &LivePathEffectEditor::on_effect_selection_changed) );
b3722066cc416b6582d9a9a3ffc8ba2e868e102cjohanengelen //Add the visibility icon column:
c42ca006cc2593efa9a0ea19f2680ea9d5792654Markus Engel Inkscape::UI::Widget::ImageToggler *eyeRenderer = Gtk::manage( new Inkscape::UI::Widget::ImageToggler(
11d3fae21261f21488c39b12b716385b5a91c847Johan Engelen INKSCAPE_ICON("object-visible"), INKSCAPE_ICON("object-hidden")) );
b3722066cc416b6582d9a9a3ffc8ba2e868e102cjohanengelen int visibleColNum = effectlist_view.append_column("is_visible", *eyeRenderer) - 1;
607ec3f31779845d307f157ff34472da27b8bdbcjohanengelen eyeRenderer->signal_toggled().connect( sigc::mem_fun(*this, &LivePathEffectEditor::on_visibility_toggled) );
b3722066cc416b6582d9a9a3ffc8ba2e868e102cjohanengelen Gtk::TreeViewColumn* col = effectlist_view.get_column(visibleColNum);
b3722066cc416b6582d9a9a3ffc8ba2e868e102cjohanengelen col->add_attribute( eyeRenderer->property_active(), columns.col_visible );
b3722066cc416b6582d9a9a3ffc8ba2e868e102cjohanengelen //Add the effect name column:
b3722066cc416b6582d9a9a3ffc8ba2e868e102cjohanengelen effectlist_view.append_column("Effect", columns.col_name);
0d00bc9f32167e81375a4be524572b27e2894ee4John Smith contents->pack_start(effectlist_vbox, true, true);
0d00bc9f32167e81375a4be524572b27e2894ee4John Smith contents->pack_start(status_label, false, false);
b4998608f5fbde14c744b6ab8020664300e11f80jucablues contents->pack_start(effectcontrol_frame, false, false);
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm // connect callback functions to buttons
0d00bc9f32167e81375a4be524572b27e2894ee4John Smith button_add.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectEditor::onAdd));
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm button_remove.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectEditor::onRemove));
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen button_up.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectEditor::onUp));
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen button_down.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectEditor::onDown));
d67024fee7c560721468212767fb6aa221d5b542John Smith desktopChangeConn = deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &LivePathEffectEditor::setDesktop) );
90a3966dd44e306d23febc15ebd65cde07d7a4ddTed GouldLivePathEffectEditor::showParams(LivePathEffect::Effect& effect)
c5526a2c3001be486990d816757dd5ac028b3c3fjohanengelen effectcontrol_vbox.pack_start(*effectwidget, true, true);
c5526a2c3001be486990d816757dd5ac028b3c3fjohanengelen // fixme: add resizing of dialog
f0ed14f45951d21de3ff2c7c131f6aafa6e30c17buliabyakLivePathEffectEditor::selectInList(LivePathEffect::Effect* effect)
f0ed14f45951d21de3ff2c7c131f6aafa6e30c17buliabyak Gtk::TreeNodeChildren chi = effectlist_view.get_model()->children();
f0ed14f45951d21de3ff2c7c131f6aafa6e30c17buliabyak for (Gtk::TreeIter ci = chi.begin() ; ci != chi.end(); ci++) {
90a3966dd44e306d23febc15ebd65cde07d7a4ddTed Gould if (ci->get_value(columns.lperef)->lpeobject->get_lpe() == effect)
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrmLivePathEffectEditor::showText(Glib::ustring const &str)
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm // fixme: do resizing of dialog ?
0d00bc9f32167e81375a4be524572b27e2894ee4John Smith //combo_effecttype.set_sensitive(sensitive);
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrmLivePathEffectEditor::onSelectionChanged(Inkscape::Selection *sel)
f0ed14f45951d21de3ff2c7c131f6aafa6e30c17buliabyak // this was triggered by selecting a row in the list, so skip reloading
f4d474ff2d58b3d32dacd5feed0c164e8df4936cJon A. Cruz SPLPEItem *lpeitem = dynamic_cast<SPLPEItem *>(item);
f4ce66b44581cea80a736cf20244c0539a7525daJohan B. C. Engelen Inkscape::LivePathEffect::Effect *lpe = lpeitem->getCurrentLPE();
f4d474ff2d58b3d32dacd5feed0c164e8df4936cJon A. Cruz // test whether linked object is supported by the CLONE_ORIGINAL LPE
f4d474ff2d58b3d32dacd5feed0c164e8df4936cJon A. Cruz // Note that an SP_USE cannot have an LPE applied, so we only need to worry about the "add effect" case.
f4d474ff2d58b3d32dacd5feed0c164e8df4936cJon A. Cruz showText(_("Click add button to convert clone"));
852b4f6c7a572bc2ccbd96e80c4063a38f77153bjohanengelen * First clears the effectlist_store, then appends all effects from the effectlist.
852b4f6c7a572bc2ccbd96e80c4063a38f77153bjohanengelenLivePathEffectEditor::effect_list_reload(SPLPEItem *lpeitem)
32143ea5edb30f496040c1f24538e38d9453fc06Johan B. C. Engelen PathEffectList effectlist = lpeitem->getEffectList();
84d6d1f7365e49f2936df9df890ce49d2c000ce2Kris for( it = effectlist.begin() ; it!=effectlist.end(); ++it)
90a3966dd44e306d23febc15ebd65cde07d7a4ddTed Gould Gtk::TreeModel::Row row = *(effectlist_store->append());
90a3966dd44e306d23febc15ebd65cde07d7a4ddTed Gould row[columns.col_name] = (*it)->lpeobject->get_lpe()->getName();
90a3966dd44e306d23febc15ebd65cde07d7a4ddTed Gould row[columns.col_visible] = (*it)->lpeobject->get_lpe()->isVisible();
90a3966dd44e306d23febc15ebd65cde07d7a4ddTed Gould Gtk::TreeModel::Row row = *(effectlist_store->append());
769a6887551cf7ff7bce4b48d3ac303cbea69507Liam P. White Inkscape::Selection *selection = desktop->getSelection();
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm selection_changed_connection = selection->connectChanged(
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm sigc::bind (sigc::ptr_fun(&lpeeditor_selection_changed), this ) );
a95be1234ba4df33d6d074589edaa56f0d546069buliabyak selection_modified_connection = selection->connectModified(
a95be1234ba4df33d6d074589edaa56f0d546069buliabyak sigc::bind (sigc::ptr_fun(&lpeeditor_selection_modified), this ) );
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm/*########################################################################
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm# BUTTON CLICK HANDLERS (callbacks)
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm########################################################################*/
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm// TODO: factor out the effect applying code which can be called from anywhere. (selection-chemistry.cpp also needs it)
edcba9f1706559e93aa06a7173daa6cd6516acb5Johan B. C. Engelen // show effectlist dialog
edcba9f1706559e93aa06a7173daa6cd6516acb5Johan B. C. Engelen using Inkscape::UI::Dialog::LivePathEffectAdd;
edcba9f1706559e93aa06a7173daa6cd6516acb5Johan B. C. Engelen LivePathEffectAdd::show(current_desktop);
edcba9f1706559e93aa06a7173daa6cd6516acb5Johan B. C. Engelen SPDocument *doc = current_desktop->doc();
edcba9f1706559e93aa06a7173daa6cd6516acb5Johan B. C. Engelen const Util::EnumData<LivePathEffect::EffectType>* data = LivePathEffectAdd::getActiveData();
edcba9f1706559e93aa06a7173daa6cd6516acb5Johan B. C. Engelen // If item is a SPRect, convert it to path first:
e25076a0c8caf01a05b34c96485471798f61b6cbEric Greveson sp_selected_path_to_curves(sel, current_desktop, false);
edcba9f1706559e93aa06a7173daa6cd6516acb5Johan B. C. Engelen item = sel->singleItem(); // get new item
edcba9f1706559e93aa06a7173daa6cd6516acb5Johan B. C. Engelen LivePathEffect::Effect::createAndApply(data->key.c_str(), doc, item);
edcba9f1706559e93aa06a7173daa6cd6516acb5Johan B. C. Engelen DocumentUndo::done(doc, SP_VERB_DIALOG_LIVE_PATH_EFFECT,
edcba9f1706559e93aa06a7173daa6cd6516acb5Johan B. C. Engelen _("Create and apply path effect"));
f4d474ff2d58b3d32dacd5feed0c164e8df4936cJon A. Cruz // item is a clone. do not show effectlist dialog.
f4d474ff2d58b3d32dacd5feed0c164e8df4936cJon A. Cruz // convert to path, apply CLONE_ORIGINAL LPE, link it to the cloned path
f4d474ff2d58b3d32dacd5feed0c164e8df4936cJon A. Cruz // test whether linked object is supported by the CLONE_ORIGINAL LPE
f4d474ff2d58b3d32dacd5feed0c164e8df4936cJon A. Cruz // select original
f4d474ff2d58b3d32dacd5feed0c164e8df4936cJon A. Cruz // delete clone but remember its id and transform
f4d474ff2d58b3d32dacd5feed0c164e8df4936cJon A. Cruz gchar *id = g_strdup(item->getRepr()->attribute("id"));
f4d474ff2d58b3d32dacd5feed0c164e8df4936cJon A. Cruz gchar *transform = g_strdup(item->getRepr()->attribute("transform"));
f4d474ff2d58b3d32dacd5feed0c164e8df4936cJon A. Cruz // run sp_selection_clone_original_path_lpe
f4d474ff2d58b3d32dacd5feed0c164e8df4936cJon A. Cruz sp_selection_clone_original_path_lpe(current_desktop);
dd0ae0a28fda34d3805f7fe6deece97c4192910aJohan B. C. Engelen // Check that the cloning was successful. We don't want to change the ID of the original referenced path!
dd0ae0a28fda34d3805f7fe6deece97c4192910aJohan B. C. Engelen new_item->getRepr()->setAttribute("id", id);
dd0ae0a28fda34d3805f7fe6deece97c4192910aJohan B. C. Engelen new_item->getRepr()->setAttribute("transform", transform);
f4d474ff2d58b3d32dacd5feed0c164e8df4936cJon A. Cruz /// \todo Add the LPE stack of the original path?
f4d474ff2d58b3d32dacd5feed0c164e8df4936cJon A. Cruz DocumentUndo::done(doc, SP_VERB_DIALOG_LIVE_PATH_EFFECT,
f4d474ff2d58b3d32dacd5feed0c164e8df4936cJon A. Cruz _("Create and apply Clone original path effect"));
f4d474ff2d58b3d32dacd5feed0c164e8df4936cJon A. Cruz SPLPEItem *lpeitem = dynamic_cast<SPLPEItem *>(item);
9ba77856a8823f85b53c0a861d220cd0347f2754Liam P. White DocumentUndo::done( current_desktop->getDocument(), SP_VERB_DIALOG_LIVE_PATH_EFFECT,
9dc68827cbd515262ecb8d5ae8547d9e82c72e00Jon A. Cruz _("Remove path effect") );
f4d474ff2d58b3d32dacd5feed0c164e8df4936cJon A. Cruz SPLPEItem *lpeitem = dynamic_cast<SPLPEItem *>(item);
9ba77856a8823f85b53c0a861d220cd0347f2754Liam P. White DocumentUndo::done( current_desktop->getDocument(), SP_VERB_DIALOG_LIVE_PATH_EFFECT,
9dc68827cbd515262ecb8d5ae8547d9e82c72e00Jon A. Cruz _("Move path effect up") );
f4d474ff2d58b3d32dacd5feed0c164e8df4936cJon A. Cruz SPLPEItem *lpeitem = dynamic_cast<SPLPEItem *>(item);
9ba77856a8823f85b53c0a861d220cd0347f2754Liam P. White DocumentUndo::done( current_desktop->getDocument(), SP_VERB_DIALOG_LIVE_PATH_EFFECT,
9dc68827cbd515262ecb8d5ae8547d9e82c72e00Jon A. Cruz _("Move path effect down") );
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelenvoid LivePathEffectEditor::on_effect_selection_changed()
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen Glib::RefPtr<Gtk::TreeSelection> sel = effectlist_view.get_selection();
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen Gtk::TreeModel::iterator it = sel->get_selected();
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen LivePathEffect::LPEObjectReference * lperef = (*it)[columns.lperef];
90a3966dd44e306d23febc15ebd65cde07d7a4ddTed Gould lpe_list_locked = true; // prevent reload of the list which would lose selection
f4ce66b44581cea80a736cf20244c0539a7525daJohan B. C. Engelen current_lpeitem->setCurrentPathEffect(lperef);
607ec3f31779845d307f157ff34472da27b8bdbcjohanengelenvoid LivePathEffectEditor::on_visibility_toggled( Glib::ustring const& str )
607ec3f31779845d307f157ff34472da27b8bdbcjohanengelen Gtk::TreeModel::Children::iterator iter = effectlist_view.get_model()->get_iter(str);
607ec3f31779845d307f157ff34472da27b8bdbcjohanengelen LivePathEffect::LPEObjectReference * lpeobjref = row[columns.lperef];
90a3966dd44e306d23febc15ebd65cde07d7a4ddTed Gould if ( lpeobjref && lpeobjref->lpeobject->get_lpe() ) {
607ec3f31779845d307f157ff34472da27b8bdbcjohanengelen /* FIXME: this explicit writing to SVG is wrong. The lpe_item should have a method to disable/enable an effect within its stack.
607ec3f31779845d307f157ff34472da27b8bdbcjohanengelen * So one can call: lpe_item->setActive(lpeobjref->lpeobject); */
90a3966dd44e306d23febc15ebd65cde07d7a4ddTed Gould lpeobjref->lpeobject->get_lpe()->getRepr()->setAttribute("is_visible", newValue ? "true" : "false");
9ba77856a8823f85b53c0a861d220cd0347f2754Liam P. White DocumentUndo::done( current_desktop->getDocument(), SP_VERB_DIALOG_LIVE_PATH_EFFECT,
9dc68827cbd515262ecb8d5ae8547d9e82c72e00Jon A. Cruz newValue ? _("Activate path effect") : _("Deactivate path effect"));
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm} // namespace Dialog
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm} // namespace UI
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm} // namespace Inkscape
ba885512446fff2803585a4aaec34e7742841f05cilix Local Variables:
ba885512446fff2803585a4aaec34e7742841f05cilix c-file-style:"stroustrup"
ba885512446fff2803585a4aaec34e7742841f05cilix c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
ba885512446fff2803585a4aaec34e7742841f05cilix indent-tabs-mode:nil
ba885512446fff2803585a4aaec34e7742841f05cilix fill-column:99
a4030d5ca449e7e384bc699cd249ee704faaeab0Chris Morgan// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :