diff options
| author | Patrick Storz <eduard.braun2@gmx.de> | 2019-08-10 17:29:51 +0000 |
|---|---|---|
| committer | Patrick Storz <eduard.braun2@gmx.de> | 2019-08-31 14:50:39 +0000 |
| commit | adceddc7970f1e88081f78f890906d9ca60d1f76 (patch) | |
| tree | 70eaaf707e133d710ab0e053aba477c4cdd8f139 /src | |
| parent | Update POTFILES.in (diff) | |
| download | inkscape-adceddc7970f1e88081f78f890906d9ca60d1f76.tar.gz inkscape-adceddc7970f1e88081f78f890906d9ca60d1f76.zip | |
Add new widgets "hbox" and "vbox" for layouting purposes
Diffstat (limited to 'src')
| -rw-r--r-- | src/extension/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/extension/prefdialog/parameter-notebook.cpp | 15 | ||||
| -rw-r--r-- | src/extension/prefdialog/widget-box.cpp | 108 | ||||
| -rw-r--r-- | src/extension/prefdialog/widget-box.h | 60 | ||||
| -rw-r--r-- | src/extension/prefdialog/widget-label.h | 2 | ||||
| -rw-r--r-- | src/extension/prefdialog/widget.cpp | 9 |
6 files changed, 188 insertions, 8 deletions
diff --git a/src/extension/CMakeLists.txt b/src/extension/CMakeLists.txt index c8d3f5fc9..ebe058761 100644 --- a/src/extension/CMakeLists.txt +++ b/src/extension/CMakeLists.txt @@ -62,6 +62,7 @@ set(extension_SRC prefdialog/parameter-optiongroup.cpp prefdialog/parameter-string.cpp prefdialog/widget.cpp + prefdialog/widget-box.cpp prefdialog/widget-label.cpp # ------ @@ -137,6 +138,7 @@ set(extension_SRC prefdialog/parameter-optiongroup.h prefdialog/parameter-string.h prefdialog/widget.h + prefdialog/widget-box.h prefdialog/widget-label.h ) diff --git a/src/extension/prefdialog/parameter-notebook.cpp b/src/extension/prefdialog/parameter-notebook.cpp index 6c2d5b314..a139bd2bd 100644 --- a/src/extension/prefdialog/parameter-notebook.cpp +++ b/src/extension/prefdialog/parameter-notebook.cpp @@ -43,11 +43,16 @@ ParamNotebook::ParamNotebookPage::ParamNotebookPage(Inkscape::XML::Node *xml, In chname++; } - if (!strcmp(chname, "param") || !strcmp(chname, "_param")) { - InxParameter *param = InxParameter::make(child_repr, ext); - if (param) { - _children.push_back(param); + if (InxWidget::is_valid_widget_name(chname)) { + InxWidget *widget = InxWidget::make(child_repr, _extension); + if (widget) { + _children.push_back(widget); } + } else if (child_repr->type() == XML::ELEMENT_NODE) { + g_warning("Invalid child element ('%s') in notebook page in extension '%s'.", + chname, _extension->get_id()); + } else if (child_repr->type() != XML::COMMENT_NODE){ + g_warning("Invalid child element found in notebook page in extension '%s'.", _extension->get_id()); } child_repr = child_repr->next(); @@ -231,7 +236,7 @@ Gtk::Widget *ParamNotebook::get_widget(sigc::signal<void> *changeSignal) Gtk::Widget *page_widget = page->get_widget(changeSignal); Glib::ustring page_text = page->_text; - if (_translatable != NO) { // translate unless explicitly marked untranslatable + if (page->_translatable != NO) { // translate unless explicitly marked untranslatable page_text = page->get_translation(page_text.c_str()); } diff --git a/src/extension/prefdialog/widget-box.cpp b/src/extension/prefdialog/widget-box.cpp new file mode 100644 index 000000000..d7b93e3ff --- /dev/null +++ b/src/extension/prefdialog/widget-box.cpp @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** @file + * Box widget for extensions + *//* + * Authors: + * Patrick Storz <eduard.braun2@gmx.de> + * + * Copyright (C) 2019 Authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "widget-box.h" + +#include <gtkmm/box.h> + +#include "xml/node.h" +#include "extension/extension.h" + +namespace Inkscape { +namespace Extension { + + +WidgetBox::WidgetBox(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext) + : InxWidget(xml, ext) +{ + // Decide orientation based on tagname (hbox vs. vbox) + const char *tagname = xml->name(); + if (!strncmp(tagname, INKSCAPE_EXTENSION_NS_NC, strlen(INKSCAPE_EXTENSION_NS_NC))) { + tagname += strlen(INKSCAPE_EXTENSION_NS); + } + if (!strcmp(tagname, "hbox")) { + _orientation = HORIZONTAL; + } else if (!strcmp(tagname, "vbox")) { + _orientation = VERTICAL; + } else { + g_assert_not_reached(); + } + + // Read XML tree of box and parse child widgets + if (xml) { + Inkscape::XML::Node *child_repr = xml->firstChild(); + while (child_repr) { + const char *chname = child_repr->name(); + if (!strncmp(chname, INKSCAPE_EXTENSION_NS_NC, strlen(INKSCAPE_EXTENSION_NS_NC))) { + chname += strlen(INKSCAPE_EXTENSION_NS); + } + if (chname[0] == '_') { // allow leading underscore in tag names for backwards-compatibility + chname++; + } + + if (InxWidget::is_valid_widget_name(chname)) { + InxWidget *widget = InxWidget::make(child_repr, _extension); + if (widget) { + _children.push_back(widget); + } + } else if (child_repr->type() == XML::ELEMENT_NODE) { + g_warning("Invalid child element ('%s') in box widget in extension '%s'.", + chname, _extension->get_id()); + } else if (child_repr->type() != XML::COMMENT_NODE){ + g_warning("Invalid child element found in box widget in extension '%s'.", _extension->get_id()); + } + + child_repr = child_repr->next(); + } + } +} + +Gtk::Widget *WidgetBox::get_widget(sigc::signal<void> *changeSignal) +{ + if (_hidden) { + return nullptr; + } + + Gtk::Orientation orientation; + if (_orientation == HORIZONTAL) { + orientation = Gtk::ORIENTATION_HORIZONTAL; + } else { + orientation = Gtk::ORIENTATION_VERTICAL; + } + + Gtk::Box *box = Gtk::manage(new Gtk::Box(orientation)); + // box->set_border_width(GUI_BOX_MARGIN); // leave at zero for now, so box is purely for layouting (not grouping) + // revisit this later, possibly implementing GtkFrame or similar + box->set_spacing(GUI_BOX_SPACING); + + // add child widgets onto page (if any) + for (auto child : _children) { + Gtk::Widget *child_widget = child->get_widget(changeSignal); + if (child_widget) { + int indent = child->get_indent(); + child_widget->set_margin_start(indent * GUI_INDENTATION); + box->pack_start(*child_widget, false, false, 0); + + const char *tooltip = child->get_tooltip(); + if (tooltip) { + child_widget->set_tooltip_text(tooltip); + } + } + } + + box->show(); + + return dynamic_cast<Gtk::Widget *>(box); +} + +} /* namespace Extension */ +} /* namespace Inkscape */ diff --git a/src/extension/prefdialog/widget-box.h b/src/extension/prefdialog/widget-box.h new file mode 100644 index 000000000..6fd7b900c --- /dev/null +++ b/src/extension/prefdialog/widget-box.h @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** @file + * Box widget for extensions + *//* + * Authors: + * Patrick Storz <eduard.braun2@gmx.de> + * + * Copyright (C) 2019 Authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#ifndef SEEN_INK_EXTENSION_WIDGET_BOX_H +#define SEEN_INK_EXTENSION_WIDGET_BOX_H + +#include "widget.h" + +#include <glibmm/ustring.h> + +namespace Gtk { + class Widget; +} + +namespace Inkscape { +namespace Xml { + class Node; +} + +namespace Extension { + +/** \brief A box widget */ +class WidgetBox : public InxWidget { +public: + WidgetBox(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext); + + Gtk::Widget *get_widget(sigc::signal<void> *changeSignal) override; +private: + enum Orientation { + HORIZONTAL, VERTICAL + }; + + /** Layout orientation of the box (default is vertical) **/ + Orientation _orientation = VERTICAL; +}; + +} /* namespace Extension */ +} /* namespace Inkscape */ + +#endif /* SEEN_INK_EXTENSION_WIDGET_BOX_H */ + +/* + 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/prefdialog/widget-label.h b/src/extension/prefdialog/widget-label.h index c456867cd..1c1655006 100644 --- a/src/extension/prefdialog/widget-label.h +++ b/src/extension/prefdialog/widget-label.h @@ -30,7 +30,7 @@ namespace Xml { namespace Extension { -/** \brief A description parameter */ +/** \brief A label widget */ class WidgetLabel : public InxWidget { public: enum AppearanceMode { diff --git a/src/extension/prefdialog/widget.cpp b/src/extension/prefdialog/widget.cpp index 7d37dd122..097406763 100644 --- a/src/extension/prefdialog/widget.cpp +++ b/src/extension/prefdialog/widget.cpp @@ -12,6 +12,7 @@ #include "parameter.h" #include "widget.h" +#include "widget-box.h" #include "widget-label.h" #include <algorithm> @@ -38,10 +39,14 @@ InxWidget *InxWidget::make(Inkscape::XML::Node *in_repr, Inkscape::Extension::Ex name++; } + // decide on widget type based on tag name + // keep in sync with list of names supported in InxWidget::is_valid_widget_name() below if (!name) { // we can't create a widget without name g_warning("InxWidget without name in extension '%s'.", in_ext->get_id()); - } else if (!strcmp(name, "description")) { + } else if (!strcmp(name, "hbox") || !strcmp(name, "vbox")) { + widget = new WidgetBox(in_repr, in_ext); + } else if (!strcmp(name, "label")) { widget = new WidgetLabel(in_repr, in_ext); } else if (!strcmp(name, "param")) { widget = InxParameter::make(in_repr, in_ext); @@ -56,7 +61,7 @@ InxWidget *InxWidget::make(Inkscape::XML::Node *in_repr, Inkscape::Extension::Ex bool InxWidget::is_valid_widget_name(const char *name) { // keep in sync with names supported in InxWidget::make() above - static const std::vector<std::string> valid_names = {"description", "param"}; + static const std::vector<std::string> valid_names = {"hbox", "vbox", "label", "param"}; if (std::find(valid_names.begin(), valid_names.end(), name) != valid_names.end()) { return true; |
