diff options
| author | Jabiertxof <jabier.arraiza@marker.es> | 2019-02-13 23:20:53 +0000 |
|---|---|---|
| committer | Jabier Arraiza <jabier.arraiza@marker.es> | 2019-02-18 21:18:27 +0000 |
| commit | d76372d5d6a8107a9f14fd563b7345bff7da711d (patch) | |
| tree | 9ee42b1548b1c25a36c7fa29d90e6729a9388e34 /src/ui | |
| parent | Improving window position (diff) | |
| download | inkscape-d76372d5d6a8107a9f14fd563b7345bff7da711d.tar.gz inkscape-d76372d5d6a8107a9f14fd563b7345bff7da711d.zip | |
Add apply function
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/dialog/livepatheffect-add.cpp | 73 | ||||
| -rw-r--r-- | src/ui/dialog/livepatheffect-add.h | 5 | ||||
| -rw-r--r-- | src/ui/dialog/livepatheffect-editor.cpp | 2 |
3 files changed, 73 insertions, 7 deletions
diff --git a/src/ui/dialog/livepatheffect-add.cpp b/src/ui/dialog/livepatheffect-add.cpp index cc4375f37..a811f5e5b 100644 --- a/src/ui/dialog/livepatheffect-add.cpp +++ b/src/ui/dialog/livepatheffect-add.cpp @@ -17,6 +17,9 @@ #include "io/resource.h" #include "live_effects/effect.h" #include "livepatheffect-add.h" +#include "object/sp-path.h" +#include "object/sp-shape.h" +#include "object/sp-item-group.h" #include <glibmm/i18n.h> #include "preferences.h" @@ -83,8 +86,30 @@ LivePathEffectAdd::LivePathEffectAdd() g_warning("Glade file loading failed for filter effect dialog"); return; } - _showfavs = false; _builder->get_widget("LPEDialogSelector", _LPEDialogSelector); + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + Inkscape::Selection *sel = desktop->getSelection(); + if ( sel && !sel->isEmpty() ) { + SPItem *item = sel->singleItem(); + if (item) { + SPShape *shape = dynamic_cast<SPShape *>(item); + SPPath *path = dynamic_cast<SPPath *>(item); + SPGroup *group = dynamic_cast<SPGroup *>(item); + _item_type = ""; + if (group) { + _item_type = "group"; + } else if (shape) { + _item_type = "shape"; + } else if (path){ + _item_type = "path"; + } else { + _LPEDialogSelector->hide(); + return; + } + } + } + _showfavs = false; + _builder->get_widget("LPESelectorFlowBox", _LPESelectorFlowBox); _builder->get_widget("LPESelectorEffectInfoPop", _LPESelectorEffectInfoPop); _builder->get_widget("LPEFilter", _LPEFilter); @@ -105,9 +130,25 @@ LivePathEffectAdd::LivePathEffectAdd() g_warning("Glade file loading failed for filter effect dialog"); return; } + const LivePathEffect::EnumEffectData<LivePathEffect::EffectType> *data = &converter.data(i); + bool disable = false; + if (_item_type == "group" && !converter.get_on_group(data->id)) { + disable = true; + } else if (_item_type == "shape" && !converter.get_on_shape(data->id)) { + disable = true; + } else if (_item_type == "path" && !converter.get_on_path(data->id)) { + disable = true; + } Gtk::EventBox *LPESelectorEffect; builder_effect->get_widget("LPESelectorEffect", LPESelectorEffect); - const LivePathEffect::EnumEffectData<LivePathEffect::EffectType> *data = &converter.data(i); + if (disable) { + LPESelectorEffect->get_parent()->get_style_context()->add_class("lpedisabled"); + } else { + LPESelectorEffect->get_parent()->get_style_context()->remove_class("lpedisabled"); + } + Gtk::Overlay * LPEOverlay; + builder_effect->get_widget("LPEOverlay", LPEOverlay); + LPEOverlay->signal_button_press_event().connect(sigc::bind<Glib::RefPtr<Gtk::Builder>, const LivePathEffect::EnumEffectData<LivePathEffect::EffectType> * >(sigc::mem_fun(*this, &LivePathEffectAdd::apply), builder_effect, &converter.data(i))); Gtk::Label *LPEName; builder_effect->get_widget("LPEName", LPEName); LPEName->set_text(converter.get_label(data->id).c_str()); @@ -134,6 +175,10 @@ LivePathEffectAdd::LivePathEffectAdd() builder_effect->get_widget("LPESelectorEffectEventFavTop", LPESelectorEffectEventFavTop); LPESelectorEffectEventFav->signal_button_press_event().connect(sigc::bind<Glib::RefPtr<Gtk::Builder> >(sigc::mem_fun(*this, &LivePathEffectAdd::fav_toggler), builder_effect)); LPESelectorEffectEventFavTop->signal_button_press_event().connect(sigc::bind<Glib::RefPtr<Gtk::Builder> >(sigc::mem_fun(*this, &LivePathEffectAdd::fav_toggler), builder_effect)); + + Gtk::EventBox *LPESelectorEffectEventApply; + builder_effect->get_widget("LPESelectorEffectEventApply", LPESelectorEffectEventApply); + LPESelectorEffectEventApply->signal_button_press_event().connect(Glib::RefPtr<Gtk::Builder>, sigc::bind<const LivePathEffect::EnumEffectData<LivePathEffect::EffectType> * >(sigc::mem_fun(*this, &LivePathEffectAdd::apply), builder_effect, &converter.data(i))); Gtk::ButtonBox *LPESelectorButtonBox; builder_effect->get_widget("LPESelectorButtonBox", LPESelectorButtonBox); LPESelectorButtonBox->signal_enter_notify_event().connect(sigc::bind<GtkWidget *>(sigc::mem_fun(*this, &LivePathEffectAdd::mouseover), GTK_WIDGET(LPESelectorEffect->gobj()))); @@ -161,13 +206,16 @@ LivePathEffectAdd::LivePathEffectAdd() _LPEDialogSelector->get_default_size (original_width, original_height); _LPEDialogSelector->get_size (width, height); if( width == original_width && height == original_height ){ - Gtk::Window *window = SP_ACTIVE_DESKTOP->getToplevel(); + Gtk::Window *window = desktop->getToplevel(); window->get_size (width, height); _LPEDialogSelector->resize(std::min(width - 300, 1800), height - 300); - reload_effect_list(); } } - +const LivePathEffect::EnumEffectData<LivePathEffect::EffectType>* +LivePathEffectAdd::getActiveData() +{ + return instance()._to_add; +} void LivePathEffectAdd::on_activate(Gtk::FlowBoxChild *child) { for (auto i : _LPESelectorFlowBox->get_children()) { @@ -275,6 +323,21 @@ bool LivePathEffectAdd::show_fav_toggler(GdkEventButton* evt) return true; } +bool LivePathEffectAdd::apply(GdkEventButton* evt, Glib::RefPtr<Gtk::Builder> builder_effect, const LivePathEffect::EnumEffectData<LivePathEffect::EffectType>* to_add) +{ + _to_add = to_add; + Gtk::EventBox *LPESelectorEffect; + builder_effect->get_widget("LPESelectorEffect", LPESelectorEffect); + if(!LPESelectorEffect->get_parent()->get_style_context()->has_class("lpeactive" || + LPESelectorEffect->get_parent()->get_style_context()->has_class("lpedisabled")) + { + return true; + } + _LPEDialogSelector->response(Gtk::RESPONSE_APPLY); + _LPEDialogSelector->hide(); + return true; +} + bool LivePathEffectAdd::on_filter(Gtk::FlowBoxChild *child) { child->set_valign(Gtk::ALIGN_START); diff --git a/src/ui/dialog/livepatheffect-add.h b/src/ui/dialog/livepatheffect-add.h index af411715d..28bebdaf2 100644 --- a/src/ui/dialog/livepatheffect-add.h +++ b/src/ui/dialog/livepatheffect-add.h @@ -50,7 +50,7 @@ public: static void show(SPDesktop *desktop); static bool isApplied() { return false; } - static const Util::EnumData<LivePathEffect::EffectType> *getActiveData() { return NULL; }; + static const LivePathEffect::EnumEffectData<LivePathEffect::EffectType>* getActiveData(); protected: /** @@ -64,6 +64,7 @@ public: bool pop_description(GdkEventButton* evt, Glib::RefPtr<Gtk::Builder> builder_effect); bool hide_pop_description(GdkEventButton* evt); bool fav_toggler(GdkEventButton* evt, Glib::RefPtr<Gtk::Builder> builder_effect); + bool apply(GdkEventButton* evt, Glib::RefPtr<Gtk::Builder> builder_effect, const LivePathEffect::EnumEffectData<LivePathEffect::EffectType>* to_add); bool show_fav_toggler(GdkEventButton* evt); bool mouseover(GdkEventCrossing* evt, GtkWidget *wdg); bool mouseout(GdkEventCrossing* evt, GtkWidget *wdg); @@ -96,6 +97,8 @@ private: Gtk::Label *_LPEInfo; Gtk::Box *_LPESelector; guint _visiblelpe; + Glib::ustring _item_type; + const LivePathEffect::EnumEffectData<LivePathEffect::EffectType>* _to_add; bool _showfavs; class Effect; const LivePathEffect::EnumEffectDataConverter<LivePathEffect::EffectType> &converter; diff --git a/src/ui/dialog/livepatheffect-editor.cpp b/src/ui/dialog/livepatheffect-editor.cpp index 60542a9d8..d5568f8e9 100644 --- a/src/ui/dialog/livepatheffect-editor.cpp +++ b/src/ui/dialog/livepatheffect-editor.cpp @@ -432,7 +432,7 @@ LivePathEffectEditor::onAdd() SPDocument *doc = current_desktop->doc(); - const Util::EnumData<LivePathEffect::EffectType>* data = LivePathEffectAdd::getActiveData(); + const LivePathEffect::EnumEffectData<LivePathEffect::EffectType>* data = LivePathEffectAdd::getActiveData(); if (!data) { return; } |
