diff options
| author | Jon A. Cruz <jon@joncruz.org> | 2008-05-24 13:43:22 +0000 |
|---|---|---|
| committer | joncruz <joncruz@users.sourceforge.net> | 2008-05-24 13:43:22 +0000 |
| commit | c818885b104797e9a194446ad04b7e6578ad3d80 (patch) | |
| tree | 7cc722983e7558fba8ba975722a4e626d17b239b | |
| parent | enable embedding of tiff images (diff) | |
| download | inkscape-c818885b104797e9a194446ad04b7e6578ad3d80.tar.gz inkscape-c818885b104797e9a194446ad04b7e6578ad3d80.zip | |
Added an 'appearance' hint to .inx optiongroups to allow for dropdowns instead of radio buttons.
(bzr r5748)
| -rw-r--r-- | share/extensions/polyhedron_3d.inx | 20 | ||||
| -rw-r--r-- | src/extension/param/parameter.cpp | 7 | ||||
| -rw-r--r-- | src/extension/param/radiobutton.cpp | 106 | ||||
| -rw-r--r-- | src/extension/param/radiobutton.h | 30 |
4 files changed, 122 insertions, 41 deletions
diff --git a/share/extensions/polyhedron_3d.inx b/share/extensions/polyhedron_3d.inx index 6a6d4010d..3ef24399e 100644 --- a/share/extensions/polyhedron_3d.inx +++ b/share/extensions/polyhedron_3d.inx @@ -6,7 +6,7 @@ <dependency type="executable" location="extensions">inkex.py</dependency>
<param name="tab" type="notebook">
<page name="common" _gui-text="Model File">
- <param name="obj" type="optiongroup" _gui-text="Object:">
+ <param name="obj" type="optiongroup" appearance="minimal" _gui-text="Object:">
<_option value="cube">Cube</_option>
<_option value="t_cube">Truncated Cube</_option>
<_option value="sn_cube">Snub Cube</_option>
@@ -26,38 +26,38 @@ <_option value="from_file">Load From File</_option>
</param>
<param name="spec_file" type="string" _gui-text="Filename:">great_rhombicuboct.obj</param>
- <param name="type" type="optiongroup" _gui-text="Object Type">
+ <param name="type" type="optiongroup" appearance="minimal" _gui-text="Object Type">
<_option value="face">Face-Specified</_option>
<_option value="edge">Edge-Specified</_option></param>
<param name="cw_wound" type="boolean" _gui-text="Clockwise Wound Object">0</param>
</page>
<page name="view" _gui-text="View">
- <param name="r1_ax" type="optiongroup" _gui-text="Rotate Around:">
+ <param name="r1_ax" type="optiongroup" appearance="minimal" _gui-text="Rotate Around:">
<_option value="x">X-Axis</_option>
<_option value="y">Y-Axis</_option>
<_option value="z">Z-Axis</_option></param>
<param name="r1_ang" type="float" min="-360" max="360" _gui-text="Rotation / Degrees">0</param>
- <param name="r2_ax" type="optiongroup" _gui-text="Then Rotate Around:">
+ <param name="r2_ax" type="optiongroup" appearance="minimal" _gui-text="Then Rotate Around:">
<_option value="x">X-Axis</_option>
<_option value="y">Y-Axis</_option>
<_option value="z">Z-Axis</_option></param>
<param name="r2_ang" type="float" min="-360" max="360" _gui-text="Rotation / Degrees">0</param>
- <param name="r3_ax" type="optiongroup" _gui-text="Then Rotate Around:">
+ <param name="r3_ax" type="optiongroup" appearance="minimal" _gui-text="Then Rotate Around:">
<_option value="x">X-Axis</_option>
<_option value="y">Y-Axis</_option>
<_option value="z">Z-Axis</_option></param>
<param name="r3_ang" type="float" min="-360" max="360" _gui-text="Rotation / Degrees">0</param>
- <param name="r4_ax" type="optiongroup" _gui-text="Rotate Around:">
+ <param name="r4_ax" type="optiongroup" appearance="minimal" _gui-text="Rotate Around:">
<_option value="x">X-Axis</_option>
<_option value="y">Y-Axis</_option>
<_option value="z">Z-Axis</_option></param>
<param name="r4_ang" type="float" min="-360" max="360" _gui-text="Rotation / Degrees">0</param>
- <param name="r5_ax" type="optiongroup" _gui-text="Then Rotate Around:">
+ <param name="r5_ax" type="optiongroup" appearance="minimal" _gui-text="Then Rotate Around:">
<_option value="x">X-Axis</_option>
<_option value="y">Y-Axis</_option>
<_option value="z">Z-Axis</_option></param>
<param name="r5_ang" type="float" min="-360" max="360" _gui-text="Rotation / Degrees">0</param>
- <param name="r6_ax" type="optiongroup" _gui-text="Then Rotate Around:">
+ <param name="r6_ax" type="optiongroup" appearance="minimal" _gui-text="Then Rotate Around:">
<_option value="x">X-Axis</_option>
<_option value="y">Y-Axis</_option>
<_option value="z">Z-Axis</_option></param>
@@ -75,12 +75,12 @@ <param name="lv_x" type="float" min="-100" max="100" _gui-text="Light x-Position">1</param>
<param name="lv_y" type="float" min="-100" max="100" _gui-text="Light y-Position">1</param>
<param name="lv_z" type="float" min="-100" max="100" _gui-text="Light z-Position">-2</param>
- <param name="show" type="optiongroup" _gui-text="Show:">
+ <param name="show" type="optiongroup" appearance="minimal" _gui-text="Show:">
<_option value="vtx">Vertices</_option>
<_option value="edg">Edges</_option>
<_option value="fce">Faces</_option></param>
<param name="back" type="boolean" _gui-text="Draw Back-Facing Polygons">0</param>
- <param name="z_sort" type="optiongroup" _gui-text="Z-Sort Faces By:">
+ <param name="z_sort" type="optiongroup" appearance="minimal" _gui-text="Z-Sort Faces By:">
<_option value="max">Maximum</_option>
<_option value="min">Minimum</_option>
<_option value="mean">Mean</_option></param>
diff --git a/src/extension/param/parameter.cpp b/src/extension/param/parameter.cpp index b356c297e..6d1a1570c 100644 --- a/src/extension/param/parameter.cpp +++ b/src/extension/param/parameter.cpp @@ -103,6 +103,7 @@ Parameter::make (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * } /* else stays false */ } + const gchar* appearance = in_repr->attribute("appearance"); /* In this case we just don't have enough information */ if (name == NULL || type == NULL) { @@ -140,7 +141,11 @@ Parameter::make (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension * } else if (!strcmp(type, "notebook")) { param = new ParamNotebook(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr); } else if (!strcmp(type, "optiongroup")) { - param = new ParamRadioButton(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr); + if (appearance && !strcmp(appearance, "minimal")) { + param = new ParamRadioButton(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr, ParamRadioButton::MINIMAL); + } else { + param = new ParamRadioButton(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr, ParamRadioButton::FULL); + } } else if (!strcmp(type, "color")) { param = new ParamColor(name, guitext, desc, scope, gui_hidden, gui_tip, in_ext, in_repr); } diff --git a/src/extension/param/radiobutton.cpp b/src/extension/param/radiobutton.cpp index ba9648618..76c3506af 100644 --- a/src/extension/param/radiobutton.cpp +++ b/src/extension/param/radiobutton.cpp @@ -9,6 +9,7 @@ * Johan Engelen <johan@shouraizou.nl> * * Copyright (C) 2006-2007 Johan Engelen + * Copyright (C) 2008 Jon A. Cruz * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -19,6 +20,7 @@ #include <gtkmm/box.h> +#include <gtkmm/comboboxtext.h> #include <gtkmm/radiobutton.h> #include <gtkmm/radiobuttongroup.h> #include <gtkmm/tooltips.h> @@ -59,12 +61,20 @@ public: Glib::ustring * guitext; }; -ParamRadioButton::ParamRadioButton (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext) +ParamRadioButton::ParamRadioButton (const gchar * name, + const gchar * guitext, + const gchar * desc, + const Parameter::_scope_t scope, + bool gui_hidden, + const gchar * gui_tip, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml, + AppearanceMode mode) : + Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), + _value(0), + _mode(mode), + choices(0) { - choices = NULL; - _value = NULL; - // Read XML tree to add enumeration items: // printf("Extension Constructor: "); if (xml != NULL) { @@ -79,14 +89,14 @@ ParamRadioButton::ParamRadioButton (const gchar * name, const gchar * guitext, c // don't translate when 'option' but do translate when '_option' newguitext = new Glib::ustring( !strcmp(chname, "_option") ? _(contents) : contents ); else - continue; - + continue; + const char * val = child_repr->attribute("value"); if (val != NULL) newvalue = new Glib::ustring(val); else newvalue = new Glib::ustring(contents); - + if ( (newguitext) && (newvalue) ) { // logical error if this is not true here choices = g_slist_append( choices, new optionentry(newvalue, newguitext) ); } @@ -219,6 +229,28 @@ ParamRadioButtonWdg::changed (void) } +class ComboWdg : public Gtk::ComboBoxText { +public: + ComboWdg(ParamRadioButton* base, SPDocument * doc, Inkscape::XML::Node * node) : + Gtk::ComboBoxText(), + base(base), + doc(doc), + node(node) + { + } + virtual ~ComboWdg() {} + +protected: + ParamRadioButton* base; + SPDocument* doc; + Inkscape::XML::Node* node; + + virtual void on_changed() { + if ( base ) { + base->set(get_active_text().c_str(), doc, node); + } + } +}; /** \brief Creates a combobox widget for an enumeration parameter @@ -226,7 +258,7 @@ ParamRadioButtonWdg::changed (void) Gtk::Widget * ParamRadioButton::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal) { - if (_gui_hidden) return NULL; + if (_gui_hidden) return NULL; Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); Gtk::VBox * vbox = Gtk::manage(new Gtk::VBox(false, 0)); @@ -235,28 +267,48 @@ ParamRadioButton::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc label->show(); hbox->pack_start(*label, false, false); + Gtk::ComboBoxText* cbt = 0; + bool comboSet = false; + if (_mode == MINIMAL) { + cbt = Gtk::manage(new ComboWdg(this, doc, node)); + cbt->show(); + vbox->pack_start(*cbt, false, false); + } + // add choice strings as radiobuttons // and select last selected option (_value) - bool first = true; - ParamRadioButtonWdg * radio; Gtk::RadioButtonGroup group; for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { optionentry * entr = reinterpret_cast<optionentry *>(list->data); Glib::ustring * text = entr->guitext; - if (first) { - radio = Gtk::manage(new ParamRadioButtonWdg(*text, this, doc, node, changeSignal)); - group = radio->get_group(); - first = false; - } else { - radio = Gtk::manage(new ParamRadioButtonWdg(group, *text, this, doc, node, changeSignal)); - } - radio->show(); - vbox->pack_start(*radio, true, true); - if (!entr->value->compare(_value)) { - radio->set_active(); + switch ( _mode ) { + case MINIMAL: + { + cbt->append_text(*text); + if (!entr->value->compare(_value)) { + cbt->set_active_text(*text); + comboSet = true; + } + } + break; + case COMPACT: + case FULL: + { + ParamRadioButtonWdg * radio = Gtk::manage(new ParamRadioButtonWdg(group, *text, this, doc, node, changeSignal)); + radio->show(); + vbox->pack_start(*radio, true, true); + if (!entr->value->compare(_value)) { + radio->set_active(); + } + } + break; } } + if ( (_mode == MINIMAL) && !comboSet) { + cbt->set_active(0); + } + vbox->show(); hbox->pack_end(*vbox, false, false); hbox->show(); @@ -269,3 +321,13 @@ ParamRadioButton::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc } /* namespace Extension */ } /* namespace Inkscape */ +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/extension/param/radiobutton.h b/src/extension/param/radiobutton.h index 4bf596e4f..ea8440de2 100644 --- a/src/extension/param/radiobutton.h +++ b/src/extension/param/radiobutton.h @@ -28,22 +28,36 @@ namespace Extension { // \brief A class to represent a radiobutton parameter of an extension class ParamRadioButton : public Parameter { +public: + enum AppearanceMode { + FULL, COMPACT, MINIMAL + }; + + ParamRadioButton(const gchar * name, + const gchar * guitext, + const gchar * desc, + const Parameter::_scope_t scope, + bool gui_hidden, + const gchar * gui_tip, + Inkscape::Extension::Extension * ext, + Inkscape::XML::Node * xml, + AppearanceMode mode); + virtual ~ParamRadioButton(void); + Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); + void string (std::string &string); + + const gchar * get (const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) { return _value; } + const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node); + private: /** \brief Internal value. This should point to a string that has been allocated in memory. And should be free'd. It is the value of the current selected string */ gchar * _value; + AppearanceMode _mode; GSList * choices; /**< A table to store the choice strings */ -public: - ParamRadioButton(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml); - virtual ~ParamRadioButton(void); - Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal<void> * changeSignal); - void string (std::string &string); - - const gchar * get (const SPDocument * /*doc*/, const Inkscape::XML::Node * /*node*/) { return _value; } - const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node); }; /* class ParamRadioButton */ |
