diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:29:01 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:29:01 +0000 |
commit | 35a96bde514a8897f6f0fcc41c5833bf63df2e2a (patch) | |
tree | 657d15a03cc46bd099fc2c6546a7a4ad43815d9f /src/live_effects/parameter/enum.h | |
parent | Initial commit. (diff) | |
download | inkscape-35a96bde514a8897f6f0fcc41c5833bf63df2e2a.tar.xz inkscape-35a96bde514a8897f6f0fcc41c5833bf63df2e2a.zip |
Adding upstream version 1.0.2.upstream/1.0.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/live_effects/parameter/enum.h')
-rw-r--r-- | src/live_effects/parameter/enum.h | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/live_effects/parameter/enum.h b/src/live_effects/parameter/enum.h new file mode 100644 index 0000000..2519593 --- /dev/null +++ b/src/live_effects/parameter/enum.h @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_ENUM_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_ENUM_H + +/* + * Inkscape::LivePathEffectParameters + * + * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl> + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "ui/widget/registered-enums.h" +#include <glibmm/ustring.h> +#include "live_effects/effect.h" +#include "live_effects/parameter/parameter.h" +#include "verbs.h" + +namespace Inkscape { + +namespace LivePathEffect { + +template<typename E> class EnumParam : public Parameter { +public: + EnumParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + const Util::EnumDataConverter<E>& c, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + E default_value, + bool sort = true) + : Parameter(label, tip, key, wr, effect) + { + enumdataconv = &c; + defvalue = default_value; + value = defvalue; + sorted = sort; + }; + + ~EnumParam() override = default;; + EnumParam(const EnumParam&) = delete; + EnumParam& operator=(const EnumParam&) = delete; + + Gtk::Widget * param_newWidget() override { + Inkscape::UI::Widget::RegisteredEnum<E> *regenum = Gtk::manage ( + new Inkscape::UI::Widget::RegisteredEnum<E>( param_label, param_tooltip, + param_key, *enumdataconv, *param_wr, param_effect->getRepr(), param_effect->getSPDoc(), sorted ) ); + + regenum->set_active_by_id(value); + regenum->combobox()->setProgrammatically = false; + regenum->combobox()->signal_changed().connect(sigc::mem_fun (*this, &EnumParam::_on_change_combo)); + regenum->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change enumeration parameter")); + + return dynamic_cast<Gtk::Widget *> (regenum); + }; + void _on_change_combo() { param_effect->refresh_widgets = true; } + bool param_readSVGValue(const gchar * strvalue) override { + if (!strvalue) { + param_set_default(); + return true; + } + + param_set_value( enumdataconv->get_id_from_key(Glib::ustring(strvalue)) ); + + return true; + }; + Glib::ustring param_getSVGValue() const override { + return enumdataconv->get_key(value); + }; + + Glib::ustring param_getDefaultSVGValue() const override { + return enumdataconv->get_key(defvalue).c_str(); + }; + + E get_value() const { + return value; + } + + inline operator E() const { + return value; + }; + + void param_set_default() override { + param_set_value(defvalue); + } + + void param_update_default(E default_value) { + defvalue = default_value; + } + + void param_update_default(const gchar * default_value) override { + param_update_default(enumdataconv->get_id_from_key(Glib::ustring(default_value))); + } + + void param_set_value(E val) { + value = val; + } + +private: + E value; + E defvalue; + bool sorted; + + const Util::EnumDataConverter<E> * enumdataconv; +}; + + +}; //namespace LivePathEffect + +}; //namespace Inkscape + +#endif |