livepatheffect-editor.cpp revision 1b3a8414f17dc95fc921d999ea715c99d10dd4aa
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.
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrmnamespace UI {
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);
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm/*#######################
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm * LivePathEffectEditor
e9b6af083e34e2397a8ddbe9781920733d09d151Ted Gould : UI::Widget::Panel("", "/dialogs/livepatheffect", SP_VERB_DIALOG_LIVE_PATH_EFFECT),
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm combo_effecttype(Inkscape::LivePathEffect::LPETypeConverter),
2b2321eb83f7bd0173589734d6f40b4fe90961f9helix // TRANSLATORS: this dialog is accessible via menu Path - Path Effect Editor...
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen //Add the TreeView, inside a ScrolledWindow, with the button underneath:
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen //Only show the scrollbars when they are necessary:
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm effectapplication_hbox.pack_start(combo_effecttype, true, true);
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm effectapplication_hbox.pack_start(button_apply, true, true);
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen effectlist_vbox.pack_start(scrolled_window, Gtk::PACK_EXPAND_WIDGET);
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen effectlist_vbox.pack_end(toolbar, Gtk::PACK_SHRINK);
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen // effectlist_vbox.pack_end(button_hbox, Gtk::PACK_SHRINK);
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm effectcontrol_vbox.pack_start(explain_label, true, true);
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen // button_hbox.pack_start(button_up, true, true);
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen // button_hbox.pack_start(button_down, true, true);
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen // button_hbox.pack_end(button_remove, true, true);
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen // Add toolbar items to toolbar
852b4f6c7a572bc2ccbd96e80c4063a38f77153bjohanengelen // Add toolbar
852b4f6c7a572bc2ccbd96e80c4063a38f77153bjohanengelen //add_toolbar(toolbar);
852b4f6c7a572bc2ccbd96e80c4063a38f77153bjohanengelen toolbar.show_all(); //Show the toolbar and all its child widgets.
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:
035e109c2dce9f6a9552f75d09b1573311d02546tweenk Inkscape::UI::Widget::ImageToggler *eyeRenderer = 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);
b4998608f5fbde14c744b6ab8020664300e11f80jucablues contents->pack_start(effectapplication_frame, false, false);
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen contents->pack_start(effectlist_frame, true, true);
b4998608f5fbde14c744b6ab8020664300e11f80jucablues contents->pack_start(effectcontrol_frame, false, false);
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm // connect callback functions to buttons
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm button_apply.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectEditor::onApply));
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));
90a3966dd44e306d23febc15ebd65cde07d7a4ddTed GouldLivePathEffectEditor::showParams(LivePathEffect::Effect& effect)
90a3966dd44e306d23febc15ebd65cde07d7a4ddTed Gould explain_label.set_markup("<b>" + effect.getName() + "</b>");
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 ?
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrmLivePathEffectEditor::onSelectionChanged(Inkscape::Selection *sel)
f0ed14f45951d21de3ff2c7c131f6aafa6e30c17buliabyak // this was triggered by selecting a row in the list, so skip reloading
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen Inkscape::LivePathEffect::Effect *lpe = sp_lpe_item_get_current_lpe(lpeitem);
852b4f6c7a572bc2ccbd96e80c4063a38f77153bjohanengelen * First clears the effectlist_store, then appends all effects from the effectlist.
852b4f6c7a572bc2ccbd96e80c4063a38f77153bjohanengelenLivePathEffectEditor::effect_list_reload(SPLPEItem *lpeitem)
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen PathEffectList effectlist = sp_lpe_item_get_effect_list(lpeitem);
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());
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm Inkscape::Selection *selection = sp_desktop_selection(desktop);
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)
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm const Util::EnumData<LivePathEffect::EffectType>* data = combo_effecttype.get_active_data();
fd4b29a5cdef220804dfed85fec8acb5daceec5fpjrm if (!data) return;
ae22ad7adc4a7a418e71f5dbab8c1f0f7f464562johanengelen // If item is a SPRect, convert it to path first:
6656f193fdace606d1b162d6dea0223bc295f0a6cilix LivePathEffect::Effect::createAndApply(data->key.c_str(), doc, item);
9dc68827cbd515262ecb8d5ae8547d9e82c72e00Jon A. Cruz DocumentUndo::done(doc, SP_VERB_DIALOG_LIVE_PATH_EFFECT,
9dc68827cbd515262ecb8d5ae8547d9e82c72e00Jon A. Cruz _("Create and apply path effect"));
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen sp_lpe_item_remove_current_path_effect(SP_LPE_ITEM(item), false);
9dc68827cbd515262ecb8d5ae8547d9e82c72e00Jon A. Cruz DocumentUndo::done( sp_desktop_document(current_desktop), SP_VERB_DIALOG_LIVE_PATH_EFFECT,
9dc68827cbd515262ecb8d5ae8547d9e82c72e00Jon A. Cruz _("Remove path effect") );
852b4f6c7a572bc2ccbd96e80c4063a38f77153bjohanengelen sp_lpe_item_up_current_path_effect(SP_LPE_ITEM(item));
9dc68827cbd515262ecb8d5ae8547d9e82c72e00Jon A. Cruz DocumentUndo::done( sp_desktop_document(current_desktop), SP_VERB_DIALOG_LIVE_PATH_EFFECT,
9dc68827cbd515262ecb8d5ae8547d9e82c72e00Jon A. Cruz _("Move path effect up") );
852b4f6c7a572bc2ccbd96e80c4063a38f77153bjohanengelen sp_lpe_item_down_current_path_effect(SP_LPE_ITEM(item));
9dc68827cbd515262ecb8d5ae8547d9e82c72e00Jon A. Cruz DocumentUndo::done( sp_desktop_document(current_desktop), 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
90a3966dd44e306d23febc15ebd65cde07d7a4ddTed Gould sp_lpe_item_set_current_path_effect(current_lpeitem, 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");
9dc68827cbd515262ecb8d5ae8547d9e82c72e00Jon A. Cruz DocumentUndo::done( sp_desktop_document(current_desktop), 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 :