From 6d5bd2bf07165531a10d9925e8800fe5c9cd9be3 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 14 Jul 2014 00:59:33 +0200 Subject: Update togglebutton parameter to handle if you want: Active text, Active icon, Inactive text, Inactive Icon (bzr r13341.1.88) --- src/live_effects/lpe-simplify.cpp | 16 +++--- src/live_effects/parameter/togglebutton.cpp | 77 ++++++++++++++++++++++++++--- src/live_effects/parameter/togglebutton.h | 16 +++++- src/ui/widget/registered-widget.cpp | 2 +- 4 files changed, 95 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp index d010e75a2..104cbde98 100644 --- a/src/live_effects/lpe-simplify.cpp +++ b/src/live_effects/lpe-simplify.cpp @@ -19,7 +19,7 @@ #include <2geom/d2.h> #include <2geom/generic-rect.h> #include <2geom/interval.h> - +#include "ui/icon-names.h" namespace Inkscape { namespace LivePathEffect { @@ -29,10 +29,14 @@ LPESimplify::LPESimplify(LivePathEffectObject *lpeobject) steps(_("Steps:"),_("Change number of simplify steps "), "steps", &wr, this,1), threshold(_("Roughly threshold:"), _("Roughly threshold:"), "threshold", &wr, this, 0.003), helper_size(_("Helper size:"), _("Helper size"), "helper_size", &wr, this, 2.), - nodes(_("Helper nodes"), _("Show helper nodes"), "nodes", &wr, this, false), - handles(_("Helper handles"), _("Show helper handles"), "handles", &wr, this, false), - simplifyindividualpaths(_("Paths separately"), _("Simplifying paths (separately)"), "simplifyindividualpaths", &wr, this, false), - simplifyJustCoalesce(_("Just coalesce"), _("Simplify just coalesce"), "simplifyJustCoalesce", &wr, this, false) + nodes(_("Helper nodes"), _("Show helper nodes"), "nodes", &wr, this, false, + "", INKSCAPE_ICON("system-run"), INKSCAPE_ICON("process-stop")), + handles(_("Helper handles"), _("Show helper handles"), "handles", &wr, this, false, + "", INKSCAPE_ICON("system-run"), INKSCAPE_ICON("process-stop")), + simplifyindividualpaths(_("Paths separately"), _("Simplifying paths (separately)"), "simplifyindividualpaths", &wr, this, false, + "", INKSCAPE_ICON("system-run"), INKSCAPE_ICON("process-stop")), + simplifyJustCoalesce(_("Just coalesce"), _("Simplify just coalesce"), "simplifyJustCoalesce", &wr, this, false, + "", INKSCAPE_ICON("system-run"), INKSCAPE_ICON("process-stop")) { registerParameter(dynamic_cast(&steps)); registerParameter(dynamic_cast(&threshold)); @@ -41,7 +45,7 @@ LPESimplify::LPESimplify(LivePathEffectObject *lpeobject) registerParameter(dynamic_cast(&handles)); registerParameter(dynamic_cast(&simplifyindividualpaths)); registerParameter(dynamic_cast(&simplifyJustCoalesce)); - threshold.param_set_range(0., Geom::infinity()); + threshold.param_set_range(0.0001, Geom::infinity()); threshold.param_set_increments(0.0001, 0.0001); threshold.param_set_digits(6); steps.param_set_range(0, 100); diff --git a/src/live_effects/parameter/togglebutton.cpp b/src/live_effects/parameter/togglebutton.cpp index d447afa6f..d92b9836f 100644 --- a/src/live_effects/parameter/togglebutton.cpp +++ b/src/live_effects/parameter/togglebutton.cpp @@ -5,6 +5,11 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include +#include +#include +#include + #include "ui/widget/registered-widget.h" #include "live_effects/parameter/togglebutton.h" #include "live_effects/effect.h" @@ -14,7 +19,6 @@ #include "inkscape.h" #include "verbs.h" #include "helper-fns.h" -#include namespace Inkscape { @@ -22,9 +26,13 @@ namespace LivePathEffect { ToggleButtonParam::ToggleButtonParam( const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, bool default_value ) - : Parameter(label, tip, key, wr, effect), value(default_value), defvalue(default_value) + Effect* effect, bool default_value, const Glib::ustring& inactive_label, + char const * icon_active, char const * icon_inactive, + Inkscape::IconSize icon_size) + : Parameter(label, tip, key, wr, effect), value(default_value), defvalue(default_value), + inactiveLabel(inactive_label), iconActive(icon_active), iconInactive(icon_inactive), iconSize(icon_size) { + checkwdg = NULL; } ToggleButtonParam::~ToggleButtonParam() @@ -61,7 +69,7 @@ ToggleButtonParam::param_newWidget() _toggled_connection.disconnect(); } - Inkscape::UI::Widget::RegisteredToggleButton * checkwdg = Gtk::manage( + checkwdg = Gtk::manage( new Inkscape::UI::Widget::RegisteredToggleButton( param_label, param_tooltip, param_key, @@ -69,21 +77,76 @@ ToggleButtonParam::param_newWidget() false, param_effect->getRepr(), param_effect->getSPDoc()) ); - + GtkWidget * boxButton = gtk_hbox_new (false, 0); + GtkWidget * labelButton = gtk_label_new (""); + if (!param_label.empty()) { + if(value || inactiveLabel.empty()){ + gtk_label_set_text(GTK_LABEL(labelButton), param_label.c_str()); + }else{ + gtk_label_set_text(GTK_LABEL(labelButton), inactiveLabel.c_str()); + } + } + gtk_widget_show(labelButton); + if ( iconActive ) { + if(!iconInactive){ + iconInactive = iconActive; + } + gtk_widget_show(boxButton); + GtkWidget *iconButton = sp_icon_new(iconSize, iconActive); + if(!value){ + iconButton = sp_icon_new(iconSize, iconInactive); + } + gtk_widget_show(iconButton); + gtk_box_pack_start (GTK_BOX(boxButton), iconButton, true, true, 2); + if (!param_label.empty()) { + gtk_box_pack_start (GTK_BOX(boxButton), labelButton, true, true, 2); + } + }else{ + gtk_box_pack_start (GTK_BOX(boxButton), labelButton, true, true, 2); + } + checkwdg->add(*Gtk::manage(Glib::wrap(boxButton))); checkwdg->setActive(value); checkwdg->setProgrammatically = false; - // TRANSLATORS: "toggle" is a verb here - checkwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Toggle path effect parameter")); + checkwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change togglebutton parameter")); _toggled_connection = checkwdg->signal_toggled().connect(sigc::mem_fun(*this, &ToggleButtonParam::toggled)); return checkwdg; } +void +ToggleButtonParam::refresh_button() +{ + if(!checkwdg){ + return; + } + Gtk::Widget * boxButton = checkwdg->get_child(); + if(!boxButton){ + return; + } + GList * childs = gtk_container_get_children(GTK_CONTAINER(boxButton->gobj())); + guint totalWidgets = g_list_length (childs); + if (!param_label.empty()) { + if(value || inactiveLabel.empty()){ + gtk_label_set_text(GTK_LABEL(g_list_nth_data(childs, totalWidgets-1)), param_label.c_str()); + }else{ + gtk_label_set_text(GTK_LABEL(g_list_nth_data(childs, totalWidgets-1)), inactiveLabel.c_str()); + } + } + if ( iconActive ) { + GdkPixbuf * iconPixbuf = sp_pixbuf_new( iconSize, iconActive ); + if(!value){ + iconPixbuf = sp_pixbuf_new( iconSize, iconInactive); + } + gtk_image_set_from_pixbuf (GTK_IMAGE(g_list_nth_data(childs, 0)), iconPixbuf); + } +} + void ToggleButtonParam::param_setValue(bool newvalue) { value = newvalue; + refresh_button(); } void diff --git a/src/live_effects/parameter/togglebutton.h b/src/live_effects/parameter/togglebutton.h index 753af6dbd..4e545bcfd 100644 --- a/src/live_effects/parameter/togglebutton.h +++ b/src/live_effects/parameter/togglebutton.h @@ -12,6 +12,8 @@ #include #include "live_effects/parameter/parameter.h" +#include "icon-size.h" +#include "ui/widget/registered-widget.h" namespace Inkscape { @@ -28,7 +30,11 @@ public: const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect, - bool default_value = false); + bool default_value = false, + const Glib::ustring& inactive_label = "", + char const * icon_active = NULL, + char const * icon_inactive = NULL, + Inkscape::IconSize icon_size = Inkscape::ICON_SIZE_SMALL_TOOLBAR); virtual ~ToggleButtonParam(); virtual Gtk::Widget * param_newWidget(); @@ -50,9 +56,15 @@ private: ToggleButtonParam(const ToggleButtonParam&); ToggleButtonParam& operator=(const ToggleButtonParam&); + void refresh_button(); bool value; bool defvalue; - + const Glib::ustring inactiveLabel; + const char * iconActive; + const char * iconInactive; + Inkscape::IconSize iconSize; + Inkscape::UI::Widget::RegisteredToggleButton * checkwdg; + sigc::signal _signal_toggled; sigc::connection _toggled_connection; }; diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp index 83da1a6d6..8a81b1c02 100644 --- a/src/ui/widget/registered-widget.cpp +++ b/src/ui/widget/registered-widget.cpp @@ -109,7 +109,7 @@ RegisteredToggleButton::~RegisteredToggleButton() } RegisteredToggleButton::RegisteredToggleButton (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Registry& wr, bool right, Inkscape::XML::Node* repr_in, SPDocument *doc_in, char const *active_str, char const *inactive_str) - : RegisteredWidget(label) + : RegisteredWidget() , _active_str(active_str) , _inactive_str(inactive_str) { -- cgit v1.2.3